Cleanish version of the remote, everything works but sooo unclean

This commit is contained in:
dandaedre 2021-10-17 17:46:56 +02:00
parent 930f658646
commit 18571ed657
6 changed files with 67 additions and 51 deletions

View File

@ -50,13 +50,9 @@ To do so add a custom patch (or use a currently defined one, but chances are pat
* TODO: Pagehandler: make a note handler
* TODO: Color management, get colors associated to all statuses
* TODO: General decorators @armtake
<<<<<<< HEAD
* TODO: Do a cleaner page printl
* TODO: Do all page tests
=======
* URGENT : Fix the connection issue
* TODO: More explicit midi output/input connection error (and backup or exit)
* TODO: CLEAN CONNECTION TO A RACK, ANYTHING BUT THIS CLUSTERF*CK
* TODO: Connect the IOHandler with handler, binding and vice-versa, check some.
>>>>>>> 24c2b19a5859b51b3f1036f08524b130635161c1
* TODO : Clean this step : Do a better IO handler

View File

@ -9,6 +9,10 @@ from random import randint
def dprint(message):
pass
class ModuleLoadingError(Exception):
def __init__(self,*args,**kwargs):
pass
class BasicMidiInterface(object):
"Basic midi interface"
def __init__(self,configfile):

View File

@ -40,17 +40,17 @@ class IOInterface():
def addActionIO(self,matchName,action):
"""Associate a function to a match to a message received
[externalP] -> Action -> [Handler]
[Handler] -> Action -> [externalP]
"""
self._listActionsIO[matchName]=action
def addActionH(self,name,action):
"""Associate a function to match to a handler action
[Handler] -> Action -> [externalP]
[externalP] -> Action -> [Handler]
"""
self._listActionsH[name]=action
def messageReceived(self,typeM,messageMatch,*args):
def receiveAction(self,typeM,messageMatch,*args):
"""Acknoledge a message and do the appropriate actions
[externalP] -> messageReceived -> Action -> [Handler]
"""
@ -59,8 +59,9 @@ class IOInterface():
self._listActionsIO[typeM](messageMatch,*args)
except KeyError:
wprint("The message type doesn't exits",typeM)
self._pageHandler.sendAction(typeM,messageMatch,*args)
def noteReceived(self,note,val):
def receiveNote(self,note,val):
"""Acknoledge a control received and do the appropriate actions
[internalMidiAction] -> [Handler]
"""
@ -89,11 +90,22 @@ class IOInterfacePulse(IOInterface):
self.addActionIO("LOADMM",self._externalProgram.loadMM)
self.addActionIO("QUICKF",self._externalProgram.quickFrame)
self.addActionIO("FREEZE",self._externalProgram.freezeScreenAll)
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):
"""A message was received from the pulse and will be redirected to the controller
"""
self._pageHandler.receiveAction(command,*args,**kwargs)
def receiveCommand(self,command,*args,**kwargs):
"A message was received from the handler and will be redirected to the pulse"
self._externalProgram.receiveMessage(command,*args,**kwargs)
class midiPageHandler(object):
"Page Handler, with some methods to manage a midi remote more easily"
@ -133,6 +145,7 @@ class midiPageHandler(object):
def noteReceived(self,note,val):
"A note has been received, do the appropriate actions"
pass
####################
# Manage attributes
def _makeNotes(self,table):
@ -386,9 +399,10 @@ class pulseController(object):
line,col=linecol
trueline=self.ranges[line]
if trueline==0: # It's a press on layer A
self.layerPress((trueline,col),trueline,val,0)
self.layerPress((trueline,col),trueline,val,1)
elif trueline==1: # It's a press on layer B
self.layerPress((trueline,col),trueline,val,0)
self.layerPress((trueline,col),trueline,val,1)
print("L2")
elif trueline==2: # It's a memory press
self.memoryPress((trueline,col),val,0)
else:
@ -409,13 +423,15 @@ class pulseController(object):
line,col=linecol
trueline=self.retunRanges[line]
truelinecol=(trueline,col)
self.returnInterface.removeStatus((trueline,self.lastlayerpressed[layer]),"Selected")
self.lastlayerpressed[layer]=col
self.returnInterface._IOInterface.sendAction("LAYERINP",0,liveprev,layer,col)
if liveprev==0:
self.returnInterface.addStatus(truelinecol,"Selected")
if liveprev==1:
color="Selected"
else:
self.returnInterface.addStatus(truelinecol,"Live")
color="Live"
self.returnInterface.removeStatus((trueline,self.lastlayerpressed[layer]),color)
self.returnInterface.addStatus(truelinecol,color)
self.lastlayerpressed[layer]=col
self.returnInterface._IOInterface.sendAction("LAYERINP",0,liveprev,layer,col+1) # TODO : Clean this step
self.returnInterface._IOInterface.sendAction("SCRNUPD")
self.returnInterface.applyChanges()
self.returnInterface.applyColors()
@ -517,6 +533,9 @@ class AkaiAPCMini(midiPageHandler):
self.output.send(mido.Message("note_on",note=note,velocity=val))
def receiveAction(self,action,*args,**kwargs):
"Receive an action from the pulse and transmit it to the handler"
dprint("ACTION TO BE HANDLED",action,args,kwargs)
_TEST=True
if __name__ == '__main__':
@ -543,10 +562,6 @@ if __name__ == '__main__':
ak.prettyPrint(ak._changedbasevalues)
print(ak.statusId(("Active","Selected","Live")))
<<<<<<< HEAD:mapping/midiPageHandler.py
# ak.
# light=lightHandler(ak.listStatus(),{})
=======
ak.addStatus((3,3),"Active")
ak.addStatus((3,3),"Active")
@ -564,5 +579,4 @@ if __name__ == '__main__':
for note,val in ak.listNoteChanges():
print (note,val)
print(ak.colorFrom((3,3)),ak.noteFrom((3,3)))
>>>>>>> 24c2b19a5859b51b3f1036f08524b130635161c1:mapping/midipagehandler.py
print(ak.colorFrom((3,3)),ak.noteFrom((3,3)))

View File

@ -32,6 +32,7 @@ if _VERBOSE>=3:
if _VERBOSE>=4:
ddprint=printl("[mPH:DDEBUG]")
_COLORS={"black":0,"green":1,"blinking_green":2,"red":3,"blinking_red":4,"yellow":5,"blinking_yellow":6}
#################################################
@ -55,46 +56,40 @@ class pulseLink(object):
def _onload(self):
"Send a reset colors"
import time,sys
<<<<<<< HEAD
# handler.prettyPrint(handler._activebasevalues)
#vars.output=self.outputs[vars.interface_nb]
def pagepress(trigger,val,note,*params):
"A key was pressed on the pagebuttons area"
try:
pos=handler._noteToPos[note]
#,handler._posToNote[pos[0],pos[1]]
dprint("Received {} (note:{})".format(pos,note))
# HOSTS=[["127.0.0.1",3000]] # Test server
HOSTS=[["192.168.0.140",10500]] # Test server
# The socket remote controller
controllerPulse=bindings.analogController(*HOSTS[0])
=======
HOSTS=[["127.0.0.1",3000]] # Test server
# The socket remote controller
controllerPulse=bindings.analogController(*HOSTS[0])
# Adding the midi interface to the controller
handler.addInterfaceOut(self.interfaceOut(1))
# Adding the midi interface to the controller
handler.addInterfaceOut(self.interfaceOut(1))
# The pulse module, bound to 3 lines
modulePulse=handler.addModule(midiPageHandler.pulseController,[4,1,2])
# The pulse module, bound to 3 lines
modulePulse=handler.addModule(midiPageHandler.pulseController,[4,1,2])
# The IO interface between the pulse and the controller, one IO is necessary per auxilliary application
IOInterface=midiPageHandler.IOInterfacePulse(handler,modulePulse,controllerPulse)
# Finishing initialising the controller (Should be done in a thread to avoid locking)
controllerPulse.addFeedbackInterface(IOInterface)
controllerPulse.connectionSequence()
#controllerPulse.keepPinging()
except ConnectionRefusedError:
eprint("The connection to the pulse failed, check your settings and try again ({})".format(HOSTS))
# The IO interface between the pulse and the controller, one IO is necessary per auxilliary application
IOInterface=midiPageHandler.IOInterfacePulse(handler,modulePulse,controllerPulse)
# Finishing initialising the controller (Should be done in a thread to avoid locking)
controllerPulse.addFeedbackInterface(IOInterface)
controllerPulse.connectionSequence()
#controllerPulse.keepPinging()
def pagepress(trigger,val,note,*params):
"A key was pressed on the pagebuttons area"
try:
# print(handler._noteToPos[note])
handler.noteReceived(note,val)
>>>>>>> 24c2b19a5859b51b3f1036f08524b130635161c1
except TypeError as e:
eprint("[Error] : Unassigned pagebutton {} - Note {:2} ({:3})".format(trigger,note,val))
eprint(e)
except SystemExit as e:
eprint("The Pulse requested a SystemExit (likely due to a connection interrupted), please check your settings")
@doublepress
def quitpress(trigger,val,note,*params):

View File

@ -2,7 +2,7 @@
import mido, argparse, sys
import configparser,importlib,mapping
import traceback
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Listen to a midi interface for incomming messages and send messages to different midi interfaces according to a patch file')
@ -47,15 +47,22 @@ if __name__ == '__main__':
print("[Unexpected error@midibind.py] {}".format(sys.exc_info()))
except ImportError as e:
print("[Error] There was an error loading module {} ({})".format(interpath,e))
traceback.print_exc()
except KeyError as e:
print("[Error] There was an error while loading patch {} ({})".format(path,e))
traceback.print_exc()
except KeyboardInterrupt:
print("[Keyboard Interrupt] : Exiting...")
sys.exit()
except ConnectionRefusedError as e:
print("A connection was refused during the execution of the program and remained uncatched")
traceback.print_exc()
except OSError as e:
print('[Error] The patch "patch/{}.ini" is ill-formed or non-existent'.format(args.patch))
print(e)
traceback.print_exc()
except TypeError as e:
print("[Error] Can't iterate over an empty list, check the list of inputs for an available input")
print(e)
traceback.print_exc()
# except:

@ -1 +1 @@
Subproject commit 298c6799e7058cddc408d070ac6dd94ffcd85551
Subproject commit 5e737f8d557ce8d932418152df0c804339ec4df1