From 3d9dd22a053279fc1f4078e78d4d0577cd268c4d Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 27 Apr 2019 00:28:37 +0200 Subject: [PATCH] midi: pc_offset option --- CHANGELOG.md | 1 + resources/docs/docs/midi.md | 5 +++-- src/python/midi.py | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcafa597..871f0fc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - added `/STATE/[GET|SET|STORE|RECALL]` methods - midi - print port name in debug messages + - added `pc_offset` option to act as if program change numbers where between 1 and 128 ## 0.45.7 diff --git a/resources/docs/docs/midi.md b/resources/docs/docs/midi.md index f20665c5..52632bff 100644 --- a/resources/docs/docs/midi.md +++ b/resources/docs/docs/midi.md @@ -17,6 +17,7 @@ When running the app, the `-m / --midi` switch must be set; it accepts the follo - `list`: prints the available MIDI ports to the console; numbers in the first column may be used for `input`/`output` definition below - `device_name:input,output`: connect to midi ports `input` and `output`; osc messages sent to target `midi:device_name` will be processed as midi events; Multiple devices can be declared - `sysex`: parse incomming system exclusive messages (disabled by default) +- `pc_offset`: send program changes with a `-1` offset to match some software/hardware implementations *Linux only:* @@ -76,10 +77,10 @@ A fader might be configured as follows in order to send a MIDI control message ( Program change event. - `channel`: integer between 1 and 16 -- `program`: integer between 0 and 127 +- `program`: integer between 0 and 127* !!! note - Some devices / softwares display the `program` value between 1 and 128, thus interpreting `program change 0` as `program change 1` and so on. + \* Some devices / softwares display the `program` value between 1 and 128, thus interpreting `program change 0` as `program change 1` and so on. Enable the `pc_offset` option to make Open Stage Control behave this way. #### `/pitch channel pitch` diff --git a/src/python/midi.py b/src/python/midi.py index 0f8e1ea5..a1c8e6d2 100644 --- a/src/python/midi.py +++ b/src/python/midi.py @@ -5,6 +5,9 @@ from utils import * if 'list' in argv: list() +# option: act as if displayed program is between 1-128 instead of 0-127 +PROGRAM_CHANGE_OFFSET = 'pc_offset' in argv + inputs = {} outputs = {} @@ -83,6 +86,9 @@ def create_callback(name): if mtype == NOTE_OFF: message[2] = 0 + elif mtype is PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET: + message[-1] = message[-1] + 1 + for data in message[1:]: osc['args'].append({'type': 'i', 'value': data}) @@ -174,6 +180,9 @@ def send_midi(name, event, *args): elif mtype is PITCH_BEND: args = args[:1] + [args[1] & 0x7f, (args[1] >> 7) & 0x7f] # convert 0-16384 -> 0-127 pair + elif mtype is PROGRAM_CHANGE and PROGRAM_CHANGE_OFFSET: + args[-1] = args[-1] - 1 + m = midi_message(mtype, *args) if m is None: