Ok its not nice and tidy, but it's a start. Unfortunately I still get some errors now and then. Referring to this line:
Code: Select all
vJoy[Joy1].setButton(Dict[midi[0].data.buffer[0]],True)
Probably has to do something with the timeout loop.. I just found this line on the internet, credits to gabrielqv on GitHub!
Code: Select all
import time
def update():
if (midi[0].data.buffer[0] == 1) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].x = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 2) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].y = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 3) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].z = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 4) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].slider = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 5) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].dial = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 6) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].rz = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 7) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].rx = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.buffer[0] == 8) and (midi[0].data.status == MidiStatus.Control):
vJoy[Joy1].ry = filters.mapRange(midi[0].data.buffer[1], 127, 0, 17873, -17873)
if (midi[0].data.status == MidiStatus.NoteOn) and (latched == False) and (midi[0].data.buffer[0] < (BgnKB+34)):
vJoy[Joy1].setButton(Dict[midi[0].data.buffer[0]],True) #Be Sure not to press a note thats not defined by the Dict{} when the diagnostics.watch(Dict[midi[0].data.buffer[0]]) is active..
timeOut[Dict[midi[0].data.buffer[0]]] = (time.time() + .03)
diagnostics.watch(midi[0].data.channel)
diagnostics.watch(midi[0].data.status)
diagnostics.watch(midi[0].data.buffer[0])
diagnostics.watch(midi[0].data.buffer[1])
# diagnostics.watch(Dict[midi[0].data.buffer[0]])
if starting:
timeOut = {}
latched = False
BgnKB = 24 # is start of Keyboard, this example begins at C2
Joy1 = 2
Dict = {(BgnKB+0):1, (BgnKB+1):2, (BgnKB+2):3, (BgnKB+3):4, (BgnKB+4):5, (BgnKB+5):6, (BgnKB+6):7, (BgnKB+7):8, (BgnKB+8):9, (BgnKB+9):10, (BgnKB+10):11, (BgnKB+11):12, (BgnKB+13):13, (BgnKB+13):14, (BgnKB+14):15, (BgnKB+15):16, (BgnKB+16):17, (BgnKB+17):18, (BgnKB+18):19, (BgnKB+19):20, (BgnKB+20):21, (BgnKB+21):22, (BgnKB+22):23, (BgnKB+23):24, (BgnKB+24):25, (BgnKB+25):26, (BgnKB+26):27, (BgnKB+27):28, (BgnKB+28):29, (BgnKB+29):30, (BgnKB+30):31, (BgnKB+31):32, (BgnKB+32):33} #Maps joystick buttons to each midi note
midi[0].update += update
buffer = timeOut.copy()
for x in buffer:
if timeOut.get(x, 0) < time.time():
vJoy[Joy1].setButton(x,False)
del(timeOut[x])
diagnostics.watch(str(timeOut))
Edit: It seems to fire the button twice when pressed.. Is there a trick to remove that first press? It has to do something with the timing.