Still some minor addentum to the GMA parsing
This commit is contained in:
parent
b67ef34693
commit
bae2e0dcc6
|
|
@ -2,7 +2,9 @@ from mapping.base import BasicMessageParse,BasicActions,MatchError,BasicMidiInte
|
|||
import mido
|
||||
import re,configparser
|
||||
|
||||
commandlist={1:"go",2:"stop",3:"resume",4:"timed_go",6:"set",7:"fire",11:"go_off",10:"exec"}
|
||||
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
|
||||
|
||||
#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"""
|
||||
|
|
@ -36,6 +38,21 @@ class MessageParse(BasicMessageParse):
|
|||
|
||||
def __str__(self):
|
||||
return "<MessageParse>[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<mx:
|
||||
if data[i]==0:
|
||||
i+=1
|
||||
break
|
||||
elif data[i]==46:
|
||||
r+="."
|
||||
else:
|
||||
r+=str(int(data[i])-48)
|
||||
i+=1
|
||||
return r,data[i:]
|
||||
# An Action object MUST be included in the file.
|
||||
class Actions(BasicActions):
|
||||
"""The list of action to perform when a message is read"""
|
||||
|
|
@ -53,10 +70,20 @@ class Actions(BasicActions):
|
|||
id=int(data[0])
|
||||
# value=int(data[2])/128+int(data[3])/1.28 the percent value
|
||||
value=int(data[3]) # Just mapped from 0 to 127
|
||||
elif action=="fire":
|
||||
id=int(match.data) # Can only be from 0 to 255 ?
|
||||
value=""
|
||||
page=""
|
||||
elif action=="go":
|
||||
nb,info=addasHex(match.data) #Could do with clever division, but I don't want to right now
|
||||
info,null=addasHex(info)
|
||||
id,page=info.split('.')
|
||||
|
||||
id,page=int(id),int(page)
|
||||
value=int(float(nb)) # There needs to be a way to do without this
|
||||
elif action=="off":
|
||||
nb,info=addasHex(match.data) #Could do with clever division, but I don't want to right now
|
||||
info,null=addasHex(info)
|
||||
id,page=info.split('.')
|
||||
|
||||
id,page=int(id),int(page)
|
||||
value=int(float(nb))
|
||||
try:
|
||||
listact=self.findAction(action,id,page)
|
||||
for act in listact:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# This is the basic mapping of a midi message, all subsequent messages must either be children of this or implement those methods
|
||||
import configparser
|
||||
import mido,re
|
||||
from math import trunc
|
||||
|
||||
class BasicMidiInterface(object):
|
||||
"Basic midi interface"
|
||||
|
|
@ -127,7 +128,7 @@ class BasicActions(object):
|
|||
trigger.addspecial(atype,conf[key])
|
||||
elif "-" in key: # There is a range of values to map
|
||||
nmin,nmax=key.split("-")
|
||||
nmin,nmax=int(nmin),int(nmax)
|
||||
nmin,nmax=trunc(float(nmin)),trunc(float(nmax))
|
||||
for i in range(nmin,nmax):
|
||||
if i not in keys:
|
||||
keys[i]=[]
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ if __name__ == '__main__':
|
|||
|
||||
for msg in Inter.input:
|
||||
if args.verbose:
|
||||
print("[Received] {}".format(msg))
|
||||
try:
|
||||
print("[Received] {}".format(str.join([hex(i).split('x')[1] for i in msg.data])))
|
||||
except:
|
||||
print("[Received {}".format(msg))
|
||||
try:
|
||||
match=Par(msg)
|
||||
res=Acts(match)
|
||||
|
|
|
|||
|
|
@ -14,3 +14,7 @@
|
|||
#57-67 = 1/cc/12-32
|
||||
#56 = 1/note/127
|
||||
#56/val = lambda x: min(x,50)*2
|
||||
|
||||
[go]
|
||||
10 = 2/cc/1;2/cc/2;2/cc/3
|
||||
10/toggle = 0/45
|
||||
|
|
|
|||
Loading…
Reference in New Issue