Skip to content

Commit

Permalink
Added selection to midi and udp io
Browse files Browse the repository at this point in the history
  • Loading branch information
neauoire committed May 9, 2020
1 parent a61b035 commit d184725
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 50 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ All commands have a shorthand equivalent to their first two characters, for exam
- `inject:pattern;12;34` Inject the local file `pattern.orca`, at `12,34`(optional).
- `write:H;12;34` Writes glyph `H`, at `12,34`(optional).
- `time` Prints the time, in minutes seconds, since `0f`.
- `midi:1;2` Set Midi output device to `#1`, and input device to `#2`.
- `udp:1234;5678` Set UDP output port to `1234`, and input port to `5678`.
- `osc:1234` Set OSC output port to `1234`.

## Base36 Table

Expand Down
2 changes: 1 addition & 1 deletion desktop/sources/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/* global Theme */

function Client () {
this.version = 175
this.version = 176
this.library = library

this.theme = new Theme(this)
Expand Down
9 changes: 8 additions & 1 deletion desktop/sources/scripts/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ function Commander (client) {
this.actives = {
// Ports
osc: (p) => { client.io.osc.select(p.int) },
udp: (p) => { client.io.udp.select(p.int) },
udp: (p) => {
client.io.udp.selectOutput(p.x)
if (p.y !== null) { client.io.udp.selectInput(p.y) }
},
midi: (p) => {
client.io.midi.selectOutput(p.x)
if (p.y !== null) { client.io.midi.selectInput(p.y) }
},
ip: (p) => { client.io.setIp(p.str) },
cc: (p) => { client.io.cc.setOffset(p.int) },
pg: (p) => { client.io.cc.stack.push({ channel: clamp(p.ints[0], 0, 15), bank: p.ints[1], sub: p.ints[2], pgm: clamp(p.ints[3], 0, 127), type: 'pg' }); client.io.cc.run() },
Expand Down
4 changes: 2 additions & 2 deletions desktop/sources/scripts/core/io/midi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -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) }
Expand Down
52 changes: 31 additions & 21 deletions desktop/sources/scripts/core/io/udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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)
}
}
24 changes: 0 additions & 24 deletions examples/setups/shift+registers.orca

This file was deleted.

2 changes: 1 addition & 1 deletion sw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 175
// 176

const assets = [
'./',
Expand Down

0 comments on commit d184725

Please sign in to comment.