midi: allow sending note off with velocity, add option for receiving note off with velocity
This commit is contained in:
parent
996537d60b
commit
a6e60e172c
7 changed files with 43 additions and 17 deletions
|
|
@ -30,4 +30,15 @@ except:
|
|||
if version_info.major == 3:
|
||||
raw_input = input
|
||||
|
||||
# option: print debug messages
|
||||
debug = 'debug' in argv
|
||||
# option: act as if displayed program is between 1-128 instead of 0-127
|
||||
program_change_offset = 'pc_offset' in argv
|
||||
# option: parse sysex
|
||||
ignore_sysex = 'sysex' not in argv
|
||||
# option: parse mtc
|
||||
ignore_mtc = 'mtc' not in argv
|
||||
# option: parse active sensing
|
||||
ignore_active_sensing = 'active_sensing' not in argv
|
||||
# option: note off velocity
|
||||
note_off_velocity = 'note_off_velocity' in argv
|
||||
|
|
|
|||
|
|
@ -14,14 +14,6 @@ if 'list-only' in argv:
|
|||
list()
|
||||
exit()
|
||||
|
||||
# option: act as if displayed program is between 1-128 instead of 0-127
|
||||
PROGRAM_CHANGE_OFFSET = 'pc_offset' in argv
|
||||
# option: parse sysex
|
||||
ignore_sysex = 'sysex' not in argv
|
||||
# option: parse mtc
|
||||
ignore_mtc = 'mtc' not in argv
|
||||
# option: parse active sensing
|
||||
ignore_active_sensing = 'active_sensing' not in argv
|
||||
|
||||
inputs = {}
|
||||
outputs = {}
|
||||
|
|
@ -140,12 +132,13 @@ def create_callback(name):
|
|||
osc['args'].append({'type': 'i', 'value': channel})
|
||||
|
||||
if mtype == NOTE_OFF:
|
||||
message[2] = 0
|
||||
if not note_off_velocity:
|
||||
message[2] = 0
|
||||
|
||||
elif mtype == PITCH_BEND:
|
||||
message = message[:1] + [message[1] + message[2] * 128] # convert 0-127 pair -> 0-16384 ->
|
||||
|
||||
elif mtype == PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET:
|
||||
elif mtype == PROGRAM_CHANGE and program_change_offset:
|
||||
message[-1] = message[-1] + 1
|
||||
|
||||
for data in message[1:]:
|
||||
|
|
@ -245,7 +238,7 @@ def send_midi(name, event, *args):
|
|||
elif mtype == PITCH_BEND:
|
||||
args = args[:1] + [args[1] & 0x7F, (args[1] >> 7) & 0x7F] # convert 0-16384 -> 0-127 pair
|
||||
|
||||
elif mtype == PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET:
|
||||
elif mtype == PROGRAM_CHANGE and program_change_offset:
|
||||
args[-1] = args[-1] - 1
|
||||
|
||||
m = midi_message(mtype, *args)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ MIDI_TO_OSC = {
|
|||
|
||||
OSC_TO_MIDI = {
|
||||
'/note': NOTE_ON,
|
||||
'/note_off': NOTE_OFF,
|
||||
'/control': CONTROL_CHANGE,
|
||||
'/program': PROGRAM_CHANGE,
|
||||
'/pitch': PITCH_BEND,
|
||||
|
|
@ -24,6 +25,10 @@ OSC_TO_MIDI = {
|
|||
'/key_pressure': POLY_PRESSURE
|
||||
}
|
||||
|
||||
if note_off_velocity:
|
||||
MIDI_TO_OSC[NOTE_OFF] = '/note_off'
|
||||
|
||||
|
||||
def midi_str(message, port):
|
||||
|
||||
mtype = message[0] & 0xF0
|
||||
|
|
@ -48,7 +53,7 @@ def midi_str(message, port):
|
|||
if mtype == NOTE_ON:
|
||||
s = 'NOTE_ON: channel=%i, note=%i, velocity=%i' % (channel, message[1], message[2])
|
||||
elif mtype == NOTE_OFF:
|
||||
s = 'NOTE_OFF: channel=%i, note=%i' % (channel, message[1])
|
||||
s = 'NOTE_OFF: channel=%i, note=%i, velocity=%i' % (channel, message[1], message[2])
|
||||
elif mtype == CONTROL_CHANGE:
|
||||
s = 'CONTROL_CHANGE: channel=%i, cc=%i, value=%i'% (channel, message[1], message[2])
|
||||
elif mtype == PROGRAM_CHANGE:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue