from mapping.base import BasicMessageParse,BasicActions,MatchError,BasicMidiInterface import mido import re,configparser commandlist={1:"go",2:"stop",3:"resume",4:"timed_go",6:"set",7:"fire",10:"go_off"} # Doc says 11 is go_off, test says otherwise def testfunction(trigger,*params): print("testfunction used in GMA",trigger,params) return 1 # Not mandatory or even codex, just for testing purposes #A MessageParse object MUST be included in the file, the rest is implementation Specific class MessageParse(BasicMessageParse): """Parsing of a gma SyEx message this parser is used once and will return a different Action object every time it is called""" def __init__(self): #The data is converted from hex to decimal for readability and usability by mido self.deviceid=127 #Will usually be 127 for ALL self.commandformat=127 #1 is general lighting format, 2 is moving light format and 127 is ALL self.command=None #from 1 to 7 plus 11 (off) self.data=None #The actual data #very pretty solution that is actually not needed... #self.pattern=re.compile("240 127 (?P\d+) 0?2 (?P\d+) (?P\d+) (?P[\d+ ]+) 247") #The regex that will map the SysEx message self._commandlist=commandlist def __call__(self,message): "Parse the message and return either a match or raise an error" if message.type=="sysex": message=message.data else: raise MatchError("Message is not sysex") try: self.deviceid=message[1] self.commandformat=message[3] self.command=message[4] self.data=message[5:] #print(self) return self except: raise MatchError("Can't parse the data {}".format(message)) def __str__(self): return "[id:{}/df:{}/cmd:{}/data:{}]".format(self.deviceid,self.commandformat,self.command,self.data) def addasHex(data): "Take a table, return a str of every hex48 gma specific nb and the rest of the table" i,mx=0,len(data) r="" while i