def _create_controls(self):
     self._encoders = ButtonMatrixElement(rows=[[
         EncoderElement(MIDI_CC_TYPE,
                        0,
                        identifier,
                        map_mode=(Live.MidiMap.MapMode.absolute),
                        name=('Volume_Encoder_{}'.format(index)))
         for index, identifier in enumerate(range(12, 20))
     ]],
                                          name='Volume_Encoders')
     self._data_encoder = EncoderElement(
         MIDI_CC_TYPE,
         0,
         22,
         map_mode=(Live.MidiMap.MapMode.relative_smooth_two_compliment),
         name='Data_Encoder')
     self._data_encoder_button = ButtonElement(True,
                                               MIDI_CC_TYPE,
                                               0,
                                               23,
                                               name='Data_Encoder_Button',
                                               skin=skin)
     self._play_button = ButtonElement(False,
                                       MIDI_CC_TYPE,
                                       0,
                                       118,
                                       name='Play_Button',
                                       skin=skin)
     self._record_button = ButtonElement(False,
                                         MIDI_CC_TYPE,
                                         0,
                                         119,
                                         name='Record_Button',
                                         skin=skin)
     self._record_stop_button = ButtonElement(False,
                                              MIDI_CC_TYPE,
                                              0,
                                              116,
                                              name='Record_Stop_Button',
                                              skin=skin)
     self._stop_button = ButtonElement(False,
                                       MIDI_CC_TYPE,
                                       0,
                                       117,
                                       name='Stop_Button',
                                       skin=skin)
     self._pads = ButtonMatrixElement(rows=[[
         ButtonElement(True,
                       MIDI_NOTE_TYPE,
                       PAD_CHANNEL,
                       identifier,
                       name=('Pad_{}'.format(index)),
                       skin=skin)
         for index, identifier in enumerate(PAD_IDS)
     ]])
Пример #2
0
 def _create_controls(self):
     self._pads_raw = [
         ButtonElement(True,
                       MIDI_NOTE_TYPE,
                       0,
                       identifier,
                       name=u'Pad_{}'.format(identifier),
                       skin=skin) for identifier in range(100)
     ]
     self._session_matrix = ButtonMatrixElement(
         rows=[[self._pads_raw[offset + col] for col in range(NUM_TRACKS)]
               for offset in range(80, 49, -10)],
         name=u'Session_Matrix')
     self._scene_launch_button_matrix = ButtonMatrixElement(
         rows=[[
             self._pads_raw[identifier]
             for identifier in range(89, 58, -10)
         ]],
         name=u'Scene_Launch_Button_Matrix')
     self._stop_all_clips_button = ButtonElement(
         True,
         MIDI_NOTE_TYPE,
         0,
         127,
         skin=skin,
         name=u'Stop_All_Clips_Button')
     self._nav_down_button = self._pads_raw[90]
     self._nav_up_button = self._pads_raw[91]
     self._nav_left_button = self._pads_raw[92]
     self._nav_right_button = self._pads_raw[93]
     self._mode_cycle_button = ButtonElement(True,
                                             MIDI_CC_TYPE,
                                             0,
                                             127,
                                             skin=skin,
                                             name=u'Mode_Button')
     self._drum_pads = ButtonMatrixElement(
         rows=[[self._pads_raw[offset + col] for col in range(4)]
               for offset in range(48, 35, -4)],
         name=u'Drum_Pads')
     self._tempo_encoder = EncoderElement(
         MIDI_PB_TYPE,
         0,
         0,
         Live.MidiMap.MapMode.absolute,
         send_should_depend_on_forwarding=False,
         name=u'Tempo_Encoder')
     self._tempo_encoder.reset = nop
     self._sysex_element = SysexElement(sysex_identifier=SYSEX_HEADER,
                                        name=u'Sysex_Element')
     self._sysex_element.add_value_listener(nop)
     self._surface_update_message_element = ButtonElement(
         True, MIDI_CC_TYPE, 0, 64, name=u'Surface_Update_Message_Element')
     self.__on_surface_update_message_received.subject = self._surface_update_message_element
Пример #3
0
def create_encoder(identifier, name, is_s_mk2=False):
    encoder = EncoderElement(
        MIDI_CC_TYPE,
        MIDI_CHANNEL,
        identifier, (Live.MidiMap.MapMode.relative_smooth_two_compliment),
        name=name,
        encoder_sensitivity=1.0)
    if is_s_mk2:
        encoder.set_feedback_delay(-1)
        encoder.mapping_sensitivity = 0.1
    return encoder
Пример #4
0
def create_encoder(identifier, name, **k):
    return EncoderElement(MIDI_CC_TYPE,
                          15,
                          identifier,
                          Live.MidiMap.MapMode.absolute,
                          name=name,
                          **k)
Пример #5
0
def create_encoder(identifier, name, **k):
    return EncoderElement(MIDI_CC_TYPE,
                          0,
                          identifier,
                          Live.MidiMap.MapMode.relative_smooth_signed_bit,
                          name=name,
                          **k)
def create_encoder(identifier,
                   name,
                   map_mode=Live.MidiMap.MapMode.absolute,
                   **k):
    return EncoderElement(MIDI_CC_TYPE,
                          MIDI_CHANNEL,
                          identifier,
                          map_mode,
                          name=name,
                          **k)
 def _create_controls(self):
     self._hardware_live_mode_switch = SysexElement(send_message_generator=lambda b: sysex.LIVE_MODE_MESSAGE_HEADER + (
      b, sysex.END_BYTE), default_value=sysex.OFF_VALUE, name=b'Hardware_Live_Mode_Switch')
     self._memory_preset_switch = SysexElement(send_message_generator=lambda b: sysex.MEMORY_PRESET_SWITCH_MESSAGE_HEADER + (
      b, sysex.END_BYTE), sysex_identifier=sysex.MEMORY_PRESET_SWITCH_MESSAGE_HEADER, name=b'Memory_Preset_Switch')
     self._memory_preset_select_mode_switch = SysexElement(sysex_identifier=sysex.MEMORY_PRESET_SELECT_MODE_MESSAGE_HEADER, name=b'Memory_Preset_Select_Mode')
     self._play_button = create_button(94, b'Play_Button')
     self._stop_button = create_button(93, b'Stop_Button')
     self._punch_in_button = create_button(87, b'Punch_In_Button')
     self._punch_out_button = create_button(88, b'Punch_Out_Button')
     self._metronome_button = create_button(89, b'Metronome_Button')
     self._loop_button = create_button(86, b'Loop_Button')
     self._rwd_button = create_button(91, b'Rewind_Button')
     self._ff_button = create_button(92, b'Fast_Forward_Button')
     self._record_button = create_button(95, b'Record_Button')
     self._undo_button = create_button(81, b'Undo_Button')
     self._bank_left_button = create_button(46, b'Bank_Left_Button')
     self._bank_right_button = create_button(47, b'Bank_Right_Button')
     self._left_button = create_button(48, b'Left_Button')
     self._right_button = create_button(49, b'Right_Button')
     self._left_arrow_button = create_button(98, b'Left_Arrow_Button')
     self._right_arrow_button = create_button(99, b'Right_Arrow_Button')
     self._marker_button = create_button(84, b'Marker_Button')
     self._pads = ButtonMatrixElement(rows=[
      [ create_button(col + 36, b'Pad_%d' % (col,), channel=10) for col in xrange(8)
      ]], name=b'Pad_Matrix')
     self._pad_leds = ButtonMatrixElement(rows=[
      [ create_pad_led(column + 112, b'Pad_LED_%d' % (column,)) for column in xrange(8)
      ]], name=b'Pad_LED_Matrix')
     self._faders = ButtonMatrixElement(rows=[
      [ SliderElement(msg_type=MIDI_PB_TYPE, channel=index, identifier=None, name=b'Fader_%d' % (index,)) for index in xrange(8)
      ]], name=b'Faders')
     self._master_fader = SliderElement(MIDI_PB_TYPE, 8, identifier=None, name=b'Master_Fader')
     self._encoders = ButtonMatrixElement(rows=[
      [ create_ringed_encoder(index + 16, index + 48, b'Encoder_%d' % (index,)) for index in xrange(8)
      ]])
     self._jogwheel = EncoderElement(MIDI_CC_TYPE, 0, 60, Live.MidiMap.MapMode.relative_smooth_signed_bit, name=b'Jogwheel')
     return
Пример #8
0
def make_encoder(identifier, name):
    return EncoderElement(MIDI_CC_TYPE,
                          0,
                          identifier,
                          Live.MidiMap.MapMode.absolute,
                          name=name)
Пример #9
0
class Blocks(ControlSurface):
    def __init__(self, *a, **k):
        super(Blocks, self).__init__(*a, **k)
        with self.component_guard():
            self._create_controls()
            self._create_session()
            self._create_navigation()
            self._create_drums()
            self._create_drum_finder()
            self._create_modes()
        self.set_feedback_channels(FEEDBACK_CHANNELS)
        self.__on_target_track_changed.subject = self._target_track_provider
        self.__on_armed_tracks_changed.subject = self._target_track_provider
        self.__on_percussion_instrument_found.subject = self._percussion_instrument_finder
        self.__on_percussion_instrument_found()
        self.__on_tempo_changed_in_live.subject = self.song
        self.__on_tempo_changed_in_live()
        self.__on_session_record_changed.subject = self.song
        self._set_feedback_velocity()

    def _create_controls(self):
        self._pads_raw = [
            ButtonElement(True,
                          MIDI_NOTE_TYPE,
                          0,
                          identifier,
                          name=u'Pad_{}'.format(identifier),
                          skin=skin) for identifier in range(100)
        ]
        self._session_matrix = ButtonMatrixElement(
            rows=[[self._pads_raw[offset + col] for col in range(NUM_TRACKS)]
                  for offset in range(80, 49, -10)],
            name=u'Session_Matrix')
        self._scene_launch_button_matrix = ButtonMatrixElement(
            rows=[[
                self._pads_raw[identifier]
                for identifier in range(89, 58, -10)
            ]],
            name=u'Scene_Launch_Button_Matrix')
        self._stop_all_clips_button = ButtonElement(
            True,
            MIDI_NOTE_TYPE,
            0,
            127,
            skin=skin,
            name=u'Stop_All_Clips_Button')
        self._nav_down_button = self._pads_raw[90]
        self._nav_up_button = self._pads_raw[91]
        self._nav_left_button = self._pads_raw[92]
        self._nav_right_button = self._pads_raw[93]
        self._mode_cycle_button = ButtonElement(True,
                                                MIDI_CC_TYPE,
                                                0,
                                                127,
                                                skin=skin,
                                                name=u'Mode_Button')
        self._drum_pads = ButtonMatrixElement(
            rows=[[self._pads_raw[offset + col] for col in range(4)]
                  for offset in range(48, 35, -4)],
            name=u'Drum_Pads')
        self._tempo_encoder = EncoderElement(
            MIDI_PB_TYPE,
            0,
            0,
            Live.MidiMap.MapMode.absolute,
            send_should_depend_on_forwarding=False,
            name=u'Tempo_Encoder')
        self._tempo_encoder.reset = nop
        self._sysex_element = SysexElement(sysex_identifier=SYSEX_HEADER,
                                           name=u'Sysex_Element')
        self._sysex_element.add_value_listener(nop)
        self._surface_update_message_element = ButtonElement(
            True, MIDI_CC_TYPE, 0, 64, name=u'Surface_Update_Message_Element')
        self.__on_surface_update_message_received.subject = self._surface_update_message_element

    def _create_session(self):
        self._session_ring = SessionRingComponent(num_tracks=NUM_TRACKS,
                                                  num_scenes=NUM_SCENES,
                                                  is_enabled=False,
                                                  name=u'Session_Ring')
        self._session = SessionComponent(session_ring=self._session_ring,
                                         name=u'Session')
        self._session.set_rgb_mode(LIVE_COLORS_TO_MIDI_VALUES, RGB_COLOR_TABLE)

    def _create_navigation(self):
        self._session_navigation = SessionNavigationComponent(
            session_ring=self._session_ring, name=u'Session_Navigation')

    def _create_drums(self):
        self._drum_group = DrumGroupComponent(
            name=u'Drum_Group', translation_channel=DRUM_FEEDBACK_CHANNEL)

    def _create_drum_finder(self):
        self._target_track_provider = TargetTrackProvider()
        self._percussion_instrument_finder = self.register_disconnectable(
            PercussionInstrumentFinder(
                device_parent=self._target_track_provider.target_track))

    def _create_modes(self):
        self._note_modes = ModesComponent(name=u'Note_Modes', is_enabled=False)
        self._melodic_pad_translator = ElementTranslator(
            self._pads_raw, MELODIC_FEEDBACK_CHANNEL, NON_FEEDBACK_CHANNEL)
        self._note_modes.add_mode(u'drum', [
            partial(self._send_mode_message, u'drum'),
            LayerMode(self._drum_group, Layer(matrix=self._drum_pads))
        ])
        self._note_modes.add_mode(u'melodic', [
            partial(self._send_mode_message, u'melodic'),
            self._melodic_pad_translator
        ])
        self._note_modes.add_mode(
            u'disabled', [partial(self._send_mode_message, u'disabled')])
        self._modes = ModesComponent(name=u'Modes')
        self._modes.add_mode(u'session', [
            partial(self._send_mode_message, u'session'),
            partial(self._clear_send_cache, self._pads_raw),
            LayerMode(
                self._session,
                Layer(clip_launch_buttons=self._session_matrix,
                      scene_launch_buttons=self._scene_launch_button_matrix,
                      stop_all_clips_button=self._stop_all_clips_button)),
            LayerMode(
                self._session_navigation,
                Layer(down_button=self._nav_down_button,
                      up_button=self._nav_up_button,
                      left_button=self._nav_left_button,
                      right_button=self._nav_right_button))
        ])
        self._modes.add_mode(u'note',
                             [self._note_modes, self._select_note_mode])
        self._modes.cycle_mode_button.set_control_element(
            self._mode_cycle_button)
        self._modes.selected_mode = u'session'

    @listens(u'target_track')
    def __on_target_track_changed(self):
        self._percussion_instrument_finder.device_parent = self._target_track_provider.target_track
        self._select_note_mode()

    @listens(u'instrument')
    def __on_percussion_instrument_found(self):
        self._drum_group.set_drum_group_device(
            self._percussion_instrument_finder.drum_group)
        self._select_note_mode()

    @listens(u'armed_tracks')
    def __on_armed_tracks_changed(self):
        self._set_feedback_velocity()

    @listens(u'tempo')
    def __on_tempo_changed_in_live(self):
        normalized_tempo = old_div(
            clamp(self.song.tempo, TEMPO_MIN, TEMPO_MAX) - TEMPO_MIN,
            TEMPO_MAX - TEMPO_MIN)
        value_to_send = clamp(int(normalized_tempo * PB_VALUE_RANGE_MAX), 0,
                              PB_VALUE_RANGE_MAX)
        self._tempo_encoder.send_value(value_to_send)

    @listens(u'session_record')
    def __on_session_record_changed(self):
        self._set_feedback_velocity()

    @listens(u'value')
    def __on_surface_update_message_received(self, value):
        if value:
            self._clear_send_cache(self.controls)
            self.update()
            self.__on_tempo_changed_in_live()

    def _set_feedback_velocity(self):
        target_track = self._target_track_provider.target_track
        if self.song.session_record and liveobj_valid(
                target_track) and target_track.arm:
            feedback_velocity = Rgb.RED.midi_value
        else:
            feedback_velocity = Rgb.GREEN.midi_value
        self._c_instance.set_feedback_velocity(int(feedback_velocity))

    def _select_note_mode(self):
        track = self._target_track_provider.target_track
        drum_device = self._percussion_instrument_finder.drum_group
        if not is_playable(track):
            self._note_modes.selected_mode = u'disabled'
        elif drum_device:
            self._note_modes.selected_mode = u'drum'
        else:
            self._note_modes.selected_mode = u'melodic'
        if self._note_modes.selected_mode == u'disabled':
            self.release_controlled_track()
        else:
            self.set_controlled_track(track)

    def _send_mode_message(self, mode):
        self._send_midi(
            (CC_STATUS + MODE_MSG_CHANNEL, MODE_NAMES_TO_IDS[mode], 127))

    def _clear_send_cache(self, controls):
        for control in controls:
            control.clear_send_cache()

    def port_settings_changed(self):
        super(Blocks, self).port_settings_changed()
        self.set_feedback_channels(FEEDBACK_CHANNELS)
Пример #10
0
    def __init__(self, *a, **k):
        super(Elements, self).__init__(*a, **k)
        self.display_up_button = create_button(81, 'Display_Up_Button')
        self.display_down_button = create_button(82, 'Display_Down_Button')
        self.up_button = create_button(85, 'Up_Button')
        self.down_button = create_button(86, 'Down_Button')
        self.mixer_up_button = create_button(87, 'Mixer_Up_Button')
        self.mixer_down_button = create_button(88, 'Mixer_Down_Button')
        self.grid_button = create_button(89, 'Grid_Button')
        self.options_button = create_button(90, 'Options_Button')
        self.shift_button = create_button(91,
                                          'Shift_Button',
                                          resource_type=PrioritizedResource)
        self.duplicate_button = create_button(92, 'Duplicate_Button')
        self.clear_button = create_button(93, 'Clear_Button')
        self.track_left_button = create_button(102, 'Track_Left_Button')
        self.track_right_button = create_button(103, 'Track_Right_Button')
        self.rw_button = create_button(112, 'RW_Button')
        self.ff_button = create_button(113, 'FF_Button')
        self.stop_button = create_button(114, 'Stop_Button')
        self.play_button = create_button(115, 'Play_Button')
        self.loop_button = create_button(116, 'Loop_Button')
        self.record_button = create_button(117, 'Record_Button')

        def with_shift(button):
            return ComboElement(control=button,
                                modifier=self.shift_button,
                                name=('{}_With_Shift').format(button.name))

        self.up_button_with_shift = with_shift(self.up_button)
        self.down_button_with_shift = with_shift(self.down_button)
        self.record_button_with_shift = with_shift(self.record_button)
        self.play_button_with_shift = with_shift(self.play_button)
        self.track_left_button_with_shift = with_shift(self.track_left_button)
        self.track_right_button_with_shift = with_shift(
            self.track_right_button)
        self.duplicate_button_with_shift = with_shift(self.duplicate_button)
        pads_raw = [[
            create_button(offset + col_index,
                          ('Pad_{}_{}').format(col_index, row_index),
                          msg_type=MIDI_NOTE_TYPE)
            for col_index in xrange(SESSION_WIDTH)
        ] for row_index, offset in enumerate((96, 112))]
        self.pads = ButtonMatrixElement(rows=pads_raw, name='Pads')
        self.pads_quadratic = ButtonMatrixElement(rows=[
            pads_raw[0][4:], pads_raw[1][4:], pads_raw[0][:4], pads_raw[1][:4]
        ],
                                                  name='Pads_Quadratic')
        self.pads_flattened = ButtonMatrixElement(
            rows=[pads_raw[0] + pads_raw[1]], name='Pads_Flattened')
        self.shifted_pad_row_1 = ButtonMatrixElement(
            rows=[[with_shift(control) for control in pads_raw[1]]],
            name='Pad_Row_1_With_Shift')
        scene_launch_buttons_raw = [
            create_button(83 + row_index,
                          name=('Scene_Launch_Button_{}').format(row_index))
            for row_index in xrange(SESSION_HEIGHT)
        ]
        self.scene_launch_buttons = ButtonMatrixElement(
            rows=[scene_launch_buttons_raw], name='Scene_Launch_Buttons')
        self.shifted_scene_launch_button_1 = with_shift(
            scene_launch_buttons_raw[1])
        sliders = [
            SpecialFeedbackChannelSliderElement(
                MIDI_CC_TYPE,
                DEFAULT_CHANNEL,
                41 + index,
                name=('Slider_{}').format(index))
            for index in xrange(SESSION_WIDTH)
        ]
        for slider in sliders:
            slider.set_feedback_delay(1)

        self.sliders = ButtonMatrixElement(rows=[sliders], name='Sliders')
        self.slider_leds = ButtonMatrixElement(rows=[[
            create_rgb_led(index + 54, ('Slider_LED_{}').format(index))
            for index in xrange(8)
        ]],
                                               name='Slider_LEDs')
        self.mixer_soft_button_row_0 = ButtonMatrixElement(
            rows=[[
                create_button(identifier,
                              ('Mixer_Soft_Button_{}_0').format(col_index))
                for col_index, identifier in enumerate(
                    xrange(59, 59 + SESSION_WIDTH))
            ]],
            name='Mixer_Soft_Button_Row_0')
        self.mixer_soft_button_row_1 = ButtonMatrixElement(
            rows=[[
                create_button(identifier,
                              ('Mixer_Soft_Button_{}_1').format(col_index))
                for col_index, identifier in enumerate(
                    xrange(59 + SESSION_WIDTH, 59 + SESSION_WIDTH * 2))
            ]],
            name='Mixer_Soft_Button_Row_1')
        self.message_display = SpecialPhysicalDisplayElement(
            width_in_chars=38,
            num_segments=NUM_MESSAGE_SEGMENTS,
            name='Message_Display')
        self.message_display.set_message_parts(sysex.SHOW_MESSAGE_MSG_HEADER,
                                               (sysex.SYSEX_END_BYTE, ))
        self.center_display_1 = mixin(CachingControlElement,
                                      ConfigurablePhysicalDisplayElement)(
                                          v_position=0,
                                          width_in_chars=9,
                                          name='Center_Display_1')
        self.center_display_2 = mixin(CachingControlElement,
                                      ConfigurablePhysicalDisplayElement)(
                                          v_position=1,
                                          width_in_chars=9,
                                          name='Center_Display_2')
        self.mixer_display_1 = mixin(CachingControlElement,
                                     ConfigurablePhysicalDisplayElement)(
                                         v_position=2,
                                         width_in_chars=9,
                                         name='Mixer_Button_Display_1')
        self.mixer_display_2 = mixin(CachingControlElement,
                                     ConfigurablePhysicalDisplayElement)(
                                         v_position=3,
                                         width_in_chars=9,
                                         name='Mixer_Button_Display_2')
        for display in (self.center_display_1, self.center_display_2,
                        self.mixer_display_1, self.mixer_display_2):
            display.set_message_parts(sysex.SET_PROPERTY_MSG_HEADER,
                                      (sysex.SYSEX_END_BYTE, ))
            display.segment(0).set_position_identifier((8, ))

        self.center_color_field = create_display_color_element(
            8, 0, 'Center_Color_Field')
        self.mixer_color_field_1 = create_display_color_element(
            8, 1, 'Mixer_Color_Field_1')
        self.mixer_color_field_2 = create_display_color_element(
            8, 2, 'Mixer_Color_Field_2')
        self.select_buttons_raw = [
            create_button(51 + index, ('Select_Button_{}').format(index))
            for index in xrange(8)
        ]
        self.select_buttons = ButtonMatrixElement(
            rows=[self.select_buttons_raw], name='Select_Buttons')
        self.select_buttons_with_shift_raw = [
            with_shift(button) for button in self.select_buttons_raw
        ]
        self.display_layout_switch = SysexElement(
            name='Display_Layout_Switch',
            send_message_generator=lambda v: sysex.
            SET_SCREEN_LAYOUT_MESSAGE_HEADER + (v, sysex.SYSEX_END_BYTE),
            default_value=sysex.EMPTY_SCREEN_LAYOUT_BYTE,
            optimized=True)
        self.text_display_line_0 = create_text_display_line(0)
        self.text_display_line_1 = create_text_display_line(1)
        self.text_display_line_2 = create_text_display_line(2)
        self.text_display_line_3 = create_text_display_line(3)
        self.text_display_line_5 = create_text_display_line(5)
        self.text_display_line_3_with_shift = with_shift(
            self.text_display_line_3)
        self.text_display_line_5_with_shift = with_shift(
            self.text_display_line_5)
        self.text_display_lines = [
            self.text_display_line_0, self.text_display_line_1,
            self.text_display_line_2, self.text_display_line_3,
            self.text_display_line_5
        ]
        color_field_line_0_raw, self.color_field_line_0 = create_display_color_element_line(
            0)
        color_field_line_1_raw, _ = create_display_color_element_line(1)
        self.color_field_line_2_raw, self.color_field_line_2 = create_display_color_element_line(
            2)
        self.color_field_lines_0_1_flattened = ButtonMatrixElement(
            rows=[color_field_line_0_raw + color_field_line_1_raw],
            name='Color_Field_Lines_0_1_Flattened')
        self.color_field_line_2_with_shift = ButtonMatrixElement(
            rows=[[
                with_shift(color_field)
                for color_field in self.color_field_line_2_raw
            ]],
            name='Color_Field_Line_2_With_Shift')
        selection_field_line_0_raw, _ = create_selection_field_line(0)
        self.selection_field_line_1_raw, self.selection_field_line_1 = create_selection_field_line(
            1)
        self.selection_field_line_2_raw, self.selection_field_line_2 = create_selection_field_line(
            2)
        self.selection_field_lines_0_1_flattened = ButtonMatrixElement(
            rows=[
                selection_field_line_0_raw + self.selection_field_line_1_raw
            ],
            name='Selection_Field_Lines_0_1_Flattened')
        self.selection_field_line_1_with_shift = ButtonMatrixElement(
            rows=[[
                with_shift(field) for field in self.selection_field_line_1_raw
            ]],
            name='Selection_Field_Line_1_With_Shift')
        self.selection_field_line_2_with_shift = ButtonMatrixElement(
            rows=[[
                with_shift(field) for field in self.selection_field_line_2_raw
            ]],
            name='Selection_Field_Line_2_With_Shift')
        encoders = [
            EncoderElement(
                MIDI_CC_TYPE,
                DEFAULT_CHANNEL,
                21 + index,
                map_mode=Live.MidiMap.MapMode.relative_smooth_two_compliment,
                name=('Encoder_{}').format(index)) for index in xrange(8)
        ]
        for encoder in encoders:
            encoder.set_feedback_delay(1)

        self.encoders = ButtonMatrixElement(rows=[encoders], name='Encoders')
        self.encoder_color_fields = ButtonMatrixElement(
            rows=[[
                create_display_color_element(
                    index, 1, ('Encoder_Color_Field_{}').format(index))
                for index in xrange(8)
            ]],
            name='Encoder_Color_Fields')
def make_encoder(identifier, name):
    return EncoderElement(MIDI_CC_TYPE,
                          0,
                          identifier,
                          (Live.MidiMap.MapMode.relative_smooth_signed_bit),
                          name=name)
Пример #12
0
    def __init__(self, product_id=None, skin=None, *a, **k):
        super(Elements, self).__init__(*a, **k)
        self._product_id = product_id
        self._skin = skin
        volume_encoder_touch_elements = [ self._make_note_button(13, index, (b'Volume_Encoder_Touch_Element_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                                        ]
        tui_volume_sliders = [ SliderElement(MIDI_CC_TYPE, index + 1, 0, name=(b'TUI_Volume_Slider_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                             ]
        for slider in tui_volume_sliders:
            slider.set_feedback_delay(1)

        physical_volume_encoders = [ TouchEncoderElement(MIDI_CC_TYPE, 13, index, Live.MidiMap.MapMode.relative_smooth_two_compliment, name=(b'Physical_Volume_Encoder_{}').format(index), touch_element=volume_encoder_touch_elements[index]) for index in xrange(NUM_TRACK_CONTROLS)
                                   ]
        for encoder in physical_volume_encoders:
            encoder.set_feedback_delay(1)

        self.volume_sliders = ButtonMatrixElement(rows=[
         [ MultiElement(tui_volume_sliders[index], physical_volume_encoders[index]) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Volume_Controls')
        self.pan_sliders = ButtonMatrixElement(rows=[
         [ SliderElement(MIDI_CC_TYPE, index + 1, 1, name=(b'TUI_Pan_Slider_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'TUI_Pan_Sliders')
        tui_device_controls = [ SliderElement(MIDI_CC_TYPE, 9, index, name=(b'TUI_Device_Control_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
                              ]
        for slider in tui_device_controls:
            slider.set_feedback_delay(1)

        self.tui_device_controls = ButtonMatrixElement(rows=[
         tui_device_controls], name=b'TUI_Device_Controls')
        self.physical_device_control_touch_elements = ButtonMatrixElement(rows=[
         [ self._make_note_button(13, index + 8, (b'Physical_Device_Control_Touch_Element_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
         ]], name=b'Physical_Device_Control_Touch_Elements')
        physical_device_controls = [ EncoderElement(MIDI_CC_TYPE, 13, index + 8, Live.MidiMap.MapMode.relative_smooth_two_compliment, name=(b'Physical_Device_Control_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
                                   ]
        for encoder in physical_device_controls:
            encoder.set_feedback_delay(1)

        self.physical_device_controls = ButtonMatrixElement(rows=[
         physical_device_controls], name=b'Physical_Device_Controls')
        self.device_parameter_enable_controls = ButtonMatrixElement(rows=[
         [ self._make_note_button(9, index + 112, (b'Device_Parameter_Enable_Control_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
         ]], name=b'Device_Parameter_Enable_Controls')
        self.solo_buttons_raw = [ MultiElement(self._make_note_button(index + 1, 0, (b'TUI_Solo_Button_{}').format(index)), name=(b'Solo_Button_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                                ]
        self.solo_buttons = ButtonMatrixElement(rows=[
         self.solo_buttons_raw], name=b'Solo_Buttons')
        self.mute_buttons_raw = [ MultiElement(self._make_note_button(index + 1, 1, (b'TUI_Mute_Button_{}').format(index)), name=(b'Mute_Button_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                                ]
        self.mute_buttons = ButtonMatrixElement(rows=[
         self.mute_buttons_raw], name=b'Mute_Buttons')
        self.solo_mute_buttons_raw = [ MultiElement(self._make_note_button(index + 1, 2, (b'TUI_Solo_Mute_Button_{}').format(index)), name=(b'Solo_Mute_Button_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                                     ]
        self.solo_mute_buttons = ButtonMatrixElement(rows=[
         self.solo_mute_buttons_raw], name=b'Solo_Mute_Buttons')
        self.arm_buttons_raw = [ MultiElement(self._make_note_button(index + 1, 5, (b'TUI_Arm_Button_{}').format(index)), name=(b'Arm_Button_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                               ]
        self.arm_buttons = ButtonMatrixElement(rows=[
         self.arm_buttons_raw], name=b'Arm_Buttons')
        self.clip_stop_buttons_raw = [ MultiElement(self._make_note_button(0, index + 16, (b'Clip_Stop_TUI_Button_{}').format(index)), name=(b'Clip_Stop_Button_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                                     ]
        self.clip_stop_buttons = ButtonMatrixElement(rows=[
         self.clip_stop_buttons_raw], name=b'Clip_Stop_Buttons')
        self.stop_all_clips_button = MultiElement(self._make_note_button(12, 89, name=b'Physical_Stop_All_Clips_Button'), self._make_note_button(10, 20, name=b'TUI_Stop_All_Clips_Button'), name=b'Stop_All_Clips_Button')
        self.send_encoders = ButtonMatrixElement(rows=[ [ EncoderElement(MIDI_CC_TYPE, row_index + 1, col_index + 3, Live.MidiMap.MapMode.absolute, name=(b'TUI_Send_Encoder_{}_{}').format(row_index, col_index)) for col_index in xrange(MAX_NUM_SENDS) ] for row_index in xrange(NUM_TRACK_CONTROLS)
                                                      ], name=b'TUI_Send_Encoders')
        self.send_value_displays = ButtonMatrixElement(rows=[ [ self._create_text_display_element((1, row_index + col_index * NUM_TRACK_CONTROLS + 24), (b'Send_Value_Display_{}_{}').format(row_index, col_index)) for col_index in xrange(MAX_NUM_SENDS) ] for row_index in xrange(NUM_TRACK_CONTROLS)
                                                            ], name=b'Send_Value_Displays')
        self.track_type_controls = ButtonMatrixElement(rows=[
         [ self._make_note_button(0, index + 8, (b'Track_Type_Control_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Track_Type_Controls')
        self.mute_button = self._make_note_button(12, 100, b'Mute_Button')
        self.solo_button = self._make_note_button(12, 101, b'Solo_Button')
        self.rec_arm_button = self._make_note_button(12, 102, b'Rec_Arm_Button')
        self.clip_stop_button = self._make_note_button(12, 103, b'Clip_Stop_Button')
        self.meter_controls_left = ButtonMatrixElement(rows=[
         [ SliderElement(MIDI_CC_TYPE, index + 1, 124, send_should_depend_on_forwarding=False, name=(b'Output_Meter_Display_Left_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Output_Meter_Displays_Left')
        self.meter_controls_right = ButtonMatrixElement(rows=[
         [ SliderElement(MIDI_CC_TYPE, index + 1, 125, send_should_depend_on_forwarding=False, name=(b'Output_Meter_Display_Right_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Output_Meter_Displays_Right')
        self._tui_track_select_buttons_raw = [ self._make_note_button(0, index, (b'TUI_Track_Select_Button_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
                                             ]
        self.track_name_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((0, index), (b'Track_Name_Display_{}').index) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Track_Name_Display')
        self.num_sends_control = ButtonElement(True, MIDI_CC_TYPE, 1, 2, name=b'Num_Sends_Control', send_should_depend_on_forwarding=False)
        self.tui_track_color_controls = ButtonMatrixElement(rows=[
         [ ButtonElement(True, MIDI_CC_TYPE, 0, index + 16, skin=skin, name=(b'TUI_Track_Color_Control_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'TUI_Track_Color_Controls')
        self.oled_display_style_controls_bank_1 = ButtonMatrixElement(rows=[
         [ self._make_note_button(13, index + 16, (b'OLED_Display_Style_Control_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'OLED_Display_Style_Controls_Bank_1')
        self.oled_display_style_controls_bank_2 = ButtonMatrixElement(rows=[
         [ self._make_note_button(13, index + 24, (b'OLED_Display_Style_Control_{}').format(index + NUM_PARAM_CONTROLS)) for index in xrange(NUM_PARAM_CONTROLS)
         ]], name=b'OLED_Display_Style_Controls_Bank_2')
        self.track_name_or_volume_value_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((18, index + 16), (b'Track_Name_Or_Volume_Value_Display_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Track_Name_Or_Volume_Value_Displays')
        self.device_parameter_name_or_value_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((18, index + 24), (b'Device_Parameter_Name_Or_Value_Display_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
         ]], name=b'Device_Parameter_Name_Or_Value_Displays')
        self.crossfade_assign_controls = ButtonMatrixElement(rows=[
         [ self._make_note_button(index + 1, 4, name=(b'Crossfade_Assign_Controk_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Crossfade_Assign_Controls')
        self.crossfader = SliderElement(MIDI_CC_TYPE, 13, 16, name=b'Crossfader')
        self.physical_clip_launch_buttons_raw = [ [ self._make_note_button(12, col_index + self.physical_clip_launch_button_id_offset + row_index * NUM_TRACK_CONTROLS, (b'Physical_Clip_Launch_Button_{}_{}').format(col_index, row_index)) for col_index in xrange(NUM_TRACK_CONTROLS) ] for row_index in xrange(NUM_SCENE_CONTROLS)
                                                ]
        self.clip_launch_buttons_raw = [ [ MultiElement(self._make_note_button(0, col_index + 24 + row_index * NUM_TRACK_CONTROLS, (b'TUI_Clip_Launch_Button_{}_{}').format(col_index, row_index)), name=(b'Clip_Launch_Button_{}_{}').format(col_index, row_index)) for col_index in xrange(NUM_TRACK_CONTROLS) ] for row_index in xrange(NUM_SCENE_CONTROLS)
                                       ]
        self.clip_launch_buttons = ButtonMatrixElement(rows=self.clip_launch_buttons_raw, name=b'Clip_Launch_Buttons')
        self.scene_launch_buttons = ButtonMatrixElement(rows=[
         [ self._make_note_button(0, index + 88, name=(b'TUI_Scene_Launch_Button_{}').format(index)) for index in xrange(NUM_SCENE_CONTROLS)
         ]], name=b'TUI_Scene_Launch_Buttons')
        self.clip_name_displays = ButtonMatrixElement(rows=[ [ self._create_text_display_element((0, row_index + 16 + col_index * NUM_SCENE_CONTROLS), (b'Clip_Name_Display_{}_{}').format(col_index, row_index)) for col_index in xrange(NUM_TRACK_CONTROLS) ] for row_index in xrange(NUM_SCENE_CONTROLS)
                                                           ])
        self.scene_name_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((0, index + 80), (b'Scene_Name_Display_{}').format(index)) for index in xrange(NUM_SCENE_CONTROLS)
         ]], name=b'Scene_Name_Displays')
        self.tui_scene_color_controls = ButtonMatrixElement(rows=[
         [ ButtonElement(True, MIDI_CC_TYPE, 0, index + 88, skin=skin, name=(b'TUI_Scene_Color_Control_{}').format(index)) for index in xrange(NUM_SCENE_CONTROLS)
         ]], name=b'TUI_Scene_Color_Controls')
        self.physical_clip_color_controls_raw = [ [ ButtonElement(True, MIDI_CC_TYPE, 12, row_index + self.pad_identifier_offset + col_index * NUM_SCENE_CONTROLS, skin=skin, name=(b'Physical_Clip_Color_Control_{}_{}').format(col_index, row_index)) for col_index in xrange(NUM_TRACK_CONTROLS) ] for row_index in xrange(NUM_SCENE_CONTROLS)
                                                ]
        self.clip_color_controls_raw = [ [ MultiElement(ButtonElement(True, MIDI_CC_TYPE, 0, row_index + 24 + col_index * NUM_SCENE_CONTROLS, skin=skin, name=(b'TUI_Clip_Color_Control_{}_{}').format(col_index, row_index)), name=(b'Clip_Color_Control_{}_{}').format(col_index, row_index)) for col_index in xrange(NUM_TRACK_CONTROLS) ] for row_index in xrange(NUM_SCENE_CONTROLS)
                                       ]
        self.clip_color_controls = ButtonMatrixElement(rows=self.clip_color_controls_raw, name=b'Clip_Color_Controls')
        self.playing_position_controls = ButtonMatrixElement(rows=[
         [ SliderElement(MIDI_CC_TYPE, 0, index, send_should_depend_on_forwarding=False, name=(b'Playing_Position_Control_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Playing_Position_Controls')
        self.shift_button = self._make_note_button(12, self.shift_button_id, b'Shift_Button', resource_type=PrioritizedResource)
        self.up_button = self._make_note_button(12, self.up_button_id, b'Up_Button')
        self.down_button = self._make_note_button(12, self.down_button_id, b'Down_Button')
        self.left_button = self._make_note_button(12, self.left_button_id, b'Left_Button')
        self.right_button = self._make_note_button(12, self.right_button_id, b'Right_Button')
        self.up_button_with_shift = ComboElement(self.up_button, modifier=[self.shift_button], name=b'Up_Button_With_Shift')
        self.down_button_with_shift = ComboElement(self.down_button, modifier=[self.shift_button], name=b'Down_Button_With_Shift')
        self.left_button_with_shift = ComboElement(self.left_button, modifier=[self.shift_button], name=b'Left_Button_With_Shift')
        self.right_button_with_shift = ComboElement(self.right_button, modifier=[
         self.shift_button], name=b'Right_Button_With_Shift')
        self.scene_selection_controls = ButtonMatrixElement(rows=[
         [ self._make_note_button(0, index + 96, (b'Scene_Selection_Control_{}').format(index)) for index in xrange(NUM_SCENE_CONTROLS)
         ]], name=b'Scene_Selection_Controls')
        self.duplicate_button = self._make_note_button(12, self.duplicate_button_id, b'Duplicate_Button')
        self.undo_button = self._make_note_button(12, self.undo_button_id, b'Undo_Button')
        self.redo_button = ComboElement(self.undo_button, modifier=[self.shift_button], name=b'Redo_Button')
        self.tui_device_parameter_name_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((2, index + 16), (b'TUI_Device_Parameter_Name_Display_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
         ]], name=b'TUI_Device_Parameter_Name_Displays')
        self.tui_device_parameter_value_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((2, index + 32), (b'TUI_Device_Parameter_Value_Display_{}').format(index)) for index in xrange(NUM_PARAM_CONTROLS)
         ]], name=b'TUI_Device_Parameter_Value_Displays')
        self.tui_arrangement_position_display = self._create_text_display_element((3,
                                                                                   16), b'TUI_Arrangement_Position_Display')
        self.tui_loop_start_display = self._create_text_display_element((3, 17), b'TUI_Loop_Start_Display')
        self.tui_loop_length_display = self._create_text_display_element((3, 18), b'TUI_Loop_Length_Display')
        self.tui_arrangement_position_control = EncoderElement(MIDI_CC_TYPE, 10, 0, Live.MidiMap.MapMode.relative_smooth_two_compliment, name=b'TUI_Arrangement_Position_Control')
        self.tui_loop_start_control = EncoderElement(MIDI_CC_TYPE, 10, 1, Live.MidiMap.MapMode.relative_smooth_two_compliment, name=b'TUI_Loop_Start_Control')
        self.tui_loop_length_control = EncoderElement(MIDI_CC_TYPE, 10, 2, Live.MidiMap.MapMode.relative_smooth_two_compliment, name=b'TUI_Loop_Length_Control')
        tempo_control_identifier = (3, 0)
        self.tempo_display = self._create_text_display_element(tempo_control_identifier, b'Tempo_Display')
        self.tempo_control = SysexElement(sysex_identifier=sysex.SYSEX_MSG_HEADER + (self._product_id, sysex.TEXT_MSG_TYPE) + tempo_control_identifier, name=b'Tempo_Control')
        self.play_button = self._make_note_button(12, self.play_button_id, b'Play_Button')
        self.stop_button = self._make_note_button(12, self.stop_button_id, b'Stop_Button')
        self.session_record_button = self._make_note_button(12, self.session_record_button_id, b'Session_Record_Button')
        self.tap_tempo_button = self._make_note_button(12, self.tap_tempo_button_id, b'Tap_Tempo_Button')
        self._tui_prev_device_button = self._make_note_button(9, 1, b'TUI_Prev_Device_Button')
        self._tui_next_device_button = self._make_note_button(9, 2, b'TUI_Next_Device_Button')
        self.device_lock_button = self._make_note_button(10, 10, b'Device_Lock_Button', is_momentary=False)
        self.num_devices_control = ButtonElement(True, MIDI_CC_TYPE, 9, 16, name=b'Num_Devices_Control')
        self.device_index_control = ButtonElement(True, MIDI_CC_TYPE, 9, 17, name=b'Device_Index_Control')
        self.device_name_display = self._create_text_display_element((2, 1), b'Device_Name_Display')
        self.device_enable_button = self._make_note_button(9, 0, b'Device_Enable_Button', is_momentary=False)
        self._tui_prev_bank_button = self._make_note_button(9, 3, b'TUI_Prev_Bank_Button')
        self._tui_next_bank_button = self._make_note_button(9, 4, b'TUI_Next_Bank_Button')
        self.device_bank_name_display = self._create_text_display_element((2, 0), b'Device_Bank_Name_Display')
        self._tui_phase_nudge_down_button = self._make_note_button(10, 12, b'TUI_Phase_Nudge_Down_Button')
        self._tui_phase_nudge_up_button = self._make_note_button(10, 13, b'TUI_Phase_Nudge_Up_Button')
        self.tui_metronome_button = self._make_note_button(10, 0, b'TUI_Metronome_Button', is_momentary=False)
        self.tui_automation_arm_button = self._make_note_button(10, 4, b'TUI_Automation_Arm_Button', is_momentary=False)
        self.loop_button = self._make_note_button(10, 5, b'Loop_Button', is_momentary=False)
        self.arrangement_overdub_button = self._make_note_button(10, 3, b'Arrangement_Overdub_Button', is_momentary=False)
        self.follow_song_button = self._make_note_button(10, 8, b'Follow_Song_Button', is_momentary=False)
        self.quantization_value_control = self._make_note_button(10, 15, b'Quantization_Value_Control')
        self._tui_quantize_button = self._make_note_button(10, 16, b'TUI_Quantize_Button')
        self.clip_trigger_quantization_control = self._make_note_button(10, 6, b'Clip_Trigger_Quantization_Control')
        self.delete_button = MultiElement(self._make_note_button(10, 14, b'TUI_Delete_Button'), self._make_note_button(12, self.delete_button_id, b'Physical_Delete_Button'), name=b'Delete_Button')
        self.volume_value_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((1, index), (b'Volume_Value_Display_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Volume_Value_Displays')
        self.pan_value_displays = ButtonMatrixElement(rows=[
         [ self._create_text_display_element((1, 16 + index), (b'Pan_Value_Display_{}').format(index)) for index in xrange(NUM_TRACK_CONTROLS)
         ]], name=b'Pan_Value_Displays')
        self.tui_arrangement_record_button = self._make_note_button(10, 22, b'TUI_Arrangement_Record_Button', False)
        self.insert_scene_button = self._make_note_button(10, 21, b'Insert_Scene_Button')
        self.launch_mode_switch = self._make_note_button(10, 23, b'Launch_Mode_Switch')