Updated tests for Empty triggers

This commit is contained in:
dandaedre 2021-09-22 17:00:06 +02:00
parent 31f0fed565
commit e0a978cff2
4 changed files with 36 additions and 16 deletions

View File

@ -127,17 +127,17 @@ class BasicActions(object):
# print(type(key_i))
keys[key_i]=[]
if special:
trigg=EmptyTrigger(self)
trigg=EmptyTrigger(self,key_i)
trigg.addspecial(special,actions_t)
keys[key_i]+=[trigg]
else:
keys[key_i]+=self.makeAllKeys(key_i,actions_t,startkey=startkey,stopkey=stopkey)
for trigger in keys[key_i]:
if special:
trigger.addspecial(special,actions_t)
else:
keys[key_i]=self.makeAllKeys(key_i,actions_t,startkey=startkey,stopkey=stopkey) #Do a different trigger for every ; and link to a different interface for every n/
else:
for trigger in keys[key_i]:
if special:
trigger.addspecial(special,actions_t)
else:
keys[key_i]=self.makeAllKeys(key_i,actions_t,startkey=startkey,stopkey=stopkey) #Do a different trigger for every ; and link to a different interface for every n/
def makeTriggers(self,conf):
"Take a section of a config and put all triggers in a dict"
@ -274,6 +274,7 @@ class BasicMidiTrigger(object):
self.binded=binded
self.parent=parent
self.funct=None
self.params=None
self.received_note=received_note
message=RecognisedMessagesTypes[messagetype]
attributes={}
@ -352,10 +353,11 @@ class BasicMidiTrigger(object):
def execspecialfn(self,val):
"Executing a special function"
try:
vprint("[Sent:({}.)]: {} - Parameters : {}".format(self.interface_short_name,self.funct,self.params))
vprint("[Sent:({}.)]: {} - Note {} / Parameters : {}".format(self.interface_short_name,self.funct,self.received_note,self.params))
# self.funct(self.params)
if self.funct:
return self.funct(val,self.received_note,*self.params)
print("Done")
except Exception as e:
print("[ERROR] The function for trigger {} stopped in an unexpected way".format(self))
print("[ERROR] {}".format(e))
@ -371,7 +373,7 @@ class BasicMidiTrigger(object):
class EmptyTrigger(BasicMidiTrigger):
"""An empty trigger, used mainly for function only triggers"""
def __init__(self,parent):
def __init__(self,parent,note):
self.output=None
self.messagetype=None
self.intensity=None
@ -385,6 +387,9 @@ class EmptyTrigger(BasicMidiTrigger):
self.valuetype={}
self.message=None
self.funct=None
self.received_note=note
self.params=None
self.funct=None
def __call__(self, val):
"Send the message"

View File

@ -13,13 +13,20 @@ BASE_NOTE=56
def presskey(val,note,*params):
"Press the given keys"
print(val,note,params)
pass#print(val,note,params)
def switchinput(val,note,*params):
"Switch to the desired layer"
topress=BASE_NOTE-note+1
pyautogui.press("i",str(topress))
topress=note-BASE_NOTE+1
print(val,note)
pyautogui.hotkey("i",str(topress))
def takeall():
"TA"
pass
def mastermemory():
"M1"
# MidiInterface(config)
class MidiInterface(BasicMidiInterface):
"Adding a couple of custom functions"

View File

@ -7,10 +7,18 @@
mapping = keystrokes
[note_on]
1-99 = 1/on/1
1-99/toggle = 127/0
1-99/funct = presskey("a","z")
#1-99 = 1/on/1
#1-99/toggle = 127/0
56-63/funct = switchinput()
56 = 1/on/56/127;1/on/57/0 ;1/on/58/0 ;1/on/59/0 ;1/on/60/0 ;1/on/61/0 ;1/on/62/0 ;1/on/63/0
57 = 1/on/56/0 ;1/on/57/127;1/on/58/0 ;1/on/59/0 ;1/on/60/0 ;1/on/61/0 ;1/on/62/0 ;1/on/63/0
58 = 1/on/56/0 ;1/on/57/0 ;1/on/58/127;1/on/59/0 ;1/on/60/0 ;1/on/61/0 ;1/on/62/0 ;1/on/63/0
59 = 1/on/56/0 ;1/on/57/0 ;1/on/58/0 ;1/on/59/127;1/on/60/0 ;1/on/61/0 ;1/on/62/0 ;1/on/63/0
60 = 1/on/56/0 ;1/on/57/0 ;1/on/58/0 ;1/on/59/0 ;1/on/60/127;1/on/61/0 ;1/on/62/0 ;1/on/63/0
61 = 1/on/56/0 ;1/on/57/0 ;1/on/58/0 ;1/on/59/0 ;1/on/60/0 ;1/on/61/127;1/on/62/0 ;1/on/63/0
62 = 1/on/56/0 ;1/on/57/0 ;1/on/58/0 ;1/on/59/0 ;1/on/60/0 ;1/on/61/0 ;1/on/62/127;1/on/63/0
63 = 1/on/56/0 ;1/on/57/0 ;1/on/58/0 ;1/on/59/0 ;1/on/60/0 ;1/on/61/0 ;1/on/62/0 ;1/on/63/127
#[control_change]
# 16-18 = 2/cc/1

View File

@ -162,7 +162,7 @@ class mappingTest(minitest.simpleTestUnit):
# print(acts)
for act in acts:
#print(act,act.funct)
if not act.funct or not act.execspecialfn():
if not act.funct or not act.execspecialfn(55):
st=False
self.addFailure("No custom function defined")
break