Redis events

This commit is contained in:
sam 2020-10-09 14:57:03 +02:00
parent 666698c633
commit fb9999c828
4 changed files with 95 additions and 21 deletions

View file

@ -159,6 +159,11 @@ def toKey(keyname,keyvalue):
# Store encoded data in Redis
return r.set(keyname,keyvalue)
def toKeyevent(eventname):
print("redis midi event key :", eventname)
r.publish("/midi/last_event", eventname)
def GetTime():
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
@ -291,15 +296,22 @@ def MidinProcess(inqueue, portname):
MidiNote = msg[1]
MidiVel = msg[2]
print()
#print(debug)
print("NOTE ON :", "Channel", MidiChannel, "note :", MidiNote, 'velocity :', MidiVel )
# redis key : "/midi/noteon/midichannel" value : "note/velocity"
if r.set("/midi/noteon/"+str(MidiChannel), str(MidiNote)+"/"+str(MidiVel))==True:
print("redis :", "/midi/noteon/"+str(MidiChannel)+" : "+ str(MidiNote)+"/"+str(MidiVel))
if debug == "True":
print("redis :", "/midi/noteon/"+str(MidiChannel)+" : "+ str(MidiNote)+"/"+str(MidiVel))
# to Key redis pubsub feed
toKeyevent("/midi/noteon/"+str(MidiChannel)+"/"+str(MidiNote)+"/"+str(MidiVel))
# OSC : /midi/noteon midichannel note velocity
SendOSC("/midi/noteon",[MidiChannel, msg[1], msg[2]])
print("osc :","/midi/noteon/",[MidiChannel, msg[1], msg[2]])
#SendOSC("/midi/noteon",[MidiChannel, msg[1], msg[2]])
#print("osc :","/midi/noteon/",[MidiChannel, msg[1], msg[2]])
'''
# Sampler mode : note <63 launch snare.wav / note > 62 kick.wav
@ -327,16 +339,22 @@ def MidinProcess(inqueue, portname):
MidiChannel = msg[0]-144
else:
MidiChannel = msg[0]-128
MidiNote = msg[1]
print("NOTE_off channel :", MidiChannel, "note :", MidiNote)
# redis key : "/midi/noteon/midichannel" value : "note"
if r.set("/midi/noteoff/"+str(MidiChannel), str(MidiNote)) ==True:
print("redis :", "/midi/noteoff/"+str(MidiChannel)+" : "+ str(MidiNote))
if debug == "True":
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
SendOSC("/midi/noteoff",[MidiChannel, msg[1]])
print('osc :', "/midi/noteoff",[MidiChannel, msg[1]])
if debug == "True":
print('osc :', "/midi/noteoff",[MidiChannel, msg[1]])
# # CC on all Midi Channels
@ -349,11 +367,15 @@ def MidinProcess(inqueue, portname):
# 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]))
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]))
# OSC : /midi/cc midichannel ccnumber value
SendOSC("/midi/cc",[msg[0]-175-1, msg[1], msg[2]])
print("osc :","/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]] )
if msg[0] == TIMING_CLOCK:
@ -399,7 +421,8 @@ def MidinProcess(inqueue, portname):
# OSC : /midi/start
SendOSC("/midi/stop",[])
print("osc : /midi/stop")
if debug =="True":
print("osc : /midi/stop")
print()
'''
# other midi message