Here is the script that will let you latch the sequencer. It will latch a single note arp. To latch more complex arps requires some extra logic. To use this you must put your keyboard into local control off. It should work fine with a desktop, but I have not tested it with my desktop yet. Now, run the program and hit a key to latch the sequencer. Hit is again, and it unlatches. If you press a different key it should automatically latch the new key and unlatch the old one.
from random import *
import mido
from mido.ports import MultiPort
import array
from time import *
import os,glob
import threading
from patterns import *
import mopho
outp= mido.get_output_names()
inp = mido.get_input_names()
print "Midi inputs"
for n in inp:
print n
print "\nMidi Outputs"
for n in outp:
print n
MOPHO_CHANNEL=0x0
keyboard_input = mido.open_input(inp[0])
#clk = mido.open_input(self.clocks.currentText())
midi_output = mido.open_output(outp[1])
def MSG(msg):
return mido.Message.from_bytes(msg)
def MIDI_NoteOn(note,chan=MOPHO_CHANNEL):
msg =
msg[0] = 0x90 + chan
msg[1] = note
msg[2] = 100
print msg
midi_output.send(MSG(msg))
def MIDI_NoteOff(note,chan = MOPHO_CHANNEL):
msg=[0]*3
msg[0] = 0x80 + chan
msg[1] = note
msg[2] = 127
midi_output.send(MSG(msg))
def Loop():
last_key = -1
while 1:
for msg in keyboard_input:
key = msg.bytes()
print key
if(key[0] == 0x90 + MOPHO_CHANNEL):
if(key[1] == last_key):
MIDI_NoteOff(key[1])
continue
if(last_key != -1):
MIDI_NoteOff(last_key)
MIDI_NoteOn(key[1])
last_key = key[1]
elif(key[0] < 0x80 or key[0] >= 0x8F):
mido.send(MSG(msg))
if __name__ == "__main__":
Loop()
That's the script and I will walk you through it. I am not a python expert, being trained in C and Basic, so there is all kinds of "Pythonic' ways to do it better, and it supports functional programming and many things that are simply beyond my knowledge. But that is why Python is useful because you can still program it in many styles. Since it's just a little script and not something that is commercial it doesn't really matter to me as long as it works.