Created
May 14, 2017 09:15
-
-
Save runekaagaard/e3d43f2a26b42df97e2f48af7001d1b1 to your computer and use it in GitHub Desktop.
A midi plugin for a 3x3 pad.
This file contains 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
from rtmidi.midiutil import open_midiport | |
NOTEON = 144 | |
NOTEOFF = 128 | |
BASE = 65 | |
SCALE = [1, 2, 1, 1, 2, 2, 1, 2] | |
NOTE = BASE | |
STEP = 0 | |
TOPBASE = BASE + 24 | |
P1, P2, P3, P4, P5, P6, P7, P8, P9 = [60, 62, 64, 65, 67, 69, 71, 72, 74] | |
def move_up_in_scale(): | |
global STEP, NOTE | |
NOTE += SCALE[STEP] | |
STEP += 1 | |
if STEP > len(SCALE) - 1: | |
STEP = 0 | |
def move_down_in_scale(): | |
global STEP, NOTE | |
NOTE -= SCALE[STEP] | |
STEP -= 1 | |
if STEP < 0: | |
STEP = len(SCALE) - 1 | |
def ping(event, data=None): | |
global NOTE, STEP | |
etype, note, value = event[0] | |
if etype == NOTEON: | |
print "Received NOTEON for:", note, value | |
if note == P1: | |
move_down_in_scale() | |
elif note == P2: | |
NOTE = TOPBASE | |
STEP = 0 | |
elif note == P3: | |
move_up_in_scale() | |
elif note == P4: | |
move_down_in_scale() | |
move_down_in_scale() | |
elif note == P5: | |
pass | |
elif note == P6: | |
move_up_in_scale() | |
move_up_in_scale() | |
elif note == P7: | |
move_down_in_scale() | |
move_down_in_scale() | |
move_down_in_scale() | |
elif note == P8: | |
NOTE = BASE | |
STEP = 0 | |
elif note == P9: | |
move_up_in_scale() | |
move_up_in_scale() | |
move_up_in_scale() | |
else: | |
print "Unknown PAD", note | |
midiout.send_message([NOTEON, NOTE, value]) | |
midiout, outport_name = open_midiport(type_="output", use_virtual=True) | |
midiin, inport_name = open_midiport(type_="input", use_virtual=True) | |
midiin.set_callback(ping) | |
while True: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment