def copy_bank(self, other): ''' Copies contents of bank into self. ARGS: other - The source bank Raises TypeError if other is not a ProgramBank. Raises ValueError if other is a ProgramBank but has the wrong format. ''' # DOES NOT SAVE UNDO STATE if is_bank(other): frmt1 = self.template.data_format frmt2 = other.template.data_format if frmt1 == frmt2: self.name = other.name self.remarks = other.remarks for i in range(min(len(self), len(other))): p = list.__getitem__(other, i) list.__setitem__(self, i, clone(p)) self.current_slot = other.current_slot self.current_program = clone(other.current_program) #self.performance.copy_erformance(other.performance) else: msg = "Can not copy %s bank into %s bank" msg = msg % (frmt2, frmt1) raise ValueError(msg) else: msg = "Can not copy %s to ProgramBank" msg = msg % type(other) raise TypeError(msg)
def test_clone(): a = SourceMapper("velocity") a.add_parameter("vibrato") b = clone(a) dump(a) dump(b) print(a is b) c = CCMapper() c.add_parameter(1, "vibrato") d = clone(c) dump(c) dump(d) print(c is d)
def clone(self): ''' Returns an exact copy of self. ''' other = ProgramBank(self.template) other.name = self.name other.remarks = self.remarks other.current_slot = self.current_slot other.current_program = clone(self.current_program) for slot, prog in enumerate(self): prog2 = clone(prog) list.__setitem__(other, slot, prog2) return other
def clone(self): ''' Returns an exact copy of self. ''' other = ProgramBank(self.template) other.name = self.name other.remarks = self.remarks other.current_slot = self.current_slot other.current_program = clone(self.current_program) for slot, prog in enumerate(self): prog2 = clone(prog) list.__setitem__(other, slot, prog2) other.undostack.clear() return other
def clone(self): ''' Returns a cloned copy of self. ''' other = Performance() other.transpose = self.transpose other._key_range = self._key_range other.bend_range = self.bend_range other.bend_parameter = self.bend_parameter other.velocity_maps = clone(self.velocity_maps) other.aftertouch_maps = clone(self.aftertouch_maps) other.pitchwheel_maps = clone(self.pitchwheel_maps) other.keynumber_maps = clone(self.keynumber_maps) other.controller_maps = clone(self.controller_maps) return other
def copy_source_mapper(self, other): self.source = other.source self.domain = other.domain self._maps = {} for m in other._maps.values(): p = m.parameter self._maps[p] = clone(m)
def copy_performance(self, other): ''' Copy all values from another Performance into self. ARGS: other - Performance, the source object. ''' self.transpose = other.transpose self._key_range = other._key_range self.bend_range = other.bend_range self.bend_parameter = other.bend_parameter self.velocity_maps = clone(other.velocity_maps) self.aftertouch_maps = clone(other.aftertouch_maps) self.pitchwheel_maps = clone(other.pitchwheel_maps) self.keynumber_maps = clone(other.keynumber_maps) self.controller_maps = clone(other.controller_maps)
def __setitem__(self, slot, obj): ''' Sets indicated program slot. ARGS: slot - int MIDI program number, 0 <= slot < 128. If slot is None, the 'current' slot is used. obj - an instance of Program. Raises TypeError if obj is not a Program. Raises ValueError if obj is a Program but has the wrong format. ''' slot = slot or self.current_slot if is_program(obj): if obj.data_format == self.template.data_format: self.push_undo("Store slot [%d] <-- '%s'" % (slot, obj.name)) list.__setitem__(self, slot, clone(obj)) else: msg = "Can not store %s program into %s bank" msg = msg % (obj.data_format, self.template.data_format) raise ValueError(msg) else: msg = "Can not store %s into ProgramBank" msg = msg % type(obj) raise TypeError(msg)
def push_undo(self, action): ''' Pushes the current state of the bank to the undo stack. The undo feature is not being used at this point. ''' if self.enable_undo: self.undostack.push_undo(action, clone(self))
def test_cc_mapper(): print("*** CCMapper test ***") a = CCMapper() a.add_parameter(1, "vibrato") a.add_parameter(4, "volume") a.add_parameter(4, "filter", "exp", range_=(100, 10000)) a.add_parameter(4, "filterRes") dump(a) print("\n*** Serialization, clone and eq ***") s = a.serialize() b = CCMapper.deserialize(s) c = clone(a) dump(b) dump(c) print("a == b", a == b, " a is b", a is b) print("a == c", a == c, " a is c", a is c) print("\n*** Remove parameters ***") b.remove_parameter(4, "filter") dump(b) b.remove_parameter(4) dump(b) c.reset() dump(c)
def initialize(self): ''' Initialize the bank by filling it with default programs. ''' for i in range(len(self)): list.__setitem__(self, i, self.create_program()) self.name = "Init" self.remarks = "" self.current_slot = 0 self.current_program = clone(self[0])
def initialize(self): ''' Initialize the bank by filling it with default programs. ''' self.push_undo("Initialize Bank") for i in range(len(self)): list.__setitem__(self, i, self.create_program()) self.name = "Init" self.remarks = "" self.current_slot = 0 self.current_program = clone(self[0])
def undo(self): ''' Restore state of self from undo stack. The undo feature is not currently being used. ''' try: obj = self.undostack.pop_undo() self.undostack.push_redo(obj.action, clone(self)) self.copy_bank(obj.payload) except IndexError: msg = "Nothing to undo" raise IndexError(msg)
def redo(self): ''' Redo the previous undo. Redo is not currently being used. ''' try: obj = self.undostack.pop_redo() self.undostack.push_undo(obj.action, clone(self)) self.copy_bank(obj.payload) except IndexError: msg = "Nothing to redo" raise IndexError(msg)
def __getitem__(self, slot): ''' Returns indicated Program ARGS: slot - int MIDI program number, 0 <= slot < 128. If slot is None, the 'current' slot is used. RETURNS: Program Raises IndexError ''' if slot is None: return self.current_program else: return clone(list.__getitem__(self, slot))
def load(self, filename, ui=None): ''' Load bank data from file into self. ARGS: filename - String Raises IOError ''' try: other = ProgramBank.read_bank(filename, ui) self.copy_bank(other) self.current_slot = 0 self.current_program = clone(self[0]) self.filename = filename except(ValueError, TypeError, IOError) as err: msg = "Error while reading ProgramBank file '%s'" % filename raise IOError(msg)
def __init__(self, template): ''' Constructs new ProgramBank instance. ARGS: template - dict holding with synth parameter keys and default values. ''' list.__init__(self) self.template = template for i in range(BANK_LENGTH): list.append(self, clone(template)) self.current_slot = 0 self.current_program = self[0] self.name = "%s Bank" % template.data_format self.remarks = "" self.filename = "" self.undostack = UndoRedoStack() self.enable_undo = True self.lock_current_program = False # if true ignore program changes
def use(self, slot, undo_action=None): ''' Mark slot as the 'current' slot, ignore if self.current_program_locked() returns True. ARGS: slot - int, MIDI program number, 0 <= slot < 1 undo_action - Depreciated value, ignore. RETURNS: int - the current program slot. ''' if not self._lock_current_program: # if not undo_action: # undo_action = "Recall slot %d" % self.current_slot # self.push_undo(undo_action) self.current_slot = slot self.current_program = clone(self[slot]) return self.current_program
def use(self, slot, undo_action=None): ''' Mark slot as the 'current' slot, ignore if self.lock_current_program is True. ARGS: slot - int, MIDI program number, 0 <= slot < 1 undo_action - optional Sting sets undo message text. RETURNS: int - the current program slot. ''' if not self.lock_current_program: if not undo_action: undo_action = "Recall slot %d" % self.current_slot self.push_undo(undo_action) self.current_slot = slot self.current_program = clone(self[slot]) return self.current_program
def load(self, filename): ''' Load bank data from file into self. ARGS: filename - String Raises IOError ''' try: self.push_undo("Load bank file '%s'" % filename) other = ProgramBank.read_bank(filename) self.copy_bank(other) self.current_slot = 0 self.current_program = clone(self[0]) self.filename = filename except (ValueError, TypeError, IOError) as err: self.undostack.pop_undo() msg = "Error while reading ProgramBank file '%s'" % filename raise IOError(msg)
def paste_clipboard(self, slot=None): ''' Paste contents of clipboard into the bank. ARGS: slot - optional MIDI program number. If not specified the current slot is used. Raises KeyError if the clipboard does not contain an appropriate Program. ''' frmt = self.template.data_format try: prog = clone(ProgramBank.clipboard[frmt]) if slot is None: self.current_program = prog else: list.__setitem__(self, slot, prog) except KeyError: msg = "ProgramBank clipboard does not contain %s Program" msg = msg % frmt raise KeyError(msg)
def paste_clipboard(self, slot=None): ''' Paste contents of clipboard into the bank. ARGS: slot - optional MIDI program number. If not specified the current slot is used. Raises KeyError if the clipboard does not contain an appropriate Program. ''' frmt = self.template.data_format try: prog = clone(ProgramBank.clipboard[frmt]) self.push_undo("Paste") if slot is None: self.current_program = prog else: list.__setitem__(self, slot, prog) except KeyError: msg = "ProgramBank clipboard does not contain %s Program" msg = msg % frmt raise KeyError(msg)
def __init__(self, template): ''' Constructs new ProgramBank instance. ARGS: template - dict holding with synth parameter keys and default values. ''' list.__init__(self) self.template = template for i in range(BANK_LENGTH): list.append(self, clone(template)) # List parameters/default-values in order # [(p1, dflt1),(p2,dflt2)...] self._parameters = [] for p in sorted(template.keys()): self._parameters.append((p,template[p])) self.current_slot = 0 self.current_program = self[0] self.name = "%s Bank" % template.data_format self.remarks = "" self.filename = "" #self.enable_undo = True # Depreciated self._lock_current_program = False # if true ignore program changes
def test_source_mapper(): print("*** SourceMapper test ***") sm1 = SourceMapper("velocity") sm1.add_parameter("A") sm1.add_parameter("B", curve="exp", modifier=2, range_=(100, 200)) sm1.add_parameter("C") dump(sm1) print("len : ", len(sm1)) print("keys : ", sm1.keys()) print("sm1['B'] --> ", sm1["B"]) print("\n*** Serilization, eq and clone ***") s = sm1.serialize() sm2 = SourceMapper.deserialize(s) dump(sm2) print("sm1 == sm2", sm1 == sm2, " sm1 is sm2", sm1 is sm2) sm3 = clone(sm1) dump(sm3) print("\n*** Remove parameters ***") sm1.remove_parameter("C") dump(sm1) sm2.remove_parameter("ALL") dump(sm2)
def copy_ccmapper(self, other): self.reset() for ctrl, pm in other._maps.items(): self._maps[ctrl] = clone(pm) return None
def clone(self): other = CCMapper() for cc, sm in self._maps.items(): other._maps[cc] = clone(sm) return other
def clone(self): other = SourceMapper(self.source, self.domain[:]) for p, m in self._maps.items(): other._maps[p] = clone(m) return other
def clone(self): other = CCMapper() for cc,sm in self._maps.items(): other._maps[cc] = clone(sm) return other
def copy_ccmapper(self, other): self.reset() for ctrl,pm in other._maps.items(): self._maps[ctrl] = clone(pm) return None
def clone(self): other = SourceMapper(self.source, self.domain[:]) for p,m in self._maps.items(): other._maps[p] = clone(m) return other