Created
July 27, 2021 16:00
-
-
Save hizkifw/5c6b2ba77aceb347555e5392ce2fc871 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
PianoTeqnician | |
Reroute MIDI events to two instances of Pianoteq to circumvent the free trial | |
limitation on certain keys. All enabled keys are routed to one normal instance | |
of Pianoteq, and the disabled ones are routed to another instance, but shifted | |
one semitone down. Then, on that other instance of Pianoteq, tune the piano to | |
466 Hz to restore the pitch of the shifted notes. | |
Requires JACK and Catia (or any other JACK patchbays) to route the MIDI data | |
to the right instances of Pianoteq. | |
python3 -m pip install JACK-Client | |
""" | |
import jack | |
import struct | |
import binascii | |
# First 4 bits of status byte: | |
NOTEON = 0x9 | |
NOTEOFF = 0x8 | |
CHANCTRL = 0xb | |
muted = [42, 44, 46, 85, 87, 90, 92, 94] | |
client = jack.Client('PianoTeqnician') | |
inport = client.midi_inports.register('input') | |
out_normal = client.midi_outports.register('normal_output') | |
out_muted = client.midi_outports.register('muted_output') | |
@client.set_process_callback | |
def process(frames): | |
out_normal.clear_buffer() | |
out_muted.clear_buffer() | |
for offset, indata in inport.incoming_midi_events(): | |
try: | |
out_normal.write_midi_event(offset, indata) | |
except: | |
pass | |
# notes | |
if len(indata) == 3: | |
status, pitch, vel = struct.unpack('3B', indata) | |
try: | |
if status >> 4 in (NOTEON, NOTEOFF) and pitch in muted: | |
out_muted.write_midi_event(offset, (status, pitch - 1, vel)) | |
elif status >> 4 == CHANCTRL: | |
out_muted.write_midi_event(offset, indata) | |
except: | |
pass | |
with client: | |
print('#' * 80) | |
print('press Return to quit') | |
print('#' * 80) | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment