Skip to content

Instantly share code, notes, and snippets.

@MegaLoler
Last active October 22, 2021 20:28
Show Gist options
  • Save MegaLoler/360f5a7211651e7e85f7bb0fccb4ea58 to your computer and use it in GitHub Desktop.
Save MegaLoler/360f5a7211651e7e85f7bb0fccb4ea58 to your computer and use it in GitHub Desktop.
jack midi python script 2 invert midi pedal messages !!!!! (on -> off, off -> on)
#!/usr/bin/env python3
"""JACK client that inverts pedal mapping."""
import jack
import struct
import threading
client = jack.Client("invert pedal")
port_input = client.midi_inports.register("input")
port_output = client.midi_outports.register("output")
@client.set_process_callback
def process(frames):
port_output.clear_buffer()
for offset, data in port_input.incoming_midi_events():
if len(data) == 3:
status, controller, value = struct.unpack('3B', data)
if status >> 4 == 0xb and controller == 0x40:
port_output.write_midi_event(offset, (status, controller, 0x7f - value))
continue
port_output.write_midi_event(offset, data)
with client:
threading.Event().wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment