Finishing the action/midi triggers
This commit is contained in:
parent
32f4bc4e87
commit
185ce923e3
26
README.md
26
README.md
|
|
@ -3,5 +3,29 @@ Get/send midi commands to a GrandMA but can be configured to bind any custom Sys
|
|||
To do so add a custom patch (or use a currently defined one, but chances are patches made for one SysEx won't work on another) and add a parser in the mapping directory
|
||||
|
||||
# Depends
|
||||
* Mostly mido (pip install mido) for the midi binding and blessings for the testing (pip install belssings)
|
||||
* Mostly mido (pip install mido) for the midi binding and blessings for the testing (pip install blessings)
|
||||
* test.py depends on the submodule minitest witch also depends on blessings but is not necessary
|
||||
|
||||
# Config Syntax
|
||||
|
||||
* [interface] : All important information concerning the midi interface
|
||||
* input : Choose which Midi interface to listen to
|
||||
* output1 : Choose which Midi interface to output to; an arbitrary number can be specified that way
|
||||
* inputchanel : Which midi channel to listen to
|
||||
* outputchannel1 : Which midi channel to output to
|
||||
* mapping : The python file in mapping to setup all the mapping between input and output
|
||||
|
||||
[set/1] #Patches layer 1 patch:2 would patch layer 2 and so on
|
||||
1 = 1/cc/10 #Send (midi) control change (10) with value mapped to the fader (1) value (fader 1 => cc 10) on output 1
|
||||
5-50 = 1/cc/11 #Map the faders 5-50 to the control change 11-45 (Straight patch) on output 1
|
||||
57-67 = 1/cc/12-32 # Will map linearly 57 to 12; 58 to 14 etc on output 1
|
||||
56 = 2/note/152 #Map fader 56 to note 152 on output 2
|
||||
56/cond = lambda x: x==50 # Function choosing conditions on the value to send
|
||||
[fire] #No layer specified
|
||||
13 = 1/note/10
|
||||
15 = 1/cc/44/127 #Send control change with value 127
|
||||
17-27 = cc/45/127 # Send control change 45-55 with value 127
|
||||
38 = 1/cc/65/124;2/cc/79/100;note/25 (Stack the action to link to)
|
||||
|
||||
# Adding another mapping interface
|
||||
*
|
||||
|
|
|
|||
|
|
@ -36,47 +36,102 @@ class Action(BasicAction):
|
|||
self.config=configparser.ConfigParser()
|
||||
self.config.read(config)
|
||||
self.sections={}
|
||||
self.outputs={} #Have every output in a dict
|
||||
self.dec10=[str(x) for x in range(10)]
|
||||
# Parse config & check sanity
|
||||
if "interface" not in self.config:
|
||||
raise IOError #You must define an interface to connect to
|
||||
self.populateSections()
|
||||
print self.sections
|
||||
|
||||
# Create all the call setups
|
||||
def populateSections(self):
|
||||
"Create all the call setups"
|
||||
for elt in self.config.sections():
|
||||
if elt !="interface":
|
||||
if "/" in elt:
|
||||
selt=elt.split("/")
|
||||
if selt[0] not in self.sections:
|
||||
self.sections[selt[0]]={}
|
||||
self.sections[selt[0]].update({selt[1]:self.config[elt]})
|
||||
self.sections[selt[0]].update({selt[1]:self.makeTriggers(self.config[elt])})
|
||||
else:
|
||||
if elt in self.sections:
|
||||
if "*" not in self.sections[elt]:
|
||||
self.sections[elt]["*"]=self.config[elt]
|
||||
self.sections[elt]["*"]=self.makeTriggers(self.config[elt])
|
||||
# This means you will override any "/x" config
|
||||
else:
|
||||
self.sections[elt]={"*":self.config[elt]}
|
||||
self.sections[elt]={"*":self.makeTriggers(self.config[elt])}
|
||||
|
||||
def makeTriggers(self,conf):
|
||||
"Take a section of a config and put all triggers in a dict"
|
||||
keys={}
|
||||
for key in conf: # Reading every mapping and liking it to the appropriate Trigger
|
||||
if "/" in key: # There is a condition to an action
|
||||
note,ctype=key.split("/")
|
||||
if "-" in note:
|
||||
nmin,nmax=note.split("-")
|
||||
nmin,nmax=int(nmin),int(nmax)
|
||||
for i in range(nmin,nmax):
|
||||
pass#keys[i].condition(ctype,conf[key])
|
||||
else:
|
||||
pass#keys[note].condition(ctype,conf[key])
|
||||
elif "-" in key: # There is a range of values to map
|
||||
nmin,nmax=key.split("-")
|
||||
nmin,nmax=int(nmin),int(nmax)
|
||||
for i in range(nmin,nmax):
|
||||
keys[i]=self.makeAllKeys(i,conf[key],startkey=nmin,stopkey=nmax) #Do a different trigger for every ; and link to a different interface for every n/
|
||||
else: # Nothing fancy
|
||||
keys[int(key)]=self.makeAllKeys(int(key),conf[key])
|
||||
return keys
|
||||
|
||||
def makeAllKeys(self,key,action,startkey=0,stopkey=0):
|
||||
"""Make all the actions associated with the key
|
||||
startkey and stopkey indicate if an interpolation over the values is to be made"""
|
||||
#print key,action,startkey,stopkey
|
||||
#Check if there are multiple actions to do
|
||||
if ';' in action:
|
||||
allactions=[]
|
||||
for a in action.split(";"):
|
||||
#print a
|
||||
allactions+=self.makeAllKeys(key,a,startkey,stopkey)
|
||||
return allactions
|
||||
try:
|
||||
pack=action.split("/")
|
||||
if len(pack)==4:
|
||||
interfaceout,midiaction,note,intensity=pack
|
||||
elif len(pack)==2:
|
||||
midiaction,note=pack
|
||||
interfaceout,intensity=1,127
|
||||
elif len(pack)==3:
|
||||
if pack[0][0] not in self.dec10:
|
||||
midiaction,note,intensity=pack
|
||||
interfaceout=1
|
||||
else:
|
||||
interfaceout,midiaction,note=pack
|
||||
intensity=127
|
||||
else:
|
||||
raise ValueError
|
||||
#print "io:{} act:{} note:{} int:{}".format(interfaceout,midiaction,note,intensity)
|
||||
intensity,interfaceout=int(intensity),int(interfaceout)
|
||||
except:
|
||||
print("Config key {} is incorrect, values {} can't be unpacked".format(key,action))
|
||||
|
||||
|
||||
# Populate all the function calls with the data of the config sections
|
||||
for elt in self.sections: #Going in every section
|
||||
for group in self.sections[elt]: # Going in every sub-group
|
||||
conf,self.sections[elt][group]=self.sections[elt][group],{} #Replacing the links to the config with the real dict of links
|
||||
for key in conf: # Reading every mapping and liking it to the appropriate Trigger
|
||||
if "/" in key: # There is a condition to an action
|
||||
note,ctype=key.split("/")
|
||||
if "-" in note:
|
||||
nmin,nmax=note.split("-")
|
||||
for i in range(nmin,nmax):
|
||||
conf.sections[elt][group][i].condition(ctype,conf[key])
|
||||
else:
|
||||
conf.sections[elt][group][note].condition(ctype,conf[key])
|
||||
elif "-" in key: # There is a range of values to map
|
||||
nmin,nmax=key.split("-")
|
||||
for i in range(nmin,nmax):
|
||||
conf.sections[elt][group][i]=MidiTrigger() #Do a different trigger for every ; and link to a different interface for every n/
|
||||
else: # Nothing fancy
|
||||
self.sections[elt][group][key]=MidiTrigger()
|
||||
return [MidiTrigger(interfaceout,midiaction,note,self.findIntensity(key,startkey,stopkey,note))]
|
||||
|
||||
def findIntensity(self,key,startkey,stopkey,note):
|
||||
if startkey!=stopkey: #do an interpolation over the values
|
||||
if "-" in note: #there is a range to interpolate over to
|
||||
nmin,nmax=note.split("-")
|
||||
nmin,nmax=int(nmin),int(nmax)
|
||||
else:
|
||||
nmin=int(note)
|
||||
nmax=nmin+stopkey-startkey #Just do the interpolation linearly
|
||||
if nmax-nmin!=stopkey-startkey:
|
||||
pad=(nmax-nmin)/(stopkey-startkey)
|
||||
else:
|
||||
pad=1
|
||||
return nmin+(key-startkey)*pad
|
||||
return int(note)
|
||||
def format(self,command,number,page):
|
||||
"Format a match to call the correct action"
|
||||
try:
|
||||
|
|
@ -90,12 +145,17 @@ class Action(BasicAction):
|
|||
# Try a predefined action
|
||||
pass
|
||||
|
||||
FTrue=lambda x: True
|
||||
|
||||
class MidiTrigger(object):
|
||||
"""A midi trigger, will do a specific action when called"""
|
||||
def __init__(self,interface,message):
|
||||
def __init__(self,interface,messagetype,value,intensity):
|
||||
self.output=interface
|
||||
self.message=message
|
||||
self.cond=False
|
||||
self.messagetype=messagetype
|
||||
self.value=value
|
||||
self.intensity=intensity
|
||||
self.condition=FTrue
|
||||
|
||||
def __call__(self,val):
|
||||
"""Execute the call if the condition is true"""
|
||||
pass
|
||||
|
|
@ -104,5 +164,8 @@ class MidiTrigger(object):
|
|||
"""Affect a specific action (usually a condition) to the execution of the event"""
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
return "MidiTrigger({}/{}/{})@{}".format(self.messagetype,self.value,self.intensity,self.output)
|
||||
|
||||
class MatchError(Exception):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -5,18 +5,31 @@
|
|||
inputchanel = 1
|
||||
outputchannel1 = 1
|
||||
outputchannel2 = 1
|
||||
mapping = GrandMA2 # Will fetch GrandMA2.py in the mappings
|
||||
# Will fetch GrandMA2.py in the mappings
|
||||
mapping = GrandMA2
|
||||
|
||||
#Patching faders
|
||||
[set/1] #Patches layer 1 patch:2 would patch layer 2 and so on
|
||||
1 = 1/cc/10 #Send (midi) control change (10) with value mapped to the fader (1) value (fader 1 => cc 10) on output 1
|
||||
5-50 = 1/cc/11 #Map the faders 5-50 to the control change 11-45 (Straight patch) on output 1
|
||||
57-67 = 1/cc/12-32 # Will map linearly 57 to 12; 58 to 14 etc on output 1
|
||||
56 = 2/note/152 #Map fader 56 to note 152 on output 2
|
||||
56/cond = lambda x: x==50 # Function choosing conditions on the value to send
|
||||
#Patching faders: Patches layer 1 patch:2 would patch layer 2 and so on
|
||||
[set/1]
|
||||
#Send (midi) control change (10) with value mapped to the fader (1) value (fader 1 => cc 10) on output 1
|
||||
1 = 1/cc/10
|
||||
#Map the faders 5-50 to the control change 11-45 (Straight patch) on output 1
|
||||
5-50 = 1/cc/11
|
||||
# Will map linearly 57 to 12; 58 to 14 etc on output 1
|
||||
57-67 = 1/cc/12-32
|
||||
#Map fader 56 to note 152 on output 2
|
||||
56 = 2/note/152
|
||||
# Function choosing the value to send, depending on the intensity received
|
||||
56/val = lambda x: min(x,50)
|
||||
|
||||
[fire] #No layer specified
|
||||
13 = 1/note/10
|
||||
15 = 1/cc/44/127 #Send control change with value 127
|
||||
17-27 = cc/45/127 # Send control change 45-55 with value 127
|
||||
38 = 1/cc/65/124;2/cc/79/100;note/25 (Stack the action to link to)
|
||||
|
||||
#No layer specified
|
||||
[fire]
|
||||
13 = 1/note/10
|
||||
#Send control change with value 127
|
||||
15 = 1/cc/44/127
|
||||
# Send control change 45-55 with value 127
|
||||
17-27 = cc/45/127
|
||||
# Will map 29 to 37 to 46
|
||||
29-37 = cc/46-46/127
|
||||
#(Stack the action to link to)
|
||||
38 = 1/cc/65/124;2/cc/79/100;note/25
|
||||
|
|
|
|||
Loading…
Reference in New Issue