diff options
author | neauoire <[email protected]> | 2020-05-10 07:22:11 +0900 |
---|---|---|
committer | neauoire <[email protected]> | 2020-05-10 07:22:11 +0900 |
commit | d184725c87a41cb22805ce449bdf2bab71834f68 (patch) | |
tree | 5a97cdf8c542691720b2ba84d260ee9a07dadf72 /desktop/sources/scripts/core | |
parent | a61b035b31b327848b759d158515395fb6eb0a85 (diff) | |
download | Orca-d184725c87a41cb22805ce449bdf2bab71834f68.tar.gz Orca-d184725c87a41cb22805ce449bdf2bab71834f68.zip |
Added selection to midi and udp io
Diffstat (limited to 'desktop/sources/scripts/core')
-rw-r--r-- | desktop/sources/scripts/core/io/midi.js | 4 | ||||
-rw-r--r-- | desktop/sources/scripts/core/io/udp.js | 52 |
2 files changed, 33 insertions, 23 deletions
diff --git a/desktop/sources/scripts/core/io/midi.js b/desktop/sources/scripts/core/io/midi.js index a298237..5fda0ae 100644 --- a/desktop/sources/scripts/core/io/midi.js +++ b/desktop/sources/scripts/core/io/midi.js @@ -146,7 +146,7 @@ function Midi (client) { this.selectOutput = function (id) { if (id === -1) { this.outputIndex = -1; console.log('MIDI', 'Select Output Device: None'); return } - if (!this.outputs[id]) { return } + if (!this.outputs[id]) { console.warn('MIDI',`Unknown device with id ${id}`); return } this.outputIndex = parseInt(id) console.log('MIDI', `Select Output Device: ${this.outputDevice().name}`) @@ -155,7 +155,7 @@ function Midi (client) { this.selectInput = function (id) { if (this.inputDevice()) { this.inputDevice().onmidimessage = null } if (id === -1) { this.inputIndex = -1; console.log('MIDI', 'Select Input Device: None'); return } - if (!this.inputs[id]) { return } + if (!this.inputs[id]) { console.warn('MIDI',`Unknown device with id ${id}`); return } this.inputIndex = parseInt(id) this.inputDevice().onmidimessage = (msg) => { this.receive(msg) } diff --git a/desktop/sources/scripts/core/io/udp.js b/desktop/sources/scripts/core/io/udp.js index 3c05055..0fe131a 100644 --- a/desktop/sources/scripts/core/io/udp.js +++ b/desktop/sources/scripts/core/io/udp.js @@ -5,31 +5,15 @@ function Udp (client) { this.stack = [] this.port = null - this.options = { default: 49161, orca: 49160 } this.socket = dgram ? dgram.createSocket('udp4') : null this.listener = dgram ? dgram.createSocket('udp4') : null this.start = function () { - if (!this.socket || !this.listener) { console.warn('UDP', 'Could not start.'); return } + if (!dgram || !this.socket || !this.listener) { console.warn('UDP', 'Could not start.'); return } console.info('UDP', 'Starting..') - this.listener.on('message', (msg, rinfo) => { - client.commander.trigger(`${msg}`) - }) - - this.listener.on('listening', () => { - const address = this.listener.address() - console.info('UDP', `Started socket at ${address.address}:${address.port}`) - }) - - this.listener.on('error', (err) => { - console.warn('UDP', `Server error:\n ${err.stack}`) - this.listener.close() - }) - - this.listener.bind(49160) - - this.select() + this.selectInput() + this.selectOutput() } this.clear = function () { @@ -53,10 +37,36 @@ function Udp (client) { }) } - this.select = function (port = this.options.default) { + this.selectOutput = function (port = 49161) { + if (!dgram) { console.warn('UDP', 'Unavailable.'); return } if (parseInt(port) === this.port) { console.warn('UDP', 'Already selected'); return } if (isNaN(port) || port < 1000) { console.warn('UDP', 'Unavailable port'); return } - console.info('UDP', `Selected port: ${port}`) + + console.log('UDP', `Output: ${port}`) this.port = parseInt(port) } + + this.selectInput = (port = 49160) => { + if (!dgram) { console.warn('UDP', 'Unavailable.'); return } + if (this.listener) { this.listener.close() } + + console.log('UDP', `Input: ${port}`) + this.listener = dgram.createSocket('udp4') + + this.listener.on('message', (msg, rinfo) => { + client.commander.trigger(`${msg}`) + }) + + this.listener.on('listening', () => { + const address = this.listener.address() + console.info('UDP', `Started socket at ${address.address}:${address.port}`) + }) + + this.listener.on('error', (err) => { + console.warn('UDP', `Server error:\n ${err.stack}`) + this.listener.close() + }) + + this.listener.bind(port) + } } |