diff options
author | Devine Lu Linvega <[email protected]> | 2019-06-06 16:10:08 +0200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2019-06-06 16:10:15 +0200 |
commit | eea65def5cc6ce465da7ee65dd73f88de2817c80 (patch) | |
tree | 2f0bcf6e9358bff5db83565c3f25f307dfe6cc3c | |
parent | 2001cc651a069eb50c87aada4ed37242ffa8aa9e (diff) | |
download | Orca-eea65def5cc6ce465da7ee65dd73f88de2817c80.tar.gz Orca-eea65def5cc6ce465da7ee65dd73f88de2817c80.zip |
Added a command to change IP
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | desktop/core/io.js | 10 | ||||
-rw-r--r-- | desktop/core/io/osc.js | 11 | ||||
-rw-r--r-- | desktop/core/io/udp.js | 7 | ||||
-rw-r--r-- | desktop/sources/scripts/commander.js | 1 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 2 |
6 files changed, 25 insertions, 10 deletions
@@ -82,13 +82,13 @@ It sends a value **between 0-127**, where the value is calculated as a ratio of ## UDP -The [UDP](https://nodejs.org/api/dgram.html#dgram_socket_send_msg_offset_length_port_address_callback) operator `;` locks each consecutive eastwardly ports. For example, `;hello`, will send the string "hello", on bang, to the port `49160` on `localhost`. In commander, use `udp:7777` to select the **custom UDP port 7777**. +The [UDP](https://nodejs.org/api/dgram.html#dgram_socket_send_msg_offset_length_port_address_callback) operator `;` locks each consecutive eastwardly ports. For example, `;hello`, will send the string "hello", on bang, to the port `49160` on `localhost`. In commander, use `udp:7777` to select the **custom UDP port 7777**, and `ip:127.0.0.12` to change the target IP. You can use the [listener.js](https://github.com/hundredrabbits/Orca/blob/master/listener.js) to test UDP messages. See it in action with [udp.orca](https://github.com/hundredrabbits/Orca/blob/master/examples/_udp.orca). ## OSC -The [OSC](https://github.com/MylesBorins/node-osc) operator `=` locks each consecutive eastwardly ports. The first character is used for the path, the following characters are sent as integers using the [base36 Table](https://github.com/hundredrabbits/Orca#base36-table). In commander, use `osc:7777` to select the **custom OSC port 7777**. +The [OSC](https://github.com/MylesBorins/node-osc) operator `=` locks each consecutive eastwardly ports. The first character is used for the path, the following characters are sent as integers using the [base36 Table](https://github.com/hundredrabbits/Orca#base36-table). In commander, use `osc:7777` to select the **custom OSC port 7777**, and `ip:127.0.0.12` to change the target IP. For example, `=1abc` will send `10`, `11` and `12` to `/1`, via the port `49162` on `localhost`; `=a123` will send `1`, `2` and `3`, to the path `/a`. You can use the [listener.js](https://github.com/hundredrabbits/Orca/blob/master/listener.js) to test OSC messages. See it in action with [osc.orca](https://github.com/hundredrabbits/Orca/blob/master/examples/_osc.orca) or try it with [SonicPi](https://github.com/hundredrabbits/Orca/blob/master/TUTORIAL.md#sonicpi). diff --git a/desktop/core/io.js b/desktop/core/io.js index 32169b3..8544065 100644 --- a/desktop/core/io.js +++ b/desktop/core/io.js @@ -7,6 +7,8 @@ import Udp from './io/udp.js' import Osc from './io/osc.js' export default function IO (terminal) { + this.ip = '127.0.0.1' + this.midi = new Midi(terminal) this.cc = new MidiCC(terminal) this.mono = new Mono(terminal) @@ -43,6 +45,13 @@ export default function IO (terminal) { this.mono.silence() } + this.setIp = function (addr = '127.0.0.1') { + if (validateIP(addr) !== true) { console.warn('IO', 'Invalid IP'); return } + this.ip = addr + console.log('IO', 'Set target IP to ' + this.ip) + this.osc.setup() + } + this.length = function () { return this.midi.length() + this.mono.length() + this.cc.stack.length + this.udp.stack.length + this.osc.stack.length } @@ -55,5 +64,6 @@ export default function IO (terminal) { return fill(text, limit, '.') } + function validateIP (addr) { return !!(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(addr)) } function fill (str, len, chr) { while (str.length < len) { str += chr }; return str } } diff --git a/desktop/core/io/osc.js b/desktop/core/io/osc.js index 5afe920..a7561cc 100644 --- a/desktop/core/io/osc.js +++ b/desktop/core/io/osc.js @@ -8,7 +8,7 @@ export default function Osc (terminal) { this.options = { default: 49162, tidalCycles: 6010, sonicPi: 4559, superCollider: 57120 } this.start = function () { - console.info('OSC Starting..') + console.info('OSC', 'Starting..') this.setup() this.select() } @@ -40,7 +40,8 @@ export default function Osc (terminal) { } this.select = function (port = this.options.default) { - if (isNaN(port) || port < 1000) { console.warn('Unavailable port'); return } + if (parseInt(port) === this.port) { console.warn('OSC', 'Already selected'); return } + if (isNaN(port) || port < 1000) { console.warn('OSC', 'Unavailable port'); return } console.info('OSC', `Selected port: ${port}`) this.port = parseInt(port) this.setup() @@ -55,8 +56,10 @@ export default function Osc (terminal) { terminal.controller.commit() } - this.setup = function (ip = '127.0.0.1') { + this.setup = function () { + if (!this.port) { return } if (this.client) { this.client.close() } - this.client = new osc.Client(ip, this.port) + this.client = new osc.Client(terminal.io.ip, this.port) + console.info('OSC', 'Started client at ' + terminal.io.ip + ':' + this.port) } } diff --git a/desktop/core/io/udp.js b/desktop/core/io/udp.js index c464c3b..811a088 100644 --- a/desktop/core/io/udp.js +++ b/desktop/core/io/udp.js @@ -27,14 +27,15 @@ export default function Udp (terminal) { } this.play = function (data) { - this.server.send(Buffer.from(`${data}`), this.port, '127.0.0.1', (err) => { + this.server.send(Buffer.from(`${data}`), this.port, terminal.io.ip, (err) => { if (err) { console.warn(err) } }) } this.select = function (port = this.options.default) { - if (isNaN(port) || port < 1000) { console.warn('Unavailable port'); return } - console.info('OSC', `Selected port: ${port}`) + 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}`) this.port = parseInt(port) this.update() } diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 405305f..a649464 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -20,6 +20,7 @@ export default function Commander (terminal) { // Ports 'osc': (val) => { terminal.io.osc.select(parseInt(val)) }, 'udp': (val) => { terminal.io.udp.select(parseInt(val)) }, + 'ip': (val) => { terminal.io.setIp(val) }, // Cursor 'copy': (val) => { terminal.cursor.copy() }, 'paste': (val) => { terminal.cursor.paste(true) }, diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index 7ede449..f8a81a1 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -12,7 +12,7 @@ import Controller from './lib/controller.js' import library from '../../core/library.js' export default function Terminal () { - this.version = 136 + this.version = 137 this.library = library this.orca = new Orca(this) |