def __init__(self, c_instance, *a, **k): product_id_bytes = consts.MANUFACTURER_ID + consts.DEVICE_CODE super(Launchpad_Pro, self).__init__(c_instance=c_instance, product_id_bytes=product_id_bytes, *a, **k) self._challenge = Live.Application.get_random_int(0, 400000000) & 2139062143 with self.component_guard(): self._skin = make_default_skin() with inject(skin=const(self._skin)).everywhere(): self._midimap = MidiMap() self._target_track_component = TargetTrackComponent(name='Target_Track') self._create_background() self._create_global_component() self._last_sent_mode_byte = None with inject(layout_setup=const(self._layout_setup), should_arm=const(self._should_arm_track)).everywhere(): self._create_session() self._create_recording() self._create_actions() self._create_drums() self._create_mixer() self._create_device() self._create_modes() self._create_m4l_interface() self._on_session_record_changed.subject = self.song() self.set_highlighting_session_component(self._session) self.set_device_component(self._device) self._device_selection_follows_track_selection = True self._on_session_record_changed()
def __init__(self, c_instance, *a, **k): product_id_bytes = consts.MANUFACTURER_ID + consts.DEVICE_CODE super(Launchpad_Pro, self).__init__(c_instance=c_instance, product_id_bytes=product_id_bytes, *a, **k) self._challenge = Live.Application.get_random_int(0, 400000000) & 2139062143 with self.component_guard(): self._skin = make_default_skin() with inject(skin=const(self._skin)).everywhere(): self._midimap = MidiMap() self._target_track_component = TargetTrackComponent(name='Target_Track') self._create_background() self._create_global_component() self._last_sent_mode_byte = None with inject(layout_setup=const(self._layout_setup), should_arm=const(self._should_arm_track)).everywhere(): self._create_session() self._create_recording() self._create_actions() self._create_drums() self._create_mixer() self._create_device() self._create_modes() self._create_user() self._on_session_record_changed.subject = self.song() self.set_device_component(self._device) self._on_session_record_changed() return
class Messenger(object): """ Externally provided interface for those components that provide global Push feedback. """ expect_dialog = dependency(expect_dialog=const(nop)) show_notification = dependency(show_notification=const(nop))
def make_injector(self): """ Adds some additional stuff to the injector, used in BaseMessenger """ return inject( double_press_context = const(self._double_press_context), control_surface = const(self), log_message = const(self.log_message))
def __init__(self, c_instance, *a, **k): super(Launchpad_MK2, self).__init__(product_id_bytes=consts.PRODUCT_ID_BYTES, c_instance=c_instance, *a, **k) self._challenge = Live.Application.get_random_int(0, 400000000) & 2139062143 with self.component_guard(): self._skin = make_default_skin() with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._create_session() self._create_mixer() self._last_sent_layout_byte = None with inject(switch_layout=const(self._switch_layout)).everywhere(): self._create_modes()
def query(self, browser): root = super(SourceBrowserQuery, self).query(browser) groups = dict() for item in root: groups.setdefault(item.source, []).append(item) return map(lambda (k, g): VirtualBrowserItem(name=k, children_query=const(g)), sorted(groups.items(), key=first))
def __init__(self, device_bank_registry=None, info_layer=None, delete_handler=None, *a, **k): super(DeviceNavigationComponent, self).__init__(*a, **k) self._make_navigation_node = partial( make_navigation_node, device_bank_registry=device_bank_registry) self._state_buttons = None self._delete_handler = delete_handler self._device_list = self.register_component( ScrollableListWithTogglesComponent()) self._on_selection_clicked_in_controller.subject = self._device_list self._on_selection_changed_in_controller.subject = self._device_list self._on_state_changed_in_controller.subject = self._device_list self._current_node = None self._message_box = self.register_component( MessageBoxComponent(layer=info_layer, is_enabled=False)) self._message_box.text = consts.MessageBoxText.EMPTY_DEVICE_CHAIN self._selected_track = None self._on_selected_track_changed.subject = self.song().view with inject(selection=const(NamedTuple( selected_device=None))).everywhere(): self._on_selected_track_changed()
def __init__(self, *a, **k): super(MIDI_Mix, self).__init__(*a, **k) with self.component_guard(): self._skin = Skin(Colors) with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._create_mixer()
def __init__(self, *a, **k): super(MIDI_Mix, self).__init__(*a, **k) with self.component_guard(): self._skin = Skin(Colors) with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._create_mixer() self._create_session() self._session.set_mixer(self._mixer) self.set_highlighting_session_component(self._session)
def __init__(self, c_instance, *a, **k): super(Launchkey_MK2, self).__init__(c_instance=c_instance, *a, **k) self._is_25_key_model = False self._is_in_control_on = True with self.component_guard(): self._skin = make_skin() with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._request_task = self._tasks.add(Task.sequence(Task.wait(self.identity_request_delay), Task.run(self._send_identity_request))) self._request_task.kill()
def __init__(self, *a, **k): super(RolandMX1, self).__init__(*a, **k) with self.component_guard(): self._skin = make_default_skin() with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._transport = self._create_transport() self._mixer = self._create_mixer() self._session = self._create_session() self._step_button_modes = self._create_step_button_modes()
def __init__(self, c_instance, *a, **k): super(Launchkey_MK2, self).__init__(c_instance=c_instance, *a, **k) self._is_25_key_model = False self._is_in_control_on = True self._identity_response_pending = False with self.component_guard(): self._skin = make_skin() with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._request_task = self._tasks.add(Task.sequence(Task.wait(self.identity_request_delay), Task.run(self._send_identity_request))) self._request_task.kill()
def make_injector(self): """ Adds some additional stuff to the injector, used in BaseMessenger """ return inject( control_surface = const(self), log_message = const(self.log_message), reset_controlled_track = const(self.reset_controlled_track), with_note = const(self.with_note), with_session = const(self.with_session), with_sequencer = const(self.with_sequencer), display_num = const(self.display_num), )
def __init__(self, c_instance, *a, **k): super(Launchkey_MK1, self).__init__(c_instance=c_instance, *a, **k) set_log_instance(self) # For Debug Output only self._is_25_key_model = False self._is_in_control_on = True with self.component_guard(): self._skin = make_skin() with inject(skin=const(self._skin)).everywhere(): self._create_controls() self._request_task = self._tasks.add(Task.sequence(Task.wait(self.identity_request_delay), Task.run(self._send_identity_request))) self._request_task.kill() self._encoder_mode_toggle_enabled = False self._encoder_mode_task = self._tasks.add(Task.sequence(Task.wait(self.encoder_in_control_double_click_time), Task.run(self._disable_toggle_encoder_mode))) self._encoder_mode_task.kill()
def __init__(self, device_bank_registry = None, info_layer = None, delete_handler = None, *a, **k): super(DeviceNavigationComponent, self).__init__(*a, **k) self._make_navigation_node = partial(make_navigation_node, device_bank_registry=device_bank_registry) self._state_buttons = None self._delete_handler = delete_handler self._device_list = self.register_component(ScrollableListWithTogglesComponent()) self._on_selection_clicked_in_controller.subject = self._device_list self._on_selection_changed_in_controller.subject = self._device_list self._on_state_changed_in_controller.subject = self._device_list self._current_node = None self._message_box = self.register_component(MessageBoxComponent(layer=info_layer, is_enabled=False)) self._message_box.text = consts.MessageBoxText.EMPTY_DEVICE_CHAIN self._selected_track = None self._on_selected_track_changed.subject = self.song().view with inject(selection=const(NamedTuple(selected_device=None))).everywhere(): self._on_selected_track_changed()
def _sigabort_create(self): if self._show_returns == 3 or self._show_returns == 4: self._fold_enabled = False self._toggle_returns = True if not self._enable_function: self._direct_bank = False self._has_transport = False if self._channel_strip: self._fold_enabled = False self._user_custom = self._enable_function and not self._direct_bank and not self._has_transport self._bcr_controls = BCL(self, self._preset, self._relative, self._bit_14) self._device_selection_follows_track_selection = True self._default_skin = make_default_skin() with inject(skin=const(self._default_skin)).everywhere(): self._create_controls() self._set_offsets_task = self._tasks.add( Task.sequence(Task.wait(0), Task.run(self._set_session_offsets))) self._set_offsets_task.kill() if self._show_selected: self._show_selected_task = self._tasks.add( Task.sequence(Task.wait(1), Task.run(self._show_selected_track))) return False
def is_pressed(self): return find_if(lambda c: getattr(c, 'is_pressed', const(False))(), self.owned_control_elements()) != None
""" __subject_events__ = ('break_double_press',) @contextmanager def breaking_double_press(self): self._broke_double_press = False yield if not self._broke_double_press: self.break_double_press() def break_double_press(self): self.notify_break_double_press() self._broke_double_press = True GLOBAL_DOUBLE_PRESS_CONTEXT_PROVIDER = const(DoublePressContext()) class DoublePressElement(WrapperElement): """ Element wrapper that provides a facade with two events, single_press and double_press. The single_press() and double_press() methods create non-momentary button-like controls that represent these events. Note that these controls are individual and have their own ownership, put the original DoublePressElement as a hidden element of the layer where these are used if ownership is to be taken into account. """ __subject_events__ = ('single_press', 'double_press') DOUBLE_PRESS_MAX_DELAY = Defaults.MOMENTARY_DELAY
def is_momentary(self): return find_if(lambda c: getattr(c, 'is_momentary', const(False)) (), self.nested_control_elements()) != None
def is_pressed(self): return find_if(lambda c: getattr(c, 'is_pressed', const(False)) (), self.owned_control_elements()) != None
""" __subject_events__ = ('break_double_press', ) @contextmanager def breaking_double_press(self): self._broke_double_press = False yield if not self._broke_double_press: self.break_double_press() def break_double_press(self): self.notify_break_double_press() self._broke_double_press = True GLOBAL_DOUBLE_PRESS_CONTEXT_PROVIDER = const(DoublePressContext()) class DoublePressElement(WrapperElement): """ Element wrapper that provides a facade with two events, single_press and double_press. The single_press() and double_press() methods create non-momentary button-like controls that represent these events. Note that these controls are individual and have their own ownership, put the original DoublePressElement as a hidden element of the layer where these are used if ownership is to be taken into account. """ __subject_events__ = ('single_press', 'double_press') DOUBLE_PRESS_MAX_DELAY = Defaults.MOMENTARY_DELAY
def make_injector(self): """ Adds some additional stuff to the injector, used in APCMessenger """ return inject( double_press_context = const(self._double_press_context), control_surface = const(self), log_message = const(self.log_message))
class ProxiedInterface(EncoderElement.ProxiedInterface): is_pressed = const(False) add_touch_value_listener = nop remove_touch_value_listener = nop touch_value_has_listener = nop
class TaskServer(Server): @depends(log_message = const(print_message), parent_task_group = None) def __init__(self, service, log_message = None, parent_task_group = None, *a, **k): super(TaskServer, self).__init__( service, *a, **k) self._log_message = log_message self._server_task = parent_task_group.add(self.tick_server).kill() self._all_poll = rpyc.lib.compat.poll() self._all_poll.register(self.listener.fileno(), 'r') self._fd_to_conn = {} self.log_message("server created") def start(self): self.listener.listen(self.backlog) self.logger.info("server started on [%s]:%s", self.host, self.port) self.active = True if self.auto_register: # [jbo] This is copied from the base class, but I am not # sure it will work nor needed... embedded Python often # needs special stuff to enable threading. t = threading.Thread(target = self._bg_register) t.setDaemon(True) t.start() self._server_task.restart() self.log_message("server started") def close(self): self._server_task.kill() super(TaskServer, self).close() self.log_message("server stopped") def log_message(self, *messages): self._log_message("[%s]" % self.service.get_service_name(), *messages) def tick_server(self, delta=None): left_attempts = RPYC_POLL_ATTEMPTS while left_attempts > 0: try: active = self._all_poll.poll(RPYC_POLL_TIMEOUT) attempts = 1 for fd, evt in active: if fd == self.listener.fileno(): self._handle_accept(fd, evt) elif fd in self._fd_to_conn: self._handle_serve(fd, evt) if 'r' in evt: attempts = RPYC_READ_ATTEMPT_FACTOR elif 'w' in evt: attempts = RPYC_WRITE_ATTEMPT_FACTOR left_attempts -= attempts except Exception, e: # The select module on Windows throws a select.error exception when any # of the elements in the select set is not a valid file descriptor any # more. It doesn't tell us which one though, so we need to iterate over # all fds and find out which ones no longer work. # # On Mac there's no such exception type (it only throws IOError there), # so we need to do these string comparisons instead of catching the # exception by type. if e.__class__.__name__ == 'error' and e.__class__.__module__ == 'select': self._drop_broken_sockets_on_windows() else: raise return Task.RUNNING
def is_momentary(self): return find_if(lambda c: getattr(c, 'is_momentary', const(False))(), self.nested_control_elements()) != None
class RpycServer(Server): @depends(parent_task_group = None, log_message = const(print_message)) def __init__(self, parent_task_group = None, log_message = None, connection_callback = lambda: None, disconnection_callback = lambda: None): if sys.platform == 'win32': kwargs = dict(hostname = rpyc_config.HOSTNAME, port = rpyc_config.PORT) else: try: os.unlink(rpyc_config.SOCKET_PATH) except OSError: pass kwargs = dict(socket_path = rpyc_config.SOCKET_PATH) super(RpycServer, self).__init__(LiveApiService, **kwargs) self._connection_callback = connection_callback self._disconnection_callback = disconnection_callback self._log_message = log_message self._live_task = parent_task_group.add(self._live_tick).kill() self._listener_poll = rpyc.lib.compat.poll() self._listener_poll.register(self.listener.fileno(), 'r') self._connection = None def start(self): self.listener.listen(1) self.active = True self._live_task.restart() self._log_message('server started', self.host, self.port) def close(self): super(RpycServer, self).close() self._live_task.kill() self._log_message('server stopped') def _live_tick(self, delta = None): if self._connection: self._serve() else: self._wait() return Task.RUNNING def _serve(self): try: """poll_all() ignores EOFError, use poll() instead higher timeout: lower client latency, less responsive ui lower timeout: higher client latency, more responsive ui""" timeout = Timeout(0.025) while not timeout.expired(): self._connection.poll(timeout.timeleft()) except: try: self._connection.close() except: pass self._connection = None self._disconnection_callback() self._log_message('client disconnected') def _wait(self): if not self._listener_poll.poll(0.01): return sock, addrinfo = self.listener.accept() self.clients.add(sock) config = dict(self.protocol_config, allow_all_attrs = True, allow_setattr = True) self._connection = Connection(self.service, Channel(SocketStream(sock)), config) self._connection_callback() self._log_message('client connected', addrinfo)
def on_nested_control_element_value(self, value, sender): with self._is_pressed(): self.notify_value(value) if value != OFF_VALUE and not getattr(sender, 'is_momentary', const(False))(): self.notify_value(OFF_VALUE)