Start animation
This commit is contained in:
parent
fb32289fa6
commit
66ba694bdc
Binary file not shown.
233
libs/midix.py
233
libs/midix.py
@ -110,6 +110,20 @@ STATUS_MAP = {
|
|||||||
'channelpressure': CHANNEL_PRESSURE
|
'channelpressure': CHANNEL_PRESSURE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PadLeds = [0] * 64
|
||||||
|
PadTops= [0] * 8
|
||||||
|
PadRights= [0] * 8
|
||||||
|
LaunchLedMatrix = [(0,1,2,3,4,5,6,7),(16,17,18,19,20,21,22,23),(32,33,34,35,36,37,38,39),(48,49,50,51,52,53,54,55),(64,65,66,67,68,69,70,71),(80,81,82,83,84,85,86,87),(96,97,98,99,100,101,102,103),(112,113,114,115,116,117,118,119)]
|
||||||
|
LaunchRight = (8,24,40,56,72,88,104,120)
|
||||||
|
# CC
|
||||||
|
LaunchTop = (104,105,106,107,108,109,110,111)
|
||||||
|
PadTop = [0,0,0,0,0,0,0,0]
|
||||||
|
PadRight = [0,0,0,0,0,0,0,0]
|
||||||
|
PadMatrix = [0] * 64
|
||||||
|
matrix1 = [1,1]
|
||||||
|
matrix2 = [1,1]
|
||||||
|
matrix3 = [1,1]
|
||||||
|
TopSelection = [0] *8
|
||||||
|
|
||||||
def SendOSC(oscaddress,oscargs=''):
|
def SendOSC(oscaddress,oscargs=''):
|
||||||
|
|
||||||
@ -146,6 +160,8 @@ def SendUI(oscaddress,oscargs=''):
|
|||||||
log.err('Connection to Aurora UI refused : died ?')
|
log.err('Connection to Aurora UI refused : died ?')
|
||||||
pass
|
pass
|
||||||
#time.sleep(0.001
|
#time.sleep(0.001
|
||||||
|
|
||||||
|
|
||||||
# Ask redis for a given key
|
# Ask redis for a given key
|
||||||
|
|
||||||
def fromKey(keyname):
|
def fromKey(keyname):
|
||||||
@ -159,11 +175,14 @@ def toKey(keyname,keyvalue):
|
|||||||
# Store encoded data in Redis
|
# Store encoded data in Redis
|
||||||
return r.set(keyname,keyvalue)
|
return r.set(keyname,keyvalue)
|
||||||
|
|
||||||
|
|
||||||
def toKeyevent(eventname):
|
def toKeyevent(eventname):
|
||||||
|
|
||||||
print("redis midi event key :", eventname)
|
print("redis midi event key :", eventname)
|
||||||
r.publish("/midi/last_event", eventname)
|
r.publish("/midi/last_event", eventname)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def GetTime():
|
def GetTime():
|
||||||
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
|
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
|
||||||
|
|
||||||
@ -283,6 +302,7 @@ def MidinProcess(inqueue, portname):
|
|||||||
last_clock = None
|
last_clock = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
msg = inqueue_get()
|
msg = inqueue_get()
|
||||||
#print("")
|
#print("")
|
||||||
@ -296,24 +316,18 @@ def MidinProcess(inqueue, portname):
|
|||||||
MidiNote = msg[1]
|
MidiNote = msg[1]
|
||||||
MidiVel = msg[2]
|
MidiVel = msg[2]
|
||||||
print()
|
print()
|
||||||
#print(debug)
|
|
||||||
print("NOTE ON :", "Channel", MidiChannel, "note :", MidiNote, 'velocity :', MidiVel )
|
print("NOTE ON :", "Channel", MidiChannel, "note :", MidiNote, 'velocity :', MidiVel )
|
||||||
NoteOn(MidiNote, MidiVel, "pads" , midichannel=MidiChannel)
|
|
||||||
|
|
||||||
# redis key : "/midi/noteon/midichannel" value : "note/velocity"
|
# redis key : "/midi/noteon/midichannel" value : "note/velocity"
|
||||||
if r.set("/midi/noteon/"+str(MidiChannel), str(MidiNote)+"/"+str(MidiVel))==True:
|
if r.set("/midi/noteon/"+str(MidiChannel), str(MidiNote)+"/"+str(MidiVel))==True:
|
||||||
if debug == "True":
|
|
||||||
print("redis :", "/midi/noteon/"+str(MidiChannel)+" : "+ str(MidiNote)+"/"+str(MidiVel))
|
print("redis :", "/midi/noteon/"+str(MidiChannel)+" : "+ str(MidiNote)+"/"+str(MidiVel))
|
||||||
|
|
||||||
# to Key redis pubsub feed
|
NoteOn(MidiNote, MidiVel, "pads" , midichannel=MidiChannel)
|
||||||
toKeyevent("/midi/noteon/"+str(MidiChannel)+"/"+str(MidiNote)+"/"+str(MidiVel))
|
|
||||||
|
|
||||||
# OSC : /midi/noteon midichannel note velocity
|
# OSC : /midi/noteon midichannel note velocity
|
||||||
#SendOSC("/midi/noteon",[MidiChannel, msg[1], msg[2]])
|
SendOSC("/midi/noteon",[MidiChannel, msg[1], msg[2]])
|
||||||
#print("osc :","/midi/noteon/",[MidiChannel, msg[1], msg[2]])
|
print("osc :","/midi/noteon/",[MidiChannel, msg[1], msg[2]])
|
||||||
|
toKeyevent("/midi/noteon/"+str(MidiChannel)+"/"+str(MidiNote)+"/"+str(MidiVel))
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# Sampler mode : note <63 launch snare.wav / note > 62 kick.wav
|
# Sampler mode : note <63 launch snare.wav / note > 62 kick.wav
|
||||||
if MidiNote < 63 and MidiVel >0:
|
if MidiNote < 63 and MidiVel >0:
|
||||||
@ -340,22 +354,16 @@ def MidinProcess(inqueue, portname):
|
|||||||
MidiChannel = msg[0]-144
|
MidiChannel = msg[0]-144
|
||||||
else:
|
else:
|
||||||
MidiChannel = msg[0]-128
|
MidiChannel = msg[0]-128
|
||||||
|
|
||||||
MidiNote = msg[1]
|
MidiNote = msg[1]
|
||||||
print("NOTE_off channel :", MidiChannel, "note :", MidiNote)
|
print("NOTE_off channel :", MidiChannel, "note :", MidiNote)
|
||||||
NoteOff(MidiNote, "pads" , midichannel=MidiChannel)
|
NoteOff(MidiNote, "pads" , midichannel=MidiChannel)
|
||||||
|
|
||||||
# redis key : "/midi/noteon/midichannel" value : "note"
|
# redis key : "/midi/noteon/midichannel" value : "note"
|
||||||
if r.set("/midi/noteoff/"+str(MidiChannel), str(MidiNote)) ==True:
|
if r.set("/midi/noteoff/"+str(MidiChannel), str(MidiNote)) ==True:
|
||||||
if debug == "True":
|
|
||||||
print("redis :", "/midi/noteoff/"+str(MidiChannel)+" : "+ str(MidiNote))
|
print("redis :", "/midi/noteoff/"+str(MidiChannel)+" : "+ str(MidiNote))
|
||||||
|
|
||||||
# to Key redis pubsub feed
|
|
||||||
#toKeyevent("/midi/noteoff/"+str(MidiChannel)+"/"+str(MidiNote))
|
|
||||||
|
|
||||||
# OSC : /midi/noteoff midichannel note
|
# OSC : /midi/noteoff midichannel note
|
||||||
SendOSC("/midi/noteoff",[MidiChannel, msg[1]])
|
SendOSC("/midi/noteoff",[MidiChannel, msg[1]])
|
||||||
if debug == "True":
|
|
||||||
print('osc :', "/midi/noteoff",[MidiChannel, msg[1]])
|
print('osc :', "/midi/noteoff",[MidiChannel, msg[1]])
|
||||||
|
|
||||||
|
|
||||||
@ -364,21 +372,18 @@ def MidinProcess(inqueue, portname):
|
|||||||
|
|
||||||
MidiChannel = msg[0]-175
|
MidiChannel = msg[0]-175
|
||||||
|
|
||||||
|
cc(MidiChannel, msg[1], msg[2], "pads" )
|
||||||
#print("channel", MidiChannel, "CC :", msg[1], msg[2])
|
#print("channel", MidiChannel, "CC :", msg[1], msg[2])
|
||||||
print("CC channel : "+str(msg[0]-175-1)+" CC :"+str(msg[1])+" value : "+str(msg[2]))
|
print("CC channel : "+str(msg[0]-175-1)+" CC :"+str(msg[1])+" value : "+str(msg[2]))
|
||||||
|
|
||||||
cc(MidiChannel, msg[1], msg[2], "pads" )
|
|
||||||
# redis key : "/midi/cc/midichannel/ccnumber" value : "ccvalue"
|
|
||||||
if r.set("/midi/cc/"+str(MidiChannel)+"/"+str(msg[1]),str(msg[2]))==True:
|
|
||||||
if debug == "True":
|
|
||||||
print("redis :", "/midi/cc/"+str(MidiChannel)+"/"+str(msg[1]), ":", str(msg[2]))
|
|
||||||
|
|
||||||
# to Key redis pubsub feed
|
|
||||||
toKeyevent("/midi/cc/"+str(MidiChannel)+"/"+str(msg[1])+"/"+str(msg[2]))
|
toKeyevent("/midi/cc/"+str(MidiChannel)+"/"+str(msg[1])+"/"+str(msg[2]))
|
||||||
|
|
||||||
|
# redis key : "/midi/cc/midichannel/ccnumber" value : "ccvalue"
|
||||||
|
if r.set("/midi/cc/"+str(MidiChannel)+"/"+str(msg[1]),str(msg[2]))==True:
|
||||||
|
print("redis :", "/midi/cc/"+str(MidiChannel)+"/"+str(msg[1]), ":", str(msg[2]))
|
||||||
|
|
||||||
# OSC : /midi/cc midichannel ccnumber value
|
# OSC : /midi/cc midichannel ccnumber value
|
||||||
#SendOSC("/midi/cc",[msg[0]-175-1, msg[1], msg[2]])
|
SendOSC("/midi/cc",[msg[0]-175-1, msg[1], msg[2]])
|
||||||
#print("osc :","/midi/cc",[msg[0]-175-1, msg[1], msg[2]] )
|
print("osc :","/midi/cc",[msg[0]-175-1, msg[1], msg[2]] )
|
||||||
|
|
||||||
|
|
||||||
if msg[0] == TIMING_CLOCK:
|
if msg[0] == TIMING_CLOCK:
|
||||||
@ -424,7 +429,6 @@ def MidinProcess(inqueue, portname):
|
|||||||
|
|
||||||
# OSC : /midi/start
|
# OSC : /midi/start
|
||||||
SendOSC("/midi/stop",[])
|
SendOSC("/midi/stop",[])
|
||||||
if debug =="True":
|
|
||||||
print("osc : /midi/stop")
|
print("osc : /midi/stop")
|
||||||
print()
|
print()
|
||||||
'''
|
'''
|
||||||
@ -455,12 +459,12 @@ def NoteOn(note, color, mididest, midichannel=0):
|
|||||||
elif mididest == "all" and midiname[port].find(mididest) != 0:
|
elif mididest == "all" and midiname[port].find(mididest) != 0:
|
||||||
midiport[port].send_message([NOTE_ON+midichannel, note, color])
|
midiport[port].send_message([NOTE_ON+midichannel, note, color])
|
||||||
|
|
||||||
|
|
||||||
elif mididest == "pads" and midiname[port].find("Launchpad") > -1:
|
elif mididest == "pads" and midiname[port].find("Launchpad") > -1:
|
||||||
midiport[port].send_message([NOTE_ON+midichannel, note, color])
|
midiport[port].send_message([NOTE_ON+midichannel, note, color])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def NoteOff(note, mididest, midichannel=0):
|
def NoteOff(note, mididest, midichannel=0):
|
||||||
global MidInsNumber
|
global MidInsNumber
|
||||||
|
|
||||||
@ -475,11 +479,11 @@ def NoteOff(note, mididest, midichannel=0):
|
|||||||
elif mididest == "all" and midiname[port].find(mididest) == -1:
|
elif mididest == "all" and midiname[port].find(mididest) == -1:
|
||||||
midiport[port].send_message([NOTE_OFF, note, 0])
|
midiport[port].send_message([NOTE_OFF, note, 0])
|
||||||
|
|
||||||
|
|
||||||
elif mididest == "pads" and midiname[port].find("Launchpad") > -1:
|
elif mididest == "pads" and midiname[port].find("Launchpad") > -1:
|
||||||
midiport[port].send_message([NOTE_OFF, note, 0])
|
midiport[port].send_message([NOTE_OFF, note, 0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Generic call back : new msg forwarded to queue
|
# Generic call back : new msg forwarded to queue
|
||||||
class AddQueue(object):
|
class AddQueue(object):
|
||||||
def __init__(self, portname, port):
|
def __init__(self, portname, port):
|
||||||
@ -555,6 +559,14 @@ def OutConfig():
|
|||||||
|
|
||||||
OutDevice.append(OutObject(name, "generic", port))
|
OutDevice.append(OutObject(name, "generic", port))
|
||||||
|
|
||||||
|
# Search for a LaunchPad
|
||||||
|
if name.find("Launchpad") == 0:
|
||||||
|
|
||||||
|
OutDevice.append(OutObject(name, "launchpad", port))
|
||||||
|
print("Launchpad mini start animation")
|
||||||
|
Start()
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
#print "")
|
#print "")
|
||||||
print(len(OutDevice), "Out devices")
|
print(len(OutDevice), "Out devices")
|
||||||
#ListOutDevice()
|
#ListOutDevice()
|
||||||
@ -684,6 +696,8 @@ def InConfig():
|
|||||||
#midinputs[port].set_callback(AddQueue(name))
|
#midinputs[port].set_callback(AddQueue(name))
|
||||||
#genericnumber += 1
|
#genericnumber += 1
|
||||||
InDevice[InObject.counter-1].rtmidi.set_callback(AddQueue(name,port))
|
InDevice[InObject.counter-1].rtmidi.set_callback(AddQueue(name,port))
|
||||||
|
if name.find("Launch") > -1:
|
||||||
|
Cls()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@ -746,7 +760,7 @@ def MidiMsg(midimsg, mididest):
|
|||||||
|
|
||||||
desterror = -1
|
desterror = -1
|
||||||
|
|
||||||
print("midi3 got midimsg", midimsg, "for", mididest)
|
print("miredis got midimsg", midimsg, "for", mididest)
|
||||||
|
|
||||||
for port in range(len(OutDevice)):
|
for port in range(len(OutDevice)):
|
||||||
# To mididest
|
# To mididest
|
||||||
@ -758,6 +772,7 @@ def MidiMsg(midimsg, mididest):
|
|||||||
|
|
||||||
elif mididest == "pads" and midiname[port].find("Launchpad") > -1:
|
elif mididest == "pads" and midiname[port].find("Launchpad") > -1:
|
||||||
midiport[port].send_message(midimsg)
|
midiport[port].send_message(midimsg)
|
||||||
|
desterror = 0
|
||||||
|
|
||||||
if desterror == -1:
|
if desterror == -1:
|
||||||
print("mididest",mididest, ": ** This midi destination doesn't exists **")
|
print("mididest",mididest, ": ** This midi destination doesn't exists **")
|
||||||
@ -778,6 +793,164 @@ def NoteOn(note, velocity, mididest):
|
|||||||
if midiname[port].find(mididest) == 0:
|
if midiname[port].find(mididest) == 0:
|
||||||
midiport[port].send_message([NOTE_ON, note, velocity])
|
midiport[port].send_message([NOTE_ON, note, velocity])
|
||||||
'''
|
'''
|
||||||
|
#
|
||||||
|
# launchpad
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
def PadNoteOn(note,color):
|
||||||
|
(x,y) = BhorIndex(note)
|
||||||
|
#print('PadNoteon', note, x, y, color)
|
||||||
|
PadNoteOnXY(x,y,color)
|
||||||
|
|
||||||
|
|
||||||
|
def PadNoteOff(note):
|
||||||
|
(x,y) = BhorIndex(note)
|
||||||
|
#print('PadNoteOFF', note, x, y)
|
||||||
|
PadNoteOffXY(x,y)
|
||||||
|
|
||||||
|
def PadNoteOnXY(x,y,color):
|
||||||
|
msg= [NOTE_ON, PadNoteXY(x,y), color]
|
||||||
|
#print(msg)
|
||||||
|
MidiMsg(msg,"Launchpad")
|
||||||
|
PadLeds[BhorNoteXY(x,y)]=color
|
||||||
|
|
||||||
|
|
||||||
|
def PadNoteOffXY(x,y):
|
||||||
|
msg= [NOTE_OFF, PadNoteXY(x,y), 0]
|
||||||
|
#print(msg)
|
||||||
|
MidiMsg(msg,"Launchpad")
|
||||||
|
PadLeds[BhorNoteXY(x,y)]=0
|
||||||
|
|
||||||
|
def PadNoteXY(x,y):
|
||||||
|
note = LaunchLedMatrix[int(y-1)][int(x-1)]
|
||||||
|
return note
|
||||||
|
|
||||||
|
def PadIndex(note):
|
||||||
|
y=note/16
|
||||||
|
x=note%16
|
||||||
|
return int(x+1),int(y+1)
|
||||||
|
|
||||||
|
def BhorIndex(note):
|
||||||
|
y=note/8
|
||||||
|
x=note%8
|
||||||
|
#print "Note : ",note
|
||||||
|
#print "BhorIndex : ", x+1,y+1
|
||||||
|
return int(x+1),int(y+1)
|
||||||
|
|
||||||
|
def BhorNoteXY(x,y):
|
||||||
|
note = (x -1)+ (y-1) * 8
|
||||||
|
return note
|
||||||
|
|
||||||
|
# top raw and right column leds are numbered humanly 1-8. So -1 is for pythonic arrays position 0-7
|
||||||
|
def PadTopOn(number, color):
|
||||||
|
msg= [CONTROLLER_CHANGE, LaunchTop[number-1], color]
|
||||||
|
MidiMsg(msg,"Launchpad")
|
||||||
|
PadTops[number-1]=color
|
||||||
|
|
||||||
|
def PadTopOff(number):
|
||||||
|
msg= [CONTROLLER_CHANGE, LaunchTop[number-1], 0]
|
||||||
|
MidiMsg(msg,"Launchpad")
|
||||||
|
PadTops[number-1]=0
|
||||||
|
|
||||||
|
def PadRightOn(number, color):
|
||||||
|
msg= [NOTE_ON, LaunchRight[number-1], color]
|
||||||
|
MidiMsg(msg,"Launchpad")
|
||||||
|
PadRights[number-1] = color
|
||||||
|
#UpdateAllCCs(number-1)
|
||||||
|
|
||||||
|
def PadRightOff(number):
|
||||||
|
msg= [NOTE_OFF, LaunchRight[number-1], 0]
|
||||||
|
MidiMsg(msg,"Launchpad")
|
||||||
|
PadRights[number-1] = 0
|
||||||
|
|
||||||
|
def TopUpdate(button, color):
|
||||||
|
#print(PadTop)
|
||||||
|
PadTop = [0,0,0,0,0,0,0,0]
|
||||||
|
PadTop[button] = color
|
||||||
|
for pad in range(7):
|
||||||
|
PadTopOn(pad+1, PadTop[pad])
|
||||||
|
|
||||||
|
def RightUpdate():
|
||||||
|
for pad in range(8):
|
||||||
|
print(pad,PadRight[pad])
|
||||||
|
PadRightOn(pad, PadRight[pad])
|
||||||
|
if PadRight[pad] == 0:
|
||||||
|
SendOSCUI('/pad/r'+ str(pad) +'/button', [0])
|
||||||
|
else:
|
||||||
|
SendOSCUI('/pad/r'+ str(pad) +'/button', [1])
|
||||||
|
|
||||||
|
def MatrixUpdate():
|
||||||
|
for pad in range(64):
|
||||||
|
PadNoteOn(pad, PadMatrix[pad])
|
||||||
|
|
||||||
|
def MatrixSelect():
|
||||||
|
MatrixUpdate()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# AllColor for launchpad on given port
|
||||||
|
def AllColorPad(color):
|
||||||
|
|
||||||
|
print('AllColorPad')
|
||||||
|
for led in range(0,64,1):
|
||||||
|
PadNoteOn(led,color)
|
||||||
|
'''
|
||||||
|
for line in LaunchLedMatrix:
|
||||||
|
for led in line:
|
||||||
|
midiport[port].send_message([NOTE_ON, led, color])
|
||||||
|
'''
|
||||||
|
for rightled in range(8):
|
||||||
|
PadRightOn(rightled+1, color)
|
||||||
|
for topled in range(8):
|
||||||
|
PadTopOn(topled+1,color)
|
||||||
|
#midiport[port].send_message([CONTROLLER_CHANGE, topled, color])
|
||||||
|
|
||||||
|
def ClsMatrix():
|
||||||
|
for led in range(0,64,1):
|
||||||
|
PadNoteOff(led)
|
||||||
|
|
||||||
|
def ClsTop():
|
||||||
|
for topled in range(8):
|
||||||
|
PadTopOff(topled+1)
|
||||||
|
|
||||||
|
def ClsRight():
|
||||||
|
|
||||||
|
for rightled in range(8):
|
||||||
|
PadRightOff(rightled+1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def Cls():
|
||||||
|
|
||||||
|
ClsMatrix()
|
||||||
|
ClsTop()
|
||||||
|
ClsRight()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def Start():
|
||||||
|
|
||||||
|
#ClsPad(port)
|
||||||
|
#time.sleep(0.3)
|
||||||
|
ClsTop()
|
||||||
|
ClsRight()
|
||||||
|
#AllColorPad(20)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
for color in range(64,128,1):
|
||||||
|
#AllColorPad(color)
|
||||||
|
PadNoteOn(color-64, color)
|
||||||
|
#print("color", color)
|
||||||
|
time.sleep(0.5)
|
||||||
|
AllColorPad(127)
|
||||||
|
time.sleep(0.5)
|
||||||
|
Cls()
|
||||||
|
#time.sleep(0.3)
|
||||||
|
#UpdateDisplay()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def listdevice(number):
|
def listdevice(number):
|
||||||
|
Loading…
Reference in New Issue
Block a user