observ-midi
v2.5.0
Published
Observe and write to midi stream as a single value, struct, array or grid.
Downloads
45
Maintainers
Readme
observ-midi
Observe and write to a midi stream as a single value, struct, array or grid.
Install via npm
$ npm install observ-midi
Examples
var ObservMidi = require('observ-midi')
var MidiStream = require('midi-stream')
var duplexPort = MidiStream('Launchpad Mini')
A single value (Observ):
var button = ObservMidi(duplexPort, '144/0') // Observ
button(function(value){
// visual feedback
button.output.set(value)
})
A range of values (ObservArray):
var range = ObservMidi(dupexPort, ['144/0', '144/1', '144/2']) // ObservArray
range(function(value){
if (value._diff){
// visual feedback
range.output.splice.apply(range.output, value._diff)
}
})
ArrayGrid (Observ(ArrayGrid))
var ArrayGrid = require('array-grid')
var grid = ObservMidi(duplexPort, ArrayGrid(['144/0', '144/1'], [2,1])) // Observ(ArrayGrid)
grid(function(value){
// value is an instance of ArrayGrid
})
Struct (ObservStruct)
var map = ObservMidi(duplexPort, { play: '176/110', stop: '176/111' }) // ObservStruct
map(function(values){
var diff = values._diff
Object.keys(diff).forEach(function(key){
// visual feedback
map[key].output.set(diff[key])
})
})
map.play(function(value){
// visual feedback
map.store.output.set(value)
})
Variable Hash (ObservVarhash)
var lookup = ObservMidi(duplexPort) // ObservVarhash
lookup(function(value){
var diff = values._diff
Object.keys(diff).forEach(function(key){
// visual feedback
lookup.output.put(key, diff[key])
})
})
Resend all output on switch
duplexPort.emit('switch') // clear input values, resend all current output values