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

@ -16,18 +16,10 @@ To enable Link :
python3 miredis.py -link python3 miredis.py -link
## New Features
## Redis keys - Added verbose mode -v
- Added redis subscribe events
"/midi/noteon/midichannel" value : "note/velocity"
"/midi/noteoff/midichannel" value : "note"
"/midi/cc/midichannel/ccnumber" value : "ccvalue"
"/beat" value : "beatnumber"
"/bpm" value : "currentbpm"
## OSC ## OSC
@ -47,3 +39,28 @@ python3 miredis.py -link
/beat beatnumber /beat beatnumber
/bpm bpm /bpm bpm
## Redis keys
"/midi/noteon/midichannel" value : "note/velocity"
"/midi/noteoff/midichannel" value : "note"
"/midi/cc/midichannel/ccnumber" value : "ccvalue"
"/beat" value : "beatnumber"
"/bpm" value : "currentbpm"
"/midi/last_event" midi events key
## Redis midi events : key "/midi/last_event"
"/midi/noteon/midichannel/note/velocity"
"/midi/noteoff/midichannel/note
"/midi/cc/midichannel/ccnumber/ccvalue"

View File

@ -159,6 +159,11 @@ 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):
print("redis midi event key :", 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())
@ -291,15 +296,22 @@ 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 )
# 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
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]])
''' '''
# Sampler mode : note <63 launch snare.wav / note > 62 kick.wav # Sampler mode : note <63 launch snare.wav / note > 62 kick.wav
@ -327,15 +339,21 @@ 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)
# 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]])
@ -349,11 +367,15 @@ def MidinProcess(inqueue, portname):
# redis key : "/midi/cc/midichannel/ccnumber" value : "ccvalue" # redis key : "/midi/cc/midichannel/ccnumber" value : "ccvalue"
if r.set("/midi/cc/"+str(MidiChannel)+"/"+str(msg[1]),str(msg[2]))==True: 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])) 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 # 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:
@ -399,6 +421,7 @@ 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()
''' '''

View File

@ -120,6 +120,40 @@ r = redis.StrictRedis(host=redisIP , port=redisPORT, db=0)
midix.r = r midix.r = r
def Osc():
p = r.pubsub()
p.subscribe('updates')
print("Artnet updates subscribed")
while True:
# Handle OSC based changed
OSCframe()
# Handle Artnet change via redis key 'updates' subscription
message = p.get_message()
if message:
messageCC = message['data']
# print(type(messageCC))
#print("Updates said: %s" % messageCC)
if messageCC != 1:
#if ":" in str(messageCC.decode('utf_8')):
messageCC = messageCC.decode('utf_8')
artnetCC = messageCC.split(":")
if len(artnetCC) > 1:
cc(int(artnetCC[0]), round(int(artnetCC[1])/2))
print()
#time.sleep(0.0)
if __name__ == '__main__': if __name__ == '__main__':