Skip to content
Permalink
Browse files

midi-out-chunk: add program change

  • Loading branch information...
mmckegg committed Nov 28, 2017
1 parent 99a1278 commit 300b643a96f9d34141b89ddce3e051d9a35c6b02
Showing with 54 additions and 14 deletions.
  1. +14 −6 lib/apply-midi-param.js
  2. +12 −0 lib/format-params.js
  3. +6 −1 nodes/midi-cc/object.js
  4. +22 −7 nodes/midi-out-chunk/view.js
@@ -16,9 +16,7 @@ function applyMidiParam (context, midiOpts, param) {
var value = param.getValueAtTime(at)
if (value !== lastValue) {
var message = getMessage(resolve(prefix), value)
var output = midiPort.stream()
if (message && output) {
output.write(message, getMidiTime(resolve(context.midiClockOffset), at))
if (write(message, at)) {
lastValue = value
}
}
@@ -27,13 +25,23 @@ function applyMidiParam (context, midiOpts, param) {

release.resend = function () {
var message = getMessage(resolve(prefix), lastValue)
write(message)
}

return release

function write (message, at) {
var time = at ? getMidiTime(resolve(context.midiClockOffset), at) : window.performance.now()
var output = midiPort.stream()
if (message && output) {
output.write(message, window.performance.now())
output.write(message, time)
if (message[0] >= 192 && message[0] <= 207) {
// flush program change messgage (running status nonsense)
output.write([254], time)
}
return true
}
}

return release
}

function getMessage (message, value) {
@@ -30,6 +30,18 @@ module.exports = {
}
},

'midi+1': {
size: function(value){
return getRatio(value, 0, 127)
},
value: function(offset, start){
return clamp(Math.round(getValueFromScreen(offset, start, 0, 127)), 0, 127)
},
display: function(value){
return String(value + 1)
}
},

'dB': {
size: function(value){
return getRatio(value, decibelsToGain(-20), decibelsToGain(20), 'db')
@@ -20,7 +20,12 @@ function MidiCCNode (context) {
Param.triggerOn(obs, context.audio.currentTime)

var message = computed([channel, obs.code], (channel, code) => {
return [176 + clamp(channel, 1, 16) - 1, code]
var channelOffset = clamp(channel, 1, 16) - 1
if (code === 'PC') {
return [192 + channelOffset]
} else {
return [176 + channelOffset, code]
}
})

var releaseMidiParam = applyMidiParam(context, { port, message }, obs.value)
@@ -9,23 +9,35 @@ var Select = require('lib/params/select')
var send = require('mutant/send')
var map = require('mutant/map')
var resolve = require('mutant/resolve')
var when = require('mutant/when')
var computed = require('mutant/computed')

var channelOptions = getRange(1, 16).map(number => [`Channel ${number}`, number])
var ccOptions = getRange(0, 119).map(number => [`CC ${number}`, number])
ccOptions.unshift(['PC', 'PC'])

module.exports = function renderMidiOutChunk (node) {
var ccSlots = map(node.continuousControllers, slot => {
var isProgramChange = computed(slot.code, x => x === 'PC')
return h('div.slot -trigger', [
Select(slot.code, {
options: ccOptions,
flex: true
}),
ModRange(slot.value, {
flex: true,
format: 'midi',
defaultValue: 0,
allowSpawnModulator: true
}),
when(isProgramChange,
ModRange(slot.value, {
flex: true,
format: 'midi+1',
defaultValue: 0,
allowSpawnModulator: true
}),
ModRange(slot.value, {
flex: true,
format: 'midi',
defaultValue: 0,
allowSpawnModulator: true
})
),
h('button.remove Button -warn', {
'ev-click': send(node.continuousControllers.remove, slot)
}, 'X')
@@ -164,7 +176,10 @@ function lastCode (collection) {
if (collection && collection.get && collection.getLength && collection.getLength()) {
var last = collection.get(collection.getLength() - 1)
if (last && last.code) {
return resolve(last.code)
var code = resolve(last.code)
if (typeof code === 'number') {
return code
}
}
}
return 0

0 comments on commit 300b643

Please sign in to comment.
You can’t perform that action at this time.