midi: optional nrpn/rpn packing/unpacking
This commit is contained in:
parent
0ac4bd60df
commit
885886d0c9
4 changed files with 38 additions and 3 deletions
|
|
@ -42,6 +42,8 @@ program_change_offset = 'pc_offset' in argv
|
|||
ignore_sysex = 'sysex' not in argv
|
||||
# option: parse mtc
|
||||
ignore_mtc = 'mtc' not in argv
|
||||
# option: parse (n)rpn
|
||||
ignore_rpn = 'rpn' not in argv and 'nrpn' not in argv
|
||||
# option: parse active sensing
|
||||
ignore_active_sensing = 'active_sensing' not in argv
|
||||
# option: note off velocity
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from head import *
|
|||
from list import *
|
||||
from utils import *
|
||||
from mtc import *
|
||||
from rpn import *
|
||||
|
||||
ipc_send('version', '1.17.1')
|
||||
|
||||
|
|
@ -130,6 +131,22 @@ def create_callback(name):
|
|||
v = ' '.join([hex(x).replace('0x', '').zfill(2) for x in message])
|
||||
osc['args'].append({'type': 'string', 'value': v})
|
||||
|
||||
|
||||
elif mtype == CONTROL_CHANGE and not ignore_rpn and is_rpn(message):
|
||||
rpn = rpn_decode(message, name)
|
||||
if rpn is not None:
|
||||
osc['address'] = MIDI_TO_OSC[rpn[0]]
|
||||
osc['args'].append({'type': 'i', 'value': rpn[1]})
|
||||
osc['args'].append({'type': 'i', 'value': rpn[2]})
|
||||
osc['args'].append({'type': 'i', 'value': rpn[3]})
|
||||
ipc_send('osc', osc)
|
||||
if debug:
|
||||
t = 'NRPN' if rpn[0] == NRPN else 'RPN'
|
||||
s = '%s: channel=%i, parameter=%i, value=%i'% (t, rpn[1], rpn[2], rpn[3])
|
||||
ipc_send('debug','in: %s From: midi:%s' % (s, name))
|
||||
# bypass (n)rpn CCs
|
||||
return
|
||||
|
||||
else:
|
||||
|
||||
status = message[0]
|
||||
|
|
@ -232,6 +249,16 @@ def send_midi(name, event, *args):
|
|||
except:
|
||||
pass
|
||||
|
||||
elif mtype == NRPN or mtype == RPN:
|
||||
m = rpn_encode(mtype, args)
|
||||
if m is not None:
|
||||
for x in m:
|
||||
outputs[name].send_message(x)
|
||||
if debug:
|
||||
t = 'NRPN' if mtype == NRPN else 'RPN'
|
||||
s = '%s: channel=%i, parameter=%i, value=%i'% (t, args[0], args[1], args[2])
|
||||
ipc_send('debug','out: %s To: midi:%s' % (s, name))
|
||||
return
|
||||
else:
|
||||
|
||||
args = [int(round(x)) for x in args]
|
||||
|
|
@ -242,7 +269,7 @@ def send_midi(name, event, *args):
|
|||
mtype = NOTE_OFF
|
||||
|
||||
elif mtype == PITCH_BEND:
|
||||
args = args[:1] + [args[1] & 0x7F, (args[1] >> 7) & 0x7F] # convert 0-16384 -> 0-127 pair
|
||||
args = args[:1] + [args[1] & 0x7F, (args[1] >> 7) & 0x7F] # convert 0-16383 -> 0-127 pair
|
||||
|
||||
elif mtype == PROGRAM_CHANGE and program_change_offset:
|
||||
args[-1] = args[-1] - 1
|
||||
|
|
@ -256,7 +283,6 @@ def send_midi(name, event, *args):
|
|||
else:
|
||||
|
||||
outputs[name].send_message(m)
|
||||
|
||||
if debug:
|
||||
ipc_send('debug','out: %s To: midi:%s' % (midi_str(m, name), name))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from head import *
|
||||
from mtc import *
|
||||
from rpn import *
|
||||
|
||||
MIDI_TO_OSC = {
|
||||
NOTE_ON: '/note',
|
||||
|
|
@ -28,6 +29,12 @@ OSC_TO_MIDI = {
|
|||
if note_off_velocity:
|
||||
MIDI_TO_OSC[NOTE_OFF] = '/note_off'
|
||||
|
||||
if not ignore_rpn:
|
||||
MIDI_TO_OSC[NRPN] = '/nrpn'
|
||||
MIDI_TO_OSC[RPN] = '/rpn'
|
||||
OSC_TO_MIDI['/nrpn'] = NRPN
|
||||
OSC_TO_MIDI['/rpn'] = RPN
|
||||
|
||||
|
||||
def midi_str(message, port):
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ module.exports = {
|
|||
},
|
||||
'm': {alias: 'midi', type: 'array', describe: 'midi router settings',
|
||||
check: (o)=>{
|
||||
var err = o.filter(item=>!item.match(/^(list|debug|jack|sysex|mtc|active_sensing|note_off_velocity|pc_offset|path=(.*)|[^:]+:(virtual|[^,]+,[^,]+))$/))
|
||||
var err = o.filter(item=>!item.match(/^(list|debug|jack|sysex|mtc|rpn|nrpn|active_sensing|note_off_velocity|pc_offset|path=(.*)|[^:]+:(virtual|[^,]+,[^,]+))$/))
|
||||
return err.length ? `Invalid option${err.length > 1 ? 's' : ''}: ${err.join(', ')}` : true
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue