diff --git a/README.md b/README.md index 0f70c2f..1ec7ff6 100644 --- a/README.md +++ b/README.md @@ -42,5 +42,11 @@ To do so add a custom patch (or use a currently defined one, but chances are pat * URGENT : Crash when assigning to an existing trigger * TODO: Make a @armtake decorator * TODO: Async and Disconnection protect for VPs -* TODO: Disconnect: 'NoneType' object has no attribute 'groups' : Should handle disconnct & Crashes +* TODO: Disconnect: 'NoneType' object has no attribute 'groups' : Should handle disconnect & Crashes * TODO: Color and uncolor VP as it connects +* TODO: Unified verbose printing & usage + + +* TODO: Pagehandler: make a note handler +* TODO: Color management, get colors associated to all statuses +* TODO: General decorators @armtake diff --git a/mapping/base.py b/mapping/base.py index 7e4764b..d99d2ce 100644 --- a/mapping/base.py +++ b/mapping/base.py @@ -4,8 +4,9 @@ import mido,re from math import trunc from math import sin,cos,tan from random import randint - -def vprint(message): +# import traceback +# print(traceback.print_stack()) +def dprint(message): pass class BasicMidiInterface(object): @@ -264,7 +265,7 @@ class MatchError(Exception): class BasicMidiTrigger(object): """A midi trigger, will do a specific action when called""" def __init__(self,interface,parent,messagetype,value,intensity,binded,received_note): - #self.vprint=vprint + #self.dprint=dprint self.output=interface self.messagetype=messagetype self.value=value @@ -314,7 +315,7 @@ class BasicMidiTrigger(object): self.message=self.message.copy(**self.valuetype) def sendmessage(self,val): - vprint("[Sent:({}.)]: {}".format(self.interface.name.split(":")[1][:12],self.message)) + dprint("[Sent:({}.)]: {}".format(self.interface.name.split(":")[1][:12],self.message)) if self.toggle!=None: self.toggle=not self.toggle self.interface.send(self.message) @@ -354,11 +355,14 @@ class BasicMidiTrigger(object): def execspecialfn(self,val): "Executing a special function" try: - vprint("[Sent:({}.)]: Note {} / Parameters : {}".format(self.interface_short_name,self.received_note,self.params)) + dprint("[Sent:({}.)]: Note {} / Parameters : {}".format(self.interface_short_name,self.received_note,self.params)) # self.funct(self.params) + if self.funct: - vprint("[Sending function {} - Note {} / Parameters : {}".format(self.funct.__name__,self.received_note,self.params)) + dprint("[Sending function {} - Note {} / Parameters : {}".format(self.funct.__name__,self.received_note,self.params)) return self.funct(self,val,self.received_note,*self.params) + except KeyboardInterrupt: + sys.exit() except Exception as e: print("[ERROR] The function for trigger {} stopped in an unexpected way".format(self)) print("[ERROR] {}".format(e)) @@ -394,7 +398,7 @@ class EmptyTrigger(BasicMidiTrigger): def __call__(self, val): "Send the message" - vprint("[Sending function (call) {} - Note {} / Parameters : {}".format(self.funct.__name__,self.received_note,self.params)) + dprint("[Sending function (call) {} - Note {} / Parameters : {}".format(self.funct.__name__,self.received_note,self.params)) self.execspecialfn(val) def changevalue(self,val): @@ -403,10 +407,9 @@ class EmptyTrigger(BasicMidiTrigger): def sendmessage(self,val): "It's empty, can't send any message" - vprint("[Sending function (send) {} - Note {} / Parameters : {}".format(self.funct,self.received_note,self.params)) + dprint("[Sending function (send) {} - Note {} / Parameters : {}".format(self.funct,self.received_note,self.params)) self.execspecialfn(val) - def addvalfn(self,nf): "There's no value to ajust" pass diff --git a/mapping/midi.py b/mapping/midi.py index 9934b22..2b9f0b2 100644 --- a/mapping/midi.py +++ b/mapping/midi.py @@ -1,6 +1,6 @@ from mapping.base import BasicMessageParse,BasicActions,MatchError,BasicMidiInterface import mido -import configparser +import configparser,sys #A MessageParse object MUST be included in the file, the rest is implementation Specific class MessageParse(BasicMessageParse): @@ -51,6 +51,8 @@ class Actions(BasicActions): listact=self.findAction(match.type,match.note,"*") for act in listact: act(match.value) + except SystemExit: + sys.exit() except: # No action linked to the trigger pass diff --git a/mapping/midipagehandler.py b/mapping/midipagehandler.py index 5a3b828..cdc5b9c 100644 --- a/mapping/midipagehandler.py +++ b/mapping/midipagehandler.py @@ -28,6 +28,33 @@ if _VERBOSE>=4: ########################### # CLASS DEFINES +class lightHandler(): + def __init__(self): + self.page=0 + + self.interface_nb=1 + self.output=None + + self.listchange=[] + self.lastpress=(None,None) #Does only account for the 8x8 + self.selected_pulse=(None,None) + self.live_pulse=(None,None) + + # Should do it in a similar way, cant find it + def addChange(self,i,j,value,reset=True): #mode=_OR + "Do a value change, store the change for update" + if i==None or j==None: + return + self.listchange+=[[i,j,value,reset]] + + def lightcolor(self,col,row,color): + self.light(col,row,val=_COLORS[color]) + + def light(self,col,row,val=1): + self.lightnote(self.findit(col,row),val) + + def lightnote(self,note,val=1): + self.output.send(mido.Message("note_on",note=note,velocity=val)) class midiPageHandler(object): "Page Handler, with some methods to manage a midi remote more easily" diff --git a/mapping/panapulse.py b/mapping/panapulse.py index 2e3ad34..5d1f8f7 100644 --- a/mapping/panapulse.py +++ b/mapping/panapulse.py @@ -2,7 +2,32 @@ from mapping.base import BasicMessageParse,BasicActions,MatchError,BasicMidiInte import mido from mapping.midi import MessageParse from mapping.midi import Actions +import sys +########################### +# FUNCTION DEFINES + +_VERBOSE=4 + +nopeF=lambda x:None +def printl(label=""): + def _pl(*args): + print(label,*args) + return _pl + +eprint=printl("[mPH:ERROR]") +dprint=nopeF +ddprint=nopeF +iprint=nopeF +wprint=nopeF +if _VERBOSE>=1: + wprint=printl("[mPH:WARNING]") +if _VERBOSE>=2: + iprint=printl("[mPH:INFO]") +if _VERBOSE>=3: + dprint=printl("[mPH:DEBUG]") +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} @@ -10,8 +35,9 @@ _COLORS={"black":0,"green":1,"blinking_green":2,"red":3,"blinking_red":4,"yellow # GLOBAL CONTROL ### -#import midiPageHandler -#create a var thingy +from mapping import midiPageHandler + +handler=midiPageHandler.AkaiAPCMini() def _onload(self): "Send a reset colors" @@ -20,15 +46,16 @@ def _onload(self): def pagepress(trigger,val,note,*params): "A key was pressed on the pagebuttons area" - #i,j=noteToPos(note) try: - pass - #_ACTIONS[vars.page][i+8*j](trigger,i,j,val,*params) - # dprint("[Info] : Action received ({}:{}) - Note {:2} ({:3})".format(i,j,note,val)) + print(handler._noteToPos[note]) except TypeError as e: - eprint("[Error] : Unassigned pagebutton ({}:{}) - Note {:2} ({:3})".format(i,j,note,val)) + eprint("[Error] : Unassigned pagebutton {} - Note {:2} ({:3})".format(trigger,note,val)) eprint(e) +def quitpress(trigger,val,note,*params): + print("Quitting...") + sys.exit() + #################################################### # INTERFACE DEFINITION ##### @@ -40,3 +67,4 @@ class MidiInterface(BasicMidiInterface): super(MidiInterface,self).__init__(configfile) _onload(self) self.functionlist["pagepress"]=pagepress + self.functionlist["quitpress"]=quitpress diff --git a/midiRebind.py b/midiRebind.py index f62930a..2f194eb 100755 --- a/midiRebind.py +++ b/midiRebind.py @@ -38,18 +38,19 @@ if __name__ == '__main__': match=Par(msg) res=Acts(match) except Module.MatchError: - pass + print("[Error] Command in {} could not be matched".format(msg)) except KeyError: - vprint("[Error] Command in {} could not be recognised".format(msg)) + print("[Error] Command in {} could not be recognised".format(msg)) + except SystemExit: + sys.exit() except: - print("[Unexpected error@midibind.py] {}".format(sys.exc_info())) + print("[Unexpected error@midibind.py] {}".format(sys.exc_info())) except ImportError as e: print("[Error] There was an error loading module {} ({})".format(interpath,e)) except KeyError as e: print("[Error] There was an error while loading patch {} ({})".format(path,e)) except KeyboardInterrupt: print("[Keyboard Interrupt] : Exiting...") - #del Inter sys.exit() except OSError as e: print('[Error] The patch "patch/{}.ini" is ill-formed or non-existent'.format(args.patch)) @@ -57,4 +58,4 @@ if __name__ == '__main__': except TypeError as e: print("[Error] Can't iterate over an empty list, check the list of inputs for an available input") print(e) - # except KeyError + # except: diff --git a/patch/panapulse.ini b/patch/panapulse.ini new file mode 100644 index 0000000..3cb336d --- /dev/null +++ b/patch/panapulse.ini @@ -0,0 +1,11 @@ +[interface] + input=APC MINI 2 + output1=APC MINI 3 + inputchanel = 1 + outputchannel1 = 1 + #outputchannel2 = 1 + mapping = panapulse + +[note_on] + 0-88/funct = pagepress() + 89/funct = quitpress()