Adding support for APC mini
This commit is contained in:
parent
58f05a4911
commit
02e8412ca0
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 "<MessageParse>[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 "<MessageParse>[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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
2
minitest
2
minitest
|
|
@ -1 +1 @@
|
|||
Subproject commit 11a1157bd86f0166e43445ab137bb483ec85d71f
|
||||
Subproject commit 3198c7fa6016752b29ff36e3e221c1238d8cbd6b
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue