Better interconnection and added the input selection partt

This commit is contained in:
Maximilien Rigaut 2021-10-18 17:04:58 +02:00
parent da792366c1
commit 37d8ccf2ca
4 changed files with 89 additions and 73 deletions

View File

@ -58,3 +58,4 @@ To do so add a custom patch (or use a currently defined one, but chances are pat
* TODO : Clean this step : Do a better IO handler * TODO : Clean this step : Do a better IO handler
* URGENT : Error on non existing patch is incorrect (win) * URGENT : Error on non existing patch is incorrect (win)
* URGENT : line 341, in POSTMATCH_SCRNUPD / if match.group("postargs")[-1]=="1" trigger out of range on incorrect formatted return args (no args) * URGENT : line 341, in POSTMATCH_SCRNUPD / if match.group("postargs")[-1]=="1" trigger out of range on incorrect formatted return args (no args)
* TODO: Get rid of match.group("postargs").split

View File

@ -7,17 +7,15 @@ import mido
_VERBOSE=4 _VERBOSE=4
nopeF=lambda x:None nopeF=lambda *x:None
def printl(label=""): def printl(label=""):
def _pl(*args): def _pl(*args):
print(label,*args) print(label,*args)
return _pl return _pl
eprint=printl("[mPH:ERROR]") eprint=printl("[mPH:ERROR]")
dprint=nopeF dprint,ddprint,iprint,wprint=nopeF,nopeF,nopeF,nopeF
ddprint=nopeF
iprint=nopeF
wprint=nopeF
if _VERBOSE>=1: if _VERBOSE>=1:
wprint=printl("[mPH:WARNING]") wprint=printl("[mPH:WARNING]")
if _VERBOSE>=2: if _VERBOSE>=2:
@ -31,12 +29,12 @@ if _VERBOSE>=4:
# CLASS DEFINES # CLASS DEFINES
class IOInterface(): class IOInterface():
"Handle the IO actions between an external script and a midiPageHandler interface" "Handle the IO actions between an external script and a midiPageHandler interface"
def __init__(self,pagehandler,remoteController): def __init__(self,pagehandler,externalProgram):
self._pageHandler=pagehandler self._pageHandler=pagehandler
self._listActionsH={} self._listActionsH={}
self._listActionsIO={} self._listActionsIO={}
self._pageHandler._IOInterface=self self._pageHandler._IOInterface=self
self._externalProgram=remoteController self._externalProgram=externalProgram
def addActionIO(self,matchName,action): def addActionIO(self,matchName,action):
"""Associate a function to a match to a message received """Associate a function to a match to a message received
@ -78,31 +76,38 @@ class IOInterface():
print(self._listActionsH) print(self._listActionsH)
wprint("Can't send action request",name) wprint("Can't send action request",name)
def toHandler(self,commandname,*args,**kwargs):
"Send directly an action to the handler"
self._pageHandler.receiveAction(commandname,*args,**kwargs)
def toExternalProgram(self,commandname,*args,**kwargs):
"Send directly a message to the pulse"
self._externalProgram.receiveCommand(commandname,*args,**kwargs)
class IOInterfacePulse(IOInterface): class IOInterfacePulse(IOInterface):
"Specialised pulse interface" "Specialised pulse interface"
def __init__(self,pagehandler,pulseModule,remoteController): def __init__(self,pagehandler,pulseModule,externalProgram):
super(IOInterfacePulse,self).__init__(pagehandler,remoteController) super(IOInterfacePulse,self).__init__(pagehandler,externalProgram)
self._pulseModule=pulseModule self._pulseModule=pulseModule
# Commands that should be sent to the pulse # Commands that should be sent to the pulse
self.addActionIO("LAYERINP",self._externalProgram.changeLayer) # self.addActionIO("LAYERINP",self._externalProgram.changeLayer)
self.addActionIO("TAKEALL",self._externalProgram.takeAll) # self.addActionIO("TAKEALL",self._externalProgram.takeAll)
self.addActionIO("LOADMM",self._externalProgram.loadMM) # self.addActionIO("LOADMM",self._externalProgram.loadMM)
self.addActionIO("QUICKF",self._externalProgram.quickFrame) # self.addActionIO("QUICKF",self._externalProgram.quickFrame)
self.addActionIO("FREEZE",self._externalProgram.freezeScreenAll) # self.addActionIO("FREEZE",self._externalProgram.freezeScreenAll)
self.addActionIO("SCRNUPD",self._externalProgram.updateFinishedAll) # self.addActionIO("SCRNUPD",self._externalProgram.updateFinishedAll)
# Command that are received from the pulse
self.addActionH("LAYERINP",self._pulseModule.layerCommand)
# self.addActionH("DETECTED",self._pulseModule.detected)
def receiveMessage(self,command,*args,**kwargs): def receiveMessage(self,command,*args,**kwargs):
"""A message was received from the pulse and will be redirected to the controller """A message was received from the pulse and will be redirected to the controller
""" """
self._pageHandler.receiveAction(command,*args,**kwargs) dprint("Using RM/Forb")
# self._pageHandler.receiveAction(command,*args,**kwargs)
self._pulseModule.receiveCommand(command,*args,**kwargs)
def receiveCommand(self,command,*args,**kwargs): def receiveCommand(self,command,*args,**kwargs):
"A message was received from the handler and will be redirected to the pulse" "A message was received from the handler and will be redirected to the pulse"
dprint("Using RC/Forb")
self._externalProgram.receiveMessage(command,*args,**kwargs) self._externalProgram.receiveMessage(command,*args,**kwargs)
@ -377,11 +382,11 @@ class midiPageHandler(object):
print(sep) print(sep)
class pulseController(object): class pulseRackController(object):
"Receive controls over a specific range and map them to commands to send" """Receive controls over a specific range and map them to commands to send"""
def __init__(self,returnInterface,ranges={j:j for j in range(3)}): def __init__(self,returnInterface,ranges={j:j for j in range(3)}):
self.ranges=ranges self.ranges=ranges
self.retunRanges={i:j for j,i in ranges.items()} self.returnRanges={i:j for j,i in ranges.items()}
_ALL_MESSAGE_TYPES=[ _ALL_MESSAGE_TYPES=[
"STATUS","LAYERINP","TAKE","TAKEALL","LOADMM","QUICKF" "STATUS","LAYERINP","TAKE","TAKEALL","LOADMM","QUICKF"
] ]
@ -394,62 +399,73 @@ class pulseController(object):
self.offset=0 # Offset on the lines self.offset=0 # Offset on the lines
def pressReceived(self,linecol,val): def pressReceived(self,linecol,val):
"Received an order from the controller, the order must be associated with an actual command and send it to the IOController" """Received an order from the controller, the order must be associated
with an actual command and send it to the IOController"""
try: try:
line,col=linecol line,col=linecol
trueline=self.ranges[line] trueline=self.ranges[line]
if trueline==0: # It's a press on layer A if trueline==0: # It's a press on layer A
self.layerPress((trueline,col),trueline,val,1) self.sendLayerInp(0,1,trueline+1,col+1)
print("L1") # print("L1")
elif trueline==1: # It's a press on layer B elif trueline==1: # It's a press on layer B
self.layerPress((trueline,col),trueline,val,1) self.sendLayerInp(0,1,trueline+1,col+1)
print("L2") # print("L2")
elif trueline==2: # It's a memory press elif trueline==2: # It's a memory press
self.memoryPress((trueline,col),val,0) self.sendMemoryChange(col,0)
print('MM') # print('MM')
else: else:
pass # The pulse only takes 3 lines pass # The pulse only takes 3 lines
except KeyError as e: except KeyError as e:
wprint("An error occured while the pulse was processing order",e) wprint("An error occured while the pulse rack module was processing order",e)
def layerCommand(self,screen,liveprev,layer,col): def receiveCommand(self,command,match,*args,**kwargs):
"Received a layer command from the handler, will now translate it for the pulse TODO: CLEAN THIS HORRENDOUS THING" "Received a command from the external program"
dprint("Received command to change layer:{} to {} on {}(live/prev)".format(layer,col,liveprev)) dprint("Received a command from the external program",command)
# self.returnInterface._IOInterface._externalProgram.changeLayer(screen,liveprev,layer,col) if command=="LAYERINP":
# Do the actual color changing self.receiveLayerInp(match)
# .changeLayer() elif command=="DETECTED":
self.receiveDetected(match)
def layerPress(self,linecol,layer,val,liveprev): def sendLayerInp(self,screen,liveprev,layer,idinput):
"Adjust the color and info depending on the press" # Bound to dissapear """Send a message to the pulse: Layer input change
self.idlastlayerpressed=layer screen: 0
line,col=linecol liveprev: 0 Live / 1 Prev
trueline=self.retunRanges[line] layer: 0(Frame) 1Pip1 2Pip2
truelinecol=(trueline,col) idinput: 0(Black) 1Input1 etc..
if liveprev==1: """
self.returnInterface._IOInterface.toExternalProgram("LAYERINP",screen,liveprev,layer,idinput)
self.returnInterface._IOInterface.toExternalProgram("SCRNUPD")
def receiveLayerInp(self,match):
"Received a message from the Pulse: Layer input was changed"
screen,ProgPrev,layer,src=[int(i) for i in match.group("postargs").split(",")]
theorical_line=layer-1 # The line it should be if it was indexed at 0
self.idlastlayerpressed=theorical_line
realline=self.returnRanges[theorical_line] # The actual line on the handler
realsrc=src-1
if ProgPrev==0:
color="Selected" color="Selected"
else: else:
color="Live" color="Live"
self.returnInterface.removeStatus((trueline,self.lastlayerpressed[layer]),color) self.returnInterface.removeStatus((realline,self.lastlayerpressed[theorical_line]),color)
self.returnInterface.addStatus(truelinecol,color) self.returnInterface.addStatus((realline,realsrc),color)
self.lastlayerpressed[layer]=col self.lastlayerpressed[theorical_line]=realsrc
self.returnInterface._IOInterface.sendAction("LAYERINP",0,liveprev,layer,col+1) # TODO : Clean this step
self.returnInterface._IOInterface.sendAction("SCRNUPD")
self.returnInterface.applyChanges() self.returnInterface.applyChanges()
self.returnInterface.applyColors() self.returnInterface.applyColors()
def memoryPress(self,linecol,val,liveprev): def receiveDetected(self,match):
"An input is detected on a position, update the controller"
def sendMemoryChange(self,memory,liveprev):
"""Adjust the color and info of a memory press (take or preview) """Adjust the color and info of a memory press (take or preview)
Should be Green if defined and Yellow if not, selecting makes it prev""" Should be Green if defined and Yellow if not, selecting makes it prev
line,col=linecol screenF,memory,screenT,ProgPrev,filter
# self.removeStatus((line,self.idlastmemorypressed),"Selected") """
# self.idlastmemorypressed=col self.returnInterface._IOInterface.toExternalProgram("LOADMM",0,memory,0,liveprev,0)
# self.addStatus(linecol,"Selected")
self._IOInterface.sendAction("LOADMM",col,liveprev)
# self.applyChanges()
# self.applyColors()
def __repr__(self): def __repr__(self):
return("PulseController{} ({self.idlastlayerpressed},{self.idlastmemorypressed})".format(list(self.ranges.keys()),self=self)) return("PulseRackController{} ({self.idlastlayerpressed},{self.idlastmemorypressed})".format(list(self.ranges.keys()),self=self))
class AkaiAPCMini(midiPageHandler): class AkaiAPCMini(midiPageHandler):
"A specific implementation of the page handler" "A specific implementation of the page handler"
@ -534,9 +550,9 @@ class AkaiAPCMini(midiPageHandler):
def lightnote(self,note,val=1): def lightnote(self,note,val=1):
self.output.send(mido.Message("note_on",note=note,velocity=val)) self.output.send(mido.Message("note_on",note=note,velocity=val))
def receiveAction(self,action,*args,**kwargs): # def receiveAction(self,action,*args,**kwargs):
"Receive an action from the pulse and transmit it to the handler" # "Receive an action from the pulse and transmit it to the handler"
dprint("ACTION TO BE HANDLED",action,args,kwargs) # dprint("ACTION TO BE HANDLED",action,args,kwargs)
# Do the changing of the light if layer press etc. # Do the changing of the light if layer press etc.
# Only hard part is knowing where # Only hard part is knowing where

View File

@ -12,17 +12,16 @@ from pythonAnalogWay import bindings
_VERBOSE=4 _VERBOSE=4
nopeF=lambda x:None nopeF=lambda *x:None
def printl(label=""): def printl(label=""):
def _pl(*args): def _pl(*args):
print(label,*args) print(label,*args)
return _pl return _pl
eprint=printl("[mPH:ERROR]") eprint=printl("[mPH:ERROR]")
dprint=nopeF dprint,ddprint,iprint,wprint=nopeF,nopeF,nopeF,nopeF
ddprint=nopeF bindings.dprint,bindings.ddprint,bindings.iprint=nopeF,nopeF,nopeF
iprint=nopeF
wprint=nopeF
if _VERBOSE>=1: if _VERBOSE>=1:
wprint=printl("[mPH:WARNING]") wprint=printl("[mPH:WARNING]")
if _VERBOSE>=2: if _VERBOSE>=2:
@ -61,20 +60,20 @@ def _onload(self):
#HOSTS=[["192.168.0.140",10500]] # Test server #HOSTS=[["192.168.0.140",10500]] # Test server
# The socket remote controller # The socket remote controller
controllerPulse=bindings.analogController(*HOSTS[0]) controllerPulse1=bindings.analogController(*HOSTS[0])
# Adding the midi interface to the controller # Adding the midi interface to the controller
handler.addInterfaceOut(self.interfaceOut(1)) handler.addInterfaceOut(self.interfaceOut(1))
# The pulse module, bound to 3 lines # The pulse module, bound to 3 lines
modulePulse=handler.addModule(midiPageHandler.pulseController,[4,1,2]) modulePulse=handler.addModule(midiPageHandler.pulseRackController,[4,1,2])
# The IO interface between the pulse and the controller, one IO is necessary per auxilliary application # The IO interface between the pulse and the controller, one IO is necessary per auxilliary application
IOInterface=midiPageHandler.IOInterfacePulse(handler,modulePulse,controllerPulse) IOInterface=midiPageHandler.IOInterfacePulse(handler,modulePulse,controllerPulse1)
# Finishing initialising the controller (Should be done in a thread to avoid locking) # Finishing initialising the controller (Should be done in a thread to avoid locking)
controllerPulse.addFeedbackInterface(IOInterface) controllerPulse1.addFeedbackInterface(IOInterface)
controllerPulse.connectionSequence() controllerPulse1.connectionSequence()
#controllerPulse.keepPinging() #controllerPulse.keepPinging()
except ConnectionRefusedError: except ConnectionRefusedError:
eprint("The connection to the pulse failed, check your settings and try again ({})".format(HOSTS)) eprint("The connection to the pulse failed, check your settings and try again ({})".format(HOSTS))

@ -1 +1 @@
Subproject commit 8a518ad83ea02a65a5d825c186ba87fa94ce6bb9 Subproject commit 0b339331624b51ea7c22126e4fe6230c3fa4521f