From 02e8412ca08a5e65265388ee90b318ea1cae5fd5 Mon Sep 17 00:00:00 2001 From: dandaedre Date: Tue, 21 Sep 2021 11:46:42 +0200 Subject: [PATCH] Adding support for APC mini --- README.md | 2 + mapping/keystrokes.py | 118 ++++++++++++++++++++++-------------------- midiRebind.py | 6 ++- minitest | 2 +- patch/pulse.ini | 19 +++++++ 5 files changed, 88 insertions(+), 59 deletions(-) create mode 100644 patch/pulse.ini diff --git a/README.md b/README.md index 0a166c7..0e7eb08 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,5 @@ To do so add a custom patch (or use a currently defined one, but chances are pat * Add Fade (in ms) from one value to another * Have a way to know last value for the note/cc (the last one sent/received) * Make toggles a function modifying a variable/state and sending result +* Allow for a multi-in interfaces +* Allow for a null interface out diff --git a/mapping/keystrokes.py b/mapping/keystrokes.py index ec4ce1e..0554076 100644 --- a/mapping/keystrokes.py +++ b/mapping/keystrokes.py @@ -1,6 +1,5 @@ #!/bin/python3 - # import pyautogui from mapping.base import BasicMessageParse,BasicActions,MatchError,BasicMidiInterface import mido @@ -8,64 +7,71 @@ import re,configparser #A MessageParse object MUST be included in the file, the rest is implementation Specific -class MessageParse(BasicMessageParse): - """Parsing of a midi 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.type=None #note_off note_on control_change program_change sysex (technically all the others but we don't care much for it) - self.channel=0 #0 by default, but can be anything - self.note=None #0 - 127 (it will be the program in program_change etc...) - self.value=None #The actual value, sometimes None - - def __call__(self,message): - "Parse the message and return either a match or raise an error" - self.type=message.type - try: - if message.type=="note_off" or message.type=="note_on": - self.channel=message.channel - self.note=message.note - self.value=message.velocity - elif message.type=="control_change": - self.channel=message.channel - self.note=message.control - self.value=message.value - elif message.type=="program_change": - self.channel=message.channel - self.note=message.program - self.value=None - else: - raise MatchError("Message is not either note_off, note_on, control_change or program_change") - return self - except: - raise MatchError("Can't parse the data {}".format(message)) - - def __str__(self): - return "[ty:{}/note:{}/value:{}]@{}".format(self.type,self.note,self.value,self.channel) +from mapping.midi import MessageParse +# class MessageParse(BasicMessageParse): +# """Parsing of a midi 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.type=None #note_off note_on control_change program_change sysex (technically all the others but we don't care much for it) +# self.channel=0 #0 by default, but can be anything +# self.note=None #0 - 127 (it will be the program in program_change etc...) +# self.value=None #The actual value, sometimes None +# +# def __call__(self,message): +# "Parse the message and return either a match or raise an error" +# self.type=message.type +# try: +# if message.type=="note_off" or message.type=="note_on": +# self.channel=message.channel +# self.note=message.note +# self.value=message.velocity +# elif message.type=="control_change": +# self.channel=message.channel +# self.note=message.control +# self.value=message.value +# elif message.type=="program_change": +# self.channel=message.channel +# self.note=message.program +# self.value=None +# else: +# raise MatchError("Message is not either note_off, note_on, control_change or program_change") +# return self +# except: +# raise MatchError("Can't parse the data {}".format(message)) +# +# def __str__(self): +# return "[ty:{}/note:{}/value:{}]@{}".format(self.type,self.note,self.value,self.channel) # An Action object MUST be included in the file. -class Actions(BasicActions): - """The list of action to perform when a message is read""" - def __init__(self, interface): - super(Actions, self).__init__(interface) - self.listfunctions["presskey"]=presskey - # self.listfunctions[""]= +from mapping.midi import Actions +# class Actions(BasicActions): +# """The list of action to perform when a message is read""" +# def __init__(self, interface): +# super(Actions, self).__init__(interface) +# self.listfunctions["presskey"]=presskey +# # self.listfunctions[""]= +# +# # This funtion is MANDATORY, it makes the link between MessageParse and Action +# def __call__(self,match): +# "Make the link between the regex and the action" +# id,value,page="1","1","*" +# try: +# listact=self.findAction(match.type,match.note,"*") +# for act in listact: +# act(match.value) +# except: +# # No action linked to the trigger +# pass - # This funtion is MANDATORY, it makes the link between MessageParse and Action - def __call__(self,match): - "Make the link between the regex and the action" - id,value,page="1","1","*" - try: - listact=self.findAction(match.type,match.note,"*") - for act in listact: - act(match.value) - except: - # No action linked to the trigger - pass - - -def presskey(val,**params): +def presskey(val,*params): "Press the given keys" print("Pressing key {},params {}".format(val,params)) + #pyautogui.press(params) # MidiInterface(config) -MidiInterface=BasicMidiInterface +class MidiInterface(BasicMidiInterface): + "Adding a couple of custom functions" + + def __init__(self,configfile): + super(MidiInterface,self).__init__(configfile) + self.functionlist["testfunction"]=testfunction diff --git a/midiRebind.py b/midiRebind.py index c16c919..58ef20d 100755 --- a/midiRebind.py +++ b/midiRebind.py @@ -43,8 +43,10 @@ if __name__ == '__main__': vprint("[Error] Command in {} could not be recognised".format(msg)) except: print("[Unexpected error@midibind.py] {}".format(sys.exc_info())) - except ImportError: - print("[Error] Module {} doesn't exist".format(interpath)) + except ImportError as e: + print("[Error] There was an error loading module {} ({})".format(interpath,e)) + except KeyError: + print("[Error] Patch {} doesn't exist".format(path)) except KeyboardInterrupt: print("[Keyboard Interrupt] : Exiting...") del Inter diff --git a/minitest b/minitest index 11a1157..3198c7f 160000 --- a/minitest +++ b/minitest @@ -1 +1 @@ -Subproject commit 11a1157bd86f0166e43445ab137bb483ec85d71f +Subproject commit 3198c7fa6016752b29ff36e3e221c1238d8cbd6b diff --git a/patch/pulse.ini b/patch/pulse.ini new file mode 100644 index 0000000..50d1585 --- /dev/null +++ b/patch/pulse.ini @@ -0,0 +1,19 @@ +[interface] + input=APC MINI MIDI 1 + output=APC MINI MIDI 1 + inputchanel = 1 + outputchannel1 = 1 + #outputchannel2 = 1 + mapping = keystrokes + +[note_on] + 1-99 = 1/on/1 + 1-99/toggle = 127/0 + 1 = 2/cc/1/45;2/cc/2/56;2/cc/3/87;2/cc/4/12;2/cc/5/50;2/cc/6/100 + 3 = 2/cc/1/89;2/cc/2/13;2/cc/3/100;2/cc/4/50;2/cc/5/80;2/cc/6/30 + 4 = 2/cc/7;2/cc/8;2/cc/9;2/cc/10;2/cc/11;2/cc/12 + 4/toggle = 0/127 + + +#[control_change] +# 16-18 = 2/cc/1