def setup(self): # Create channels for section in self.config.sections(): if section.find('Channel_') == 0: name = self.config.get(section, 'name') input = self.config.get(section, 'input') output = self.config.get(section, 'output') channel = self.config.getint(section, 'channel') self.channels[name] = Channel(name, input, output, channel) # Create translators for section in self.config.sections(): if section.find('Translator') == 0: values = section.split('_') name = values[0] options = {} for key, value in self.config.items(section): options[key] = value translator = TranslatorFactory.create(self, name, options) if translator: self.translators.append(translator) # Open channels for channel in self.channels.values(): channel.receive = self.__receive channel.open()
DEAD = 0.05 def __init__(self, core, options): super(TranslatorDoubleFilter, self).__init__(core, options) self.controller = self.add_channel(options['controller']) self.host = self.add_channel(options['host']) self.add_knob('cutoff', self.__knob_cutoff, self.controller, int(options['knob_cutoff'])) self.add_ctrl('cutoff_lp', self.host, int(options['cc_cutoff_lp'])) self.add_ctrl('cutoff_hp', self.host, int(options['cc_cutoff_hp'])) def __knob_cutoff(self, knob, value): cutoff = float(value) / self.RANGE lp = 1.0 hp = 0.0 if cutoff < 0.5 - self.DEAD: lp = cutoff / (0.5 - self.DEAD) elif cutoff > 0.5 + self.DEAD: hp = (cutoff - (0.5 + self.DEAD)) / (0.5 - self.DEAD) self.send_ctrl('cutoff_lp', round(lp * self.RANGE)) self.send_ctrl('cutoff_hp', round(hp * self.RANGE)) TranslatorFactory.register(TranslatorDoubleFilter)
self.add_knob("source1", self.__knob_source, self.controller, int(options["knob_source1"])) self.add_knob("source2", self.__knob_source, self.controller, int(options["knob_source2"])) self.add_knob("source3", self.__knob_source, self.controller, int(options["knob_source3"])) self.add_knob("source4", self.__knob_source, self.controller, int(options["knob_source4"])) self.add_knob("source5", self.__knob_source, self.controller, int(options["knob_source5"])) self.add_knob("source6", self.__knob_source, self.controller, int(options["knob_source6"])) self.add_knob("source7", self.__knob_source, self.controller, int(options["knob_source7"])) self.add_ctrl("source1", self.host, int(options["cc_source1"])) self.add_ctrl("source2", self.host, int(options["cc_source2"])) self.add_ctrl("source3", self.host, int(options["cc_source3"])) self.add_ctrl("source4", self.host, int(options["cc_source4"])) self.add_ctrl("source5", self.host, int(options["cc_source5"])) self.add_ctrl("source6", self.host, int(options["cc_source6"])) self.add_ctrl("source7", self.host, int(options["cc_source7"])) def __knob_source(self, knob, value): self.send_ctrl("source1", 0) self.send_ctrl("source2", 0) self.send_ctrl("source3", 0) self.send_ctrl("source4", 0) self.send_ctrl("source5", 0) self.send_ctrl("source6", 0) self.send_ctrl("source7", 0) self.send_ctrl(knob, 127) TranslatorFactory.register(TranslatorMIDISource)
from translator.base import Translator from translator.factory import TranslatorFactory class TranslatorTest(Translator): def __init__(self, core, options): super(TranslatorTest, self).__init__(core, options) self.controller = self.add_channel(options['controller']) self.host = self.add_channel(options['host']) TranslatorFactory.register(TranslatorTest)
self.send_ctrl('send1', 0) self.send_ctrl('send2', 0) elif self.__state == self.STATE_MUTE: self.__update_levels(0, 0, 0) self.send_ctrl('master', 0) self.send_ctrl('send1', 0) self.send_ctrl('send2', 0) elif self.__state == self.STATE_FX1: self.__update_levels(0, 127, 0) self.send_ctrl('send1', 127) time.sleep(self.SWITCH_INTERVAL) self.send_ctrl('master', 0) self.send_ctrl('send2', 0) elif self.__state == self.STATE_FX2: self.__update_levels(0, 0, 127) time.sleep(self.SWITCH_INTERVAL) self.send_ctrl('send2', 127) self.send_ctrl('master', 0) self.send_ctrl('send1', 0) self.send_ctrl('selector', (self.__state / 3.0) * 127.0) def __update_levels(self, master, send1, send2): return self.send_ctrl('master', master) self.send_ctrl('send1', send1) self.send_ctrl('send2', send2) TranslatorFactory.register(TranslatorFx)
self.send_ctrl('fx4', 0) self.__state = [False, False, False, False] def __key_fx1(self, key): self.__switch(0) def __key_fx2(self, key): self.__switch(1) def __key_fx3(self, key): self.__switch(2) def __key_fx4(self, key): self.__switch(3) def __switch(self, fx): self.__state[fx] = not self.__state[fx] Logger.debug("Switching state of fx%d to %d" % (fx, self.__state[fx])) if self.__state[fx]: value = 127 else: value = 0 self.send_ctrl(['fx1', 'fx2', 'fx3', 'fx4'][fx], value) self.set_led(['led1', 'led2', 'led3', 'led4'][fx], self.__state[fx]) TranslatorFactory.register(TranslatorFXSelect)
self.add_key('key_play', self.__key_play, self.controller, int(options['key_play'])) self.add_key('key_prev_scene', self.__key_prev_scene, self.controller, int(options['key_prev_scene'])) self.add_key('key_next_scene', self.__key_next_scene, self.controller, int(options['key_next_scene'])) self.add_cmd('play', self.host, int(options['note_play'])) self.add_cmd('prev_scene', self.host, int(options['note_prev_scene'])) self.add_cmd('next_scene', self.host, int(options['note_next_scene'])) def __live_play(self, key): self.send_cmd('play') def __live_prev_scene(self, key): self.send_cmd('prev_scene') def __live_next_scene(self, key): self.send_cmd('next_scene') def __key_play(self, key): self.send_cmd('play') def __key_prev_scene(self, key): pass #self.send_cmd('prev_scene') def __key_next_scene(self, key): pass #self.send_cmd('next_scene') TranslatorFactory.register(TranslatorTransport)
self.__set_state(self.STATE_IDLE) elif self.__state == self.STATE_OVERDUB: # Stop overdub recording and switch to IDLE state self.send_cmd('stop') self.set_led('led1', False) self.__set_state(self.STATE_IDLE) elif self.__state == self.STATE_IDLE: # Clear recording and switch to CLEAR state self.send_cmd('clear') self.set_led('led1', False) self.set_led('led2', False) self.__set_state(self.STATE_CLEAR) def __key_half(self, key): self.send_cmd('focus') self.send_cmd('half') def __key_double(self, key): self.send_cmd('focus') self.send_cmd('double') def __key_undo(self, key): self.send_cmd('focus') self.send_cmd('undo_redo') def __set_state(self, state): self.__state = state Logger.debug("Switching state to: %s" % (self.state_names[self.__state])) TranslatorFactory.register(TranslatorLooper)