import json class Ports: def __init__(self, js): if isinstance(js, object): self.input = js["input"] if ("input" in js and isinstance(js["input"], str)) else "" self.output = js["output"] if ("output" in js and isinstance(js["output"], str)) else "" else: self.input="" self.output="" def json(self): return {"input": self.input, "output" : self.output} def _Note(t, ch=-1, k=-1, vel=-1): return [ t, ch if ch!=None else -1, k if k!=None else -1, vel if vel!=None else -1] def NoteOn(ch=-1, k=-1, vel=-1): return _Note("noteon", ch, k, vel) def NoteOff(ch=-1, k=-1, vel=-1): return _Note("noteoff", ch, k, vel) class InputDef: def __init__(self, name, type): self.name=name self.type=type self.actions={} @staticmethod def button(name): return InputDef(name, "BUTTON") @staticmethod def controller(name): return InputDef(name, "CONTROLLER") def add_actions(self, name, action): self.actions[name]=action def add_noteon(self, name, ch=-1, k=-1, vel=-1): self.actions[name]=NoteOn(ch, k, vel) def add_noteoff(self, name, ch=-1, k=-1, vel=-1): self.actions[name]=NoteOn(ch, k, vel) def json(self): return { "type" : self.type, "actions" : self.actions } def instance(self, ch, key): return { "type" : self.name, "channel" : ch, "key" : key, "velocity" : 0, "locked" : None } class Pad: def __init__(self, name, w, h, ip="", op=""): self.name = name self.width = w self.height = h self.ports = Ports({"input" : ip, "output" : op}) self.matrix=[] i=0 l = self.width*self.height while i