class DisplayingSkinableModesComponent(SkinableModesComponent): mode_display = TextDisplayControl(segments=(u'', ) * MAX_MODE_NUMBER) mode_color_fields = control_list(ColorSysexControl, MAX_MODE_NUMBER) mode_selection_fields = control_list(BinaryControl, MAX_MODE_NUMBER) selected_mode_color_field = ColorSysexControl() def __init__(self, *a, **k): super(DisplayingSkinableModesComponent, self).__init__(*a, **k) self.__on_selected_mode_changed.subject = self def add_mode_button_control(self, mode_name, behaviour): super(DisplayingSkinableModesComponent, self).add_mode_button_control(mode_name, behaviour) self.mode_display[len(self._mode_list) - 1] = to_camel_case_name(mode_name, separator=' ') self.mode_color_fields[(len(self._mode_list) - 1)].color = 'Mode.' + to_camel_case_name(mode_name) + '.On' @listens('selected_mode') def __on_selected_mode_changed(self, _): self._update_selection_fields() self._update_selected_mode_color_field() def _update_selection_fields(self): for field, mode in izip(self.mode_selection_fields, self._mode_list): field.is_on = mode == self.selected_mode def _update_selected_mode_color_field(self): self.selected_mode_color_field.color = ('Mode.{}.On').format(to_camel_case_name(self.selected_mode)) if self.selected_mode else 'DefaultButton.Disabled'
class DisplayingNavigatableModesComponent(NavigatableModesComponent): display_1 = TextDisplayControl(segments=(u'', )) display_2 = TextDisplayControl(segments=(u'', )) color_field_1 = ColorSysexControl() color_field_2 = ColorSysexControl() def _update_selected_mode(self): super(DisplayingNavigatableModesComponent, self)._update_selected_mode() self._update_mode_displays() def _update_mode_displays(self): if self.selected_mode: for display, color_field, name in izip_longest((self.display_1, self.display_2), ( self.color_field_1, self.color_field_2), self.selected_mode.split('_')[:2]): display[0] = name.capitalize() if name else '' color_field.color = ('Mode.{}.On').format(name.capitalize()) if name else 'DefaultButton.Disabled'
class MixerComponent(MixerComponentBase): send_up_button = ButtonControl(color='Mixer.Send') send_down_button = ButtonControl(color='Mixer.Send') pan_value_display = ConfigurableTextDisplayControl(segments=(u'', ) * SESSION_WIDTH) send_value_display = ConfigurableTextDisplayControl(segments=(u'', ) * SESSION_WIDTH) mixer_display = TextDisplayControl(segments=(u'Mixer', )) pan_display = TextDisplayControl(segments=(u'Pan', )) send_index_display = ConfigurableTextDisplayControl(segments=(u'', )) send_encoder_color_fields = control_list(ColorSysexControl, SESSION_WIDTH) selected_track_color_field = ColorSysexControl() def __init__(self, *a, **k): super(MixerComponent, self).__init__( channel_strip_component_type=ChannelStripComponent, *a, **k) self.__on_selected_track_changed.subject = self.song.view self.__on_selected_track_changed() self.pan_value_display.set_data_sources([ strip.pan_value_display_data_source for strip in self._channel_strips ]) self.on_send_index_changed() @property def controlled_tracks(self): return self._track_assigner.tracks(self._provider) @property def controlled_sends(self): tracks = self.controlled_tracks controlled_sends = [None] * len(tracks) send_index = self.send_index for index, track in enumerate(tracks): if liveobj_valid(track): sends = track.mixer_device.sends if send_index != None and send_index < len(sends): controlled_sends[index] = sends[send_index] return controlled_sends @send_up_button.pressed def send_up_button(self, _): self.send_index -= 1 @send_down_button.pressed def send_down_button(self, _): self.send_index += 1 def set_track_names_display(self, display): if display: display.set_data_sources([ strip.track_name_data_source() for strip in self._channel_strips ]) def set_selected_track_name_display(self, display): if display: display.set_data_sources( [self._selected_strip.track_name_data_source()]) def set_pan_encoder_color_fields(self, controls): for strip, control in izip_longest(self._channel_strips, controls or []): strip.pan_encoder_color_field.set_control_element(control) def set_track_color_fields(self, controls): for strip, control in izip_longest(self._channel_strips, controls or []): strip.track_color_field.set_control_element(control) def set_track_selection_fields(self, controls): for strip, control in izip_longest(self._channel_strips, controls or []): strip.track_selection_field.set_control_element(control) def set_volume_leds(self, controls): for strip, control in izip_longest(self._channel_strips, controls or []): strip.volume_led.set_control_element(control) def set_monitoring_state_buttons(self, controls): for strip, control in izip_longest(self._channel_strips, controls or []): strip.monitoring_state_button.set_control_element(control) def on_send_index_changed(self): self._update_send_value_subjects() self._update_send_navigation_buttons() self._update_send_index_display() self._update_send_value_display() def on_num_sends_changed(self): self._update_send_navigation_buttons() self._update_send_value_display() def _update_send_navigation_buttons(self): send_index = self.send_index self.send_up_button.enabled = send_index != None and send_index > 0 self.send_down_button.enabled = send_index != None and send_index < self.num_sends - 1 return def _update_send_index_display(self): send_index = self.send_index self.send_index_display[0] = 'Send ' + chr( send_index + 65) if send_index != None else '' return def _update_send_value_display(self): for index, send in enumerate(self.controlled_sends): self.send_value_display[index] = str(send) if send else '' def _update_send_encoder_color_fields(self): for index, send in enumerate(self.controlled_sends): self.send_encoder_color_fields[ index].color = 'Mixer.Send' if send else 'DefaultButton.Disabled' def _update_selected_track_color_field(self): self.selected_track_color_field.color = color_for_track( self.song.view.selected_track) def _update_send_value_subjects(self): self.__on_send_value_changed.replace_subjects(self.controlled_sends) @listens('selected_track') def __on_selected_track_changed(self): self._update_selected_strip() self._update_selected_track_color_field() self.__on_selected_track_color_changed.subject = self.song.view.selected_track @listens('color') def __on_selected_track_color_changed(self): self._update_selected_track_color_field() @listens_group('value') def __on_send_value_changed(self, _): self._update_send_value_display() def _reassign_tracks(self): super(MixerComponent, self)._reassign_tracks() self._update_send_value_subjects() self._update_send_value_display() self._update_send_encoder_color_fields()
class ChannelStripComponent(ChannelStripComponentBase, Messenger): empty_color = b'DefaultButton.Disabled' monitoring_state_button = ButtonControl() pan_encoder_color_field = ColorSysexControl() track_color_field = ColorSysexControl() volume_led = ColorSysexControl() track_selection_field = BinaryControl() def __init__(self, *a, **k): super(ChannelStripComponent, self).__init__(*a, **k) self._pan_value_display_data_source = DisplayDataSource() self.__on_selected_track_changed.subject = self.song.view @property def pan_value_display_data_source(self): return self._pan_value_display_data_source def set_track(self, track): super(ChannelStripComponent, self).set_track(track) self._update_pan_encoder_color_field() self._update_track_selection_field() self._update_listeners() def set_volume_control(self, control): super(ChannelStripComponent, self).set_volume_control(control) self.__on_volume_control_value_received.subject = control def set_pan_control(self, control): if control != None: control.mapping_sensitivity = CONTINUOUS_MAPPING_SENSITIVITY super(ChannelStripComponent, self).set_pan_control(control) return def set_send_controls(self, controls): for control in controls or []: if control != None: control.mapping_sensitivity = CONTINUOUS_MAPPING_SENSITIVITY super(ChannelStripComponent, self).set_send_controls(controls) return @monitoring_state_button.pressed def monitoring_state_button(self, _): if has_monitoring_state(self.track): self.track.current_monitoring_state = ( self.track.current_monitoring_state + 1) % len( monitoring_states.values) self._message_monitoring_state() def _message_monitoring_state(self): track = self.track self.message(track.name, (b'Monitor {}').format( MONITORING_STATES_TO_STR[track.current_monitoring_state])) def _update_monitoring_state_button(self): color = self.empty_color if liveobj_valid(self.track): if has_monitoring_state(self.track): color = (b'Monitor.{}').format(MONITORING_STATES_TO_STR[ self.track.current_monitoring_state]) else: color = b'Monitor.Disabled' self.monitoring_state_button.color = color def _update_volume_led(self): track = self.track value = (0, 0, 0) if liveobj_valid(track): value = tuple([ clamp( int( round(channel * normalized_parameter_value( track.mixer_device.volume) / 2)), 0, 127) for channel in hex_to_channels(track.color) ]) self.volume_led.color = SysexRGBColor(value) def _message_volume_value(self): track = self.track if liveobj_valid(track): self.message(track.name, str(track.mixer_device.volume)) def _update_pan_encoder_color_field(self): self.pan_encoder_color_field.color = b'Mixer.Pan' if liveobj_valid( self.track) else b'DefaultButton.Disabled' def _update_pan_value_display(self): track = self.track self.pan_value_display_data_source.set_display_string( str(track.mixer_device.panning) if liveobj_valid(track) else b'') def _update_track_color_field(self): self.track_color_field.color = color_for_track(self.track) def _update_select_button(self): track = self.track color = b'DefaultButton.Disabled' if liveobj_valid(track): if track == self.song.view.selected_track: color = color_for_track(track) else: color = b'Mixer.TrackSelect' self.select_button.color = color def _update_track_selection_field(self): self.track_selection_field.is_on = self.track == self.song.view.selected_track @listens(b'current_monitoring_state') def __on_track_monitoring_state_changed(self): self._update_monitoring_state_button() @listens(b'value') def __on_volume_changed(self): self._update_volume_led() @listens(b'value') def __on_pan_changed(self): self._update_pan_value_display() @listens(b'color') def __on_track_color_changed(self): self._update_track_color_field() self._update_select_button() self._update_volume_led() @listens(b'selected_track') def __on_selected_track_changed(self): self._update_select_button() self._update_track_selection_field() @listens(b'value') def __on_volume_control_value_received(self, _): self._message_volume_value() def _update_listeners(self): track = self.track self.__on_track_monitoring_state_changed.subject = track self.__on_track_monitoring_state_changed() self.__on_volume_changed.subject = track.mixer_device.volume if liveobj_valid( track) else None self.__on_volume_changed() self.__on_pan_changed.subject = track.mixer_device.panning if liveobj_valid( track) else None self.__on_pan_changed() self.__on_track_color_changed.subject = track if liveobj_valid( track) else None self.__on_track_color_changed() return