def _on_control_surface_offset_changed(self): """ Updates offsets in serato to be the same as in control surface Called whenever control surface offsets are changed. """ SessionComponent.set_offsets(self, self._synced_session.track_offset(), self._synced_session.scene_offset())
class SessionControl(): def __init__(self, control_surface): self.control_surface = control_surface self.width = 8 self.height = 1 self.component = SessionComponent(self.width, self.height) self.component.set_offsets( 0, 0 ) #(track_offset, scene_offset) Sets the initial offset of the "red box" from top left # navigation control_surface.get_encoder(3, 7).add_value_listener(self._track_nav) def _track_nav(self, value): value -= 64 session = self.component track_offset = min( max(0, session.track_offset() + value), max(0, len(self.control_surface.song().tracks) - self.width)) #self.control_surface.log_message("track_offset %d" % track_offset) session.set_offsets(track_offset, session.scene_offset())
class SessionManager(AbstractControlSurfaceComponent): def __init__(self, *a, **k): super(SessionManager, self).__init__(*a, **k) self.session = None # type: SessionComponent self.register_slot(self.parent.songManager, self._setup_session_control, "selected_track") self.register_slot(self.parent.songManager, self._setup_session_control, "scene_list") @catch_and_log def _setup_session_control(self): if not self.is_enabled() or self.song.current_track is None: return session_track_offset = self.session_track_offset if self.session: self.session.disconnect() num_tracks = len([ track for track in self.song.current_track.all_tracks if track.is_visible ]) self.session = SessionComponent(num_tracks=num_tracks, num_scenes=len(self.song.scenes)) self.session.set_offsets(track_offset=session_track_offset, scene_offset=0) self.parent.set_highlighting_session_component(self.session) @property def session_track_offset(self): # type: () -> int try: return [t for t in self.song.simple_tracks if t.is_visible].index(self.song.current_track.base_track) except ValueError: return self.session.track_offset() if self.session else 0
def _setup_session_control(self): is_momentary = True num_tracks = COLS num_scenes = ROWS global session session = SessionComponent(num_tracks, num_scenes) session.name = "Session" session.set_offsets(0, 0) self._session = session self._session.set_stop_track_clip_value(0) self._scene = [None for index in range(ROWS)] for row in range(num_scenes): self._scene[row] = session.scene(row) self._scene[row].name = 'Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_' + str(row) clip_slot.set_triggered_to_play_value(64) clip_slot.set_triggered_to_record_value(64) clip_slot.set_stopped_value(0) clip_slot.set_started_value(64) clip_slot.set_recording_value(64) #clip_slot.set_launch_button(self._grid[column][row]) #comment out if you don't want clip launch session.set_mixer(mixer) self._session_zoom = SessionZoomingComponent(session) self._session_zoom.name = 'Session_Overview' self._session_zoom.set_stopped_value(0) self._session_zoom.set_playing_value(64) self._session_zoom.set_selected_value(64) if STANDALONE is True: self.set_highlighting_session_component(self._session) self._session.set_track_bank_buttons(self._grid[5][3], self._grid[4][3]) #comment out when using with Griid self._session.set_scene_bank_buttons(self._grid[7][3], self._grid[6][3]) # comment out when using with Griid
def _setup_session_control(self): is_momentary = True # Size of session box num_tracks = 8 # column num_scenes = 1 # row """ Buttons declaration """ # Navigation button_navig_up = ButtonElement(is_momentary, MIDI_CC_TYPE, midi_channel, midi_session_up) button_navig_down = ButtonElement(is_momentary, MIDI_CC_TYPE, midi_channel, midi_session_down) """ Declare our session box """ global session #We want to instantiate the global session as a SessionComponent object (it was a global "None" type up until now...) session = SessionComponent(num_tracks, num_scenes) #(num_tracks, num_scenes) A session highlight ("red box") will appear with any two non-zero values session.set_offsets(0, 0) #(track_offset, scene_offset) Sets the initial offset of the "red box" from top left session._do_show_highlight() #to ensure that this session will be highlighted """ Buttons association """ # Navigation up, down, left, right session.set_scene_bank_buttons(button_navig_down, button_navig_up) # Launch selected clip for index in range(num_tracks): session.scene(0).clip_slot(index).set_launch_button(ButtonElement(is_momentary, MIDI_CC_TYPE, midi_channel, midi_session_launch_clip[index])) # Stop selected track stop_track_buttons = [] for index in range(num_tracks): stop_track_buttons.append(ButtonElement(is_momentary, MIDI_CC_TYPE, midi_channel, midi_session_stop_track[index])) session.set_stop_track_clip_buttons(tuple(stop_track_buttons)) #array size needs to match num_tracks
def _setup_session_control(self): is_momentary = True num_tracks = COLS num_scenes = ROWS global session session = SessionComponent(num_tracks, num_scenes) session.name = "Session" session.set_offsets(0, 0) self._session = session self._session.set_stop_clip_value(0) self._scene = [None for index in range(ROWS)] for row in range(num_scenes): self._scene[row] = session.scene(row) self._scene[row].name = 'Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_' + str(row) clip_slot.set_triggered_to_play_value(64) clip_slot.set_triggered_to_record_value(64) clip_slot.set_stopped_value(0) clip_slot.set_started_value(64) clip_slot.set_recording_value(64) #clip_slot.set_launch_button(self._grid[column][row]) #comment out if you don't want clip launch session.set_mixer(mixer) self._session_zoom = SessionZoomingComponent(session) self._session_zoom.name = 'Session_Overview' self._session_zoom.set_stopped_value(0) self._session_zoom.set_playing_value(64) self._session_zoom.set_selected_value(64) if STANDALONE is True: self.set_highlighting_session_component(self._session) self._session.set_track_bank_buttons(self._grid[5][3], self._grid[4][3]) #comment out when using with Griid self._session.set_scene_bank_buttons(self._grid[7][3], self._grid[6][3]) # comment out when using with Griid
class MaschinAble(ControlSurface): __module__ = __name__ __doc__ = '''Midi Remote Script for Clip launch control on the\n Native Instruments Maschine Controller''' def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) self.log_message("====================== MaschineAble Log opened ======================") self.set_suppress_rebuild_requests(True) self._suggested_input_port = 'Maschine Controller In' self._suggested_output_port = 'Maschine Controller Out' self.session = None self._setup_session_control() self.set_suppress_rebuild_requests(False) def _setup_session_control(self): is_momentary = True num_tracks = 4 num_scenes = 4 self.session = SessionComponent(num_tracks, num_scenes) self.session.name = 'MaschinAble_session_control' matrix = ButtonMatrixElement() self.session.set_offsets(0, 0) up_button = ButtonElement(is_momentary, 1, 1, 108) down_button = ButtonElement(is_momentary, 1, 1, 109) left_button = ButtonElement(is_momentary, 1, 1, 110) right_button = ButtonElement(is_momentary, 1, 1, 111) self.session.set_track_bank_buttons(right_button, left_button) self.session.set_scene_bank_buttons(down_button, up_button) launch_notes_start_from = 112 launch_notes = range(launch_notes_start_from, launch_notes_start_from + 16) current_scene = list( self.song().scenes).index(self.song().view.selected_scene) current_track = list( self.song().tracks).index(self.song().view.selected_track) for scene_index in range(num_scenes): button_row = [] for track_index in range(num_tracks): clip_slot = self.session.scene(num_scenes - 1 - scene_index + current_scene).clip_slot(track_index + current_track) button = ButtonElement(is_momentary, 0, 1, launch_notes[track_index+(4*scene_index)]) button_row.append(button) if clip_slot.has_clip: clip_slot.set_stopped_value(1) else: clip_slot.set_stopped_value(0) clip_slot.set_triggered_to_play_value(2) clip_slot.set_triggered_to_record_value(2) clip_slot.set_launch_button(button) matrix.add_row(tuple(button_row)) def disconnect(self): ControlSurface.disconnect(self) self.log_message("====================== MaschineAble Log closed ======================")
def _setup_session_control(self): is_momentary = True num_tracks = 1 #single column num_scenes = 7 #seven rows, which will be mapped to seven "white" notes global session #We want to instantiate the global session as a SessionComponent object (it was a global "None" type up until now...) session = SessionComponent( num_tracks, num_scenes ) #(num_tracks, num_scenes) A session highlight ("red box") will appear with any two non-zero values session.set_offsets( 0, 0 ) #(track_offset, scene_offset) Sets the initial offset of the "red box" from top left """set up the session navigation buttons""" session.set_select_buttons( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 25), ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 27) ) # (next_button, prev_button) Scene select buttons - up & down - we'll also use a second ControlComponent for this (yellow box) session.set_scene_bank_buttons( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 51), ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 49) ) # (up_button, down_button) This is to move the "red box" up or down (increment track up or down, not screen up or down, so they are inversed) #session.set_track_bank_buttons(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 56), ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 54)) # (right_button, left_button) This moves the "red box" selection set left & right. We'll put our track selection in Part B of the script, rather than here... session.set_stop_all_clips_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 70)) session.selected_scene().set_launch_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 30)) """Here we set up the scene launch assignments for the session""" launch_notes = [ 60, 62, 64, 65, 67, 69, 71 ] #this is our set of seven "white" notes, starting at C4 for index in range( num_scenes ): #launch_button assignment must match number of scenes session.scene(index).set_launch_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, launch_notes[index]) ) #step through the scenes (in the session) and assign corresponding note from the launch_notes array """Here we set up the track stop launch assignment(s) for the session""" #The following code is set up for a longer array (we only have one track, so it's over-complicated, but good for future adaptation).. stop_track_buttons = [] for index in range(num_tracks): stop_track_buttons.append( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 58 + index) ) #this would need to be adjusted for a longer array (because we've already used the next note numbers elsewhere) session.set_stop_track_clip_buttons( tuple(stop_track_buttons)) #array size needs to match num_tracks """Here we set up the clip launch assignments for the session""" clip_launch_notes = [ 48, 50, 52, 53, 55, 57, 59 ] #this is a set of seven "white" notes, starting at C3 for index in range(num_scenes): session.scene(index).clip_slot(0).set_launch_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, clip_launch_notes[index]) ) #step through scenes and assign a note to first slot of each """Here we set up a mixer and channel strip(s) which move with the session""" session.set_mixer( mixer) #Bind the mixer to the session so that they move together
def _setup_session_control(self): num_tracks = 7 num_scenes = 4 session_nav_button = [ ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, SESSION_NAV_BUTTONS[index]) for index in range(2) ] session_stop_button = [] matrix = ButtonMatrixElement() matrix.name = 'Button_Matrix' global session session = SessionComponent(num_tracks, num_scenes) session.name = 'Session_Control' session.set_offsets(0, 0) session.set_scene_bank_buttons(session_nav_button[1], session_nav_button[0]) #session.set_track_bank_buttons(session_nav_button[3], session_nav_button[2]) for row in xrange(num_scenes): scene_launch_button = ButtonElement(True, MIDI_NOTE_TYPE, CHANNEL, SCENE_LAUNCH_BUTTONS[row]) session_row = [] scene = session.scene(row) scene.name = 'Scene' + str(row) scene.set_launch_button(scene_launch_button) scene.set_triggered_value(2) #scene_launch_button._set_skin_light(68) for column in xrange(num_tracks): clip_launch_button = ButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, CLIP_LAUNCH_BUTTONS[row][column]) clip_launch_button.name = str(column) + '_Clip_' + str( row) + '_Button' session_row.append(clip_launch_button) clip_slot = scene.clip_slot(column) clip_slot.name = str(column) + '_ClipSlot_' + str(row) clip_slot.set_launch_button(clip_launch_button) #clip_launch_button._set_skin_light(76) matrix.add_row(tuple(session_row)) for column in xrange(num_tracks): session_stop_button.append( ButtonElement(True, MIDI_NOTE_TYPE, CHANNEL, SESSION_STOP_BUTTONS[column])) self._supress_session_highlight = False self._supress_send_midi = False self.set_highlighting_session_component(session) session.set_stop_track_clip_buttons(tuple(session_stop_button))
class AAB(ControlSurface): def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.session = SessionComponent(4, 4) self.session.set_offsets(0, 0) self.session.scene(0).clip_slot(0).set_launch_button(ButtonElement(False, 1, 6, 2)) self.session.scene(0).clip_slot(1).set_launch_button(ButtonElement(False, 0, 6, 0)) self.set_highlighting_session_component(self.session)
class SessionManager(AbstractControlSurfaceComponent): def __init__(self, *a, **k): # type: (Any, Any) -> None super(SessionManager, self).__init__(*a, **k) self.session = None # type: Optional[SessionComponent] # self.register_slot(self.parent.songManager, self.display_session_ring, "selected_track") def toggle_session_ring(self): # type: () -> None self._display_session_ring() self._hide_session_ring() def _display_session_ring(self): # type: () -> None if self.session: self._hide_session_ring() try: if not self.song.selected_track.IS_ACTIVE: return except IndexError: return def get_all_sub_tracks_inclusive(parent_track): # type: (SimpleTrack) -> List[SimpleTrack] sub_tracks = [parent_track] for sub_track in parent_track.sub_tracks: sub_tracks.extend(get_all_sub_tracks_inclusive(sub_track)) return sub_tracks total_tracks = get_all_sub_tracks_inclusive(self.song.current_track.base_track) num_tracks = len([track for track in total_tracks if track.is_visible]) track_offset = self.session_track_offset with self.parent.component_guard(): self.session = SessionComponent(num_tracks=num_tracks, num_scenes=len(self.song.scenes)) self.session.set_offsets(track_offset=track_offset, scene_offset=0) if track_offset != len(list(self.song.visible_tracks)) - 1: self.parent.set_highlighting_session_component(self.session) def _hide_session_ring(self): # type: () -> None if self.session: self.session.set_show_highlight(False) self.session.disconnect() @property def session_track_offset(self): # type: () -> int try: return list(self.song.visible_tracks).index(self.song.current_track.base_track) except ValueError: return self.session.track_offset() if self.session else 0
class AAB(ControlSurface): def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.session = SessionComponent(4, 4) self.session.set_offsets(0, 0) self.session.scene(0).clip_slot(0).set_launch_button( ButtonElement(False, 1, 6, 2)) self.session.scene(0).clip_slot(1).set_launch_button( ButtonElement(False, 0, 6, 0)) self.set_highlighting_session_component(self.session)
def _setup_selection_box_control(self, indexDicer): is_momentary = True # Size of session box num_tracks = 1 #1 column num_scenes = 1 #1 row """ Buttons declaration """ # Navigation button_navig_up = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[0]) button_navig_down = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[1]) button_navig_left = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[3]) button_navig_right = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[4]) # Launch clip button_launch_clip = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[2]) # Stop track button_stop_track = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_shifted[2]) # Stop all tracks #button_stop_track_all """ Declare our session box """ global session #We want to instantiate the global session as a SessionComponent object (it was a global "None" type up until now...) session = SessionComponent( num_tracks, num_scenes ) #(num_tracks, num_scenes) A session highlight ("red box") will appear with any two non-zero values session.set_offsets( indexDicer * 4, 0 ) #(track_offset, scene_offset) Sets the initial offset of the "red box" from top left session._do_show_highlight( ) #to ensure that this session will be highlighted """ Buttons association """ # Navigation up, down, left, right session.set_scene_bank_buttons(button_navig_down, button_navig_up) session.set_track_bank_buttons(button_navig_right, button_navig_left) # Launch selected clip session.scene(0).clip_slot(0).set_launch_button(button_launch_clip) # Stop selected track stop_track_buttons = [] stop_track_buttons.append(button_stop_track) session.set_stop_track_clip_buttons( tuple(stop_track_buttons)) #array size needs to match num_tracks
def _setup_session_control(self): is_momentary = True num_tracks = 7 num_scenes = 5 global session session = SessionComponent(num_tracks, num_scenes) session.name = "Session" self._session = session session.set_offsets(0, 0) self._scene = [None for index in range(6)] for row in range(num_scenes): self._scene[row] = session.scene(row) self._scene[row].name = 'Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_' + str(row) session.set_mixer(self._mixer) self._session_zoom = SessionZoomingComponent(session) self._session_zoom.name = 'Session_Overview'
class midilooper(ControlSurface): def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self._instance = c_instance self._has_slider_section = True self.log_message("Midilooper initializing...") # register_sender(self) self._session = SessionComponent(NUM_TRACKS, NUM_ROWS) self._session.name = 'Session_Control' self._mixer = MixerComponent(NUM_TRACKS, NUM_RETURNS) for track in range(NUM_TRACKS): strip = self._mixer.channel_strip(track) strip.name = 'Channel_Strip_' + str(track) # encoder = EncoderElement(MIDI_CC_TYPE, 0, 20 + track, Live.MidiMap.MapMode.absolute) control = SliderElement(MIDI_CC_TYPE, 0, 20+track) control.name = str(track) + '_Volume_Control' strip.set_volume_control(control) for track in range(NUM_RETURNS): strip = self._mixer.return_strip(track) control = SliderElement(MIDI_CC_TYPE, 0, 40+track) control.name = str(track) + '_Return_Control' strip.set_volume_control(control) strip = self._mixer.master_strip() strip.name = 'Master_Channel_Strip' control = SliderElement(MIDI_CC_TYPE, 0, 50) control.name = 'Master_Volume_Control' strip.set_volume_control(control) self._session.set_offsets(0, 0); self._session.set_mixer(self._mixer) for row in range(NUM_ROWS): scene = self._session.scene(row) for track in range(NUM_TRACKS): slot = scene.clip_slot(track) button = ButtonElement(True, MIDI_NOTE_TYPE, track, 36+row) slot.set_launch_button(button) self.set_highlighting_session_component(self._session) self.request_rebuild_midi_map() self.log_message("Midilooper initialized.") def disconnect(self): ControlSurface.disconnect(self)
class SessionControl(): def __init__(self, control_surface): self.control_surface = control_surface self.width = 8 self.height = 1 self.component = SessionComponent(self.width, self.height) self.component.set_offsets(0, 0) #(track_offset, scene_offset) Sets the initial offset of the "red box" from top left # navigation control_surface.get_encoder(3,7).add_value_listener(self._track_nav) def _track_nav(self, value): value-= 64 session = self.component track_offset = min(max(0, session.track_offset()+value), max(0, len(self.control_surface.song().tracks)-self.width)) #self.control_surface.log_message("track_offset %d" % track_offset) session.set_offsets(track_offset, session.scene_offset())
class Pw(ControlSurface): def __init__(self, c_instance): super(Pw, self).__init__(c_instance) with self.component_guard(): self.clips = [] config = self._open_config() self._setup_session(config['width'], config['height']) self._setup_strip() self._track_clip_slots_info() def _open_config(self): with open('/users/berry/config.json') as f: data = json.load(f) self.log(json.dumps(data)) return json.loads(json.dumps(data)) def _track_clip_slots_info(self): track = self.session.tracks_to_use()[0] for cs in track.clip_slots: if cs.clip is not None: self.clips.append(cs.clip.name) self.log(json.dumps(self.clips)) def _setup_session(self, width, height): self.session = SessionComponent(width, height) self.session.set_offsets(0, 0) self.set_highlighting_session_component(self.session) def _setup_strip(self): self.strip = ChannelStripComponent() self._update_strip() def _update_strip(self): self.strip.set_track(self.session.tracks_to_use()[0]) def log(self, message): log_str = 'LOG: ' + message + '\n' with io.open("/users/berry/somefile.txt", mode='w', encoding='utf-8') as f: f.write(log_str) f.close()
def _setup_session_control(self): is_momentary = True num_tracks = 7 num_scenes = 7 ###changed from 5 for HH global session session = SessionComponent(num_tracks, num_scenes) session.name = "Session" session.set_offsets(0, 0) self._session = session self._scene = [None for index in range(num_scenes)] for row in range(num_scenes): self._scene[row] = session.scene(row) self._scene[row].name = 'Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_' + str(row) session.set_mixer(mixer) self._session_zoom = SessionZoomingComponent(session) self._session_zoom.name = 'Session_Overview' #self._session_zoom.set_enabled(False) self.set_highlighting_session_component(self._session)
def _create_session_control(self): is_momentary = True num_tracks = 1 num_scenes = 7 global session session = SessionComponent(num_tracks, num_scenes) session.set_offsets(0, 0) """set up the session navigation buttons""" session.set_select_buttons( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 25), ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 27)) session.set_scene_bank_buttons( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 51), ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 49)) session.set_stop_all_clips_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 70)) session.selected_scene().set_launch_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 30)) """Here we set up the scene launch assignments for the session""" launch_notes = [60, 62, 64, 65, 67, 69, 71] for index in range(num_scenes): session.scene(index).set_launch_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, launch_notes[index])) """Here we set up the track stop launch assignment(s) for the session""" stop_track_buttons = [] for index in range(num_tracks): stop_track_buttons.append( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 58 + index)) session.set_stop_track_clip_buttons(tuple(stop_track_buttons)) """Here we set up the clip launch assignments for the session""" clip_launch_notes = [48, 50, 52, 53, 55, 57, 59] for index in range(num_scenes): session.scene(index).clip_slot(0).set_launch_button( ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, clip_launch_notes[index])) """Here we set up a mixer and channel strip(s) which move with the session""" self.log_message("Captain's log stardate 3")
def _setup_selection_box_control(self, indexDicer): is_momentary = True # Size of session box num_tracks = 1 #1 column num_scenes = 1 #1 row """ Buttons declaration """ # Navigation button_navig_up = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[0]) button_navig_down = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[1]) button_navig_left = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[3]) button_navig_right = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[4]) # Launch clip button_launch_clip = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_normal[2]) # Stop track button_stop_track = ButtonElement(is_momentary, MIDI_NOTE_TYPE, midi_channel_red[indexDicer] - 1, midi_cc_shifted[2]) # Stop all tracks #button_stop_track_all """ Declare our session box """ global session #We want to instantiate the global session as a SessionComponent object (it was a global "None" type up until now...) session = SessionComponent(num_tracks, num_scenes) #(num_tracks, num_scenes) A session highlight ("red box") will appear with any two non-zero values session.set_offsets(indexDicer * 4, 0) #(track_offset, scene_offset) Sets the initial offset of the "red box" from top left session._do_show_highlight() #to ensure that this session will be highlighted """ Buttons association """ # Navigation up, down, left, right session.set_scene_bank_buttons(button_navig_down, button_navig_up) session.set_track_bank_buttons(button_navig_right, button_navig_left) # Launch selected clip session.scene(0).clip_slot(0).set_launch_button(button_launch_clip) # Stop selected track stop_track_buttons = [] stop_track_buttons.append(button_stop_track) session.set_stop_track_clip_buttons(tuple(stop_track_buttons)) #array size needs to match num_tracks
def _setup_session_control(self): global session is_momentary = True num_tracks = 7 num_scenes = 5 session = SessionComponent(num_tracks, num_scenes) session.name = 'Session' self._session = session session.set_offsets(0, 0) self._scene = [ None for index in range(6) ] for row in range(num_scenes): self._scene[row] = session.scene(row) self._scene[row].name = 'Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_' + str(row) session.set_mixer(self._mixer) session.set_show_highlight(True) self._session_zoom = SessionZoomingComponent(session) self._session_zoom.name = 'Session_Overview' self.set_highlighting_session_component(self._session)
class LemurPad(MonOhm): __module__ = __name__ __doc__ = " Lemur version of the MonOhm companion controller script " def __init__(self, *a, **k): self._timer_callbacks = [] #Used for _monobridge, which uses L8 method for registering timer callbacks. deprecated, needs to be replaced by new L9 Task class. self._osc_registry = {} self._display_button_names = DISPLAY_BUTTON_NAMES super(LemurPad, self).__init__(*a, **k) self._host_name = "LemurPad" self._color_type = 'AumPad' self.connected = 0 with self.component_guard(): self._setup_touchosc() self._assign_host2() self._assign_session_colors() def query_ohm(self): pass """script initialization methods""" def _setup_monobridge(self): self._monobridge = OSCMonoBridgeElement(self) self._monobridge.name = 'MonoBridge' def _setup_controls(self): is_momentary = True self._fader = [None for index in range(8)] self._dial = [None for index in range(16)] self._button = [None for index in range(8)] self._menu = [None for index in range(6)] for index in range(8): self._fader[index] = OSCMonoEncoderElement(MIDI_CC_TYPE, CHANNEL, OHM_FADERS[index], Live.MidiMap.MapMode.absolute, 'Fader_' + str(index), index, '/Fader_'+str(index)+'/x', '/Strip'+str(index+8)+'/set', '/Strip'+str(index)+'/set', self) for index in range(8): self._button[index] = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, OHM_BUTTONS[index], 'Button_'+str(index), '/Select_'+str(index)+'/value', '/Select/set '+str(index), '/Select/text '+str(index), self) for index in range(16): self._dial[index] = OSCMonoEncoderElement(MIDI_CC_TYPE, CHANNEL, OHM_DIALS[index], Live.MidiMap.MapMode.absolute, 'Dial_' + str(index), index + 8, '/Dial_'+str(index)+'/x', '/Dial'+str(index)+'val/set', '/Dial'+str(index)+'name/set', self) for index in range(6): self._menu[index] = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, OHM_MENU[index], 'Menu_' + str(index), '/Function_'+str(index)+'/value', '/Function/set '+str(index), '/Function/text '+str(index), self) self._crossfader = OSCMonoEncoderElement(MIDI_CC_TYPE, CHANNEL, CROSSFADER, Live.MidiMap.MapMode.absolute, "Crossfader", 24, '/XFader/x', '/XFader/none', None, self) self._livid = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, LIVID, 'Livid_Button', '/Livid/x', '/Livid/x', None, self) self._shift_l = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, SHIFT_L, 'Shift_Button_Left', '/ShiftL/x', '/ShiftL/x', None, self) self._shift_r = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, SHIFT_R, 'Shift_Button_Right', '/ShiftR/x', '/ShiftR/x', None, self) self._matrix = ButtonMatrixElement() self._matrix.name = 'Matrix' self._monomod = ButtonMatrixElement() self._monomod.name = 'Monomod' self._grid = [None for index in range(8)] for column in range(8): self._grid[column] = [None for index in range(8)] for row in range(8): self._grid[column][row] = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, (column * 8) + row, 'Grid_' + str(column) + '_' + str(row), '/ClipGrid_'+str(column)+'_'+str(row)+'/value', '/ClipGrid/set '+str(column)+' '+str(row), '/ClipGrid/text '+str(column)+' '+str(row), self) for row in range(5): button_row = [] for column in range(7): button_row.append(self._grid[column][row]) self._matrix.add_row(tuple(button_row)) for row in range(8): button_row = [] for column in range(8): button_row.append(self._grid[column][row]) self._monomod.add_row(tuple(button_row)) self._dummy_button = ButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, 125) self._dummy_button.name = 'Dummy1' self._dummy_button2 = ButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, 126) self._dummy_button2.name = 'Dummy2' self._dummy_button3 = ButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, 127) self._dummy_button2.name = 'Dummy3' self._monomod256 = ButtonMatrixElement() self._monomod256.name = 'Monomod256' self._square = [None for index in range(16)] for column in range(16): self._square[column] = [None for index in range(16)] for row in range(16): self._square[column][row] = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, int(column/8) + 1, row + ((column%8) * 16), '256Grid_' + str(column) + '_' + str(row), '/Grid_'+str(column)+'_'+str(row)+'/value', '/Grid/set '+str(column)+' '+str(row), None, self) #self._square[column][row] = FlashingButtonElement(is_momentary, 0, 15, -1, '256Grid_' + str(column) + '_' + str(row), '/1/p_grid/'+str(column)+'/'+str(row), '/1/c_grid/'+str(column)+'/'+str(row), self) for row in range(16): button_row = [] for column in range(16): button_row.append(self._square[column][row]) self._monomod256.add_row(tuple(button_row)) self._bank_buttons = ButtonMatrixElement() self._key_buttons = ButtonMatrixElement() self._bank_button = [None for index in range(2)] for index in range(2): self._bank_button[index] = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, index, '256Grid_Bank_' + str(index), '/Shift_'+str(index)+'/value', '/Shift/set '+str(index), None, self) button_row = [] for index in range(2): button_row.append(self._bank_button[index]) self._bank_buttons.add_row(tuple(button_row)) button_row = [] self._key_button = [None for index in range(8)] for index in range(8): self._key_button[index] = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, index+8, '256Grid_Key_' + str(index), '/Keys_'+str(index)+'/value', '/Keys/set '+str(index), None, self) for index in range(8): button_row.append(self._key_button[index]) self._key_buttons.add_row(tuple(button_row)) self._pedal = [None for index in range(8)] if self._use_pedal is True: for index in range(8): self._pedal[index] = EncoderElement(MIDI_CC_TYPE, 0, 25+index, Live.MidiMap.MapMode.absolute) self._pedal[index].name = 'Pedal_'+str(index) self._pedal[index]._report = False def _setup_session_control(self): is_momentary = True num_tracks = 4 num_scenes = 5 self._session = NameServerSessionComponent(num_tracks, num_scenes, self) self._session.name = "Left_Session" self._session.set_offsets(0, 0) self._session.set_stop_clip_value(self._color_defs['STOP_CLIP']) self._scene = [None for index in range(5)] for row in range(num_scenes): self._scene[row] = self._session.scene(row) self._scene[row].name = 'L_Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_L_' + str(row) clip_slot.set_triggered_to_play_value(self._color_defs['CLIP_TRG_PLAY']) clip_slot.set_triggered_to_record_value(self._color_defs['CLIP_TRG_REC']) clip_slot.set_stopped_value(self._color_defs['CLIP_STOP']) clip_slot.set_started_value(self._color_defs['CLIP_STARTED']) clip_slot.set_recording_value(self._color_defs['CLIP_RECORDING']) self._session.set_mixer(self._mixer) self._session_zoom = SessionZoomingComponent(self._session) self._session_zoom.name = 'L_Session_Overview' self._session_zoom.set_stopped_value(self._color_defs['ZOOM_STOPPED']) self._session_zoom.set_playing_value(self._color_defs['ZOOM_PLAYING']) self._session_zoom.set_selected_value(self._color_defs['ZOOM_SELECTED']) self._session_zoom._zoom_button = (self._dummy_button) self._session_zoom.set_enabled(True) self._session2 = SessionComponent(num_tracks, num_scenes) self._session2.name = 'Right_Session' self._session2.set_offsets(4, 0) self._session2.set_stop_clip_value(self._color_defs['STOP_CLIP']) self._scene2 = [None for index in range(5)] for row in range(num_scenes): self._scene2[row] = self._session2.scene(row) self._scene2[row].name = 'R_Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene2[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_R_' + str(row) clip_slot.set_triggered_to_play_value(self._color_defs['CLIP_TRG_PLAY']) clip_slot.set_triggered_to_record_value(self._color_defs['CLIP_TRG_REC']) clip_slot.set_stopped_value(self._color_defs['CLIP_STOP']) clip_slot.set_started_value(self._color_defs['CLIP_STARTED']) clip_slot.set_recording_value(self._color_defs['CLIP_RECORDING']) self._session2.set_mixer(self._mixer2) self._session2.add_offset_listener(self._on_session_offset_changes) self._session_zoom2 = SessionZoomingComponent(self._session2) self._session_zoom2.name = 'R_Session_Overview' self._session_zoom2.set_stopped_value(self._color_defs['ZOOM_STOPPED']) self._session_zoom2.set_playing_value(self._color_defs['ZOOM_PLAYING']) self._session_zoom2.set_selected_value(self._color_defs['ZOOM_SELECTED']) self._session_zoom.set_enabled(True) self._session_zoom2._zoom_button = (self._dummy_button2) self._session_main = SessionComponent(8, num_scenes) self._session_main.name = 'Main_Session' self._session_main.set_stop_clip_value(self._color_defs['STOP_CLIP']) self._scene_main = [None for index in range(5)] for row in range(num_scenes): self._scene_main[row] = self._session_main.scene(row) self._scene_main[row].name = 'M_Scene_' + str(row) for column in range(8): clip_slot = self._scene_main[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_M_' + str(row) clip_slot.set_triggered_to_play_value(self._color_defs['CLIP_TRG_PLAY']) clip_slot.set_triggered_to_record_value(self._color_defs['CLIP_TRG_REC']) clip_slot.set_stopped_value(self._color_defs['CLIP_STOP']) clip_slot.set_started_value(self._color_defs['CLIP_STARTED']) clip_slot.set_recording_value(self._color_defs['CLIP_RECORDING']) self._session_main.set_mixer(self._mixer) self._session_zoom_main = SessionZoomingComponent(self._session_main) self._session_zoom_main.name = 'M_Session_Overview' self._session_zoom_main.set_stopped_value(self._color_defs['ZOOM_STOPPED']) self._session_zoom_main.set_playing_value(self._color_defs['ZOOM_PLAYING']) self._session_zoom_main.set_selected_value(self._color_defs['ZOOM_SELECTED']) self._session_zoom_main.set_enabled(True) self._session_zoom_main._zoom_button = (self._dummy_button3) self._sessions = [self._session, self._session2, self._session_main] self._zooms = [self._session_zoom, self._session_zoom2, self._session_zoom_main] def _setup_monomod(self): self._host = MonomodComponent(self) self._host.name = 'Monomod_Host' self._host2 = SpecialMonomodComponent(self) self._host2.name = '256_Monomod_Host' self.hosts = [self._host, self._host2] def _assign_host2(self): self._host2._set_shift_button(self._bank_button[0]) self._host2._set_alt_button(self._bank_button[1]) self._host2._set_button_matrix(self._monomod256) self._host2._set_key_buttons(self._key_button) self._host2.set_enabled(True) def _setup_touchosc(self): self._osc_registry = {} #self._osc_registry['/ping'] = self._monobridge.ping #self._osc_registry['/1'] = self._monobridge.page1 #self._osc_registry['/2'] = self._monobridge.page2 for control in self.controls: if hasattr(control, 'osc'): self._osc_registry[control.osc] = control.set_value #if hasattr(control, 'osc_alt'): # self._osc_registry[control.osc_alt] = control.set_value #self.log_message('create dict key: ' + str(control.osc) + str(control.name)) """shift/zoom methods""" def deassign_matrix(self): super(LemurPad, self).deassign_matrix() self.clear_grid_names() """menu button management methods""" def deassign_menu(self): super(LemurPad, self).deassign_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(' ')) def assign_device_nav_to_menu(self): super(LemurPad, self).assign_device_nav_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(DEVICE_NAV_NAMES[index]))) def assign_transport_to_menu(self): super(LemurPad, self).assign_transport_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(TRANSPORT_NAMES[index]))) def assign_session_nav_to_menu(self): super(LemurPad, self).assign_session_nav_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(SESSION_NAV_NAMES[index]))) def assign_session_main_nav_to_menu(self): super(LemurPad, self).assign_session_main_nav_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(SESSION_NAV_NAMES[index]))) def assign_monomod_shift_to_menu(self): super(LemurPad, self).assign_monomod_shift_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(MONOMOD_SHIFT_NAMES[index]))) def assign_monomod_to_menu(self): super(LemurPad, self).assign_monomod_shift_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(MONOMOD_NAMES[index]))) def assign_session_bank_to_menu(self): super(LemurPad, self).assign_session_bank_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(SESSION_BANK_NAMES[index]))) def assign_session2_bank_to_menu(self): super(LemurPad, self).assign_session2_bank_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(SESSION_BANK2_NAMES[index]))) def assign_session_main_nav_to_menu(self): super(LemurPad, self).assign_session_main_nav_to_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(str(SESSION_MAIN_BANK_NAMES[index]))) """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 9 if (not display_string): return ('`_') if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center((NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP) return '`' + ret.replace(' ', '_') def notification_to_bridge(self, name, value, sender): if(isinstance(sender, MonoEncoderElement2)): #self.log_message(str(name) + str(value) + str(sender.num)) self._monobridge._send('lcd_name', sender.name, self.generate_strip_string(str(name))) self._monobridge._send('lcd_value', sender.name, self.generate_strip_string(str(value))) def clip_name(self, sender, name): #self.log_message('clip name ' + str(sender.osc_name) + ' ' + str(self.generate_strip_string(str(name)))) self._monobridge._send_osc(sender.osc_name, self.generate_strip_string(str(name))) """def get_clip_names(self): clip_names = [] for scene in self._session._scenes: for clip_slot in scene._clip_slots: if clip_slot.has_clip(): clip_names.append(clip_slot._clip_slot)##.clip.name) #return clip_slot._clip_slot #self.log_message('clip name' + str(clip_slot._clip_slot.clip.name)) return clip_names""" """called on timer""" def update_display(self): super(LemurPad, self).update_display() for callback in self._timer_callbacks: callback() def flash(self): if(self.flash_status > 0): for control in self.controls: if isinstance(control, MonoButtonElement): control.flash(self._timer) def strobe(self): pass """general functionality""" def disconnect(self): super(MonOhm, self).disconnect() def clear_grid_names(self): #self.log_message('clear grid names' + str(self)) for column in range(8): for row in range(8): self._monobridge._send_osc(self._grid[column][row].osc_name, '`_') def _register_timer_callback(self, callback): """ Registers a callback that is triggerd on every call of update_display """ assert (callback != None) assert (dir(callback).count('im_func') is 1) assert (self._timer_callbacks.count(callback) == 0) self._timer_callbacks.append(callback) return None def _unregister_timer_callback(self, callback): """ Unregisters a timer callback """ assert (callback != None) assert (dir(callback).count('im_func') is 1) assert (self._timer_callbacks.count(callback) == 1) self._timer_callbacks.remove(callback) return None def _set_brightness(self, value): #self._bright = (value != 0) #for control in self.controls: # if isinstance(control, OSCMonoButtonElement): # self._monobridge._send_osc(control.osc_alt, int(self._bright), True) pass def reset(self): #self._monobridge._send_osc('/reset') for control in self.controls: control.reset() def assign_lower_grid_names(self, mode): if self._display_button_names is True: for column in range(8): for row in range(3): self._monobridge._send_osc(self._grid[column][row+5].osc_name, self.generate_strip_string(str(GRID_NAMES[mode][row][column]))) def reset_and_refresh_state(self, *a, **k): self.schedule_message(1, self.reset) self.schedule_message(2, self.refresh_state)
def set_offsets(self, track_offset, scene_offset): if self._synced_session != None: self._synced_session.set_offsets(track_offset, scene_offset) else: SessionComponent.set_offsets(self, track_offset, scene_offset)
class MPK_mini_hero(ControlSurface): """ Script for Novation's Launchkey 25/49/61 keyboards """ def __init__(self, c_instance, identity_response = SIZE_RESPONSE): ControlSurface.__init__(self, c_instance) self._identity_response = identity_response with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._device_selection_follows_track_selection = True self._suggested_input_port = 'MPK mini' self._suggested_output_port = 'MPK mini' self._setup_buttons() self._setup_components() for component in self.components: component.set_enabled(True) # Puvodne False def refresh_state(self): ControlSurface.refresh_state(self) # for val in range(127): # self.schedule_message(2, self._send_midi, (144, val, 0)) # self.schedule_message(3, self._send_midi, (144, 9, 127)) def handle_sysex(self, midi_bytes): self._send_midi(LED_FLASHING_ON) self._update_mixer_offset() for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) self.request_rebuild_midi_map() def disconnect(self): ControlSurface.disconnect(self) self._encoders = None self._transport_view_modes = None self._send_midi(LED_FLASHING_OFF) self._send_midi(LIVE_MODE_OFF) def _setup_buttons(self): # Pads CC Mode self._scene_launch_button = make_pad_button(PAD_MODE_CC, 1, 'Scene_Launch_Button') self._overdub_button = make_pad_button(PAD_MODE_CC, 2, 'Session_Overdub_Button') self._ffwd_button = make_pad_button(PAD_MODE_CC, 3, 'FFwd_Button') self._clip_undo_button = make_pad_button(PAD_MODE_CC, 4, 'Clip_Undo_Button') self._prev_track_button = make_pad_button(PAD_MODE_CC, 5, 'Prev_Track_Button') self._next_track_button = make_pad_button(PAD_MODE_CC, 6, 'Next_Track_Button') self._rwd_button = make_pad_button(PAD_MODE_CC, 7, 'Rwd_Button') self._scene_stop_button = make_pad_button(PAD_MODE_CC, 9, 'Scene_Stop_Button') self._stop_button = make_pad_button(PAD_MODE_CC, 10, 'Stop_Button') self._play_button = make_pad_button(PAD_MODE_CC, 11, 'Play_Button') self._loop_button = make_pad_button(PAD_MODE_CC, 12, 'Loop_Button') self._rec_button = make_pad_button(PAD_MODE_CC, 13, 'Record_Button') # Pads Notes Mode self._clip_launch_buttons = [ make_pad_button(PAD_MODE_NOTES, index, 'Clip_Launch_%d' % index) for index in xrange(8) ] self._clip_stop_buttons = [ make_pad_button(PAD_MODE_NOTES, 8 + index, 'Clip_Stop_%d' % index) for index in xrange(8) ] # Encoders self._encoders = tuple([ make_encoder(21 + index, 'Device_Control_%d' % index) for index in xrange(8) ]) # Scenes self._scene_launch_buttons = [] for key_no in [0,2,4,5,7,9,11, 12,14,16,17,19,21,23, 24]: self._scene_launch_buttons.append(make_scene_button(key_no, 'Scene_Launch_%d' % key_no)) def _setup_components(self): # Session self._session = SessionComponent(8, len(self._scene_launch_buttons)) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.selected_scene().set_launch_button(self._scene_launch_button) self._session.set_stop_all_clips_button(self._scene_stop_button) for index in range(8): clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_launch_button(self._clip_launch_buttons[index]) clip_slot.name = 'Selected_Clip_Slot_' + str(index) self._session.set_stop_track_clip_buttons(tuple(self._clip_stop_buttons)) # Undo self._do_undo.subject = self._clip_undo_button; # Transport transport = TransportComponent() transport.name = 'Transport' transport.set_stop_button(self._stop_button) transport.set_play_button(self._play_button) transport.set_record_button(self._rec_button) transport.set_loop_button(self._loop_button) self._transport_view_modes = TransportViewModeSelector(transport, self._session, self._ffwd_button, self._rwd_button) self._transport_view_modes.name = 'Transport_View_Modes' session_recording = SessionRecordingComponent(ClipCreator(), ViewControlComponent(), name='Session_Recording', is_enabled=False, layer=Layer(record_button=self._overdub_button)) # Device # device = DeviceComponent() # device.name = 'Device_Component' # self.set_device_component(device) # device.set_parameter_controls(self._encoders) # Navigation self._session_navigation = SessionNavigationComponent(name='Session_Navigation') self._session_navigation.set_next_track_button(self._next_track_button) self._session_navigation.set_prev_track_button(self._prev_track_button) # Playing # self._session.set_scene_launch_buttons(tuple(self._scene_launch_buttons)) for index in range(len(self._scene_launch_buttons)): scene = self._session.scene(index) scene.set_launch_button(self._scene_launch_buttons[index]) @subject_slot('value') def _do_undo(self, value): if value: if self.song().can_undo == 1: self.song().undo() self.show_message(str('UNDO')) def _dummy_listener(self, value): pass def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._update_mixer_offset() def _update_mixer_offset(self): all_tracks = self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks: track_index = list(all_tracks).index(selected_track) new_offset = track_index - track_index % num_strips self._session.set_offsets(new_offset, self._session.scene_offset())
class Tweaker(ControlSurface): __module__ = __name__ __doc__ = " MonOhmod companion controller script " def __init__(self, c_instance): """everything except the '_on_selected_track_changed' override and 'disconnect' runs from here""" ControlSurface.__init__(self, c_instance) with self.component_guard(): self._update_linked_device_selection = None self._tweaker_version = '0.4' self.log_message("--------------= Tweaker Mixer " + str(self._tweaker_version) + " log opened =--------------") self._update_linked_device_selection = None self._setup_mixer_control() self._setup_session_control() """script initialization methods""" def _setup_controls(self): is_momentary = True self._grid = [None for index in range(8)] for column in range(8): self._grid[column] = [FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, column + (row * 8), 'Grid_' + str(column) + '_' + str(row), self) for row in range(4)] self._button = [FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_BUTTONS[index], 'Button_' + str(index), self) for index in range(len(TWEAKER_BUTTONS))] self._nav = [FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_NAVS[index], 'Nav_' + str(index), self) for index in range(len(TWEAKER_NAVS))] self._encoder_buttons = [FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_ENCODER_BUTTONS[index], 'Encoder_Button_' + str(index), self) for index in range(len(TWEAKER_ENCODER_BUTTONS))] self._dial = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_DIALS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_DIALS))] self._fader = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_FADERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_FADERS))] self._crossfader = EncoderElement(MIDI_CC_TYPE, CHANNEL, CROSSFADER, Live.MidiMap.MapMode.absolute) self._encoder = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_ENCODERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_ENCODERS))] self._pad = [FlashingButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, TWEAKER_PADS[index], 'Pad_' + str(index), self) for index in range(len(TWEAKER_PADS))] self._matrix = ButtonMatrixElement() self._matrix.name = 'Matrix' for row in range(4): button_row = [] for column in range(7): button_row.append(self._grid[column][row]) self._matrix.add_row(tuple(button_row)) def _setup_transport_control(self): self._transport = TransportComponent() self._transport.name = 'Transport' def _setup_mixer_control(self): is_momentary = True self._num_tracks = (2) #A mixer is one-dimensional; self._mixer = MixerComponent(2, 0, False, True) self._mixer.name = 'Mixer' self._mixer.tracks_to_use = self._mixer_tracks_to_use(self._mixer) self._mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) def _setup_session_control(self): is_momentary = True num_tracks = 2 num_scenes = 3 self._session = SessionComponent(num_tracks, num_scenes) self._session.name = "Session" self._session.set_offsets(0, 0) self._session.set_mixer(self._mixer) self.set_highlighting_session_component(self._session) """general functionality""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates!=0)) def disconnect(self): """clean things up on disconnect""" if self._session._is_linked(): self._session._unlink() self.log_message("--------------= Tweaker Mixer " + str(self._tweaker_version) + " log closed =--------------") #Create entry in log file ControlSurface.disconnect(self) return None def connect_script_instances(self, instanciated_scripts): link = False for s in instanciated_scripts: if '_tweaker_version' in dir(s): if s._tweaker_version == self._tweaker_version: link = True if not s is self: s._linked_session = self._session #break if link is True: if not self._session._is_linked(): #self._session.set_offsets(0, 0) self._session._link() def _mixer_tracks_to_use(self, mixer): def tracks_to_use(): return tuple(self.song().visible_tracks) + tuple(self.song().return_tracks) return tracks_to_use # a
class Novation_Impulse(ControlSurface): """ Script for Novation's Impulse keyboards """ def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._suggested_input_port = b'Impulse' self._suggested_output_port = b'Impulse' self._has_sliders = True self._current_midi_map = None self._display_reset_delay = -1 self._shift_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 39) self._preview_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 41) self._master_slider = SliderElement(MIDI_CC_TYPE, 0, 8) self._shift_button.name = b'Shift_Button' self._master_slider.name = b'Master_Volume_Control' self._master_slider.add_value_listener(self._slider_value, identify_sender=True) self._preview_button.add_value_listener(self._preview_value) self._setup_mixer() self._setup_session() self._setup_transport() self._setup_device() self._setup_name_display() device_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 10) mixer_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 9) device_button.name = b'Encoder_Device_Mode' mixer_button.name = b'Encoder_Mixer_Mode' self._encoder_modes = EncoderModeSelector(self._device_component, self._mixer, self._next_bank_button, self._prev_bank_button, self._encoders) self._encoder_modes.set_device_mixer_buttons( device_button, mixer_button) self._string_to_display = None for component in self.components: component.set_enabled(False) return def refresh_state(self): ControlSurface.refresh_state(self) self.schedule_message(3, self._send_midi, SYSEX_START + (6, 1, 1, 1, 247)) def handle_sysex(self, midi_bytes): if midi_bytes[0:-2] == SYSEX_START + (7, ) and midi_bytes[(-2)] != 0: self._has_sliders = midi_bytes[(-2)] != 25 self.schedule_message(1, self._show_startup_message) for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) if self._has_sliders: self._mixer.master_strip().set_volume_control( self._master_slider) self._mixer.update() else: self._mixer.master_strip().set_volume_control(None) self._mixer.selected_strip().set_volume_control( self._master_slider) for index in range(len(self._sliders)): self._mixer.channel_strip(index).set_volume_control(None) slider = self._sliders[index] slider.release_parameter() if slider.value_has_listener(self._slider_value): slider.remove_value_listener(self._slider_value) self._encoder_modes.set_provide_volume_mode(not self._has_sliders) self.request_rebuild_midi_map() return def disconnect(self): self._name_display_data_source.set_display_string(b' ') for encoder in self._encoders: encoder.remove_value_listener(self._encoder_value) self._master_slider.remove_value_listener(self._slider_value) if self._has_sliders: for slider in tuple(self._sliders): slider.remove_value_listener(self._slider_value) for button in self._strip_buttons: button.remove_value_listener(self._mixer_button_value) self._preview_button.remove_value_listener(self._preview_value) ControlSurface.disconnect(self) self._encoders = None self._sliders = None self._strip_buttons = None self._master_slider = None self._current_midi_map = None self._shift_button = None self._name_display = None self._prev_bank_button = None self._next_bank_button = None self._encoder_modes = None self._transport_view_modes = None self._send_midi(SYSEX_START + (6, 0, 0, 0, 247)) return def build_midi_map(self, midi_map_handle): self._current_midi_map = midi_map_handle ControlSurface.build_midi_map(self, midi_map_handle) def update_display(self): ControlSurface.update_display(self) if self._string_to_display != None: self._name_display_data_source.set_display_string( self._string_to_display) self._string_to_display = None if self._display_reset_delay >= 0: self._display_reset_delay -= 1 if self._display_reset_delay == -1: self._show_current_track_name() return def _setup_mixer(self): mute_solo_flip_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 34) self._next_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 37) self._prev_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 38) self._strip_buttons = [] mute_solo_flip_button.name = b'Mute_Solo_Flip_Button' self._next_nav_button.name = b'Next_Track_Button' self._prev_nav_button.name = b'Prev_Track_Button' self._mixer = SpecialMixerComponent(8) self._mixer.name = b'Mixer' self._mixer.set_select_buttons(self._next_nav_button, self._prev_nav_button) self._mixer.selected_strip().name = b'Selected_Channel_Strip' self._mixer.master_strip().name = b'Master_Channel_Strip' self._mixer.master_strip().set_volume_control(self._master_slider) self._sliders = [] for index in range(8): strip = self._mixer.channel_strip(index) strip.name = b'Channel_Strip_' + str(index) strip.set_invert_mute_feedback(True) self._sliders.append(SliderElement(MIDI_CC_TYPE, 0, index)) self._sliders[(-1)].name = str(index) + b'_Volume_Control' self._sliders[(-1)].set_feedback_delay(-1) self._sliders[(-1)].add_value_listener(self._slider_value, identify_sender=True) strip.set_volume_control(self._sliders[(-1)]) self._strip_buttons.append( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 9 + index)) self._strip_buttons[(-1)].name = str(index) + b'_Mute_Button' self._strip_buttons[(-1)].add_value_listener( self._mixer_button_value, identify_sender=True) self._mixer.master_strip().set_mute_button( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 17)) self._mixer.set_strip_mute_solo_buttons(tuple(self._strip_buttons), mute_solo_flip_button) def _setup_session(self): num_pads = len(PAD_TRANSLATIONS) self._track_left_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 36) self._track_right_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 35) self._session = SessionComponent(8, 0) self._session.name = b'Session_Control' self._session.selected_scene().name = b'Selected_Scene' self._session.set_mixer(self._mixer) self._session.set_page_left_button(self._track_left_button) self._session.set_page_right_button(self._track_right_button) pads = [] for index in range(num_pads): pads.append( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 60 + index)) pads[(-1)].name = b'Pad_' + str(index) clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_triggered_to_play_value(GREEN_BLINK) clip_slot.set_triggered_to_record_value(RED_BLINK) clip_slot.set_stopped_value(AMBER_FULL) clip_slot.set_started_value(GREEN_FULL) clip_slot.set_recording_value(RED_FULL) clip_slot.set_launch_button(pads[(-1)]) clip_slot.name = str(index) + b'_Selected_Clip_Slot' def _setup_transport(self): rwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 27) ffwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 28) stop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 29) play_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 30) loop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 31) rec_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 32) ffwd_button.name = b'FFwd_Button' rwd_button.name = b'Rwd_Button' loop_button.name = b'Loop_Button' play_button.name = b'Play_Button' stop_button.name = b'Stop_Button' rec_button.name = b'Record_Button' transport = ShiftableTransportComponent() transport.name = b'Transport' transport.set_stop_button(stop_button) transport.set_play_button(play_button) transport.set_record_button(rec_button) transport.set_shift_button(self._shift_button) self._transport_view_modes = TransportViewModeSelector( transport, self._session, ffwd_button, rwd_button, loop_button) self._transport_view_modes.name = b'Transport_View_Modes' def _setup_device(self): encoders = [] for index in range(8): encoders.append( PeekableEncoderElement( MIDI_CC_TYPE, 1, index, Live.MidiMap.MapMode.relative_binary_offset)) encoders[(-1)].set_feedback_delay(-1) encoders[(-1)].add_value_listener(self._encoder_value, identify_sender=True) encoders[(-1)].name = b'Device_Control_' + str(index) self._encoders = tuple(encoders) self._prev_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 12) self._next_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 11) self._prev_bank_button.name = b'Device_Bank_Down_Button' self._next_bank_button.name = b'Device_Bank_Up_Button' device = DeviceComponent(device_selection_follows_track_selection=True) device.name = b'Device_Component' self.set_device_component(device) device.set_parameter_controls(self._encoders) device.set_bank_nav_buttons(self._prev_bank_button, self._next_bank_button) def _setup_name_display(self): self._name_display = PhysicalDisplayElement(16, 1) self._name_display.name = b'Display' self._name_display.set_message_parts(SYSEX_START + (8, ), (247, )) self._name_display_data_source = DisplayDataSource() self._name_display.segment(0).set_data_source( self._name_display_data_source) def _encoder_value(self, value, sender): assert sender in self._encoders assert value in range(128) if self._device_component.is_enabled(): display_string = b' - ' if sender.mapped_parameter() != None: display_string = sender.mapped_parameter().name self._set_string_to_display(display_string) return def _slider_value(self, value, sender): assert sender in tuple(self._sliders) + (self._master_slider, ) assert value in range(128) if self._mixer.is_enabled(): display_string = b' - ' if sender.mapped_parameter() != None: master = self.song().master_track tracks = self.song().tracks returns = self.song().return_tracks track = None if sender == self._master_slider: if self._has_sliders: track = master else: track = self.song().view.selected_track else: track = self._mixer.channel_strip( self._sliders.index(sender))._track if track == master: display_string = b'Master' elif track in tracks: display_string = str(list(tracks).index(track) + 1) elif track in returns: display_string = str( chr(ord(b'A') + list(returns).index(track))) else: assert False display_string += b' Volume' self._set_string_to_display(display_string) return def _mixer_button_value(self, value, sender): assert value in range(128) if self._mixer.is_enabled() and value > 0: strip = self._mixer.channel_strip( self._strip_buttons.index(sender)) if strip != None: self._string_to_display = None self._name_display.segment(0).set_data_source( strip.track_name_data_source()) self._name_display.update() self._display_reset_delay = STANDARD_DISPLAY_DELAY else: self._set_string_to_display(b' - ') return def _preview_value(self, value): assert value in range(128) for encoder in self._encoders: encoder.set_peek_mode(value > 0) def _show_current_track_name(self): if self._name_display != None and self._mixer != None: self._string_to_display = None self._name_display.segment(0).set_data_source( self._mixer.selected_strip().track_name_data_source()) self._name_display.update() return def _show_startup_message(self): self._name_display.display_message(b'LIVE') self._display_reset_delay = INITIAL_DISPLAY_DELAY def _set_string_to_display(self, string_to_display): assert isinstance(string_to_display, (str, unicode)) self._name_display.segment(0).set_data_source( self._name_display_data_source) self._string_to_display = string_to_display self._display_reset_delay = STANDARD_DISPLAY_DELAY def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._show_current_track_name() all_tracks = self._has_sliders or self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks: track_index = list(all_tracks).index(selected_track) new_offset = track_index - track_index % num_strips if not new_offset / num_strips == int(new_offset / num_strips): raise AssertionError self._session.set_offsets(new_offset, self._session.scene_offset())
class Tweaker(ControlSurface): __module__ = __name__ __doc__ = " MonOhmod companion controller script " def __init__(self, c_instance): """everything except the '_on_selected_track_changed' override and 'disconnect' runs from here""" ControlSurface.__init__(self, c_instance) with self.component_guard(): self._update_linked_device_selection = None self._tweaker_version = "0.4" self.log_message( "--------------= Tweaker Mixer " + str(self._tweaker_version) + " log opened =--------------" ) self._update_linked_device_selection = None self._setup_mixer_control() self._setup_session_control() """script initialization methods""" def _setup_controls(self): is_momentary = True self._grid = [None for index in range(8)] for column in range(8): self._grid[column] = [ FlashingButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, column + (row * 8), "Grid_" + str(column) + "_" + str(row), self, ) for row in range(4) ] self._button = [ FlashingButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_BUTTONS[index], "Button_" + str(index), self ) for index in range(len(TWEAKER_BUTTONS)) ] self._nav = [ FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_NAVS[index], "Nav_" + str(index), self) for index in range(len(TWEAKER_NAVS)) ] self._encoder_buttons = [ FlashingButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_ENCODER_BUTTONS[index], "Encoder_Button_" + str(index), self, ) for index in range(len(TWEAKER_ENCODER_BUTTONS)) ] self._dial = [ EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_DIALS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_DIALS)) ] self._fader = [ EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_FADERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_FADERS)) ] self._crossfader = EncoderElement(MIDI_CC_TYPE, CHANNEL, CROSSFADER, Live.MidiMap.MapMode.absolute) self._encoder = [ EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_ENCODERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_ENCODERS)) ] self._pad = [ FlashingButtonElement( not is_momentary, MIDI_CC_TYPE, CHANNEL, TWEAKER_PADS[index], "Pad_" + str(index), self ) for index in range(len(TWEAKER_PADS)) ] self._matrix = ButtonMatrixElement() self._matrix.name = "Matrix" for row in range(4): button_row = [] for column in range(7): button_row.append(self._grid[column][row]) self._matrix.add_row(tuple(button_row)) def _setup_transport_control(self): self._transport = TransportComponent() self._transport.name = "Transport" def _setup_mixer_control(self): is_momentary = True self._num_tracks = 2 # A mixer is one-dimensional; self._mixer = MixerComponent(2, 0, False, True) self._mixer.name = "Mixer" self._mixer.tracks_to_use = self._mixer_tracks_to_use(self._mixer) self._mixer.set_track_offset(0) # Sets start point for mixer strip (offset from left) def _setup_session_control(self): is_momentary = True num_tracks = 2 num_scenes = 3 self._session = SessionComponent(num_tracks, num_scenes) self._session.name = "Session" self._session.set_offsets(0, 0) self._session.set_mixer(self._mixer) self.set_highlighting_session_component(self._session) """general functionality""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates != 0)) def disconnect(self): """clean things up on disconnect""" if self._session._is_linked(): self._session._unlink() self.log_message( "--------------= Tweaker Mixer " + str(self._tweaker_version) + " log closed =--------------" ) # Create entry in log file ControlSurface.disconnect(self) return None def connect_script_instances(self, instanciated_scripts): link = False for s in instanciated_scripts: if "_tweaker_version" in dir(s): if s._tweaker_version == self._tweaker_version: link = True if not s is self: s._linked_session = self._session # break if link is True: if not self._session._is_linked(): # self._session.set_offsets(0, 0) self._session._link() def _mixer_tracks_to_use(self, mixer): def tracks_to_use(): return tuple(self.song().visible_tracks) + tuple(self.song().return_tracks) return tracks_to_use
class Novation_Impulse2(ControlSurface): """ Script for Novation's Impulse keyboards """ def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) self.c_instance = c_instance with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._device_selection_follows_track_selection = True self._suggested_input_port = 'Impulse' self._suggested_output_port = 'Impulse' self._has_sliders = True self._current_midi_map = None self._display_reset_delay = -1 self._string_to_display = None self.shift_pressed = False # special alternative buttons mode. for now only mixer buttons become record buttons. later we will add something more self.alternative_buttons_mode = False self._shift_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 39) self._preview_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 41) self._master_slider = SliderElement(MIDI_CC_TYPE, 0, 8) self._shift_button.name = 'Shift_Button' self._master_slider.name = 'Master_Volume_Control' self._master_slider.add_value_listener(self._slider_value, identify_sender=True) self._preview_button.add_value_listener(self._preview_value) self._setup_mixer() self._setup_session() self._setup_transport() self._setup_device() self._setup_name_display() device_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 10) mixer_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 9) device_button.name = 'Encoder_Device_Mode' mixer_button.name = 'Encoder_Mixer_Mode' self._encoder_modes = EncoderModeSelector(self._device_component, self._mixer, self._next_bank_button, self._prev_bank_button, self._encoders) self._encoder_modes.set_device_mixer_buttons( device_button, mixer_button) self._shift_button.add_value_listener(self._shift_button_handler) for component in self.components: component.set_enabled(False) # attributes def alternative_buttons_mode(self): return self.alternative_buttons_mode def alternative_buttons_mode(self, value): self.log('alternative_buttons_mode_value ' + str(value)) self.alternative_buttons_mode = value def shift_pressed(self): return self.shift_pressed def shift_pressed(self, value): self.log('shift_pressed value ' + str(value)) self.shift_pressed = value def refresh_state(self): ControlSurface.refresh_state(self) self.schedule_message(3, self._send_midi, SYSEX_START + (6, 1, 1, 1, 247)) def handle_sysex(self, midi_bytes): if midi_bytes[0:-2] == SYSEX_START + (7, ) and midi_bytes[-2] != 0: self._has_sliders = midi_bytes[-2] != 25 self.schedule_message(1, self._show_startup_message) for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) if self._has_sliders: self._mixer.master_strip().set_volume_control( self._master_slider) self._mixer.update() else: self._mixer.master_strip().set_volume_control(None) self._mixer.selected_strip().set_volume_control( self._master_slider) for index in range(len(self._sliders)): self._mixer.channel_strip(index).set_volume_control(None) slider = self._sliders[index] slider.release_parameter() if slider.value_has_listener(self._slider_value): slider.remove_value_listener(self._slider_value) self._encoder_modes.set_provide_volume_mode(not self._has_sliders) self.request_rebuild_midi_map() def disconnect(self): self.log('starting disconnect 1') self._name_display_data_source.set_display_string(' ') for encoder in self._encoders: encoder.remove_value_listener(self._encoder_value) self._master_slider.remove_value_listener(self._slider_value) if self._has_sliders: for slider in tuple(self._sliders): slider.remove_value_listener(self._slider_value) for button in self._strip_buttons: button.remove_value_listener(self._mixer_button_value) self._preview_button.remove_value_listener(self._preview_value) self.log('starting disconnect 3') ControlSurface.disconnect(self) self.log('starting disconnect 3') self._encoders = None self._sliders = None self._strip_buttons = None self._master_slider = None self._current_midi_map = None self._name_display = None self._prev_bank_button = None self._next_bank_button = None self._encoder_modes = None self._transport_view_modes = None self.log('starting disconnect 4') self._send_midi(SYSEX_START + (6, 0, 0, 0, 247)) self.log('starting disconnect 5') if self._shift_button != None: self._shift_button.remove_value_listener( self._shift_button_handler) self._shift_button = None self.log('starting disconnect 6') def build_midi_map(self, midi_map_handle): self._current_midi_map = midi_map_handle ControlSurface.build_midi_map(self, midi_map_handle) def update_display(self): ControlSurface.update_display(self) if self._string_to_display != None: self._name_display_data_source.set_display_string( self._string_to_display) self._string_to_display = None if self._display_reset_delay >= 0: self._display_reset_delay -= 1 if self._display_reset_delay == -1: self._show_current_track_name() def _setup_mixer(self): self.log('setup mixer') mute_solo_flip_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 34) self._next_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 37) self._prev_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 38) self._strip_buttons = [] mute_solo_flip_button.name = 'Mute_Solo_Flip_Button' self._next_nav_button.name = 'Next_Track_Button' self._prev_nav_button.name = 'Prev_Track_Button' self._mixer = SpecialMixerComponent(self, 8, self.c_instance) self._mixer.name = 'Mixer' self._mixer.set_select_buttons(self._next_nav_button, self._prev_nav_button) self._mixer.selected_strip().name = 'Selected_Channel_Strip' self._mixer.master_strip().name = 'Master_Channel_Strip' self._mixer.master_strip().set_volume_control(self._master_slider) self._sliders = [] for index in range(8): strip = self._mixer.channel_strip(index) strip.name = 'Channel_Strip_' + str(index) strip.set_invert_mute_feedback(True) self._sliders.append(SliderElement(MIDI_CC_TYPE, 0, index)) self._sliders[-1].name = str(index) + '_Volume_Control' self._sliders[-1].set_feedback_delay(-1) self._sliders[-1].add_value_listener(self._slider_value, identify_sender=True) strip.set_volume_control(self._sliders[-1]) self._strip_buttons.append( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 9 + index)) self._strip_buttons[-1].name = str(index) + '_Mute_Button' self._strip_buttons[-1].add_value_listener( self._mixer_button_value, identify_sender=True) self._mixer.master_strip().set_mute_button( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 17)) self._mixer.set_strip_mute_solo_buttons(tuple(self._strip_buttons), mute_solo_flip_button) #self._mixer.set_shift_button(self._shift_button) self._mixer.updateMixerButtons() self._button9 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 9 + 8) def _setup_session(self): num_pads = len(PAD_TRANSLATIONS) self._session = SessionComponent(8, 0) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.set_mixer(self._mixer) # for ableton 9.1.1 and lower #self._session.set_track_banking_increment(num_pads) #self._session.set_track_bank_buttons(ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 35), ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 36)) # for ableton 9.1.1 and higher self._track_left_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 36) self._track_right_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 35) self._session.set_page_left_button(self._track_left_button) self._session.set_page_right_button(self._track_right_button) pads = [] for index in range(num_pads): pads.append( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 60 + index)) pads[-1].name = 'Pad_' + str(index) clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_triggered_to_play_value(GREEN_BLINK) clip_slot.set_triggered_to_record_value(RED_BLINK) clip_slot.set_stopped_value(AMBER_FULL) clip_slot.set_started_value(GREEN_FULL) clip_slot.set_recording_value(RED_FULL) clip_slot.set_launch_button(pads[-1]) clip_slot.name = str(index) + '_Selected_Clip_Slot' def _setup_transport(self): rwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 27) ffwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 28) stop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 29) play_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 30) loop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 31) rec_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 32) ffwd_button.name = 'FFwd_Button' rwd_button.name = 'Rwd_Button' loop_button.name = 'Loop_Button' play_button.name = 'Play_Button' stop_button.name = 'Stop_Button' rec_button.name = 'Record_Button' self._transport = ShiftableTransportComponent(self.c_instance, self._session, self, ffwd_button, rwd_button) self._transport.name = 'Transport' self._transport.set_stop_buttonOnInit(stop_button) self._transport.set_play_button(play_button) self._transport.set_record_buttonOnInit(rec_button) # self._transport.set_shift_button(self._shift_button) self._transport.set_mixer9_button(self._button9) self._transport_view_modes = TransportViewModeSelector( self, self.c_instance, self._transport, self._session, ffwd_button, rwd_button, loop_button) self._transport_view_modes.name = 'Transport_View_Modes' def _setup_device(self): encoders = [] for index in range(8): encoders.append( PeekableEncoderElement( MIDI_CC_TYPE, 1, index, Live.MidiMap.MapMode.relative_binary_offset)) encoders[-1].set_feedback_delay(-1) encoders[-1].add_value_listener(self._encoder_value, identify_sender=True) encoders[-1].name = 'Device_Control_' + str(index) self._encoders = tuple(encoders) self._prev_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 12) self._next_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 11) self._prev_bank_button.name = 'Device_Bank_Down_Button' self._next_bank_button.name = 'Device_Bank_Up_Button' device = DeviceComponent() device.name = 'Device_Component' self.set_device_component(device) device.set_parameter_controls(self._encoders) device.set_bank_nav_buttons(self._prev_bank_button, self._next_bank_button) def _setup_name_display(self): self._name_display = PhysicalDisplayElement(16, 1) self._name_display.name = 'Display' self._name_display.set_message_parts(SYSEX_START + (8, ), (247, )) self._name_display_data_source = DisplayDataSource() self._name_display.segment(0).set_data_source( self._name_display_data_source) def _encoder_value(self, value, sender): if not sender in self._encoders: raise AssertionError if not value in range(128): raise AssertionError # display_string = self._device_component.is_enabled() and ' - ' # display_string = sender.mapped_parameter() != None and sender.mapped_parameter().name display_string = '' if self._device_component.is_enabled(): # display_string = sender.name # track = self.song().view.selected_track # display_string = str(list(tracks).index(track) + 1) pass if (sender.mapped_parameter() != None): # display_string = display_string + '-' display_string = display_string + sender.mapped_parameter().name self._set_string_to_display(display_string) def _slider_value(self, value, sender): self.log('_slider_value ' + str(value) + ' ' + str(sender)) if not sender in tuple(self._sliders) + (self._master_slider, ): raise AssertionError if not value in range(128): raise AssertionError if self._mixer.is_enabled(): display_string = ' - ' master = self.song().master_track tracks = self.song().tracks returns = self.song().return_tracks track = None if sender.mapped_parameter() != None: self.log('1') if sender == self._master_slider: self.log('2') # track = self._has_sliders and master if self._has_sliders: track = master else: self.log('2.1') track = self.song().view.selected_track else: self.log('3') track = self._mixer.channel_strip( self._sliders.index(sender))._track else: self.log('4') track = self.song().view.selected_track self.log('track=' + str(track)) if track == master: display_string = 'Master' elif track in tracks: display_string = str(list(tracks).index(track) + 1) elif track in returns: display_string = str( chr(ord('A') + list(returns).index(track))) else: # raise False or AssertionError raise AssertionError display_string += ' Volume' self._set_string_to_display(display_string) def _mixer_button_value(self, value, sender): self.log('__mixer_button_value ' + str(value) + ' ' + str(sender)) if not value in range(128): raise AssertionError #if self._mixer.is_enabled() and value > 0: if self._mixer.is_enabled(): strip = self._mixer.channel_strip( self._strip_buttons.index(sender)) #self._string_to_display = strip != None and None self._name_display.segment(0).set_data_source( strip.track_name_data_source()) self._name_display.update() self._display_reset_delay = STANDARD_DISPLAY_DELAY else: self._set_string_to_display(' - ') # if shift_pressed XOR alternative_mode if self.shift_pressed <> self.alternative_buttons_mode: self.log("_mixer_button_value") self.log(str(value)) if (value == 0): self.select_armed_track_if_only_one() def select_armed_track_if_only_one(self): self.log("select_armed_track_if_only_one") song = self.song() armed_tracks = [] tracks = song.tracks self.log("select_armed_track_if_only_one 2") for track in tracks: if track.can_be_armed and track.arm: armed_tracks.append(track) self.log(str(len(armed_tracks))) if (len(armed_tracks) == 1): self.log("selecting the track") sel_track = armed_tracks[0] self.song().view.selected_track = sel_track self._mixer._selected_tracks = [] self._mixer._selected_tracks.append(sel_track) self._mixer.on_selected_track_changed() def _preview_value(self, value): if not value in range(128): raise AssertionError for encoder in self._encoders: encoder.set_peek_mode(value > 0) def _show_current_track_name(self): if self._name_display != None and self._mixer != None: self._string_to_display = None self._name_display.segment(0).set_data_source( self._mixer.selected_strip().track_name_data_source()) self._name_display.update() def _show_startup_message(self): self._name_display.display_message('LIVE') self._display_reset_delay = INITIAL_DISPLAY_DELAY def _set_string_to_display(self, string_to_display): if not isinstance(string_to_display, (str, unicode)): raise AssertionError self._name_display.segment(0).set_data_source( self._name_display_data_source) self._string_to_display = string_to_display self._display_reset_delay = STANDARD_DISPLAY_DELAY def _on_selected_track_changed(self): self.log('_on_selected_track_changed') ControlSurface._on_selected_track_changed(self) self._show_current_track_name() #all_tracks = self._has_sliders or self._session.tracks_to_use() all_tracks2 = self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks2: track_index = list(all_tracks2).index(selected_track) self.log('track_index ' + str(track_index)) new_offset = track_index - track_index % num_strips self.log('new_offset ' + str(new_offset)) if not new_offset / num_strips == int(new_offset / num_strips): raise AssertionError self._session.set_offsets(new_offset, self._session.scene_offset()) def _shift_button_handler(self, value): self.log("root shift handler : " + str(value)) if not self._shift_button != None: raise AssertionError if not value in range(128): raise AssertionError self.log("root shift handler 2") self.shift_pressed = value > 0 # calling other handlers self._mixer._shift_button_handler(value) self._transport._shift_button_handler(value) self._transport_view_modes._shift_button_handler(value) #clip stop self.log("root shift handler 3") num_pads = len(PAD_TRANSLATIONS) pads = [] for index in range(num_pads): pads.append( ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 60 + index)) pads[-1].name = 'Pad_' + str(index) clip_slot = self._session.selected_scene().clip_slot(index) if self.shift_pressed: clip_slot.set_launch_button(None) else: clip_slot.set_launch_button(pads[index]) if self.shift_pressed: self._session.set_stop_track_clip_buttons(tuple(pads)) else: self._session.set_stop_track_clip_buttons(None) self.log("root shift handler 4") def flipAlternativeButtonMode(self): self.alternative_buttons_mode = not self.alternative_buttons_mode self.updateAlternativeButtonMode() def updateAlternativeButtonMode(self): self._mixer.updateMixerButtons() self._transport_view_modes.update() def log(self, message): pass
class Alias(ControlSurface): __module__ = __name__ __doc__ = " Alias 8 controller script " def __init__(self, c_instance): super(Alias, self).__init__(c_instance) with self.component_guard(): self._host_name = 'Alias' self._color_type = 'OhmRGB' self.log_message( "--------------= Alias log opened =--------------") self._rgb = 0 self._timer = 0 self.flash_status = 1 self._clutch_device_selection = False self._touched = 0 self._update_linked_device_selection = None self._setup_monobridge() self._setup_controls() self._setup_m4l_interface() self._setup_mixer_control() self._setup_session_control() self._setup_mixer_nav() """script initialization methods""" def _setup_monobridge(self): self._monobridge = MonoBridgeElement(self) self._monobridge.name = 'MonoBridge' def _setup_controls(self): is_momentary = True self._fader = [ MonoEncoderElement(MIDI_CC_TYPE, CHANNEL, ALIAS_FADERS[index], Live.MidiMap.MapMode.absolute, 'Fader_' + str(index), index, self) for index in range(9) ] self._button = [ MonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, ALIAS_BUTTONS[index], 'Button_' + str(index), self) for index in range(16) ] self._dial = [ MonoEncoderElement(MIDI_CC_TYPE, CHANNEL, ALIAS_DIALS[index], Live.MidiMap.MapMode.absolute, 'Dial_' + str(index), index + 8, self) for index in range(16) ] self._encoder = MonoEncoderElement(MIDI_CC_TYPE, CHANNEL, ALIAS_ENCODER, Live.MidiMap.MapMode.absolute, 'Encoder', 0, self) def _setup_m4l_interface(self): self._m4l_interface = M4LInterfaceComponent( controls=self.controls, component_guard=self.component_guard) self.get_control_names = self._m4l_interface.get_control_names self.get_control = self._m4l_interface.get_control self.grab_control = self._m4l_interface.grab_control self.release_control = self._m4l_interface.release_control def _setup_mixer_control(self): is_momentary = True self._num_tracks = (8) #A mixer is one-dimensional; self._mixer = AliasMixerComponent(8, 0, False, False) self._mixer.name = 'Mixer' self._mixer.set_track_offset( 0) #Sets start point for mixer strip (offset from left) for index in range(8): self._mixer.channel_strip(index).set_volume_control( self._fader[index]) self._mixer.channel_strip(index).set_send_controls( tuple([self._dial[index], self._dial[index + 8]])) self._mixer.channel_strip(index).set_mute_button( self._button[index]) self._button[index].set_on_off_values(MUTE_TOG, 0) self._mixer.channel_strip(index)._invert_mute_feedback = True self._mixer.channel_strip(index).set_arm_button( self._button[index + 8]) self._button[index + 8].set_on_off_values(REC_TOG, 0) self._mixer.channel_strip( index).name = 'Mixer_ChannelStrip_' + str(index) self._mixer.master_strip().set_volume_control(self._fader[8]) self.song().view.selected_track = self._mixer.channel_strip(0)._track def _setup_session_control(self): self._session = SessionComponent(8, 1) self._session.set_mixer(self._mixer) self.set_highlighting_session_component(self._session) def _setup_mixer_nav(self): if not self._encoder.value_has_listener(self._nav_change): self._encoder.add_value_listener(self._nav_change) """shift/zoom methods""" def _nav_change(self, value): self._session.set_offsets( int((float(value) / float(127)) * max(8, len(self._mixer.tracks_to_use()) - 8)), self._session._scene_offset) """called on timer""" def update_display(self): ControlSurface.update_display(self) self._timer = (self._timer + 1) % 256 self.flash() def flash(self): if (self.flash_status > 0): for control in self.controls: if isinstance(control, MonoButtonElement): control.flash(self._timer) """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 12 if (not display_string): return (' ' * NUM_CHARS_PER_DISPLAY_STRIP) if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center( (NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' ret = ret.replace(' ', '_') assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP) return ret def notification_to_bridge(self, name, value, sender): if isinstance(sender, MonoEncoderElement): self._monobridge._send(sender.name, 'lcd_name', str(self.generate_strip_string(name))) self._monobridge._send(sender.name, 'lcd_value', str(self.generate_strip_string(value))) def touched(self): if self._touched is 0: self._monobridge._send('touch', 'on') self.schedule_message(2, self.check_touch) self._touched += 1 def check_touch(self): if self._touched > 5: self._touched = 5 elif self._touched > 0: self._touched -= 1 if self._touched is 0: self._monobridge._send('touch', 'off') else: self.schedule_message(2, self.check_touch) """general functionality""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates != 0)) def disconnect(self): if self._encoder.value_has_listener(self._nav_change): self._encoder.remove_value_listener(self._nav_change) self.log_message("--------------= Alias log closed =--------------") super(Alias, self).disconnect() rebuild_sys() def handle_sysex(self, midi_bytes): pass def device_follows_track(self, val): self._device_selection_follows_track_selection = (val == 1) return self def assign_alternate_mappings(self): pass def _get_num_tracks(self): return self.num_tracks def _on_device_changed(self, device): #self.log_message('new device ' + str(type(device))) if self._update_linked_device_selection != None: self._update_linked_device_selection(device) def _on_session_offset_changes(self): if self._r_function_mode._mode_index in range(0, 3): self._mem[int(self._r_function_mode._mode_index )] = self._session2.track_offset() def connect_script_instances(self, instanciated_scripts): pass # a
class LemurPad(MonOhm): __module__ = __name__ __doc__ = " Lemur version of the MonOhm companion controller script " def __init__(self, *a, **k): self._timer_callbacks = [ ] #Used for _monobridge, which uses L8 method for registering timer callbacks. deprecated, needs to be replaced by new L9 Task class. self._osc_registry = {} self._display_button_names = DISPLAY_BUTTON_NAMES super(LemurPad, self).__init__(*a, **k) self._host_name = "LemurPad" self._color_type = 'AumPad' self.connected = 0 with self.component_guard(): self._setup_touchosc() self._assign_host2() self._assign_session_colors() def query_ohm(self): pass """script initialization methods""" def _setup_monobridge(self): self._monobridge = OSCMonoBridgeElement(self) self._monobridge.name = 'MonoBridge' def _setup_controls(self): is_momentary = True self._fader = [None for index in range(8)] self._dial = [None for index in range(16)] self._button = [None for index in range(8)] self._menu = [None for index in range(6)] for index in range(8): self._fader[index] = OSCMonoEncoderElement( MIDI_CC_TYPE, CHANNEL, OHM_FADERS[index], Live.MidiMap.MapMode.absolute, 'Fader_' + str(index), index, self, osc='/Fader_' + str(index) + '/x', osc_parameter='/Strip' + str(index + 8) + '/set', osc_name='/Strip' + str(index) + '/set') for index in range(8): self._button[index] = OSCMonoButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, OHM_BUTTONS[index], 'Button_' + str(index), self, osc='/Select_' + str(index) + '/value', osc_alt='/Select/set ' + str(index), osc_name='/Select/text ' + str(index)) for index in range(16): self._dial[index] = OSCMonoEncoderElement( MIDI_CC_TYPE, CHANNEL, OHM_DIALS[index], Live.MidiMap.MapMode.absolute, 'Dial_' + str(index), index + 8, self, osc='/Dial_' + str(index) + '/x', osc_parameter='/Dial' + str(index) + 'val/set', osc_name='/Dial' + str(index) + 'name/set') for index in range(6): self._menu[index] = OSCMonoButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, OHM_MENU[index], 'Menu_' + str(index), self, osc='/Function_' + str(index) + '/value', osc_alt='/Function/set ' + str(index), osc_name='/Function/text ' + str(index)) self._crossfader = OSCMonoEncoderElement(MIDI_CC_TYPE, CHANNEL, CROSSFADER, Live.MidiMap.MapMode.absolute, "Crossfader", 24, self, osc='/XFader/x', osc_parameter='/XFader/none', osc_name=None) self._livid = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, LIVID, 'Livid_Button', self, osc='/Livid/x', osc_alt='/Livid/x', osc_name=None) self._shift_l = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, SHIFT_L, 'Shift_Button_Left', self, osc='/ShiftL/x', osc_alt='/ShiftL/x', osc_name=None) self._shift_r = OSCMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, SHIFT_R, 'Shift_Button_Right', self, osc='/ShiftR/x', osc_alt='/ShiftR/x', osc_name=None) self._matrix = ButtonMatrixElement() self._matrix.name = 'Matrix' self._monomod = ButtonMatrixElement() self._monomod.name = 'Monomod' self._grid = [None for index in range(8)] for column in range(8): self._grid[column] = [None for index in range(8)] for row in range(8): self._grid[column][row] = OSCMonoButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, (column * 8) + row, 'Grid_' + str(column) + '_' + str(row), self, osc='/ClipGrid_' + str(column) + '_' + str(row) + '/value', osc_alt='/ClipGrid/set ' + str(column) + ' ' + str(row), osc_name='/ClipGrid/text ' + str(column) + ' ' + str(row)) for row in range(5): button_row = [] for column in range(7): button_row.append(self._grid[column][row]) self._matrix.add_row(tuple(button_row)) for row in range(8): button_row = [] for column in range(8): button_row.append(self._grid[column][row]) self._monomod.add_row(tuple(button_row)) self._dummy_button = ButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, 125) self._dummy_button.name = 'Dummy1' self._dummy_button2 = ButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, 126) self._dummy_button2.name = 'Dummy2' self._dummy_button3 = ButtonElement(is_momentary, MIDI_NOTE_TYPE, 15, 127) self._dummy_button2.name = 'Dummy3' self._monomod256 = ButtonMatrixElement() self._monomod256.name = 'Monomod256' self._square = [None for index in range(16)] for column in range(16): self._square[column] = [None for index in range(16)] for row in range(16): self._square[column][row] = OSCMonoButtonElement( is_momentary, MIDI_NOTE_TYPE, int(column / 8) + 1, row + ((column % 8) * 16), '256Grid_' + str(column) + '_' + str(row), self, osc='/Grid_' + str(column) + '_' + str(row) + '/value', osc_alt='/Grid/set ' + str(column) + ' ' + str(row), osc_name=None) #self._square[column][row] = FlashingButtonElement(is_momentary, 0, 15, -1, '256Grid_' + str(column) + '_' + str(row), '/1/p_grid/'+str(column)+'/'+str(row), '/1/c_grid/'+str(column)+'/'+str(row), self) for row in range(16): button_row = [] for column in range(16): button_row.append(self._square[column][row]) self._monomod256.add_row(tuple(button_row)) self._bank_buttons = ButtonMatrixElement() self._key_buttons = ButtonMatrixElement() self._bank_button = [None for index in range(2)] for index in range(2): self._bank_button[index] = OSCMonoButtonElement( is_momentary, MIDI_NOTE_TYPE, 15, index, '256Grid_Bank_' + str(index), self, osc='/Shift_' + str(index) + '/value', osc_alt='/Shift/set ' + str(index), osc_name=None) button_row = [] for index in range(2): button_row.append(self._bank_button[index]) self._bank_buttons.add_row(tuple(button_row)) button_row = [] self._key_button = [None for index in range(8)] for index in range(8): self._key_button[index] = OSCMonoButtonElement( is_momentary, MIDI_NOTE_TYPE, 15, index + 8, '256Grid_Key_' + str(index), self, osc='/Keys_' + str(index) + '/value', osc_alt='/Keys/set ' + str(index), osc_name=None) for index in range(8): button_row.append(self._key_button[index]) self._key_buttons.add_row(tuple(button_row)) def _setup_session_control(self): is_momentary = True num_tracks = 4 num_scenes = 5 self._session = NameServerSessionComponent(num_tracks, num_scenes, self) self._session.name = "Left_Session" self._session.set_offsets(0, 0) self._session.set_stop_clip_value(self._color_defs['STOP_CLIP']) self._scene = [None for index in range(5)] for row in range(num_scenes): self._scene[row] = self._session.scene(row) self._scene[row].name = 'L_Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_L_' + str(row) clip_slot.set_triggered_to_play_value( self._color_defs['CLIP_TRG_PLAY']) clip_slot.set_triggered_to_record_value( self._color_defs['CLIP_TRG_REC']) clip_slot.set_stopped_value(self._color_defs['CLIP_STOP']) clip_slot.set_started_value(self._color_defs['CLIP_STARTED']) clip_slot.set_recording_value( self._color_defs['CLIP_RECORDING']) self._session.set_mixer(self._mixer) self._session_zoom = SessionZoomingComponent(self._session) self._session_zoom.name = 'L_Session_Overview' self._session_zoom.set_stopped_value(self._color_defs['ZOOM_STOPPED']) self._session_zoom.set_playing_value(self._color_defs['ZOOM_PLAYING']) self._session_zoom.set_selected_value( self._color_defs['ZOOM_SELECTED']) self._session_zoom._zoom_button = (self._dummy_button) self._session_zoom.set_enabled(True) self._session2 = SessionComponent(num_tracks, num_scenes) self._session2.name = 'Right_Session' self._session2.set_offsets(4, 0) self._session2.set_stop_clip_value(self._color_defs['STOP_CLIP']) self._scene2 = [None for index in range(5)] for row in range(num_scenes): self._scene2[row] = self._session2.scene(row) self._scene2[row].name = 'R_Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene2[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_R_' + str(row) clip_slot.set_triggered_to_play_value( self._color_defs['CLIP_TRG_PLAY']) clip_slot.set_triggered_to_record_value( self._color_defs['CLIP_TRG_REC']) clip_slot.set_stopped_value(self._color_defs['CLIP_STOP']) clip_slot.set_started_value(self._color_defs['CLIP_STARTED']) clip_slot.set_recording_value( self._color_defs['CLIP_RECORDING']) self._session2.set_mixer(self._mixer2) self._session2.add_offset_listener(self._on_session_offset_changes) self._session_zoom2 = SessionZoomingComponent(self._session2) self._session_zoom2.name = 'R_Session_Overview' self._session_zoom2.set_stopped_value(self._color_defs['ZOOM_STOPPED']) self._session_zoom2.set_playing_value(self._color_defs['ZOOM_PLAYING']) self._session_zoom2.set_selected_value( self._color_defs['ZOOM_SELECTED']) self._session_zoom.set_enabled(True) self._session_zoom2._zoom_button = (self._dummy_button2) self._session_main = SessionComponent(8, num_scenes) self._session_main.name = 'Main_Session' self._session_main.set_stop_clip_value(self._color_defs['STOP_CLIP']) self._scene_main = [None for index in range(5)] for row in range(num_scenes): self._scene_main[row] = self._session_main.scene(row) self._scene_main[row].name = 'M_Scene_' + str(row) for column in range(8): clip_slot = self._scene_main[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_M_' + str(row) clip_slot.set_triggered_to_play_value( self._color_defs['CLIP_TRG_PLAY']) clip_slot.set_triggered_to_record_value( self._color_defs['CLIP_TRG_REC']) clip_slot.set_stopped_value(self._color_defs['CLIP_STOP']) clip_slot.set_started_value(self._color_defs['CLIP_STARTED']) clip_slot.set_recording_value( self._color_defs['CLIP_RECORDING']) self._session_main.set_mixer(self._mixer) self._session_zoom_main = SessionZoomingComponent(self._session_main) self._session_zoom_main.name = 'M_Session_Overview' self._session_zoom_main.set_stopped_value( self._color_defs['ZOOM_STOPPED']) self._session_zoom_main.set_playing_value( self._color_defs['ZOOM_PLAYING']) self._session_zoom_main.set_selected_value( self._color_defs['ZOOM_SELECTED']) self._session_zoom_main.set_enabled(True) self._session_zoom_main._zoom_button = (self._dummy_button3) self._sessions = [self._session, self._session2, self._session_main] self._zooms = [ self._session_zoom, self._session_zoom2, self._session_zoom_main ] def _setup_mod(self): self.monomodular = get_monomodular(self) self.monomodular.name = 'monomodular_switcher' self.modhandler = LemurOhmModHandler(self) self.modhandler.name = 'ModHandler' self.modhandler256 = LemurModHandler(self) self.modhandler256.name = 'ModHandler256' def _assign_host2(self): self.modhandler256.set_shift_button(self._bank_button[0]) self.modhandler256.set_alt_button(self._bank_button[1]) self.modhandler256.set_grid(self._monomod256) self.modhandler256.set_key_buttons(self._key_buttons) self.modhandler256.set_enabled(True) def _setup_touchosc(self): self._osc_registry = {} #self._osc_registry['/ping'] = self._monobridge.ping #self._osc_registry['/1'] = self._monobridge.page1 #self._osc_registry['/2'] = self._monobridge.page2 for control in self.controls: if hasattr(control, 'osc'): self._osc_registry[control.osc] = control.set_value #if hasattr(control, 'osc_alt'): # self._osc_registry[control.osc_alt] = control.set_value #self.log_message('create dict key: ' + str(control.osc) + str(control.name)) """shift/zoom methods""" def deassign_matrix(self): super(LemurPad, self).deassign_matrix() self.clear_grid_names() """menu button management methods""" def deassign_menu(self): super(LemurPad, self).deassign_menu() for index in range(6): self._monobridge._send_osc(self._menu[index].osc_name, self.generate_strip_string(' ')) def assign_device_nav_to_menu(self): super(LemurPad, self).assign_device_nav_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(DEVICE_NAV_NAMES[index]))) def assign_transport_to_menu(self): super(LemurPad, self).assign_transport_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(TRANSPORT_NAMES[index]))) def assign_session_nav_to_menu(self): super(LemurPad, self).assign_session_nav_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(SESSION_NAV_NAMES[index]))) def assign_session_main_nav_to_menu(self): super(LemurPad, self).assign_session_main_nav_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(SESSION_NAV_NAMES[index]))) def assign_monomod_shift_to_menu(self): super(LemurPad, self).assign_monomod_shift_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(MONOMOD_SHIFT_NAMES[index]))) def assign_monomod_to_menu(self): super(LemurPad, self).assign_monomod_shift_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(MONOMOD_NAMES[index]))) def assign_session_bank_to_menu(self): super(LemurPad, self).assign_session_bank_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(SESSION_BANK_NAMES[index]))) def assign_session2_bank_to_menu(self): super(LemurPad, self).assign_session2_bank_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str(SESSION_BANK2_NAMES[index]))) def assign_session_main_nav_to_menu(self): super(LemurPad, self).assign_session_main_nav_to_menu() for index in range(6): self._monobridge._send_osc( self._menu[index].osc_name, self.generate_strip_string(str( SESSION_MAIN_BANK_NAMES[index]))) """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 9 if (not display_string): return ('`_') if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center( (NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP) return '`' + ret.replace(' ', '_') def notification_to_bridge(self, name, value, sender): if (isinstance(sender, MonoEncoderElement2)): #self.log_message(str(name) + str(value) + str(sender.num)) self._monobridge._send('lcd_name', sender.name, self.generate_strip_string(str(name))) self._monobridge._send('lcd_value', sender.name, self.generate_strip_string(str(value))) def clip_name(self, sender, name): #self.log_message('clip name ' + str(sender.osc_name) + ' ' + str(self.generate_strip_string(str(name)))) self._monobridge._send_osc(sender.osc_name, self.generate_strip_string(str(name))) """def get_clip_names(self): clip_names = [] for scene in self._session._scenes: for clip_slot in scene._clip_slots: if clip_slot.has_clip(): clip_names.append(clip_slot._clip_slot)##.clip.name) #return clip_slot._clip_slot #self.log_message('clip name' + str(clip_slot._clip_slot.clip.name)) return clip_names""" """called on timer""" def update_display(self): super(LemurPad, self).update_display() for callback in self._timer_callbacks: callback() def strobe(self): pass """general functionality""" def disconnect(self): super(MonOhm, self).disconnect() def clear_grid_names(self): #self.log_message('clear grid names' + str(self)) for column in range(8): for row in range(8): self._monobridge._send_osc(self._grid[column][row].osc_name, '`_') def _register_timer_callback(self, callback): """ Registers a callback that is triggerd on every call of update_display """ assert (callback != None) assert (dir(callback).count('im_func') is 1) assert (self._timer_callbacks.count(callback) == 0) self._timer_callbacks.append(callback) return None def _unregister_timer_callback(self, callback): """ Unregisters a timer callback """ assert (callback != None) assert (dir(callback).count('im_func') is 1) assert (self._timer_callbacks.count(callback) == 1) self._timer_callbacks.remove(callback) return None def _set_brightness(self, value): #self._bright = (value != 0) #for control in self.controls: # if isinstance(control, OSCMonoButtonElement): # self._monobridge._send_osc(control.osc_alt, int(self._bright), True) pass def reset(self): #self._monobridge._send_osc('/reset') for control in self.controls: control.reset() def assign_lower_grid_names(self, mode): if self._display_button_names is True: for column in range(8): for row in range(3): self._monobridge._send_osc( self._grid[column][row + 5].osc_name, self.generate_strip_string( str(GRID_NAMES[mode][row][column]))) def reset_and_refresh_state(self, *a, **k): self.schedule_message(1, self.reset) self.schedule_message(2, self.refresh_state)
class AumTroll_G(AumTroll): def __init__(self, *a, **k): super(AumTroll_G, self).__init__(*a, **k) with self.component_guard(): self._setup_session_recording_component() self._setup_APC_detail_component() self.log_message('Aumtroll G 4') def _setup_session_recording_component(self): self._recorder = SessionRecordingComponent(ClipCreator(), ViewControlComponent()) def _setup_APC_detail_component(self): self._alt_device_navigator = DetailViewCntrlComponent() """the mixer component corresponds and moves with our selection in Live, and allows us to assign physical controls""" """to Live's mixer functions without having to make all the links ourselves""" def _setup_mixer_control(self): is_momentary = True self._num_tracks = (8) #A mixer is one-dimensional; self._mixer = MixerComponent( 8, 2, True, False ) #These values represent the (Number_of_tracks, Number_of_returns, EQ_component, Filter_component) self._mixer.name = 'Mixer' #We name everything that we might want to access in m4l self._mixer.set_track_offset( 0) #Sets start point for mixer strip (offset from left) for index in range(8): #self._mixer.channel_strip(index).set_volume_control(self._fader[index]) #Since we gave our mixer 4 tracks above, we'll now assign our fader controls to it self._mixer.channel_strip( index ).name = 'Mixer_ChannelStrip_' + str( index ) #We also name the individual channel_strip so we can access it self._mixer.track_eq(index).name = 'Mixer_EQ_' + str( index ) #We also name the individual EQ_component so we can access it self._mixer.channel_strip( index )._invert_mute_feedback = True #This makes it so that when a track is muted, the corresponding button is turned off self.song().view.selected_track = self._mixer.channel_strip( 0 )._track #set the selected strip to the first track, so that we don't, for example, try to assign a button to arm the master track, which would cause an assertion error self._send_reset = ResetSendsComponent( self ) #This creates a custom MonoComponent that allows us to reset all the sends on a track to zero with a single button self._send_reset.name = 'Sends_Reset' #We name it so that we can access it from m4l """the session component represents a grid of buttons that can be used to fire, stop, and navigate clips in the session view""" def _setup_session_control(self): is_momentary = True num_tracks = 8 #we are working with a 4x4 grid, num_scenes = 4 #so the height and width are both set to 4 self._session = SessionComponent( num_tracks, num_scenes ) #we create our SessionComponent with the variables we set above it self._session.name = "Session" #we name it so we can access it in m4l self._session.set_offsets( 0, 0 ) #we set the initial offset to the far left, top of the session grid self._session._track_banking_increment = 4 self._session.set_stop_clip_value( STOP_CLIP[self._rgb] ) #we assign the colors that will be displayed when the stop_clip button is pressed. This value comes from CNTRLR_Map.py, which is imported in the header of our script self._scene = [ None for index in range(4) ] #we create an array to hold the Scene subcomponents so that we can get to them if we need them. for row in range( num_scenes ): #now we'll fill the array with different objects that were created when we called the SessionComponent() module self._scene[row] = self._session.scene( row) #each session row is a SceneComponent self._scene[row].name = 'Scene_' + str( row) #name it so we can access it in m4l for column in range( num_tracks ): #now we'll create holders and names for the contents of each scene clip_slot = self._scene[row].clip_slot( column ) #we use our assignment of the scene above to gain access to the individual clipslots. Here, we are just assigning 'clip_slot' each time as a local variable so we can manipulated it's properties clip_slot.name = str(column) + '_Clip_Slot' + str( row) #name it so that we can acces it in m4l clip_slot.set_triggered_to_play_value( CLIP_TRG_PLAY[self._rgb]) #set its triggered to play color clip_slot.set_triggered_to_record_value( CLIP_TRG_REC[ self._rgb]) #set its triggered to record color clip_slot.set_stopped_value( CLIP_STOP[self._rgb]) #set its stop color clip_slot.set_started_value( CLIP_STARTED[self._rgb]) #set its started color clip_slot.set_recording_value( CLIP_RECORDING[self._rgb]) #set its recording value self._session.set_mixer( self._mixer ) #now we link the MixerComponent we created in _setup_mixer_control() to our session component so that they will follow each other when either is navigated self.set_highlighting_session_component(self._session) self._session_zoom = SessionZoomingComponent( self._session ) #this creates the ZoomingComponent that allows navigation when the shift button is pressed self._session_zoom.name = 'Session_Overview' #name it so we can access it in m4l self._session_zoom.set_stopped_value( ZOOM_STOPPED[self._rgb]) #set the zooms stopped color self._session_zoom.set_playing_value( ZOOM_PLAYING[self._rgb]) #set the zooms playing color self._session_zoom.set_selected_value( ZOOM_SELECTED[self._rgb]) #set the zooms selected color self._session_zoom.set_button_matrix( self._matrix ) #assign the ButtonMatrixElement that we created in _setup_controls() to the zooming component so that we can control it self._session_zoom.set_zoom_button( self._button[31] ) #assign a shift button so that we can switch states between the SessionComponent and the SessionZoomingComponent """this section is used so that we can reassign the color properties of each state. Legacy, from the OhmModes script, to support either RGB or Monochrome""" def _assign_session_colors(self): num_tracks = 8 num_scenes = 4 self._session.set_stop_clip_value(STOP_ALL[self._rgb]) for row in range(num_scenes): for column in range(num_tracks): self._scene[row].clip_slot(column).set_triggered_to_play_value( CLIP_TRG_PLAY[self._rgb]) self._scene[row].clip_slot( column).set_triggered_to_record_value( CLIP_TRG_REC[self._rgb]) self._scene[row].clip_slot(column).set_stopped_value( CLIP_STOP[self._rgb]) self._scene[row].clip_slot(column).set_started_value( CLIP_STARTED[self._rgb]) self._scene[row].clip_slot(column).set_recording_value( CLIP_RECORDING[self._rgb]) self._session_zoom.set_stopped_value(ZOOM_STOPPED[self._rgb]) self._session_zoom.set_playing_value(ZOOM_PLAYING[self._rgb]) self._session_zoom.set_selected_value(ZOOM_SELECTED[self._rgb]) self.refresh_state() def deassign_live_controls(self, *a, **k): for index in range(4): self._encoder[index].send_value(0, True) self._encoder[index].clear_send_cache() self._mixer.channel_strip(index + 4).set_volume_control( None ) #Since we gave our mixer 4 tracks above, we'll now assign our fader controls to it #for the left side of the mixer self._mixer.channel_strip(index + 4).set_solo_button( None) #remove the solo button assignments self._mixer.channel_strip(index + 4).set_arm_button( None) #remove the arm button assignments self._mixer.channel_strip(index + 4).set_mute_button( None) #remove the mute button assignments self._mixer.channel_strip(index + 4).set_select_button( None) #remove the select button assignments #self._alt_device_navigator.set_arrange_session_toggle_button(None) self._alt_device_navigator.set_device_clip_toggle_button(None) self._alt_device_navigator.set_detail_toggle_button(None) self._alt_device_navigator.set_enabled(False) #self._alt_device_navigator.set_shift_button(None) self._transport.set_nudge_buttons(None, None) self._recorder.set_record_button(None) self._recorder.set_re_enable_automation_button(None) super(AumTroll_G, self).deassign_live_controls(*a, **k) def assign_live_controls(self): """the following lines update all of the controls' last_sent properties, so that they forward the next value they receive regardless of whether or not it is the same as the last it recieved""" """we also reset the encoder rings and buttons, since the device component will not update them if it is not locked to a device in Live""" for index in range(16): self._grid[index].force_next_send() for index in range(32): #self._button[index].set_on_off_values(0, 127) self._button[index].send_value(0, True) self._button[index].force_next_send() for index in range(8): self._encoder_button[index + 4].send_value(0, True) self._encoder_button[index + 4].force_next_send() for index in range(12): self._encoder[index].send_value(0, True) self._encoder[index].force_next_send() """here we assign the left side of our mixer's buttons on the lower 32 keys""" if self._monohm is None: with self.component_guard(): for index in range( 4 ): #we set up a recursive loop to assign all four of our track channel strips' controls self._button[index + 16].set_on_value( MUTE[self._rgb]) #set the mute color from the Map.py self._mixer.channel_strip(index).set_mute_button( self._button[index + 16] ) #assign the mute buttons to our mixer channel strips self._button[index + 28].set_on_value( MUTE[self._rgb]) #set the mute color from the Map.py self._mixer.channel_strip(index + 4).set_mute_button( self._button[index + 28] ) #assign the mute buttons to our mixer channel strips self._button[index].set_on_off_values( SELECT[self._rgb], SELECT_OFF[self._rgb]) self._mixer.channel_strip(index).set_select_button( self._button[index] ) #assign the select buttons to our mixer channel strips self._button[index + 12].set_on_off_values( SELECT[self._rgb], SELECT_OFF[ self._rgb]) #set the select color from the Map.py self._mixer.channel_strip(index + 4).set_select_button( self._button[index + 12] ) #assign the select buttons to our mixer channel strips #self._session.set_stop_track_clip_buttons(tuple(self._button[index+4] for index in range(8))) #these last two lines assign the send_reset buttons and the stop_clip buttons for each track for index in range(8): #self._button[index + 4].set_on_off_values(SOLO[self._rgb], SOLO[self._rgb]) #this assigns the custom colors defined in the Map.py file to the stop_clip buttons. They have seperate on/off values, but we assign them both the same value so we can always identify them self._mixer.channel_strip(index).set_solo_button( self._button[index + 4]) #self._button[index + 4].send_value(STOP_CLIP[self._rgb], True) #finally, we send the on/off colors out to turn the LEDs on for the stop clip buttons for index in range( 4 ): #set up a for loop to generate an index for assigning the session nav buttons' colors self._button[index + 20].set_on_off_values( SESSION_NAV[self._rgb], SESSION_NAV_OFF[self._rgb] ) #assign the colors from Map.py to the session nav buttons self._session.set_track_bank_buttons( self._button[21], self._button[20] ) #set the track bank buttons for the Session navigation controls self._session.set_scene_bank_buttons( self._button[23], self._button[22] ) #set the scnee bank buttons for the Session navigation controls """this section assigns the grid to the clip launch functionality of the SessionComponent""" for column in range( 4 ): #we need to set up a double recursion so that we can generate the indexes needed to assign the grid buttons for row in range( 4 ): #the first recursion passes the column index, the second the row index self._scene[row].clip_slot(column).set_launch_button( self._grid[(row * 4) + column] ) #we use the indexes to grab the first the scene and then the clip we assigned above, and then we use them again to define the button held in the grid array that we want to assign to the clip slot from the session component for index in range( 4 ): #set up a for loop to generate an index for assigning the session nav buttons' colors self._button[index + 24].set_on_off_values( SHIFTS[self._rgb], SHIFTS_OFF[self._rgb] ) #assign the colors from Map.py to the session nav buttons self._session.update( ) #tell the Session component to update so that the grid will display the currently selected session region self._session.set_enabled(True) #enable the Session Component self._session_zoom.set_enabled(True) #enable the Session Zoom #self._alt_device_navigator.set_arrange_session_toggle_button(self._encoder_button[4]) self._alt_device_navigator.set_device_clip_toggle_button( self._encoder_button[5]) self._alt_device_navigator.set_detail_toggle_button( self._encoder_button[6]) #self._device_navigator.set_shift_button(self._encoder_button[7]) self._session_zoom.set_zoom_button( self._encoder_button[7] ) #assign the lower right key button to the shift function of the Zoom component self._session.set_scene_bank_buttons(self._button[25], self._button[24]) self._recorder.set_record_button(self._button[27]) self._recorder.set_re_enable_automation_button( self._button[26]) else: for index in range(8): self._mixer2.channel_strip(index).set_volume_control( self._fader[index]) self._mixer2.set_track_offset(TROLL_OFFSET) self._device_selector.set_mode_buttons(self._grid) if not self._shifted: self._assign_monomodular_controls() else: self._assign_shifted_controls() self._device1.set_parameter_controls( tuple([self._knobs[index] for index in range(8)])) self._device2.set_parameter_controls( tuple([self._knobs[index + 12] for index in range(8)])) self._device1.set_enabled(True) self._device2.set_enabled(True) self._find_devices() self._device1.update() self._device2.update() """this section assigns the encoders and encoder buttons""" self._device.set_parameter_controls( tuple([self._encoder[index + 4] for index in range(8)]) ) #assign the encoders from the device component controls - we are doing this here b #self._encoder_button[7].set_on_value(DEVICE_LOCK[self._rgb]) #set the on color for the Device lock encoder button #self._device.set_lock_button(self._encoder_button[7]) #assign encoder button 7 to the device lock control #self._encoder_button[4].set_on_value(DEVICE_ON[self._rgb]) #set the on color for the Device on/off encoder button #self._device.set_on_off_button(self._encoder_button[4]) #assing encoder button 4 to the device on/off control for index in range( 2 ): #setup a recursion to generate indexes so that we can reference the correct controls to assing to the device_navigator functions self._encoder_button[index + 8].set_on_value( DEVICE_NAV[ self._rgb]) #assign the on color for the device navigator self._encoder_button[index + 10].set_on_value( DEVICE_BANK[self._rgb] ) #assign the on color for the device bank controls self._device_navigator.set_nav_buttons( self._encoder_button[10], self._encoder_button[11] ) #set the device navigators controls to encoder buttons 10 and 11 self._device.set_bank_nav_buttons( self._encoder_button[8], self._encoder_button[9] ) #set the device components bank nav controls to encoder buttons 8 and 9 """now we turn on and update some of the components we've just made assignments to""" self._device.set_enabled(True) #enable the Device Component self._device_navigator.set_enabled(True) #enable the Device Navigator self._alt_device_navigator.set_enabled(True) self._device.update( ) #tell the Device component to update its assingments so that it will detect the currently selected device parameters and display them on the encoder rings
class SongController: """ The Song Controller listens to all of the changes in the song composition such as the adding of new tracks, scenes, and clips. """ # Session Parameters m_NumSessionTracks = 6 m_NumSessionScenes = 12 m_SessionTrackOffset = 0 m_SessionSceneOffset = 0 m_Session = None # Song Information m_NumScenes = None m_NumTracks = None # Live tracks m_Tracks = None def __init__(self, transport, NumSessionTracks, NumSessionScenes, SessionTrackOffset, SessionSceneOffset): """ Song Controller Constructor """ self.m_song = Live.Application.get_application().get_document() self.UpdateSong() self.m_transport = transport self.SetupSongHandlers() self.SetupSession(NumSessionTracks, NumSessionScenes, SessionTrackOffset, SessionSceneOffset) self.SetupTracks() def UpdateSong(self): self.m_NumTracks = len(self.m_song.tracks) self.m_NumScenes = len(self.m_song.scenes) def Disconnect(self): self.m_transport.LogMessage("+SongController::Disconnect") self.ClearTracks() self.RemoveSongHandlers() def FindHighlightedTrack(self): slot = self.m_song.view.highlighted_clip_slot i = 0 j = 0 #self.m_transport.LogMessage(str(slot)) for track in self.m_song.tracks: for clipslot in track.clip_slots: if (slot == clipslot): return (i, j) j += 1 i += 1 j = 0 return (-1, -1) def GetSlot(self, trackNum, rowNum): i = 0 j = 0 for track in self.m_song.tracks: if (i == trackNum): for clipslot in track.clip_slots: if (rowNum == j): return clipslot j += 1 i += 1 return None def FireHighlightedSlot(self): self.m_song.view.highlighted_clip_slot.fire() def StopHighlightedSlot(self): self.m_song.view.highlighted_clip_slot.stop() def HighlightSlot(self, track, row): slot = self.GetSlot(track, row) self.m_transport.LogMessage(str(slot)) if (slot): self.m_song.view.highlighted_clip_slot = slot return slot def FindFirstArmedTrackIndex(self): i = 0 for track in self.m_song.tracks: if (track.arm): self.m_transport.LogMessage("Found arm track: " + str(i)) track.arm = False return i i += 1 self.m_transport.LogMessage("No armed tracks found") return -1 def MoveHighlightedClipslotDown(self): slotTuple = self.FindHighlightedTrack() col = slotTuple[0] row = slotTuple[1] + 1 if (row >= len(self.m_song.tracks[col].clip_slots)): row = 0 self.HighlightSlot(col, row) def MoveHighlightedClipslotUp(self): slotTuple = self.FindHighlightedTrack() col = slotTuple[0] row = slotTuple[1] - 1 if (row < 0): row = len(self.m_song.tracks[col].clip_slots) - 1 self.HighlightSlot(col, row) def MoveArmTrackLeft(self): index = self.FindFirstArmedTrackIndex() row = self.FindHighlightedTrack()[1] if (index != -1 and index > 0): self.m_song.tracks[index].arm = False index -= 1 self.m_song.tracks[index].arm = True elif (index == -1): index = len(self.m_song.tracks) - 1 self.m_song.tracks[index].arm = True self.HighlightSlot(index, row) def MoveArmTrackRight(self): index = self.FindFirstArmedTrackIndex() row = self.FindHighlightedTrack()[1] if (index != -1 and index < len(self.m_song.tracks) - 1): self.m_song.tracks[index].arm = False index += 1 self.m_song.tracks[index].arm = True elif (index == -1): index = 0 self.m_song.tracks[index].arm = True self.HighlightSlot(index, row) def SetupSession(self, NumSessionTracks, NumSessionScenes, SessionTrackOffset, SessionSceneOffset): """Setup the session control""" self.m_NumSessionTracks = NumSessionTracks self.m_NumSessionScenes = NumSessionScenes self.m_SessionTrackOffset = SessionTrackOffset self.m_SessionSceneOffset = SessionSceneOffset self.m_Session = SessionComponent(self.m_NumSessionTracks, self.m_NumSessionScenes) self.m_Session.set_offsets(self.m_SessionTrackOffset, self.m_SessionSceneOffset) def MoveSessionByOffset(self, XOffset, YOffset): self.m_transport.LogMessage("Moving Session by (x, y): " + str(XOffset) + ", " + str(YOffset)) self.ClearTracks() # clear the tracks self.m_SessionTrackOffset += XOffset if (self.m_SessionTrackOffset < 0): self.m_SessionTrackOffset = 0 self.m_SessionSceneOffset += YOffset if (self.m_SessionSceneOffset < 0): self.m_SessionSceneOffset = 0 # Update the session self.m_Session.set_offsets(self.m_SessionTrackOffset, self.m_SessionSceneOffset) self.SetupTracks() def TriggerFromStrFret(self, gStr, gFret): if (self.m_Tracks and gStr <= len(self.m_Tracks)): triggerTrack = self.m_Tracks[gStr - 1] triggerTrack.TriggerClipSlot(gFret) else: return None def ClearTracks(self): if (self.m_Tracks and len(self.m_Tracks) > 0): for track in self.m_Tracks: track.Disconnect() del track track = None self.m_Tracks = [] def SetupTracks(self): self.m_Tracks = [] for i in range(self.m_SessionTrackOffset, self.m_SessionTrackOffset + self.m_NumSessionTracks): if i >= len(self.m_song.tracks): break else: self.m_transport.LogMessage("Setup Track #:" + str(i)) newTrack = TrackController(self, self.m_song.tracks[i], i) self.m_Tracks.append(newTrack) def UpdateDisplay(self): for track in self.m_Tracks: track.UpdateDisplay() def SetupSongHandlers(self): if not self.m_song: return None self.m_song.add_is_playing_listener(self.OnSongPlayingChanged) self.m_song.add_tracks_listener(self.OnSongTracksChanged) self.m_song.add_scenes_listener(self.OnSongScenesChanged) def RemoveSongHandlers(self): if not self.m_song: return None self.m_song.remove_is_playing_listener(self.OnSongPlayingChanged) self.m_song.remove_tracks_listener(self.OnSongTracksChanged) self.m_song.remove_scenes_listener(self.OnSongScenesChanged) def PlaySong(self): self.m_song.start_playing() def StopSong(self): self.m_song.stop_playing() def OnSongPlayingChanged(self): self.m_transport.LogMessage("+OnSongPlayingChanged") self.m_transport.m_GtarController.UpdatePlayStopButton( self.m_song.is_playing) def OnSongTracksChanged(self): self.m_transport.LogMessage("+OnSongTracksChanged") NumTracks = len(self.m_song.tracks) if NumTracks != self.m_NumTracks: self.m_NumTracks = NumTracks self.m_transport.LogMessage("New # of tracks: " + str(self.m_NumTracks)) def OnSongScenesChanged(self): self.m_transport.LogMessage("+OnSongScenesChanged") NumScenes = len(self.m_song.scenes) if NumScenes != self.m_NumScenes: self.m_NumScenes = NumScenes self.m_transport.LogMessage("New # of scenes: " + str(self.m_NumScenes)) def __del__(self): pass
class MIDI_Mix(APC, OptimizedControlSurface): 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 _create_controls(self): self._sliders = make_button_row( chain(xrange(19, 32, 4), xrange(49, 62, 4)), make_slider, 'Volume_Slider') self._rec_arm_buttons = make_button_row(xrange(3, 25, 3), make_button, 'Record_Arm_Button') self._mute_buttons = make_button_row(xrange(1, 23, 3), make_button, 'Mute_Button') self._solo_buttons = make_button_row(xrange(2, 24, 3), make_button, 'Solo_Button') self._send_encoders = ButtonMatrixElement(rows=[[ make_encoder( id, 'Send_Encoder_%d' % (id_index + row_index * NUM_TRACKS)) for id_index, id in enumerate(row) ] for row_index, row in enumerate(SEND_IDS)]) self._pan_encoders = make_button_row( chain(xrange(18, 31, 4), xrange(48, 61, 4)), make_encoder, 'Pan_Encoder') self._bank_left_button = make_button(25, 'Bank_Left_Button') self._bank_right_button = make_button(26, 'Bank_Right_Button') self._solo_mode_button = make_button(27, 'Solo_Mode_Button') self._master_slider = make_slider(62, 'Master_Slider') def _create_mixer(self): self._mixer = MixerComponent( num_tracks=NUM_TRACKS, is_enabled=False, invert_mute_feedback=True, layer=Layer(volume_controls=self._sliders, pan_controls=self._pan_encoders, send_controls=self._send_encoders, bank_down_button=self._bank_left_button, bank_up_button=self._bank_right_button, arm_buttons=self._rec_arm_buttons, solo_buttons=self._solo_buttons, mute_buttons=self._mute_buttons)) self._mixer.master_strip().layer = Layer( volume_control=self._master_slider) def _create_session(self): """ Creates SessionComponent which is used for banking and visual focus box. """ self._session = SessionComponent(num_tracks=NUM_TRACKS, num_scenes=NUM_SCENES, is_enabled=True, auto_name=True, enable_skinning=True) self._session.set_offsets(0, 0) self._session.layer = Layer( track_bank_left_button=self._bank_left_button, track_bank_right_button=self._bank_right_button) self._on_session_offset_changed.subject = self._session @subject_slot('offset') def _on_session_offset_changed(self): session = self._on_session_offset_changed.subject self._show_controlled_tracks_message(session) def _show_controlled_tracks_message(self, session): """ Let the user know which range of tracks is in focus. """ start = session.track_offset() + 1 end = min(start + 8, len(session.tracks_to_use())) if start < end: self.show_message('Controlling Track %d to %d' % (start, end)) else: self.show_message('Controlling Track %d' % start) def _enable_components(self): with self.component_guard(): for component in self.components: component.set_enabled(True) self._suppress_session_highlight = False self.set_highlighting_session_component(self._session) def _on_identity_response(self, midi_bytes): super(MIDI_Mix, self)._on_identity_response(midi_bytes) self._enable_components() def _on_handshake_successful(self): self._suppress_session_highlight = False pass def _product_model_id_byte(self): return 49 def _send_dongle_challenge(self): pass def port_settings_changed(self): self.set_highlighting_session_component(None) super(MIDI_Mix, self).port_settings_changed() return def disconnect(self): self.set_highlighting_session_component(None) super(MIDI_Mix, self).disconnect() return
class Alias(ControlSurface): __module__ = __name__ __doc__ = " Alias 8 controller script " def __init__(self, c_instance): super(Alias, self).__init__(c_instance) with self.component_guard(): self._host_name = "Alias" self._color_type = "OhmRGB" self.log_message("--------------= Alias log opened =--------------") self._rgb = 0 self._timer = 0 self.flash_status = 1 self._clutch_device_selection = False self._touched = 0 self._update_linked_device_selection = None self._setup_monobridge() self._setup_controls() self._setup_m4l_interface() self._setup_mixer_control() self._setup_session_control() self._setup_mixer_nav() """script initialization methods""" def _setup_monobridge(self): self._monobridge = MonoBridgeElement(self) self._monobridge.name = "MonoBridge" def _setup_controls(self): is_momentary = True self._fader = [ MonoEncoderElement( MIDI_CC_TYPE, CHANNEL, ALIAS_FADERS[index], Live.MidiMap.MapMode.absolute, "Fader_" + str(index), index, self, ) for index in range(9) ] self._button = [ MonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, ALIAS_BUTTONS[index], "Button_" + str(index), self) for index in range(16) ] self._dial = [ MonoEncoderElement( MIDI_CC_TYPE, CHANNEL, ALIAS_DIALS[index], Live.MidiMap.MapMode.absolute, "Dial_" + str(index), index + 8, self, ) for index in range(16) ] self._encoder = MonoEncoderElement( MIDI_CC_TYPE, CHANNEL, ALIAS_ENCODER, Live.MidiMap.MapMode.absolute, "Encoder", 0, self ) def _setup_m4l_interface(self): self._m4l_interface = M4LInterfaceComponent(controls=self.controls, component_guard=self.component_guard) self.get_control_names = self._m4l_interface.get_control_names self.get_control = self._m4l_interface.get_control self.grab_control = self._m4l_interface.grab_control self.release_control = self._m4l_interface.release_control def _setup_mixer_control(self): is_momentary = True self._num_tracks = 8 # A mixer is one-dimensional; self._mixer = AliasMixerComponent(8, 0, False, False) self._mixer.name = "Mixer" self._mixer.set_track_offset(0) # Sets start point for mixer strip (offset from left) for index in range(8): self._mixer.channel_strip(index).set_volume_control(self._fader[index]) self._mixer.channel_strip(index).set_send_controls(tuple([self._dial[index], self._dial[index + 8]])) self._mixer.channel_strip(index).set_mute_button(self._button[index]) self._button[index].set_on_off_values(MUTE_TOG, 0) self._mixer.channel_strip(index)._invert_mute_feedback = True self._mixer.channel_strip(index).set_arm_button(self._button[index + 8]) self._button[index + 8].set_on_off_values(REC_TOG, 0) self._mixer.channel_strip(index).name = "Mixer_ChannelStrip_" + str(index) self._mixer.master_strip().set_volume_control(self._fader[8]) self.song().view.selected_track = self._mixer.channel_strip(0)._track def _setup_session_control(self): self._session = SessionComponent(8, 1) self._session.set_mixer(self._mixer) self.set_highlighting_session_component(self._session) def _setup_mixer_nav(self): if not self._encoder.value_has_listener(self._nav_change): self._encoder.add_value_listener(self._nav_change) """shift/zoom methods""" def _nav_change(self, value): self._session.set_offsets( int((float(value) / float(127)) * max(8, len(self._mixer.tracks_to_use()) - 8)), self._session._scene_offset ) """called on timer""" def update_display(self): ControlSurface.update_display(self) self._timer = (self._timer + 1) % 256 self.flash() def flash(self): if self.flash_status > 0: for control in self.controls: if isinstance(control, MonoButtonElement): control.flash(self._timer) """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 12 if not display_string: return " " * NUM_CHARS_PER_DISPLAY_STRIP if (len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and ( display_string.endswith("dB") and (display_string.find(".") != -1) ): display_string = display_string[:-2] if len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1): for um in [" ", "i", "o", "u", "e", "a"]: while (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1): um_pos = display_string.rfind(um, 1) display_string = display_string[:um_pos] + display_string[(um_pos + 1) :] else: display_string = display_string.center((NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u"" for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if (ord(display_string[i]) > 127) or (ord(display_string[i]) < 0): ret += " " else: ret += display_string[i] ret += " " ret = ret.replace(" ", "_") assert len(ret) == NUM_CHARS_PER_DISPLAY_STRIP return ret def notification_to_bridge(self, name, value, sender): if isinstance(sender, MonoEncoderElement): self._monobridge._send(sender.name, "lcd_name", str(self.generate_strip_string(name))) self._monobridge._send(sender.name, "lcd_value", str(self.generate_strip_string(value))) def touched(self): if self._touched is 0: self._monobridge._send("touch", "on") self.schedule_message(2, self.check_touch) self._touched += 1 def check_touch(self): if self._touched > 5: self._touched = 5 elif self._touched > 0: self._touched -= 1 if self._touched is 0: self._monobridge._send("touch", "off") else: self.schedule_message(2, self.check_touch) """general functionality""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates != 0)) def disconnect(self): if self._encoder.value_has_listener(self._nav_change): self._encoder.remove_value_listener(self._nav_change) self.log_message("--------------= Alias log closed =--------------") super(Alias, self).disconnect() rebuild_sys() def handle_sysex(self, midi_bytes): pass def device_follows_track(self, val): self._device_selection_follows_track_selection = val == 1 return self def assign_alternate_mappings(self): pass def _get_num_tracks(self): return self.num_tracks def _on_device_changed(self, device): # self.log_message('new device ' + str(type(device))) if self._update_linked_device_selection != None: self._update_linked_device_selection(device) def _on_session_offset_changes(self): if self._r_function_mode._mode_index in range(0, 3): self._mem[int(self._r_function_mode._mode_index)] = self._session2.track_offset() def connect_script_instances(self, instanciated_scripts): pass
class ControlMI(ControlSurface): __module__ = __name__ __doc__ = " ControlMI controller script" def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) self._suppress_session_highlight = True self._suppress_send_midi = True # Turn off rebuild MIDI map until after we're done setting up self.log("--------------= ControlMI log opened =--------------") with self.component_guard(): # OBJECTS self.session = None self.mixer = None self.view = None self.device = None self.transport = None # INITIALIZE MIXER, SESSIONS self._setup_session_control() # Setup the session object self._setup_mixer_control() # Setup the mixer object self.session.set_mixer(self.mixer) # Bind mixer to session self._setup_device_control() # Setup the device object self._setup_transport_control() # Setup transport object self._set_initial_mode() self.set_device_component( self.device) # Bind device to control surface- self.set_highlighting_session_component(self.session) for component in self.components: component.set_enabled(True) self._suppress_session_highlight = True self._suppress_send_midi = True # Turn rebuild back on, once we're done setting up def _setup_session_control(self): self.show_message( "#################### SESSION: ON ##############################") self.session = SessionComponent(num_tracks, num_scenes) self.session.set_offsets(0, 0) self.session.set_track_bank_buttons( ButtonElement(False, MIDI_CC_TYPE, data_channel, session_right), ButtonElement(False, MIDI_CC_TYPE, data_channel, session_left)) def _setup_mixer_control(self): self.mixer = MixerComponent(num_tracks, 0, False, False) self.mixer.name = 'Mixer' self.mixer.set_track_offset(0) def _setup_device_control(self): self.device = DeviceComponent() self.device.name = 'Device_Component' def _setup_transport_control(self): self.transport = TransportComponent(self) def _clear_controls(self): self.mixer._set_send_nav(None, None) for track_index in range(num_tracks): strip = self.mixer.channel_strip(track_index) strip.set_solo_button(None) strip.set_mute_button(None) strip.set_arm_button(None) strip.set_select_button(None) # TRANSPORT self.transport.set_stop_button(None) self.transport.set_play_button(None) self.transport.set_record_button(None) self.log_message("Controls Cleared") def _set_initial_mode(self): is_momentary = True ### MIXER for index in range(num_tracks): strip = self.mixer.channel_strip(index) strip.name = 'Mixer_ChannelStrip_' + str(index) strip.set_volume_control( SliderElement(MIDI_CC_TYPE, data_channel, mixer_volume_cc[index])) strip._invert_mute_feedback = True self.mixer.master_strip().set_volume_control( SliderElement(MIDI_CC_TYPE, data_channel, mixer_master_cc)) self.transport.set_stop_button( ButtonElement(False, MIDI_CC_TYPE, data_channel, transport_stop_cc)) self.transport.set_play_button( ButtonElement(False, MIDI_CC_TYPE, data_channel, transport_play_cc)) self.transport.set_record_button( ButtonElement(False, MIDI_CC_TYPE, data_channel, transport_record_cc)) self.log("color: " + str(self.session.tracks_to_use()[0].color)) self.log("color: " + str(self.session.tracks_to_use()[1].color)) self.log("color: " + str(self.session.tracks_to_use()[2].color)) self.log("color: " + str(self.session.tracks_to_use()[3].color)) self._send_midi([0x09, 0x09, 0x09, 0x09]) def disconnect(self): """clean things up on disconnect""" self.log("--------------= ControlMI log closed =--------------") self._clear_controls() self.session = None self.mixer = None self.view = None self.device = None self.transport = None self.set_device_component(None) ControlSurface.disconnect(self) return None def log(self, message): self.log_message( time.strftime("%d.%m.%Y %H:%M:%S", time.localtime()) + message)
class NanoKontrolShift(ControlSurface): __module__ = __name__ __doc__ = " NanoKontrolShift controller script " def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) self._suppress_session_highlight = True self._suppress_send_midi = True # Turn off rebuild MIDI map until after we're done setting up self.log_message(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime()) + "--------------= NanoKontrolShift log opened =--------------") # Writes message into Live's main log file. This is a ControlSurface method. with self.component_guard(): # OBJECTS self.session = None #session object self.mixer = None #mixer object self.view = None #clip/device view object self.device = None #device object self.transport = None #transport object # MODES self._shift_button = None self._shift_button_pressed = False self._alt_button = None self._alt_button_pressed = False self._ctrl_button = None self._ctrl_button_pressed = False # INITIALIZE MIXER, SESSIONS self._setup_session_control() # Setup the session object self._setup_mixer_control() # Setup the mixer object self._setup_view_control() # Setup the clip/view toggler self.session.set_mixer(self.mixer) # Bind mixer to session self._setup_device_control() # Setup the device object self._setup_transport_control() # Setup transport object self.set_device_component(self.device) # Bind device to control surface # SET INITIAL SESSION/MIXER AND MODIFIERS BUTTONS self._set_modifiers_buttons() self.__update_matrix() # self.set_highlighting_session_component(self.session) for component in self.components: component.set_enabled(True) # self._suppress_session_highlight = True self._suppress_send_midi = True # Turn rebuild back on, once we're done setting up def _setup_session_control(self): self.show_message("#################### SESSION: ON ##############################") is_momentary = True # CREATE SESSION, SET OFFSETS, BUTTONS NAVIGATION AND BUTTON MATRIX self.session = SessionComponent(num_tracks, num_scenes) #(num_tracks, num_scenes) self.session.set_offsets(0, 0) # self.session.set_scene_bank_buttons(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, session_down), ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, session_up)) # self.session.set_track_bank_buttons(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, session_right), ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, session_left)) # (right_button, left_button) This moves the "red box" selection set left & right. We'll use the mixer track selection instead... def _setup_mixer_control(self): is_momentary = True #CREATE MIXER, SET OFFSET (SPECIALMIXERCOMPONENT USES SPECIALCHANNELSTRIP THAT ALLOWS US TO UNFOLD TRACKS WITH TRACK SELECT BUTTON) self.mixer = SpecialMixerComponent(num_tracks, 0, False, False) # 4 tracks, 2 returns, no EQ, no filters self.mixer.name = 'Mixer' self.mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) def _setup_view_control(self): # CREATES OBJECT SO WE CAN TOGGLE DEVICE/CLIP, LOCK DEVICE self.view = ViewTogglerComponent(num_tracks, self) def _setup_device_control(self): # CREATE DEVICE TO ASSIGN PARAMETERS BANK self.device = DeviceComponent() self.device.name = 'Device_Component' def _setup_transport_control(self): # CREATE TRANSPORT DEVICE self.transport = SpecialTransportComponent(self) def _on_selected_scene_changed(self): # ALLOWS TO GRAB THE FIRST DEVICE OF A SELECTED TRACK IF THERE'S ANY ControlSurface._on_selected_track_changed(self) track = self.song().view.selected_track if (track.devices is not None): self._ignore_track_selection = True device_to_select = track.devices[0] self.song().view.select_device(device_to_select) self._device_component.set_device(device_to_select) self._ignore_track_selection = False """ LED ON, OFF, FLASH WITH SESSION CLIPS """ # UPDATING BUTTONS FROM CLIP MATRIX IN NK AS SESSION MOVES def __update_matrix(self): for scene_index in range(num_scenes): scene = self.session.scene(scene_index) for track_index in range(num_tracks): clip_slot = scene.clip_slot(track_index) button = clip_slot._launch_button_value.subject value_to_send = -1 if clip_slot._clip_slot != None: if clip_slot.has_clip(): value_to_send = 127 if clip_slot._clip_slot.clip.is_triggered: if clip_slot._clip_slot.clip.will_record_on_start: value_to_send = clip_slot._triggered_to_record_value else: value_to_send = clip_slot._triggered_to_play_value ''' elif clip_slot._clip_slot.clip.is_playing: if clip_slot._clip_slot.clip.is_recording: value_to_send = 127 ######### CLIPS PLAYING WILL FLASH for i in range(2000): if i % 50 == 0: button.send_value(127) else: button.send_value(0) else: for i in range(2000): if i % 50 == 0: button.send_value(127) else: button.send_value(0) ''' elif clip_slot._clip_slot.is_triggered: if clip_slot._clip_slot.will_record_on_start: value_to_send = clip_slot._triggered_to_record_value else: value_to_send = clip_slot._triggered_to_play_value elif clip_slot._clip_slot.is_playing: if clip_slot._clip_slot.is_recording: value_to_send = clip_slot._recording_value else: value_to_send = clip_slot._started_value elif clip_slot._clip_slot.controls_other_clips: value_to_send = 0 ''' if value_to_send in range(128): button.send_value(value_to_send) else: button.turn_off() ''' """ MODIFIERS, MODES, KEYS CONFIG """ #MODES ARE HERE: INITIALIZATIONS, DISCONNECTS BUTTONS, SLIDERS, ENCODERS def _clear_controls(self): # TURNING OFF ALL LEDS IN MATRIX self._turn_off_matrix() # SESSION resetsend_controls = [] self.mixer.send_controls = [] for scene_index in range(num_scenes): scene = self.session.scene(scene_index) scene.set_launch_button(None) for track_index in range(num_tracks): clip_slot = scene.clip_slot(track_index) clip_slot.set_launch_button(None) self.session.set_stop_track_clip_buttons(None) self.session.set_stop_all_clips_button(None) # REMOVE LISTENER TO SESSION MOVES if self.session.offset_has_listener(self.__update_matrix): self.session.remove_offset_listener(self.__update_matrix) self.session.set_stop_all_clips_button(None) # MIXER self.mixer._set_send_nav(None, None) for track_index in range(num_tracks): strip = self.mixer.channel_strip(track_index) strip.set_solo_button(None) strip.set_mute_button(None) strip.set_arm_button(None) resetsend_controls.append(None) strip.set_select_button(None) for i in range(12): self.mixer.send_controls.append(None) strip.set_send_controls(tuple(self.mixer.send_controls)) self.mixer.set_resetsend_buttons(tuple(resetsend_controls)) # VIEW self.view.set_device_nav_buttons(None, None) detailclip_view_controls = [] for track_index in range(num_tracks): detailclip_view_controls.append(None) self.view.set_buttons(tuple(detailclip_view_controls)) # DEVICE PARAMETERS device_param_controls = [] self.device.set_parameter_controls(tuple(device_param_controls)) self.device.set_on_off_button(None) self.device.set_lock_button(None) # TRANSPORT self.transport.set_stop_button(None) self.transport.set_play_button(None) self.transport.set_record_button(None) self.transport._set_quant_toggle_button(None) self.transport.set_metronome_button(None) self.transport._set_tempo_buttons(None, None) self.log_message("Controls Cleared") def _set_normal_mode(self): is_momentary = True self.mixer._set_send_nav(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, send_up), ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, send_down)) for index in range(num_tracks): strip = self.mixer.channel_strip(index) strip.name = 'Mixer_ChannelStrip_' + str(index) self.mixer._update_send_index(self.mixer.sends_index) strip.set_volume_control(SliderElement(MIDI_CC_TYPE, CHANNEL, mixer_volumefader_cc[index])) self.mixer.send_controls[self.mixer.sends_index] = EncoderElement(MIDI_CC_TYPE, CHANNEL, mixer_sendknob_cc[index], Live.MidiMap.MapMode.absolute) strip.set_send_controls(tuple(self.mixer.send_controls)) strip._invert_mute_feedback = True ### SET ARM, SOLO, MUTE for index in range(num_tracks): strip = self.mixer.channel_strip(index) strip.set_send_controls(tuple(self.mixer.send_controls)) strip.set_solo_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, track_solo_cc[index])) strip.set_mute_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, track_mute_cc[index])) strip.set_arm_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, track_arm_cc[index])) # self.transport.set_stop_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, transport_stop_cc)) for i in range(12): self.mixer.send_controls.append(None) self.mixer.send_controls[self.mixer.sends_index] = EncoderElement(MIDI_CC_TYPE, CHANNEL, mixer_sendknob_cc[index], Live.MidiMap.MapMode.absolute) strip.set_send_controls(tuple(self.mixer.send_controls)) strip._invert_mute_feedback = True self.mixer._update_send_index(self.mixer.sends_index) def _set_alt_mode(self): is_momentary = True self.mixer._set_send_nav(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, send_up), ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, send_down)) stop_track_controls = [] resetsend_controls = [] button = None buttons = None # SET SESSION TRACKSTOP, TRACK SELECT, RESET SEND KNOB for index in range(num_tracks): strip = self.mixer.channel_strip(index) strip.set_select_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, track_select_cc[index])) button = ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, stop_track_cc[index]) stop_track_controls.append(button) buttons = ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, track_resetsend_cc[index]) resetsend_controls.append(buttons) self.session.set_stop_track_clip_buttons(tuple(stop_track_controls)) self.mixer.set_resetsend_buttons(tuple(resetsend_controls)) self.mixer._update_send_index(self.mixer.sends_index) def _set_ctrl_mode(self): # CLIP/DEVICE VIEW TOGGLE is_momentary = True self.view.set_device_nav_buttons(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, device_left_cc), ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, device_right_cc)) button = None detailclip_view_controls = [] for index in range(num_tracks): button = ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, detailclip_view_cc[index]) detailclip_view_controls.append(button) self.view.set_buttons(tuple(detailclip_view_controls)) # DEVICE ON/OFF, LOCK AND PARAMETERS device_param_controls = [] onoff_control = ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, onoff_device_cc) setlock_control = ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, lock_device_cc) for index in range(num_tracks): knob = None knob = EncoderElement(MIDI_CC_TYPE, CHANNEL, device_param_cc[index], Live.MidiMap.MapMode.absolute) device_param_controls.append(knob) if None not in device_param_controls: self.device.set_parameter_controls(tuple(device_param_controls)) self.device.set_on_off_button(onoff_control) self.device.set_lock_button(setlock_control) # TRANSPORT # self.transport.set_stop_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, transport_stop_cc)) # self.transport.set_play_button(ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, transport_play_cc)) # self.transport.set_record_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, transport_record_cc)) self.transport._set_quant_toggle_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, transport_quantization_cc)) self.transport.set_metronome_button(ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, transport_metronome_cc)) self.transport._set_tempo_buttons(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, transport_tempodown_cc), ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, transport_tempoup_cc)) # SESSION STOP ALL CLIPS AND SCENE LAUNCH self.session.set_stop_all_clips_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, session_stopall_cc)) for index in range(num_scenes): self.session.scene(index).set_launch_button(ButtonElement(is_momentary, MIDI_CC_TYPE, CHANNEL, session_scenelaunch_cc[index])) def _set_modifiers_buttons(self): is_momentary = True self._shift_button = ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, shift_mod) self._alt_button = ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, alt_mod) self._ctrl_button = ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, ctrl_mod) if (self._shift_button != None): self._shift_button.add_value_listener(self._shift_value) if (self._alt_button != None): self._alt_button.add_value_listener(self._alt_value) if (self._ctrl_button != None): self._ctrl_button.add_value_listener(self._ctrl_value) #INIT NORMAL MODE self._manage_modes(0) # MODIFIERS LISTENERS FUNCS ARE HERE def _shift_value(self, value): assert isinstance(value, int) assert isinstance(self._shift_button, ButtonElement) if value == 127: if self._shift_button_pressed is False: self._unpress_modes() self._shift_button_pressed = True self._manage_modes(0) def _alt_value(self, value): assert isinstance(value, int) assert isinstance(self._alt_button, ButtonElement) if value == 127: if self._alt_button_pressed is False: self._unpress_modes() self._alt_button_pressed = True self._manage_modes(2) def _ctrl_value(self, value): assert isinstance(value, int) assert isinstance(self._ctrl_button, ButtonElement) if value == 127: if self._ctrl_button_pressed is False: self._unpress_modes() self._ctrl_button_pressed = True self._manage_modes(3) def _manage_modes(self, mode_index): if mode_index == 0: self._clear_controls() self._set_normal_mode() # self._shift_button.turn_on() self._alt_button.turn_on() self._ctrl_button.turn_on() self.log_message("NORMAL ON") elif mode_index == 2: self._clear_controls() self._set_alt_mode() self._alt_button.turn_on() self._shift_button.turn_off() self._ctrl_button.turn_off() self.log_message("ALT ON") elif mode_index == 3: self._clear_controls() self._set_ctrl_mode() self._ctrl_button.turn_on() self._shift_button.turn_off() self._alt_button.turn_off() self.log_message("CTRL ON") def _unpress_modes(self): self._shift_button_pressed = False self._alt_button_pressed = False self._ctrl_button_pressed = False def _turn_off_matrix(self): for index in range(24): self._send_midi(tuple([176,index+16,0])) def disconnect(self): """clean things up on disconnect""" self.log_message(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime()) + "--------------= NanoKontrolShift log closed =--------------") #Create entry in log file self._clear_controls() self.session = None self.mixer = None self.view = None self.device = None self.transport = None # MODES self._shift_button = None self._alt_button = None self._ctrl_button = None # SENDS self.send_button_up = None self.send_button_down = None self.send_controls = [] self.send_reset = [] self.set_device_component(None) ControlSurface.disconnect(self) return None
class Codec(ControlSurface): __module__ = __name__ __doc__ = " MonoCode controller script " def __init__(self, c_instance): """everything except the '_on_selected_track_CHANNELged' override and 'disconnect' runs from here""" ControlSurface.__init__(self, c_instance) self.set_suppress_rebuild_requests( True ) # Turn off rebuild MIDI map until after we're done setting up self._monomod_version = 'b995' self._version_check = 'b995' self._host_name = 'Codec' self._color_type = 'Monochrome' self._link_mixer = LINK_MIXER self.log_message('<<<<<<<<<<<<<<<<<<<<<<<<< Codec ' + str(self._monomod_version) + ' log opened >>>>>>>>>>>>>>>>>>>>>>>>>') self._hosts = [] self._linked_script = None self._local_ring_control = True self.set_local_ring_control(1) self._setup_controls() self._last_device = None self._device_list = [None, None, None, None] self._device_select_buttons = None self._last_device_component = None self._timer = 0 self._touched = 0 self._locked = False self.flash_status = 1 self._shift_button = None self._shift_pressed = 0 self._shift_pressed_timer = 0 self._shift_thresh = SHIFT_THRESH self._use_device_selector = USE_DEVICE_SELECTOR self._device_selection_follows_track_selection = FOLLOW self.set_suppress_rebuild_requests( False) #Turn rebuild back on, now that we're done setting up self.song().view.add_selected_track_listener( self._update_selected_device) self.show_message('Codec Control Surface Loaded') #self.local_ring_control(True) #self.set_absolute_mode(True) self._setup_monobridge() self._setup_device_controls() self._setup_special_device_control() self._device.append( self._special_device ) #necessary for device browsing to work with special device self._setup_device_chooser() self._setup_mixer_controls() self._setup_monomod() self._setup_modes() self._setup_device_selector() self._setup_send_reset() self._setup_default_buttons() self._initialize_code() self.request_rebuild_midi_map() #Monomodular.create_instance(c_instance) #self._setup_disconnect() """script initialization methods""" def _initialize_code(self): self._send_midi(factoryreset) self._send_midi(btn_channels) self._send_midi(enc_channels) #pass def _setup_monobridge(self): self._monobridge = MonoBridgeElement(self) self._monobridge.name = 'MonoBridge' def _setup_controls(self): is_momentary = True self._livid = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, LIVID, 'Livid_Button', self) self._dial = [None for index in range(8)] for column in range(8): self._dial[column] = [None for index in range(4)] for row in range(4): self._dial[column][row] = CodecEncoderElement( MIDI_CC_TYPE, CHANNEL, CODE_DIALS[row][column], Live.MidiMap.MapMode.absolute, 'Dial_' + str(column) + '_' + str(row), (column + (row * 8)), self) #CODE_DIALS[row][column] self._button = [None for index in range(8)] for column in range(8): self._button[column] = [None for index in range(4)] for row in range(4): self._button[column][row] = FlashingButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, CODE_BUTTONS[row][column], 'Button_' + str(column) + '_' + str(row), self) self._column_button = [None for index in range(8)] for index in range(8): self._column_button[index] = FlashingButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, CODE_COLUMN_BUTTONS[index], 'Column_Button_' + str(index), self) self._row_button = [None for index in range(4)] for index in range(4): self._row_button[index] = FlashingButtonElement( is_momentary, MIDI_NOTE_TYPE, CHANNEL, CODE_ROW_BUTTONS[index], 'Row_Button_' + str(index), self) self._dial_matrix = EncoderMatrixElement(self) self._dial_matrix.name = 'Encoder_Matrix' for row in range(4): dial_row = tuple([self._dial[column][row] for column in range(8)]) self._dial_matrix.add_row(dial_row) self._button_matrix = ButtonMatrixElement() self._button_matrix.name = 'Button_Matrix' for row in range(4): button_row = [self._button[column][row] for column in range(8)] button_row.append(self._row_button[row]) self._button_matrix.add_row(tuple(button_row)) self._button_matrix.add_row(tuple(self._column_button + [self._livid])) def _setup_modes(self): self._monomod_mode = MonomodModeComponent(self) self._monomod_mode.name = 'Monomod_Mode' self._monomod_mode.update = self._mod_mode_update #self._monomod_mode.set_mode_toggle(self._livid) self.set_shift_button(self._livid) self._shift_mode = ShiftModeComponent(self, self._shift_update) self._shift_mode.name = 'Shift_Mode' self._shift_mode.set_mode_buttons( tuple([ self._row_button[0], self._row_button[1], self._row_button[2], self._row_button[3] ])) def _setup_transport_control(self): self._transport = TransportComponent() self._transport.name = 'Transport' def _setup_monomod(self): self._host = MonomodComponent(self) self._host.name = 'Monomod_Host' self._host._set_dial_matrix(self._dial_matrix, self._button_matrix) self.hosts = [self._host] encs = [] for row in range(4): for col in range(8): encs.append(self._dial[col][row]) self._host._set_parameter_controls(encs) def _setup_mixer_controls(self): is_momentary = True self._num_tracks = (8) self._session = SessionComponent(self._num_tracks, 0) self._session.name = 'Session' self._mixer = MixerComponent(self._num_tracks, 0, False, False) self._mixer.name = 'Mixer' self._mixer._next_track_value = self._mixer_next_track_value( self._mixer) self._mixer._prev_track_value = self._mixer_prev_track_value( self._mixer) self._mixer.set_track_offset( 0) #Sets start point for mixer strip (offset from left) #for index in range(8): #use the bottom row of encoders for volume, so add 24 to offset the index # self._mixer.channel_strip(index).set_volume_control(self._dial[index+24]) for index in range(8): self._mixer.channel_strip( index).name = 'Mixer_ChannelStrip_' + str(index) self._mixer.channel_strip(index)._invert_mute_feedback = True self._mixer.channel_strip( index)._mute_value = self._channelstrip_mute_value( self._mixer.channel_strip(index)) self._mixer.channel_strip( index)._solo_value = self._channelstrip_solo_value( self._mixer.channel_strip(index)) #mixer.channel_strip(index).set_select_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CH, track_select_notes[index])) self.song().view.selected_track = self._mixer.channel_strip( 0 )._track #set the selected strip to the first track, so that we don't, for example, try to assign a button to arm the master track, which would cause an assertion error self._session.set_mixer(self._mixer) def _setup_device_controls(self): self._device = [None for index in range(4)] for index in range(4): self._device[index] = CodecDeviceComponent(self) self._device[index].name = 'CodecDevice_Component_' + str(index) device_param_controls = [] for control in range(8): device_param_controls.append(self._dial[control][index]) self._device[index].set_on_off_button(self._button[1][index]) self._device[index].set_lock_button(self._button[2][index]) self._device[index].set_bank_nav_buttons(self._button[4][index], self._button[5][index]) self._device[index].set_nav_buttons(self._button[6][index], self._button[7][index]) self._device[index].set_parameter_controls( tuple(device_param_controls)) self.set_device_component(self._device[0]) self._last_device_component = self._device[0] def _setup_special_device_control(self): self._special_device = SpecialCodecDeviceComponent(self) self._special_device.name = 'SpecialCodecDeviceComponent' self._special_device.set_on_off_button(self._button[1][0]) self._special_device.set_lock_button(self._button[2][0]) self._special_device.set_bank_nav_buttons(self._button[4][0], self._button[5][0]) self._special_device.set_nav_buttons(self._button[6][0], self._button[7][0]) device_param_controls = [] for row in range(4): for column in range(8): device_param_controls.append(self._dial[column][row]) self._special_device.set_parameter_controls( tuple(device_param_controls)) def _setup_device_chooser(self): self._selected_device = self._device[0] self._last_selected_device = self._device[0] self._device_select_buttons = [ self._button[0][index] for index in range(4) ] for button in self._device_select_buttons: button.add_value_listener(self._device_select_value, True) def _setup_device_selector(self): self._device_selector = CodecDeviceSelectorComponent( self, 'c', self._device + [self._special_device]) self._device_selector.name = 'Device_Selector' self._device_selector.set_mode_buttons(self._column_button) #self._device_selector.set_mode_toggle(self._livid) def _setup_send_reset(self): self._send_reset = CodecResetSendsComponent(self) self._send_reset.set_buttons(self._button) def _setup_default_buttons(self): self._value_default = ParameterDefaultComponent(self) buttons = [] dials = [] for column in self._button: for button in column: buttons.append(button) for column in self._dial: for dial in column: dials.append(dial) self._value_default.set_buttons(buttons) self._value_default.set_dials(dials) """multiple device support""" def _device_select_value(self, value, sender): #self.log_message('device_select_value ' + str(value) + ' ' + str(self._device_select_buttons.index(sender))) if not self._shift_pressed: if sender.is_momentary or value > 0: if self._shift_mode._mode_index == 2: self.set_device_component(self._device[ self._device_select_buttons.index(sender)]) self._last_device_component = self._device_component if self._device_component != None and isinstance( self._device_component._device, Live.Device.Device): if self._device_component.find_track( self._device_component._device) == self.song( ).view.selected_track: self._device_component.display_device() """livid double press mechanism""" def set_shift_button(self, button): assert ((button == None) or (isinstance(button, FlashingButtonElement))) if self._shift_button != None: self._shift_button.remove_value_listener(self._shift_value) self._shift_button = button if self._shift_button != None: self._shift_button.add_value_listener(self._shift_value) def _shift_value(self, value): self._shift_pressed = int(value != 0) if self._shift_pressed > 0: self._send_midi(SLOWENCODER) if (self._shift_pressed_timer + self._shift_thresh) > self._timer: #if(self._host.is_enabled() != True) self._monomod_mode.set_mode( abs(self._monomod_mode._mode_index - 1)) #else: # self._monomod_mode.set_mode(0) self._shift_pressed_timer = self._timer % 256 else: self._send_midi(NORMALENCODER) def _mod_mode_update(self): if (self._monomod_mode._mode_index == 0): self._host._set_shift_button(None) self._host.set_enabled(False) self._dial_matrix.reset() self._shift_mode.set_enabled(True) self._shift_update() self.request_rebuild_midi_map() self._livid.turn_off() elif (self._monomod_mode._mode_index == 1): self._shift_mode.set_enabled(False) self._deassign_all() self._dial_matrix.reset() self._button_matrix.reset() self._livid.turn_on() if not self._host._active_client == None: self._host.set_enabled(True) self._host._set_shift_button(self._livid) else: self._assign_alternate_mappings(1) self.request_rebuild_midi_map() """Mode Functions""" def _shift_update(self): if (self._shift_mode.is_enabled()): self.allow_updates(False) if (not self._in_build_midi_map): self.set_suppress_rebuild_requests(True) self._deassign_all() if (self._shift_mode._mode_index is 0): self._assign_volume() elif (self._shift_mode._mode_index is 1): self._assign_sends() elif (self._shift_mode._mode_index is 2): self._assign_devices() elif (self._shift_mode._mode_index is 3): self._assign_special_device() for index in range(self._shift_mode.number_of_modes()): if index == self._shift_mode._mode_index: self._shift_mode._modes_buttons[index].turn_on() else: self._shift_mode._modes_buttons[index].turn_off() self.allow_updates(True) self.set_suppress_rebuild_requests(False) self.request_rebuild_midi_map() def _deassign_all(self): self._assign_alternate_mappings(0) self._device_selector.set_enabled(False) for index in range(8): self._mixer.channel_strip(index).set_volume_control(None) self._mixer.channel_strip(index).set_pan_control(None) self._mixer.channel_strip(index).set_send_controls( tuple([None, None, None, None])) for index in range(4): self._device[index].set_enabled(False) self._device[index]._parameter_controls = None #self._device_navigator[index].set_enabled(False) self._special_device.set_enabled(False) self._special_device._parameter_controls = None self._device_selector.set_enabled(False) self._deassign_buttons() for control in self.controls: control.reset() self.request_rebuild_midi_map() def _deassign_buttons(self): for index in range(8): self._mixer.channel_strip(index).set_select_button(None) self._mixer.channel_strip(index).set_solo_button(None) self._mixer.channel_strip(index).set_mute_button(None) self._mixer.set_select_buttons(None, None) self._send_reset.set_enabled(False) def _assign_volume(self): for index in range(8): self._mixer.channel_strip(index).set_volume_control( self._dial[index][3]) self._mixer.channel_strip(index).set_pan_control( self._dial[index][2]) self._mixer.channel_strip(index).set_send_controls( tuple([self._dial[index][0], self._dial[index][1]])) self._mixer.channel_strip(index).set_select_button( self._column_button[index]) self._mixer.channel_strip(index).set_solo_button( self._button[index][2]) self._mixer.channel_strip(index).set_mute_button( self._button[index][3]) self._mixer.set_select_buttons(self._button[7][0], self._button[6][0]) def _assign_sends(self): for index in range(8): self._mixer.channel_strip(index).set_send_controls( tuple([ self._dial[index][0], self._dial[index][1], self._dial[index][2], self._dial[index][3] ])) self._mixer.channel_strip(index).set_select_button( self._column_button[index]) self._send_reset.set_enabled(True) def _assign_devices(self): self.set_device_component(self._last_device_component) self._device_select_value( 1, self._device_select_buttons[self._device.index( self._device_component)]) for index in range(4): device_param_controls = [] for control in range(8): device_param_controls.append(self._dial[control][index]) self._device[index].set_parameter_controls( tuple(device_param_controls)) self._device[index].set_enabled(True) self._device_selector.set_enabled(self._use_device_selector) if not self._use_device_selector: for index in range(8): self._mixer.channel_strip(index).set_select_button( self._column_button[index]) def _assign_special_device(self): self.set_device_component(self._special_device) device_param_controls = [] for row in range(4): for column in range(8): device_param_controls.append(self._dial[column][row]) self._special_device.set_parameter_controls( tuple(device_param_controls)) self._special_device.set_enabled(True) self._device_selector.set_enabled(self._use_device_selector) if not self._use_device_selector: for index in range(8): self._mixer.channel_strip(index).set_select_button( self._column_button[index]) def _assign_alternate_mappings(self, chan): for column in self._dial: for control in column: control.set_channel(chan) control.set_enabled(chan is 0) for column in self._button: for control in column: control.set_channel(chan) control.set_enabled(chan is 0) for control in self._column_button: control.set_channel(chan) control.set_enabled(chan is 0) for control in self._row_button: control.set_channel(chan) control.set_enabled(chan is 0) """general functionality""" def disconnect(self): """clean things up on disconnect""" if not self._shift_button is None: if self._shift_button.value_has_listener(self._shift_value): self._shift_button.remove_value_listener(self._shift_value) for button in self._device_select_buttons: if button.value_has_listener(self._device_select_value): button.remove_value_listener(self._device_select_value) if self._session._is_linked(): self._session._unlink() self.song().view.remove_selected_track_listener( self._update_selected_device) """for cs in self._control_surfaces(): for host in self._hosts: self.log_message('installed: ' + str(cs) + ' vs. ' + str(host)) if str(type(cs)) == str(type(host)): self.log_message('disconnecting: ' + str(type(cs))) cs.disconnect(cs)""" #self._host._set_parameter_controls(None) self._hosts = [] if self._linked_script != None: self._linked_script._update_linked_device_selection = None self._linked_script = None #self._disconnect_notifier.set_mode(0) self.log_message( '<<<<<<<<<<<<<<<<<<<<<<<<< Codec log closed >>>>>>>>>>>>>>>>>>>>>>>>>' ) ControlSurface.disconnect(self) return None def connect_script_instances(self, instanciated_scripts): found = False for s in instanciated_scripts: if '_codec_version' in dir(s): if s._codec_version == self._version_check: if s._host_name == ('MonOhm'): self.log_message('found codec version ' + str(s._codec_version) + ' in script ' + str(s._host_name)) found = True self._linked_script = s self._linked_script._update_linked_device_selection = self._update_linked_device_selection if not self._session._is_linked( ) and self._link_mixer is True: self._session.set_offsets(LINK_OFFSET[0], LINK_OFFSET[1]) self._session._link() else: self.log_message('version mismatch: Monomod version ' + str(self._version_check) + ' vs. Host version ' + str(s._codec_version)) if found == False: for s in instanciated_scripts: if '_codec_version' in dir(s): if s._codec_version == self._version_check: if s._host_name == 'BlockMod': self.log_message('found codec version ' + str(s._codec_version) + ' in script ' + str(s._host_name)) self._linked_script = s self._linked_script._update_linked_device_selection = self._update_linked_device_selection if not self._session._is_linked( ) and self._link_mixer is True: self._session.set_offsets(LINK_OFFSET[0], LINK_OFFSET[1]) self._session._link() else: self.log_message('version mismatch: Monomod version ' + str(self._version_check) + ' vs. Host version ' + str(s._codec_version)) #self.log_message('hosts: ' + str(self._hosts))""" def update_display(self): ControlSurface.update_display( self ) #since we are overriding this from the inherited method, we need to call the original routine as well self._timer = (self._timer + 1) % 256 if (self._timer == 0): self._shift_pressed_timer = -12 if (self._local_ring_control is False): self.send_ring_leds() self.flash() def handle_sysex(self, midi_bytes): #self._send_midi(tuple([240, 00, 01, 97, 04, 15, 01, 247])) #response = [long(0),long(0)] #self.log_message(response) pass def flash(self): if (self.flash_status > 0): for control in self.controls: if isinstance(control, FlashingButtonElement): control.flash(self._timer) def send_ring_leds(self): leds = [240, 0, 1, 97, 4, 31] for column in range(8): for row in range(4): wheel = self._dial[column][row] bytes = wheel._get_ring() leds.append(bytes[0]) leds.append(int(bytes[1]) + int(bytes[2])) #if(row == 1 and column == 0): # self.log_message(str(leds) + ' ' + str(bytes[0]) + ' ' + str(bytes[1]) + ' ' + str(bytes[2])) leds.append(247) self._send_midi(tuple(leds)) def set_absolute_mode(self, val=1): self._absolute_mode = (val != 0) if self._absolute_mode is True: self._send_midi( tuple([240, 0, 1, 97, 4, 17, 0, 0, 0, 0, 0, 0, 0, 0, 247])) else: self._send_midi( tuple([ 240, 0, 1, 97, 4, 17, 127, 127, 127, 127, 127, 127, 127, 127, 247 ])) def set_local_ring_control(self, val=1): self._local_ring_control = (val != 0) if (self._local_ring_control is True): #self._send_midi(tuple([240, 0, 1, 97, 4, 32, 0, 247])) self._send_midi(tuple([240, 0, 1, 97, 4, 8, 72, 247])) else: #self._send_midi(tuple([240, 0, 1, 97, 4, 32, 1, 247])) self._send_midi(tuple([240, 0, 1, 97, 4, 8, 64, 247])) def device_follows_track(self, val): self._device_selection_follows_track_selection = (val == 1) return self """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 12 if (not display_string): return (' ' * NUM_CHARS_PER_DISPLAY_STRIP) if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center( (NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP) return ret def notification_to_bridge(self, name, value, sender): if (isinstance(sender, CodecEncoderElement)): self._monobridge._send(sender.name, 'lcd_name', str(self.generate_strip_string(name))) self._monobridge._send(sender.name, 'lcd_value', str(self.generate_strip_string(value))) def touched(self): if not self._host.is_enabled(): if self._touched is 0: self._monobridge._send('touch', 'on') self.schedule_message(2, self.check_touch) self._touched += 1 def check_touch(self): if self._touched > 5: self._touched = 5 elif self._touched > 0: self._touched -= 1 if self._touched is 0: self._monobridge._send('touch', 'off') else: self.schedule_message(2, self.check_touch) def get_clip_names(self): clip_names = [] for scene in self._session._scenes: for clip_slot in scene._clip_slots: if clip_slot.has_clip() is True: clip_names.append(clip_slot._clip_slot) ##.clip.name) return clip_slot._clip_slot ##self.log_message(str(clip_slot._clip_slot.clip.name)) return clip_names """overrides""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates != 0)) def set_device_component(self, device_component): if self._device_component != None: self._device_component._lock_callback = None assert (device_component != None) assert isinstance(device_component, DeviceComponent) self._device_component = device_component self._device_component._lock_callback = self._toggle_lock #old: self._device_component.set_lock_callback(self._toggle_lock) if self._device_select_buttons != None: for button in self._device_select_buttons: button.send_value( self._device_select_buttons.index(button) == self._device.index(self._device_component)) self._update_device_selection() return None def _update_selected_device(self): if self._device_selection_follows_track_selection is True: self._update_device_selection() return None def _update_linked_device_selection(self, device): #self.log_message('codec received ' + str(device.name)) if self._device_component != None and device != None: if not self._device_component.is_locked(): self._device_component.set_device(device) def _get_num_tracks(self): return self.num_tracks def _update_device_selection(self): #new method: code to verify #self.log_message('_update_device_selection') if self._device_component != None: if not self._device_component.is_locked(): track = self.song().view.selected_track device_to_select = track.view.selected_device if ((device_to_select == None) and (len(track.devices) > 0)): device_to_select = track.devices[0] if (device_to_select != None): self.song().view.select_device(device_to_select) self._device_component.set_device(device_to_select) def _channelstrip_mute_value(self, channelstrip): def _mute_value(value): if not self._shift_pressed: self.log_message('shift not pressed') ChannelStripComponent._mute_value(channelstrip, value) return _mute_value def _channelstrip_solo_value(self, channelstrip): def _solo_value(value): if not self._shift_pressed: ChannelStripComponent._solo_value(channelstrip, value) return _solo_value def _mixer_next_track_value(self, mixer): def _next_track_value(value): if not self._shift_pressed: MixerComponent._next_track_value(mixer, value) return _next_track_value def _mixer_prev_track_value(self, mixer): def _prev_track_value(value): if not self._shift_pressed: MixerComponent._prev_track_value(mixer, value) return _prev_track_value
class Novation_Impulse2(ControlSurface): """ Script for Novation's Impulse keyboards """ def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) self.c_instance = c_instance with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._device_selection_follows_track_selection = True self._suggested_input_port = 'Impulse' self._suggested_output_port = 'Impulse' self._has_sliders = True self._current_midi_map = None self._display_reset_delay = -1 self._string_to_display = None self.shift_pressed = False # special alternative buttons mode. for now only mixer buttons become record buttons. later we will add something more self.alternative_buttons_mode = False self._shift_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 39) self._preview_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 41) self._master_slider = SliderElement(MIDI_CC_TYPE, 0, 8) self._shift_button.name = 'Shift_Button' self._master_slider.name = 'Master_Volume_Control' self._master_slider.add_value_listener(self._slider_value, identify_sender=True) self._preview_button.add_value_listener(self._preview_value) self._setup_mixer() self._setup_session() self._setup_transport() self._setup_device() self._setup_name_display() device_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 10) mixer_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 9) device_button.name = 'Encoder_Device_Mode' mixer_button.name = 'Encoder_Mixer_Mode' self._encoder_modes = EncoderModeSelector(self._device_component, self._mixer, self._next_bank_button, self._prev_bank_button, self._encoders) self._encoder_modes.set_device_mixer_buttons(device_button, mixer_button) self._shift_button.add_value_listener(self._shift_button_handler) for component in self.components: component.set_enabled(False) # attributes def alternative_buttons_mode(self): return self.alternative_buttons_mode def alternative_buttons_mode(self,value): self.log ('alternative_buttons_mode_value ' + str(value)) self.alternative_buttons_mode = value def shift_pressed(self): return self.shift_pressed def shift_pressed(self,value): self.log ('shift_pressed value ' + str(value)) self.shift_pressed = value def refresh_state(self): ControlSurface.refresh_state(self) self.schedule_message(3, self._send_midi, SYSEX_START + (6, 1, 1, 1, 247)) def handle_sysex(self, midi_bytes): if midi_bytes[0:-2] == SYSEX_START + (7,) and midi_bytes[-2] != 0: self._has_sliders = midi_bytes[-2] != 25 self.schedule_message(1, self._show_startup_message) for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) if self._has_sliders: self._mixer.master_strip().set_volume_control(self._master_slider) self._mixer.update() else: self._mixer.master_strip().set_volume_control(None) self._mixer.selected_strip().set_volume_control(self._master_slider) for index in range(len(self._sliders)): self._mixer.channel_strip(index).set_volume_control(None) slider = self._sliders[index] slider.release_parameter() if slider.value_has_listener(self._slider_value): slider.remove_value_listener(self._slider_value) self._encoder_modes.set_provide_volume_mode(not self._has_sliders) self.request_rebuild_midi_map() def disconnect(self): self.log('starting disconnect 1') self._name_display_data_source.set_display_string(' ') for encoder in self._encoders: encoder.remove_value_listener(self._encoder_value) self._master_slider.remove_value_listener(self._slider_value) if self._has_sliders: for slider in tuple(self._sliders): slider.remove_value_listener(self._slider_value) for button in self._strip_buttons: button.remove_value_listener(self._mixer_button_value) self._preview_button.remove_value_listener(self._preview_value) self.log('starting disconnect 3') ControlSurface.disconnect(self) self.log('starting disconnect 3') self._encoders = None self._sliders = None self._strip_buttons = None self._master_slider = None self._current_midi_map = None self._name_display = None self._prev_bank_button = None self._next_bank_button = None self._encoder_modes = None self._transport_view_modes = None self.log('starting disconnect 4') self._send_midi(SYSEX_START + (6, 0, 0, 0, 247)) self.log('starting disconnect 5') if self._shift_button != None: self._shift_button.remove_value_listener(self._shift_button_handler) self._shift_button = None self.log('starting disconnect 6') def build_midi_map(self, midi_map_handle): self._current_midi_map = midi_map_handle ControlSurface.build_midi_map(self, midi_map_handle) def update_display(self): ControlSurface.update_display(self) if self._string_to_display != None: self._name_display_data_source.set_display_string(self._string_to_display) self._string_to_display = None if self._display_reset_delay >= 0: self._display_reset_delay -= 1 if self._display_reset_delay == -1: self._show_current_track_name() def _setup_mixer(self): self.log('setup mixer') mute_solo_flip_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 34) self._next_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 37) self._prev_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 38) self._strip_buttons = [] mute_solo_flip_button.name = 'Mute_Solo_Flip_Button' self._next_nav_button.name = 'Next_Track_Button' self._prev_nav_button.name = 'Prev_Track_Button' self._mixer = SpecialMixerComponent(self, 8, self.c_instance) self._mixer.name = 'Mixer' self._mixer.set_select_buttons(self._next_nav_button, self._prev_nav_button) self._mixer.selected_strip().name = 'Selected_Channel_Strip' self._mixer.master_strip().name = 'Master_Channel_Strip' self._mixer.master_strip().set_volume_control(self._master_slider) self._sliders = [] for index in range(8): strip = self._mixer.channel_strip(index) strip.name = 'Channel_Strip_' + str(index) strip.set_invert_mute_feedback(True) self._sliders.append(SliderElement(MIDI_CC_TYPE, 0, index)) self._sliders[-1].name = str(index) + '_Volume_Control' self._sliders[-1].set_feedback_delay(-1) self._sliders[-1].add_value_listener(self._slider_value, identify_sender=True) strip.set_volume_control(self._sliders[-1]) self._strip_buttons.append(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 9 + index)) self._strip_buttons[-1].name = str(index) + '_Mute_Button' self._strip_buttons[-1].add_value_listener(self._mixer_button_value, identify_sender=True) self._mixer.master_strip().set_mute_button(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 17)) self._mixer.set_strip_mute_solo_buttons(tuple(self._strip_buttons), mute_solo_flip_button) #self._mixer.set_shift_button(self._shift_button) self._mixer.updateMixerButtons() self._button9 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 9 + 8) def _setup_session(self): num_pads = len(PAD_TRANSLATIONS) self._session = SessionComponent(8, 0) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.set_mixer(self._mixer) # for ableton 9.1.1 and lower #self._session.set_track_banking_increment(num_pads) #self._session.set_track_bank_buttons(ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 35), ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 36)) # for ableton 9.1.1 and higher self._track_left_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 36) self._track_right_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 35) self._session.set_page_left_button(self._track_left_button) self._session.set_page_right_button(self._track_right_button) pads = [] for index in range(num_pads): pads.append(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 60 + index)) pads[-1].name = 'Pad_' + str(index) clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_triggered_to_play_value(GREEN_BLINK) clip_slot.set_triggered_to_record_value(RED_BLINK) clip_slot.set_stopped_value(AMBER_FULL) clip_slot.set_started_value(GREEN_FULL) clip_slot.set_recording_value(RED_FULL) clip_slot.set_launch_button(pads[-1]) clip_slot.name = str(index) + '_Selected_Clip_Slot' def _setup_transport(self): rwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 27) ffwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 28) stop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 29) play_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 30) loop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 31) rec_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 32) ffwd_button.name = 'FFwd_Button' rwd_button.name = 'Rwd_Button' loop_button.name = 'Loop_Button' play_button.name = 'Play_Button' stop_button.name = 'Stop_Button' rec_button.name = 'Record_Button' self._transport = ShiftableTransportComponent(self.c_instance,self._session, self, ffwd_button, rwd_button) self._transport.name = 'Transport' self._transport.set_stop_buttonOnInit(stop_button) self._transport.set_play_button(play_button) self._transport.set_record_buttonOnInit(rec_button) # self._transport.set_shift_button(self._shift_button) self._transport.set_mixer9_button(self._button9) self._transport_view_modes = TransportViewModeSelector(self,self.c_instance,self._transport, self._session, ffwd_button, rwd_button, loop_button) self._transport_view_modes.name = 'Transport_View_Modes' def _setup_device(self): encoders = [] for index in range(8): encoders.append(PeekableEncoderElement(MIDI_CC_TYPE, 1, index, Live.MidiMap.MapMode.relative_binary_offset)) encoders[-1].set_feedback_delay(-1) encoders[-1].add_value_listener(self._encoder_value, identify_sender=True) encoders[-1].name = 'Device_Control_' + str(index) self._encoders = tuple(encoders) self._prev_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 12) self._next_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 11) self._prev_bank_button.name = 'Device_Bank_Down_Button' self._next_bank_button.name = 'Device_Bank_Up_Button' device = DeviceComponent() device.name = 'Device_Component' self.set_device_component(device) device.set_parameter_controls(self._encoders) device.set_bank_nav_buttons(self._prev_bank_button, self._next_bank_button) def _setup_name_display(self): self._name_display = PhysicalDisplayElement(16, 1) self._name_display.name = 'Display' self._name_display.set_message_parts(SYSEX_START + (8,), (247,)) self._name_display_data_source = DisplayDataSource() self._name_display.segment(0).set_data_source(self._name_display_data_source) def _encoder_value(self, value, sender): if not sender in self._encoders: raise AssertionError if not value in range(128): raise AssertionError # display_string = self._device_component.is_enabled() and ' - ' # display_string = sender.mapped_parameter() != None and sender.mapped_parameter().name display_string = '' if self._device_component.is_enabled(): # display_string = sender.name # track = self.song().view.selected_track # display_string = str(list(tracks).index(track) + 1) pass if (sender.mapped_parameter() != None): # display_string = display_string + '-' display_string = display_string + sender.mapped_parameter().name self._set_string_to_display(display_string) def _slider_value(self, value, sender): self.log ('_slider_value ' + str(value) + ' ' +str(sender)) if not sender in tuple(self._sliders) + (self._master_slider,): raise AssertionError if not value in range(128): raise AssertionError if self._mixer.is_enabled(): display_string = ' - ' master = self.song().master_track tracks = self.song().tracks returns = self.song().return_tracks track = None if sender.mapped_parameter() != None: self.log ('1') if sender == self._master_slider: self.log ('2') # track = self._has_sliders and master if self._has_sliders: track = master else: self.log ('2.1') track = self.song().view.selected_track else: self.log ('3') track = self._mixer.channel_strip(self._sliders.index(sender))._track else: self.log ('4') track = self.song().view.selected_track self.log('track='+str(track)) if track == master: display_string = 'Master' elif track in tracks: display_string = str(list(tracks).index(track) + 1) elif track in returns: display_string = str(chr(ord('A') + list(returns).index(track))) else: # raise False or AssertionError raise AssertionError display_string += ' Volume' self._set_string_to_display(display_string) def _mixer_button_value(self, value, sender): self.log ('__mixer_button_value ' + str(value) + ' ' +str(sender)) if not value in range(128): raise AssertionError #if self._mixer.is_enabled() and value > 0: if self._mixer.is_enabled(): strip = self._mixer.channel_strip(self._strip_buttons.index(sender)) #self._string_to_display = strip != None and None self._name_display.segment(0).set_data_source(strip.track_name_data_source()) self._name_display.update() self._display_reset_delay = STANDARD_DISPLAY_DELAY else: self._set_string_to_display(' - ') # if shift_pressed XOR alternative_mode if self.shift_pressed <> self.alternative_buttons_mode: self.log("_mixer_button_value") self.log(str(value)) if (value == 0): self.select_armed_track_if_only_one() def select_armed_track_if_only_one(self): self.log("select_armed_track_if_only_one") song = self.song() armed_tracks = [] tracks = song.tracks self.log("select_armed_track_if_only_one 2") for track in tracks: if track.can_be_armed and track.arm: armed_tracks.append(track) self.log(str(len(armed_tracks))) if (len(armed_tracks) == 1): self.log("selecting the track") sel_track = armed_tracks[0] self.song().view.selected_track = sel_track self._mixer._selected_tracks = [] self._mixer._selected_tracks.append(sel_track) self._mixer.on_selected_track_changed() def _preview_value(self, value): if not value in range(128): raise AssertionError for encoder in self._encoders: encoder.set_peek_mode(value > 0) def _show_current_track_name(self): if self._name_display != None and self._mixer != None: self._string_to_display = None self._name_display.segment(0).set_data_source(self._mixer.selected_strip().track_name_data_source()) self._name_display.update() def _show_startup_message(self): self._name_display.display_message('LIVE') self._display_reset_delay = INITIAL_DISPLAY_DELAY def _set_string_to_display(self, string_to_display): if not isinstance(string_to_display, (str, unicode)): raise AssertionError self._name_display.segment(0).set_data_source(self._name_display_data_source) self._string_to_display = string_to_display self._display_reset_delay = STANDARD_DISPLAY_DELAY def _on_selected_track_changed(self): self.log('_on_selected_track_changed') ControlSurface._on_selected_track_changed(self) self._show_current_track_name() #all_tracks = self._has_sliders or self._session.tracks_to_use() all_tracks2 = self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks2: track_index = list(all_tracks2).index(selected_track) self.log('track_index '+ str(track_index)) new_offset = track_index - track_index % num_strips self.log('new_offset '+ str(new_offset)) if not new_offset / num_strips == int(new_offset / num_strips): raise AssertionError self._session.set_offsets(new_offset, self._session.scene_offset()) def _shift_button_handler(self, value): self.log("root shift handler : "+ str(value)) if not self._shift_button != None: raise AssertionError if not value in range(128): raise AssertionError self.log("root shift handler 2") self.shift_pressed = value > 0 # calling other handlers self._mixer._shift_button_handler(value) self._transport._shift_button_handler(value) self._transport_view_modes._shift_button_handler(value) #clip stop self.log("root shift handler 3") num_pads = len(PAD_TRANSLATIONS) pads = [] for index in range(num_pads): pads.append(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 60 + index)) pads[-1].name = 'Pad_' + str(index) clip_slot = self._session.selected_scene().clip_slot(index) if self.shift_pressed: clip_slot.set_launch_button(None) else: clip_slot.set_launch_button(pads[index]) if self.shift_pressed: self._session.set_stop_track_clip_buttons(tuple(pads)) else: self._session.set_stop_track_clip_buttons(None) self.log("root shift handler 4") def flipAlternativeButtonMode(self): self.alternative_buttons_mode = not self.alternative_buttons_mode self.updateAlternativeButtonMode() def updateAlternativeButtonMode(self): self._mixer.updateMixerButtons() self._transport_view_modes.update() def log(self, message): pass
class LiveStrip_A(ControlSurface): #Control Surface is central base class. acts as container. __module__ = __name__ __doc__ = "Ableton Live control surface script for liveStrip A" def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self._suppress_send_midi = True self._suppress_session_highlight = True #non-throw-away variables ??? #self._suggested_input_port = 'LiveStrip' #??? #self._suggested_output_port = 'LiveStrip' #??? #self._control_is_with_automap = False #for buttons ??? mabye for user-defined mappings self._transport = None #setup a blank transport self._session = None #setup a blank session self._device = None #setup a blank device #self._is_locked = False #for device or track self.setup_button_control() #buttons first - important #self.setup_rotary_control() #then rotary encoders - important self.setup_transport_control() #then transport.. self.setup_session_control() #..then the rest self.setup_device_control() self.assign_button_control( ) #after everything is set up we can then assign the buttons to things. ref this for updating aswell ??? self._end_buttons[0].add_value_listener(self._bt0_value) self._end_buttons[1].add_value_listener(self._bt1_value) self._end_buttons[2].add_value_listener(self._bt2_value) self._end_buttons[3].add_value_listener(self._bt3_value) self.set_highlighting_session_component(self._session) self._suppress_session_highlight = False self.log_message("LiveStrip loaded") #def refresh_state(self): #nothing def disconnect(self): self._suppress_send_midi = True #clean up things self._end_buttons[0].remove_value_listener(self._bt0_value) self._end_buttons[1].remove_value_listener(self._bt1_value) self._end_buttons[2].remove_value_listener(self._bt2_value) self._end_buttons[3].remove_value_listener(self._bt3_value) #create entry in log file then do final control surface disconnect self.log_message( time.strftime("%d.%m.%Y %H:%M:%S", time.localtime()) + " - LiveStrip disconnected") ControlSurface.disconnect(self) return None def setup_button_control(self): #setup the buttons on the end of the LiveStrip #but does not assign them #prob do something like enter menu mode by selecting 1 & 2 together, ..blink, confirm, ..then use buttons and knobs for selection. is_momentary = True #button setting (throw-away variable) self._end_buttons = [ ButtonElement(is_momentary, 0, settings.MIDI_CHANNEL, settings.END_NOTES[index]) for index in range(4) ] for index in range(4): #self._end_buttons[index] = ButtonElement(is_momentary, 0, settings.MIDI_CHANNEL, settings.END_NOTES[index]) self._end_buttons[index].name = settings.BUTTONS_MAP_LIST[ settings.END_BUTTONS_CURRENT[index]] #def setup_rotary_control(self): #setup the rotary encoders def setup_transport_control(self): #is_momentary = True #button setting (throw-away variable) self._transport = TransportComponent( ) #Instantiate a Transport Component #for index in range(4): #if settings.END_BUTTONS_CURRENT[index] == 4: #BUTTONS_MAP_LIST - play #self._transport.set_play_button(self._end_buttons[index]) #ButtonElement(is_momentary, msg_type, channel, identifier) #for index in range(4): #if settings.END_BUTTONS_CURRENT[index] == 5: #BUTTONS_MAP_LIST - stop #self._transport.set_stop_button(self._end_buttons[index]) def setup_session_control(self): #do i actually need session control ??? ...erm.. ...no, i don't think i do #num_tracks = 1 #8 columns (tracks) - see consts #num_scenes = 8 #8 rows (scenes) - see consts #(num_tracks, num_scenes) a session highlight ("red box") #self.session = SessionComponent(num_tracks,num_scenes) self._session = SessionComponent(settings.NUM_TRACKS, settings.NUM_SCENES) self._session.set_offsets(0, 0) def setup_device_control(self): #is_momentary = True self._device = DeviceComponent() self._device.name = 'Device_Component' device_param_controls = [] #for index in range(8): # device_param_controls.append(self._ctrl_map[PARAMCONTROL[index]]) #if None not in device_param_controls: # self._device.set_parameter_controls(tuple(device_param_controls)) #self._device.set_on_off_button(self._note_map[DEVICEONOFF]) #have to hand this a button #for index in range(4): #if settings.END_BUTTONS_CURRENT[index] == 1: #BUTTONS_MAP_LIST - device lock #self._device.set_lock_button(self._end_buttons[index]) #watch out, this way could set several to be the same #for index in range(4): #if settings.END_BUTTONS_CURRENT[index] == 2: #BUTTONS_MAP_LIST - device onOff #self._device.set_on_off_button(self._end_buttons[index]) #watch out, this way could set several to be the same self.set_device_component(self._device) def assign_button_control(self): for index in range(4): self.assign_individual_button_control(index) def assign_individual_button_control(self, index): if settings.END_BUTTONS_CURRENT[ index] == 0: #BUTTONS_MAP_LIST - NONE, or internal to LiveStrip unit. #self._device.set_lock_button(self._end_buttons[index]) #watch out, this way could set several to be the same do_nothing = True elif settings.END_BUTTONS_CURRENT[ index] == 1: #BUTTONS_MAP_LIST - play self._transport.set_play_button( self._end_buttons[index] ) #ButtonElement(is_momentary, msg_type, channel, identifier) elif settings.END_BUTTONS_CURRENT[ index] == 2: #BUTTONS_MAP_LIST - stop self._transport.set_stop_button(self._end_buttons[index]) elif settings.END_BUTTONS_CURRENT[ index] == 3: #BUTTONS_MAP_LIST - device lock self._device.set_lock_button(self._end_buttons[index]) elif settings.END_BUTTONS_CURRENT[ index] == 4: #BUTTONS_MAP_LIST - device on off self._device.set_on_off_button(self._end_buttons[index]) elif settings.END_BUTTONS_CURRENT[index] == 5: #BUTTONS_MAP_LIST - ??? #self._device.set_on_off_button(self._end_buttons[index]) do_nothing = False self._end_buttons[index].name = settings.BUTTONS_MAP_LIST[ settings.END_BUTTONS_CURRENT[index]] #set the name def _bt0_value(self, value): #callback when bt0 is triggered assert value in range(128) self.button_trigger(0, value) self.log_message("_bt0_value triggered %d" % (value)) def _bt1_value(self, value): #callback when bt1 is triggered assert value in range(128) self.button_trigger(1, value) self.log_message("_bt1_value triggered %d" % (value)) def _bt2_value(self, value): #callback when bt2 is triggered assert value in range(128) self.button_trigger(2, value) self.log_message("_bt2_value triggered %d" % (value)) def _bt3_value(self, value): #callback when bt3 is triggered assert value in range(128) self.button_trigger(3, value) self.log_message("_bt3_value triggered %d" % (value)) def button_trigger(self, index, value): if settings.END_BUTTONS_CURRENT[ index] == 0: #BUTTONS_MAP_LIST - NONE, or internal to LiveStrip unit. #self._device.set_lock_button(self._end_buttons[index]) #watch out, this way could set several to be the same do_nothing = True elif settings.END_BUTTONS_CURRENT[ index] == 1: #BUTTONS_MAP_LIST - play if (value != 0): do_nothing = False #self._play_button.turn_on() else: do_nothing = True #self._play_button.turn_off() elif settings.END_BUTTONS_CURRENT[ index] == 2: #BUTTONS_MAP_LIST - stop self._transport.set_stop_button(self._end_buttons[index]) elif settings.END_BUTTONS_CURRENT[ index] == 3: #BUTTONS_MAP_LIST - device lock self._device.set_lock_button(self._end_buttons[index]) elif settings.END_BUTTONS_CURRENT[ index] == 4: #BUTTONS_MAP_LIST - device on off self._device.set_on_off_button(self._end_buttons[index]) elif settings.END_BUTTONS_CURRENT[index] == 5: #BUTTONS_MAP_LIST - ??? #self._device.set_on_off_button(self._end_buttons[index]) do_nothing = False
class Tweaker(ControlSurface): __module__ = __name__ __doc__ = " Tweaker control surface script " def __init__(self, c_instance, *a, **k): super(Tweaker, self).__init__(c_instance, *a, **k) with self.component_guard(): self._update_linked_device_selection = None self._tweaker_version_check = '0.3' self.log_message("--------------= Tweaker Session " + str(self._tweaker_version_check) + " log opened =--------------") self._timer = 0 self.flash_status = 1 self._last_selected_strip_number = 0 self._device_selection_follows_track_selection = False #self._pad_translations = PAD_TRANSLATION self._linked_session = None self._mixer_offset = 0 self._nav_lock = True self._setup_controls() self._setup_transport_control() self._setup_device_control() self._setup_mixer_control() self._setup_session_control() self._setup_crossfader() self._setup_modes() self._setup_pads() self._setup_navigation_lock() self._setup_arrange_session_toggle() #self.assign_main_configuration() #self.request_rebuild_midi_map() #self._mixer._reassign_tracks() #this is to update rebuild the cf_assign closure, otherwise the colors aren't correct #self.schedule_message(30, self._detect_devices) self.show_message('Tweaker Control Surface Loaded') self.show_message('Tweaker Control Surface Loaded') #self._shift_value(0) #this updates the pads so that they transmit to Live on the assigned PAD_CHANNEL...also, lights shift button self.assign_main_configuration() #self.schedule_message(2, self._shift_value, 0) self.schedule_message(3, self._mixer._reassign_tracks) """script initialization methods""" def _setup_controls(self): is_momentary = True self._grid = [None for index in range(8)] for column in range(8): self._grid[column] = [TweakerMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, column + (row * 8) + 1, 'Grid_' + str(column) + '_' + str(row), self) for row in range(4)] self._button = [TweakerMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_BUTTONS[index], 'Button_' + str(index), self) for index in range(len(TWEAKER_BUTTONS))] self._nav = [TweakerMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_NAVS[index], 'Nav_' + str(index), self) for index in range(len(TWEAKER_NAVS))] self._encoder_button = [TweakerMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_ENCODER_BUTTONS[index], 'Encoder_Button_' + str(index), self) for index in range(len(TWEAKER_ENCODER_BUTTONS))] self._dial = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_DIALS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_DIALS))] self._fader = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_FADERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_FADERS))] self._crossfader = EncoderElement(MIDI_CC_TYPE, CHANNEL, CROSSFADER, Live.MidiMap.MapMode.absolute) self._encoder = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_ENCODERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_ENCODERS))] self._pad = [TweakerMonoButtonElement(False, MIDI_NOTE_TYPE, CHANNEL, TWEAKER_PADS[index], 'Pad_' + str(index), self) for index in range(len(TWEAKER_PADS))] for index in range(4): self._pad[index].set_enabled(False) self._pad[index].set_channel(PAD_CHANNEL) self._pad[index].set_identifier(index + 4) self._pad[index+4].set_enabled(False) self._pad[index+4].set_channel(PAD_CHANNEL) self._pad[index+4].set_identifier(index) self._pad_pressure = [EncoderElement(MIDI_CC_TYPE, CHANNEL, TWEAKER_PAD_PRESSURES[index], Live.MidiMap.MapMode.absolute) for index in range(len(TWEAKER_PADS))] for index in range(8): self._pad_pressure[index]._last_sent = 0 self._matrix = ButtonMatrixElement() self._matrix.name = 'Matrix' for row in range(4): button_row = [] for column in range(7): button_row.append(self._grid[column][row]) self._matrix.add_row(tuple(button_row)) self._send_midi(tuple([240,0,1,106,01,07,21,21,247])) #set all pots to walk mode self._send_midi(tuple([240, 0, 1, 106, 1, 6, 127 , 127, 25, 0, 15, 0, 9, PAD_SENSITIVITY, 247])) #set pads to sensitivity set in Map file def _setup_transport_control(self): self._transport = TransportComponent() self._transport.name = 'Transport' def _setup_mixer_control(self): is_momentary = True self._num_tracks = (2) #A mixer is one-dimensional; self._mixer = MixerComponent(2, 0, False, False) self._mixer.name = 'Mixer' self._mixer.tracks_to_use = self._mixer_tracks_to_use(self._mixer) self._device_navigator = [None for index in range(2)] self._mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) for index in range(2): self._mixer.channel_strip(index).set_volume_control(self._fader[index]) self._mixer.channel_strip(index)._on_cf_assign_changed = self._channelstrip_on_cf_assign_changed(self._mixer.channel_strip(index)) self._mixer.channel_strip(index).name = 'Mixer_ChannelStrip_' + str(index) #mixer.track_filter(index).name = 'Mixer_TrackFilter_' + str(index) self._mixer.channel_strip(index)._invert_mute_feedback = True self._mixer.channel_strip(index)._device_component = self._device[index] self._mixer.channel_strip(index).update = self._channelstrip_update(self._mixer.channel_strip(index)) self._mixer.channel_strip(index)._select_value = self._channelstrip_select_value(self._mixer.channel_strip(index), index) self._device_navigator[index] = DetailViewControllerComponent(self, self._mixer.channel_strip(index)) self._device_navigator[index].name = 'Device_Navigator_'+str(index) self._mixer.channel_strip(0).set_track = self._channelstrip_set_track(self._mixer.channel_strip(0), self._channelstrip1_cb) self._mixer.channel_strip(1).set_track = self._channelstrip_set_track(self._mixer.channel_strip(1), self._channelstrip2_cb) self.song().view.selected_track = self._mixer.channel_strip(0)._track #set the selected strip to the first track, so that we don't, for example, try to assign a button to arm the master track, which would cause an assertion error #self._mixer._reassign_tracks() def _setup_session_control(self): is_momentary = True num_tracks = NUM_TRACKS num_scenes = NUM_SCENES self._session = SessionComponent(num_tracks, num_scenes) self._session.name = "Session" self._session.set_offsets(0, 0) self._session.set_stop_track_clip_value(STOP_CLIP) self._scene = [None for index in range(3)] for row in range(num_scenes): self._scene[row] = self._session.scene(row) self._scene[row].name = 'Scene_' + str(row) for column in range(num_tracks): clip_slot = self._scene[row].clip_slot(column) clip_slot.name = str(column) + '_Clip_Slot_' + str(row) clip_slot.set_triggered_to_play_value(CLIP_TRG_PLAY) clip_slot.set_triggered_to_record_value(CLIP_TRG_REC) clip_slot.set_stopped_value(CLIP_STOP) clip_slot.set_started_value(CLIP_STARTED) clip_slot.set_recording_value(CLIP_RECORDING) self._session._stop_track_value = self._session_stop_track_value(self._session) self._session._on_fired_slot_index_changed = self._session_on_fired_slot_index_changed(self._session) self._session._change_offsets = self._session_change_offsets(self._session) self._session.update = self._session_update(self._session) #self._session.add_offset_listener(self._update_navigation_view) self._session.set_mixer(self._mixer) self.set_highlighting_session_component(self._session) self._session_zoom = SessionZoomingComponent(self._session) self._session_zoom.name = 'Session_Overview' self._session_zoom.set_stopped_value(ZOOM_STOPPED) self._session_zoom.set_playing_value(ZOOM_PLAYING) self._session_zoom.set_selected_value(ZOOM_SELECTED) #self._session_zoom.set_enabled(True) def _setup_device_control(self): self._device = [None for index in range(2)] for index in range(2): self._device[index] = DeviceComponent() self._device[index].name = 'Device_Component_'+str(index) self._device[index].set_enabled(True) self._device[index]._number_of_parameter_banks = self._device_number_of_parameter_banks(self._device[index]) self._device[index]._assign_parameters = self._device_assign_parameters(self._device[index]) self._device[index]._device_banks = DEVICE_DICT self._device[index]._device_best_banks = DEVICE_BOB_DICT self._device[index]._device_bank_names = BANK_NAME_DICT def _setup_crossfader(self): self._mixer.set_crossfader_control(self._crossfader) def _setup_modes(self): self._pad_offset = PadOffsetComponent(self) self._pad_offset._set_protected_mode_index(0) self._pad_offset.set_enabled(False) def _setup_pads(self): for pad in self._pad_pressure: pad.add_value_listener(self._light_pad, True) def _setup_navigation_lock(self): if(self._encoder_button[0].value_has_listener(self._nav_lock_value)): self._encoder_button[0].remove_value_listener(self._nav_lock_value) self._encoder_button[0].add_value_listener(self._nav_lock_value) def _setup_arrange_session_toggle(self): if(self._nav[1].value_has_listener(self._arrange_session_value)): self._nav[1].remove_value_listener(self._arrange_session_value) self._nav[1].add_value_listener(self._arrange_session_value) """configuration methods""" def assign_main_configuration(self): for column in range(7): for row in range(3): self._scene[row].clip_slot(column).set_launch_button(self._grid[column][row]) self._session.set_stop_track_clip_buttons(tuple([self._grid[index][3] for index in range(7)])) for row in range(3): self._scene[row].set_launch_button(self._grid[7][row]) self._device[0].set_parameter_controls(tuple([self._encoder[index+1] for index in range(3)])) self._device[0].set_enabled(True) self._device[1].set_parameter_controls(tuple([self._encoder[index+4] for index in range(3)])) self._device[1].set_enabled(True) for track in range(2): self._mixer.channel_strip(track).set_volume_control(self._fader[track]) self._mixer.channel_strip(track).set_solo_button(self._button[track*3]) self._button[track*3].set_on_off_values(SOLO, 0) self._mixer.channel_strip(track).set_arm_button(self._button[1 + (track*3)]) self._button[1 + (track*3)].set_on_off_values(ARM, 0) self._mixer.channel_strip(track).set_crossfade_toggle(self._button[2 + (track*3)]) self._mixer.master_strip().set_volume_control(self._dial[1]) self._mixer.set_prehear_volume_control(self._dial[0]) self._session.set_track_bank_buttons(self._nav[4], self._nav[3]) self._session.set_scene_bank_buttons(self._nav[2], self._nav[0]) self._session_zoom.set_zoom_button(self._grid[7][3]) self._session_zoom.set_nav_buttons(self._nav[0], self._nav[2], self._nav[3], self._nav[4]) self._session_zoom.set_button_matrix(self._matrix) self._device[0].set_on_off_button(self._encoder_button[1]) self._device_navigator[0].set_device_nav_buttons(self._encoder_button[2], self._encoder_button[3]) self._device[1].set_on_off_button(self._encoder_button[4]) self._device_navigator[1].set_device_nav_buttons(self._encoder_button[5], self._encoder_button[6]) for track in range(2): self._update_device(self._mixer.channel_strip(track)) #self._device.set_bank_nav_buttons(self._menu[0], self._menu[3]) self.assign_track_selector(self._encoder[0]) #for index in range(8): # self._pad[index].send_value(1, True) # self._pad[index].set_channel(1) # self._pad[index].set_identifier(index) # self._pad[index].set_enabled(False) #this has to happen for translate to work if not self._grid[7][3].value_has_listener(self._shift_value): self._grid[7][3].add_value_listener(self._shift_value) self._grid[7][3].send_value(127, True) self.request_rebuild_midi_map() """Tweaker custom methods""" def _shift_value(self, value): self._pad_offset.set_enabled(value>0) if value > 0: self._update_navigation_view() for pad in self._pad: pad.use_default_message() pad.set_enabled(True) self._pad_offset.set_mode_buttons(tuple(self._pad)) self.schedule_message(1, self._pad_offset.update) if self._session.is_enabled(): #self._update_navigation_view() #self.schedule_message(1, self._update_navigation_veiw) self._update_navigation_view() self._grid[7][3].send_value(SHIFT_ON) for track in range(2): self._mixer.channel_strip(track).set_crossfade_toggle(None) self._mixer.channel_strip(track).set_select_button(self._button[2 + (track*3)]) else: self._pad_offset.set_mode_buttons(None) for index in range(4): self._pad[index].set_enabled(False) self._pad[index].set_channel(PAD_CHANNEL) self._pad[index].set_identifier(index + 4 + (self._pad_offset._mode_index * 8)) self._pad[index+4].set_enabled(False) self._pad[index+4].set_channel(PAD_CHANNEL) self._pad[index+4].set_identifier(index + (self._pad_offset._mode_index * 8)) self._grid[7][3].send_value(SHIFT_OFF) for track in range(2): self._mixer.channel_strip(track).set_select_button(None) self._mixer.channel_strip(track).set_crossfade_toggle(self._button[2 + (track*3)]) def assign_track_selector(self, encoder): assert isinstance(encoder, EncoderElement) if not encoder.value_has_listener(self._track_selector_value): encoder.add_value_listener(self._track_selector_value) def deassign_track_selector(self, encoder): if encoder.value_has_listener(self._track_selector_value): encoder.remove_value_listener(self._track_selector_value) def _nav_lock_value(self, value): if value > 0: if self._nav_lock: self._mixer_offset = self._mixer_offset + self._session._track_offset self._mixer.set_track_offset(self._mixer_offset) else: if self._mixer_offset in range(self._session._track_offset, self._session._track_offset + 5): self._mixer_offset = self._mixer_offset - self._session._track_offset elif self._mixer_offset < self._session._track_offset: self._mixer_offset = 0 else: self._mixer_offset = min(self._session._track_offset+5, len(self._session.tracks_to_use())-2) self._mixer.set_track_offset(self._session._track_offset + self._mixer_offset) self._nav_lock = not self._nav_lock self._session.update() def _arrange_session_value(self, value): if value > 0: if (self.application().view.is_view_visible('Arranger')): self.application().view.show_view('Session') else: self.application().view.show_view('Arranger') def _track_selector_value(self, value): if(value is 1): if self._nav_lock: self._mixer_offset = min(self._mixer_offset + 1, min(NUM_TRACKS - 2, len(self._session.tracks_to_use())-self._session._track_offset-2)) else: self._mixer_offset = min(self._mixer_offset + 1, len(self._session.tracks_to_use())-2) elif(value is 127): self._mixer_offset = max(self._mixer_offset - 1, 0) if self._nav_lock: self._mixer.set_track_offset(self._session._track_offset + self._mixer_offset) #self._session.set_offsets(self._session._track_offset) ?? else: self._mixer.set_track_offset(self._mixer_offset) self._session.update() if self._mixer.channel_strip(self._last_selected_strip_number)._track != None: self.song().view.selected_track = self._mixer.channel_strip(self._last_selected_strip_number)._track if self._linked_session != None: if self._linked_session._is_linked(): self._linked_session._unlink() self._linked_session.set_offsets(self._mixer._track_offset, self._linked_session._scene_offset) self._linked_session._link() def _update_navigation_view(self): dif = self._mixer._track_offset - self._session._track_offset for index in range(7): #if (index + self._session._track_offset) in range(len(self._session.tracks_to_use())): if (index + self._session._track_offset) in range(0, len(self.song().visible_tracks)): self._grid[index][3].send_value(NAV_COLORS[int(index in range(dif, dif + 2))], True) elif (index + self._session._track_offset) in range(len(self.song().visible_tracks), len(self._session.tracks_to_use())): self._grid[index][3].send_value(RETURN_NAV_COLORS[int(index in range(dif, dif + 2))], True) else: self._grid[index][3].send_value(0, True) self._send_midi(tuple([240,0,1,106,01,07,21,21,247])) #set all pots to walk mode def _update_device(self, channelstrip): for control in channelstrip._device_component._parameter_controls: control.send_value(0, True) if channelstrip._device_component._on_off_button != None: channelstrip._device_component._on_off_button.turn_off() if not channelstrip._track is None: if not channelstrip._device_component._device in channelstrip._track.devices: track = channelstrip._track device_to_select = track.view.selected_device if (device_to_select == None) and (len(track.devices) > 0): device_to_select = track.devices[0] elif channelstrip._device_component and not type(channelstrip._device_component) is type(None): channelstrip._device_component.set_device(device_to_select) else: channelstrip._device_component.set_device(None) else: pass else: channelstrip._device_component.set_device(None) channelstrip._device_component._on_on_off_changed() def _light_pad(self, value, sender): if not self._pad_offset.is_enabled(): if value > sender._last_sent: if self._pad[self._pad_pressure.index(sender)]._last_sent_value < 1: self._pad[self._pad_pressure.index(sender)].send_value(127, True) else: self._pad[self._pad_pressure.index(sender)].send_value(0, True) sender._last_sent = value """called on timer""" def update_display(self): super(Tweaker, self).update_display() self._timer = (self._timer + 1) % 256 self.flash() def flash(self): if(self.flash_status > 0): for control in self.controls: if isinstance(control, TweakerMonoButtonElement): control.flash(self._timer) """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 12 if (not display_string): return (' ' * NUM_CHARS_PER_DISPLAY_STRIP) if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center((NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' return ret def notification_to_bridge(self, name, value, sender): if(isinstance(sender, MonoEncoderElement2)): self._monobridge._send(sender.name, 'lcd_name', str(self.generate_strip_string(name))) self._monobridge._send(sender.name, 'lcd_value', str(self.generate_strip_string(value))) def touched(self): if(self._shift_mode._mode_index < 2): if self._touched is 0: self._monobridge._send('touch', 'on') self.schedule_message(2, self.check_touch) self._touched +=1 def check_touch(self): if(self._shift_mode._mode_index < 2): if self._touched > 5: self._touched = 5 elif self._touched > 0: self._touched -= 1 if self._touched is 0: self._monobridge._send('touch', 'off') else: self.schedule_message(2, self.check_touch) def handle_sysex(self, midi_bytes): pass """general functionality""" def disconnect(self): """clean things up on disconnect""" #self._update_linked_device_selection = None if self._session.offset_has_listener(self._update_navigation_view): self._session.remove_offset_listener(self._update_navigation_view) if(self._nav[1].value_has_listener(self._arrange_session_value)): self._nav[1].remove_value_listener(self._arrange_session_value) if(self._encoder_button[0].value_has_listener(self._nav_lock_value)): self._encoder_button[0].remove_value_listener(self._nav_lock_value) for pad in self._pad_pressure: if pad.value_has_listener(self._light_pad): pad.remove_value_listener(self._light_pad) if self._grid[7][3].value_has_listener(self._shift_value): self._grid[7][3].remove_value_listener(self._shift_value) if self._session._is_linked(): self._session._unlink() self.deassign_track_selector(self._encoder[0]) self.log_message("--------------= Tweaker Session " + str(self._tweaker_version_check) + " log closed =--------------") #Create entry in log file super(Tweaker, self).disconnect() return None def _get_num_tracks(self): return self.num_tracks def _on_selected_track_changed(self): super(Tweaker, self)._on_selected_track_changed() if self._session.is_enabled(): self._session.update() for index in range(2): self._update_device(self._mixer.channel_strip(index)) self._mixer.on_selected_track_changed() def connect_script_instances(self, instanciated_scripts): link = False for s in instanciated_scripts: if '_tweaker_version' in dir(s): if s._tweaker_version == self._tweaker_version_check: link = True break if link == True: if not self._session._is_linked(): self._session._link() """SessionComponent overrides""" def _session_update(self, session): def _update(): SessionComponent.update(session) if session.is_enabled(): self._update_navigation_view() return _update def _session_change_offsets(self, session): def _change_offsets(track_increment, scene_increment): offsets_changed = (track_increment != 0) or (scene_increment != 0) if offsets_changed: session._track_offset += track_increment session._scene_offset += scene_increment assert (session._track_offset >= 0) assert (session._scene_offset >= 0) if (session._mixer != None): if(self._nav_lock): if (session.track_offset() + self._mixer_offset) > (len(session.tracks_to_use())-2): self._mixer_offset = max(len(session.tracks_to_use()) - session._track_offset - 2, 0) session._mixer.set_track_offset(max(0, session.track_offset() + self._mixer_offset)) session._reassign_tracks() if offsets_changed: session._reassign_scenes() # this is replaced by notify_offset() in Live9 #for callback in session._offset_callbacks: # this is replaced by notify_offset() in Live9 # callback() session.notify_offset() self._update_navigation_view() if self._mixer.channel_strip(self._last_selected_strip_number)._track != None: self.song().view.selected_track = self._mixer.channel_strip(self._last_selected_strip_number)._track if ((session.width() > 0) and (session.height() > 0)): session._do_show_highlight() return _change_offsets def _session_on_fired_slot_index_changed(self, session): def _on_fired_slot_index_changed(index): tracks_to_use = tuple(self.song().visible_tracks) + tuple(self.song().return_tracks) track_index = index + session.track_offset() if session.is_enabled() and session._stop_track_clip_buttons != None: if index < len(session._stop_track_clip_buttons): button = session._stop_track_clip_buttons[index] if button != None: if(track_index < len(tracks_to_use)) and (tracks_to_use[track_index].clip_slots) and (tracks_to_use[track_index].fired_slot_index == -2): button.send_value(session._stop_track_clip_value) #elif index in range(len(session.tracks_to_use())): # dif = self._mixer._track_offset - self._session._track_offset # button.send_value(NAV_COLORS[int(index in range(dif, dif + 2))], True) #else: # button.turn_off() else: self._update_navigation_view() return _on_fired_slot_index_changed def _session_stop_track_value(self, session): def _stop_track_value(value, sender): assert (session._stop_track_clip_buttons != None) assert (list(session._stop_track_clip_buttons).count(sender) == 1) assert (value in range(128)) if session.is_enabled(): if ((value is not 0) or (not sender.is_momentary())): tracks = session.tracks_to_use() track_index = (list(session._stop_track_clip_buttons).index(sender) + session.track_offset()) if (track_index in range(len(tracks))) and (tracks[track_index] in session.song().tracks): tracks[track_index].stop_all_clips() sender.send_value(3, True) self.schedule_message(10, self._update_navigation_view) return _stop_track_value """ChannelStripComponent overrides""" def _channelstrip_update(self, channelstrip): def _update(): ChannelStripComponent.update(channelstrip) self._update_device(channelstrip) return _update def _channelstrip_set_track(self, channelstrip, cb): def _set_track(track): assert ((track == None) or isinstance(track, Live.Track.Track)) if channelstrip._track != None and isinstance(channelstrip._track, Live.Track.Track): if channelstrip._track.devices_has_listener(cb): channelstrip._track.remove_devices_listener(cb) if (track != None): track.add_devices_listener(cb) ChannelStripComponent.set_track(channelstrip, track) return _set_track def _channelstrip_select_value(self, channelstrip, index): def _select_value(value): ChannelStripComponent._select_value(channelstrip, value) self._last_selected_strip_number = index return _select_value def _channelstrip_on_cf_assign_changed(self, channel_strip): def _on_cf_assign_changed(): if (channel_strip.is_enabled() and (channel_strip._crossfade_toggle != None)): if (channel_strip._track != None) and (channel_strip._track in chain(self.song().tracks, self.song().return_tracks)): if channel_strip._track.mixer_device.crossfade_assign == 1: #modified channel_strip._crossfade_toggle.turn_off() elif channel_strip._track.mixer_device.crossfade_assign == 0: channel_strip._crossfade_toggle.send_value(CROSSFADE_A) else: channel_strip._crossfade_toggle.send_value(CROSSFADE_B) return _on_cf_assign_changed def _channelstrip1_cb(self): self._on_selected_track_changed() def _channelstrip2_cb(self): self._on_selected_track_changed() """MixerComponent overrides""" def _mixer_tracks_to_use(self, mixer): def tracks_to_use(): return tuple(self.song().visible_tracks) + tuple(self.song().return_tracks) return tracks_to_use """SessionComponent overrides""" def _device_number_of_parameter_banks(self, device): def _number_of_parameter_banks(): return number_of_parameter_banks(device._device) #added return _number_of_parameter_banks def _device_assign_parameters(self, device): def _assign_parameters(): assert device.is_enabled() assert (device._device != None) assert (device._parameter_controls != None) device._bank_name = ('Bank ' + str(device._bank_index + 1)) #added if (device._device.class_name in device._device_banks.keys()): #modified assert (device._device.class_name in device._device_best_banks.keys()) banks = device._device_banks[device._device.class_name] bank = None if (not device._is_banking_enabled()): banks = device._device_best_banks[device._device.class_name] device._bank_name = 'Best of Parameters' #added if (len(banks) > device._bank_index): bank = banks[device._bank_index] if device._is_banking_enabled(): #added if device._device.class_name in device._device_bank_names.keys(): #added device._bank_name[device._bank_index] = device._device_bank_names[device._device.class_name] #added *recheck assert ((bank == None) or (len(bank) >= len(device._parameter_controls))) for index in range(len(device._parameter_controls)): parameter = None if (bank != None): parameter = get_parameter_by_name(device._device, bank[index]) if (parameter != None): device._parameter_controls[index].connect_to(parameter) else: device._parameter_controls[index].release_parameter() else: parameters = device._device_parameters_to_map() num_controls = len(device._parameter_controls) index = (device._bank_index * num_controls) for control in device._parameter_controls: if (index < len(parameters)): control.connect_to(parameters[index]) else: control.release_parameter() index += 1 return _assign_parameters
class Alias(ControlSurface): __module__ = __name__ __doc__ = " Alias 8 controller script " def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) self.set_suppress_rebuild_requests(True) self._host_name = 'Alias' self._color_type = 'OhmRGB' self.log_message("--------------= Alias log opened =--------------") self._rgb = 0 self._timer = 0 self.flash_status = 1 self._clutch_device_selection = False self._touched = 0 self._update_linked_device_selection = None self._setup_monobridge() self._setup_controls() self._setup_mixer_control() self._setup_session_control() self._setup_mixer_nav() self.set_suppress_rebuild_requests(False) """script initialization methods""" def _setup_monobridge(self): self._monobridge = MonoBridgeElement(self) self._monobridge.name = 'MonoBridge' def _setup_controls(self): is_momentary = True self._fader = [MonoEncoderElement(MIDI_CC_TYPE, CHANNEL, ALIAS_FADERS[index], Live.MidiMap.MapMode.absolute, 'Fader_' + str(index), index, self) for index in range(9)] self._button = [MonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, ALIAS_BUTTONS[index], 'Button_' + str(index), self) for index in range(16)] self._dial = [MonoEncoderElement(MIDI_CC_TYPE, CHANNEL, ALIAS_DIALS[index], Live.MidiMap.MapMode.absolute, 'Dial_' + str(index), index + 8, self) for index in range(16)] self._encoder = MonoEncoderElement(MIDI_CC_TYPE, CHANNEL, ALIAS_ENCODER, Live.MidiMap.MapMode.absolute, 'Encoder', 0, self) def _setup_mixer_control(self): is_momentary = True self._num_tracks = (8) #A mixer is one-dimensional; self._mixer = AliasMixerComponent(8, 0, False, False) self._mixer.name = 'Mixer' self._mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) for index in range(8): self._mixer.channel_strip(index).set_volume_control(self._fader[index]) self._mixer.channel_strip(index).set_send_controls(tuple([self._dial[index], self._dial[index+8]])) self._mixer.channel_strip(index).set_mute_button(self._button[index]) self._button[index].set_on_off_values(MUTE_TOG, 0) self._mixer.channel_strip(index)._invert_mute_feedback = True self._mixer.channel_strip(index).set_arm_button(self._button[index+8]) self._button[index+8].set_on_off_values(REC_TOG, 0) self._mixer.channel_strip(index).name = 'Mixer_ChannelStrip_' + str(index) self._mixer.master_strip().set_volume_control(self._fader[8]) self.song().view.selected_track = self._mixer.channel_strip(0)._track def _setup_session_control(self): self._session = SessionComponent(8, 1) self._session.set_mixer(self._mixer) def _setup_mixer_nav(self): if not self._encoder.value_has_listener(self._nav_change): self._encoder.add_value_listener(self._nav_change) """shift/zoom methods""" def _nav_change(self, value): self._session.set_offsets(int((float(value)/float(127))*max(8, len(self._mixer.tracks_to_use())-8)), self._session._scene_offset) """called on timer""" def update_display(self): ControlSurface.update_display(self) self._timer = (self._timer + 1) % 256 self.flash() def flash(self): if(self.flash_status > 0): for control in self.controls: if isinstance(control, MonoButtonElement): control.flash(self._timer) """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 12 if (not display_string): return (' ' * NUM_CHARS_PER_DISPLAY_STRIP) if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center((NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' ret = ret.replace(' ', '_') assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP) return ret def notification_to_bridge(self, name, value, sender): if isinstance(sender, MonoEncoderElement): self._monobridge._send(sender.name, 'lcd_name', str(self.generate_strip_string(name))) self._monobridge._send(sender.name, 'lcd_value', str(self.generate_strip_string(value))) def touched(self): if self._touched is 0: self._monobridge._send('touch', 'on') self.schedule_message(2, self.check_touch) self._touched +=1 def check_touch(self): if self._touched > 5: self._touched = 5 elif self._touched > 0: self._touched -= 1 if self._touched is 0: self._monobridge._send('touch', 'off') else: self.schedule_message(2, self.check_touch) """general functionality""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates!=0)) def disconnect(self): if self._encoder.value_has_listener(self._nav_change): self._encoder.remove_value_listener(self._nav_change) self.log_message("--------------= Alias log closed =--------------") ControlSurface.disconnect(self) return None def handle_sysex(self, midi_bytes): pass def device_follows_track(self, val): self._device_selection_follows_track_selection = (val == 1) return self def assign_alternate_mappings(self): pass def _get_num_tracks(self): return self.num_tracks def _on_device_changed(self, device): #self.log_message('new device ' + str(type(device))) if self._update_linked_device_selection != None: self._update_linked_device_selection(device) def _on_session_offset_changes(self): if self._r_function_mode._mode_index in range(0,3): self._mem[int(self._r_function_mode._mode_index)] = self._session2.track_offset() def connect_script_instances(self, instanciated_scripts): pass # a
class AumTroll_G(AumTroll): def __init__(self, *a, **k): super(AumTroll_G, self).__init__(*a, **k) with self.component_guard(): self._setup_session_recording_component() self._setup_APC_detail_component() self.log_message('Aumtroll G 4') def _setup_session_recording_component(self): self._recorder = SessionRecordingComponent(ClipCreator(), ViewControlComponent()) def _setup_APC_detail_component(self): self._alt_device_navigator = DetailViewCntrlComponent() """the mixer component corresponds and moves with our selection in Live, and allows us to assign physical controls""" """to Live's mixer functions without having to make all the links ourselves""" def _setup_mixer_control(self): is_momentary = True self._num_tracks = (8) #A mixer is one-dimensional; self._mixer = MixerComponent(8, 2, True, False) #These values represent the (Number_of_tracks, Number_of_returns, EQ_component, Filter_component) self._mixer.name = 'Mixer' #We name everything that we might want to access in m4l self._mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) for index in range(8): #self._mixer.channel_strip(index).set_volume_control(self._fader[index]) #Since we gave our mixer 4 tracks above, we'll now assign our fader controls to it self._mixer.channel_strip(index).name = 'Mixer_ChannelStrip_' + str(index) #We also name the individual channel_strip so we can access it self._mixer.track_eq(index).name = 'Mixer_EQ_' + str(index) #We also name the individual EQ_component so we can access it self._mixer.channel_strip(index)._invert_mute_feedback = True #This makes it so that when a track is muted, the corresponding button is turned off self.song().view.selected_track = self._mixer.channel_strip(0)._track #set the selected strip to the first track, so that we don't, for example, try to assign a button to arm the master track, which would cause an assertion error self._send_reset = ResetSendsComponent(self) #This creates a custom MonoComponent that allows us to reset all the sends on a track to zero with a single button self._send_reset.name = 'Sends_Reset' #We name it so that we can access it from m4l """the session component represents a grid of buttons that can be used to fire, stop, and navigate clips in the session view""" def _setup_session_control(self): is_momentary = True num_tracks = 8 #we are working with a 4x4 grid, num_scenes = 4 #so the height and width are both set to 4 self._session = SessionComponent(num_tracks, num_scenes) #we create our SessionComponent with the variables we set above it self._session.name = "Session" #we name it so we can access it in m4l self._session.set_offsets(0, 0) #we set the initial offset to the far left, top of the session grid self._session._track_banking_increment = 4 self._session.set_stop_clip_value(STOP_CLIP[self._rgb]) #we assign the colors that will be displayed when the stop_clip button is pressed. This value comes from CNTRLR_Map.py, which is imported in the header of our script self._scene = [None for index in range(4)] #we create an array to hold the Scene subcomponents so that we can get to them if we need them. for row in range(num_scenes): #now we'll fill the array with different objects that were created when we called the SessionComponent() module self._scene[row] = self._session.scene(row) #each session row is a SceneComponent self._scene[row].name = 'Scene_' + str(row) #name it so we can access it in m4l for column in range(num_tracks): #now we'll create holders and names for the contents of each scene clip_slot = self._scene[row].clip_slot(column) #we use our assignment of the scene above to gain access to the individual clipslots. Here, we are just assigning 'clip_slot' each time as a local variable so we can manipulated it's properties clip_slot.name = str(column) + '_Clip_Slot' + str(row) #name it so that we can acces it in m4l clip_slot.set_triggered_to_play_value(CLIP_TRG_PLAY[self._rgb]) #set its triggered to play color clip_slot.set_triggered_to_record_value(CLIP_TRG_REC[self._rgb])#set its triggered to record color clip_slot.set_stopped_value(CLIP_STOP[self._rgb]) #set its stop color clip_slot.set_started_value(CLIP_STARTED[self._rgb]) #set its started color clip_slot.set_recording_value(CLIP_RECORDING[self._rgb]) #set its recording value self._session.set_mixer(self._mixer) #now we link the MixerComponent we created in _setup_mixer_control() to our session component so that they will follow each other when either is navigated self.set_highlighting_session_component(self._session) self._session_zoom = SessionZoomingComponent(self._session) #this creates the ZoomingComponent that allows navigation when the shift button is pressed self._session_zoom.name = 'Session_Overview' #name it so we can access it in m4l self._session_zoom.set_stopped_value(ZOOM_STOPPED[self._rgb]) #set the zooms stopped color self._session_zoom.set_playing_value(ZOOM_PLAYING[self._rgb]) #set the zooms playing color self._session_zoom.set_selected_value(ZOOM_SELECTED[self._rgb]) #set the zooms selected color self._session_zoom.set_button_matrix(self._matrix) #assign the ButtonMatrixElement that we created in _setup_controls() to the zooming component so that we can control it self._session_zoom.set_zoom_button(self._button[31]) #assign a shift button so that we can switch states between the SessionComponent and the SessionZoomingComponent """this section is used so that we can reassign the color properties of each state. Legacy, from the OhmModes script, to support either RGB or Monochrome""" def _assign_session_colors(self): num_tracks = 8 num_scenes = 4 self._session.set_stop_clip_value(STOP_ALL[self._rgb]) for row in range(num_scenes): for column in range(num_tracks): self._scene[row].clip_slot(column).set_triggered_to_play_value(CLIP_TRG_PLAY[self._rgb]) self._scene[row].clip_slot(column).set_triggered_to_record_value(CLIP_TRG_REC[self._rgb]) self._scene[row].clip_slot(column).set_stopped_value(CLIP_STOP[self._rgb]) self._scene[row].clip_slot(column).set_started_value(CLIP_STARTED[self._rgb]) self._scene[row].clip_slot(column).set_recording_value(CLIP_RECORDING[self._rgb]) self._session_zoom.set_stopped_value(ZOOM_STOPPED[self._rgb]) self._session_zoom.set_playing_value(ZOOM_PLAYING[self._rgb]) self._session_zoom.set_selected_value(ZOOM_SELECTED[self._rgb]) self.refresh_state() def deassign_live_controls(self, *a, **k): for index in range(4): self._encoder[index].send_value(0, True) self._encoder[index].clear_send_cache() self._mixer.channel_strip(index+4).set_volume_control(None) #Since we gave our mixer 4 tracks above, we'll now assign our fader controls to it #for the left side of the mixer self._mixer.channel_strip(index+4).set_solo_button(None) #remove the solo button assignments self._mixer.channel_strip(index+4).set_arm_button(None) #remove the arm button assignments self._mixer.channel_strip(index+4).set_mute_button(None) #remove the mute button assignments self._mixer.channel_strip(index+4).set_select_button(None) #remove the select button assignments #self._alt_device_navigator.set_arrange_session_toggle_button(None) self._alt_device_navigator.set_device_clip_toggle_button(None) self._alt_device_navigator.set_detail_toggle_button(None) self._alt_device_navigator.set_enabled(False) #self._alt_device_navigator.set_shift_button(None) self._transport.set_nudge_buttons(None, None) self._recorder.set_record_button(None) self._recorder.set_re_enable_automation_button(None) super(AumTroll_G, self).deassign_live_controls(*a, **k) def assign_live_controls(self): """the following lines update all of the controls' last_sent properties, so that they forward the next value they receive regardless of whether or not it is the same as the last it recieved""" """we also reset the encoder rings and buttons, since the device component will not update them if it is not locked to a device in Live""" for index in range(16): self._grid[index].force_next_send() for index in range(32): #self._button[index].set_on_off_values(0, 127) self._button[index].send_value(0, True) self._button[index].force_next_send() for index in range(8): self._encoder_button[index+4].send_value(0, True) self._encoder_button[index+4].force_next_send() for index in range(12): self._encoder[index].send_value(0, True) self._encoder[index].force_next_send() """here we assign the left side of our mixer's buttons on the lower 32 keys""" if self._monohm is None: with self.component_guard(): for index in range(4): #we set up a recursive loop to assign all four of our track channel strips' controls self._button[index+16].set_on_value(MUTE[self._rgb]) #set the mute color from the Map.py self._mixer.channel_strip(index).set_mute_button(self._button[index+16]) #assign the mute buttons to our mixer channel strips self._button[index+28].set_on_value(MUTE[self._rgb]) #set the mute color from the Map.py self._mixer.channel_strip(index+4).set_mute_button(self._button[index+28]) #assign the mute buttons to our mixer channel strips self._button[index].set_on_off_values(SELECT[self._rgb], SELECT_OFF[self._rgb]) self._mixer.channel_strip(index).set_select_button(self._button[index]) #assign the select buttons to our mixer channel strips self._button[index+12].set_on_off_values(SELECT[self._rgb], SELECT_OFF[self._rgb]) #set the select color from the Map.py self._mixer.channel_strip(index+4).set_select_button(self._button[index+12]) #assign the select buttons to our mixer channel strips #self._session.set_stop_track_clip_buttons(tuple(self._button[index+4] for index in range(8))) #these last two lines assign the send_reset buttons and the stop_clip buttons for each track for index in range(8): #self._button[index + 4].set_on_off_values(SOLO[self._rgb], SOLO[self._rgb]) #this assigns the custom colors defined in the Map.py file to the stop_clip buttons. They have seperate on/off values, but we assign them both the same value so we can always identify them self._mixer.channel_strip(index).set_solo_button(self._button[index+4]) #self._button[index + 4].send_value(STOP_CLIP[self._rgb], True) #finally, we send the on/off colors out to turn the LEDs on for the stop clip buttons for index in range(4): #set up a for loop to generate an index for assigning the session nav buttons' colors self._button[index + 20].set_on_off_values(SESSION_NAV[self._rgb], SESSION_NAV_OFF[self._rgb]) #assign the colors from Map.py to the session nav buttons self._session.set_track_bank_buttons(self._button[21], self._button[20]) #set the track bank buttons for the Session navigation controls self._session.set_scene_bank_buttons(self._button[23], self._button[22]) #set the scnee bank buttons for the Session navigation controls """this section assigns the grid to the clip launch functionality of the SessionComponent""" for column in range(4): #we need to set up a double recursion so that we can generate the indexes needed to assign the grid buttons for row in range(4): #the first recursion passes the column index, the second the row index self._scene[row].clip_slot(column).set_launch_button(self._grid[(row*4)+column]) #we use the indexes to grab the first the scene and then the clip we assigned above, and then we use them again to define the button held in the grid array that we want to assign to the clip slot from the session component for index in range(4): #set up a for loop to generate an index for assigning the session nav buttons' colors self._button[index + 24].set_on_off_values(SHIFTS[self._rgb], SHIFTS_OFF[self._rgb]) #assign the colors from Map.py to the session nav buttons self._session.update() #tell the Session component to update so that the grid will display the currently selected session region self._session.set_enabled(True) #enable the Session Component self._session_zoom.set_enabled(True) #enable the Session Zoom #self._alt_device_navigator.set_arrange_session_toggle_button(self._encoder_button[4]) self._alt_device_navigator.set_device_clip_toggle_button(self._encoder_button[5]) self._alt_device_navigator.set_detail_toggle_button(self._encoder_button[6]) #self._device_navigator.set_shift_button(self._encoder_button[7]) self._session_zoom.set_zoom_button(self._encoder_button[7]) #assign the lower right key button to the shift function of the Zoom component self._session.set_scene_bank_buttons(self._button[25], self._button[24]) self._recorder.set_record_button(self._button[27]) self._recorder.set_re_enable_automation_button(self._button[26]) else: for index in range(8): self._mixer2.channel_strip(index).set_volume_control(self._fader[index]) self._mixer2.set_track_offset(TROLL_OFFSET) self._device_selector.set_mode_buttons(self._grid) if not self._shifted: self._assign_monomodular_controls() else: self._assign_shifted_controls() self._device1.set_parameter_controls(tuple([self._knobs[index] for index in range(8)])) self._device2.set_parameter_controls(tuple([self._knobs[index+12] for index in range(8)])) self._device1.set_enabled(True) self._device2.set_enabled(True) self._find_devices() self._device1.update() self._device2.update() """this section assigns the encoders and encoder buttons""" self._device.set_parameter_controls(tuple([self._encoder[index+4] for index in range(8)])) #assign the encoders from the device component controls - we are doing this here b #self._encoder_button[7].set_on_value(DEVICE_LOCK[self._rgb]) #set the on color for the Device lock encoder button #self._device.set_lock_button(self._encoder_button[7]) #assign encoder button 7 to the device lock control #self._encoder_button[4].set_on_value(DEVICE_ON[self._rgb]) #set the on color for the Device on/off encoder button #self._device.set_on_off_button(self._encoder_button[4]) #assing encoder button 4 to the device on/off control for index in range(2): #setup a recursion to generate indexes so that we can reference the correct controls to assing to the device_navigator functions self._encoder_button[index + 8].set_on_value(DEVICE_NAV[self._rgb]) #assign the on color for the device navigator self._encoder_button[index + 10].set_on_value(DEVICE_BANK[self._rgb]) #assign the on color for the device bank controls self._device_navigator.set_nav_buttons(self._encoder_button[10], self._encoder_button[11]) #set the device navigators controls to encoder buttons 10 and 11 self._device.set_bank_nav_buttons(self._encoder_button[8], self._encoder_button[9]) #set the device components bank nav controls to encoder buttons 8 and 9 """now we turn on and update some of the components we've just made assignments to""" self._device.set_enabled(True) #enable the Device Component self._device_navigator.set_enabled(True) #enable the Device Navigator self._alt_device_navigator.set_enabled(True) self._device.update() #tell the Device component to update its assingments so that it will detect the currently selected device parameters and display them on the encoder rings
class Novation_Impulse(ControlSurface): """ Script for Novation's Impulse keyboards """ def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._device_selection_follows_track_selection = True self._suggested_input_port = 'Impulse' self._suggested_output_port = 'Impulse' self._has_sliders = True self._current_midi_map = None self._display_reset_delay = -1 self._shift_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 39) self._preview_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 41) self._master_slider = SliderElement(MIDI_CC_TYPE, 0, 8) self._shift_button.name = 'Shift_Button' self._master_slider.name = 'Master_Volume_Control' self._master_slider.add_value_listener(self._slider_value, identify_sender=True) self._preview_button.add_value_listener(self._preview_value) self._setup_mixer() self._setup_session() self._setup_transport() self._setup_device() self._setup_name_display() device_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 10) mixer_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 1, 9) device_button.name = 'Encoder_Device_Mode' mixer_button.name = 'Encoder_Mixer_Mode' self._encoder_modes = EncoderModeSelector(self._device_component, self._mixer, self._next_bank_button, self._prev_bank_button, self._encoders) self._encoder_modes.set_device_mixer_buttons(device_button, mixer_button) self._string_to_display = None for component in self.components: component.set_enabled(False) def refresh_state(self): ControlSurface.refresh_state(self) self.schedule_message(3, self._send_midi, SYSEX_START + (6, 1, 1, 1, 247)) def handle_sysex(self, midi_bytes): if midi_bytes[0:-2] == SYSEX_START + (7,) and midi_bytes[-2] != 0: self._has_sliders = midi_bytes[-2] != 25 self.schedule_message(1, self._show_startup_message) for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) if self._has_sliders: self._mixer.master_strip().set_volume_control(self._master_slider) self._mixer.update() else: self._mixer.master_strip().set_volume_control(None) self._mixer.selected_strip().set_volume_control(self._master_slider) for index in range(len(self._sliders)): self._mixer.channel_strip(index).set_volume_control(None) slider = self._sliders[index] slider.release_parameter() if slider.value_has_listener(self._slider_value): slider.remove_value_listener(self._slider_value) self._encoder_modes.set_provide_volume_mode(not self._has_sliders) self.request_rebuild_midi_map() def disconnect(self): self._name_display_data_source.set_display_string(' ') for encoder in self._encoders: encoder.remove_value_listener(self._encoder_value) self._master_slider.remove_value_listener(self._slider_value) if self._has_sliders: for slider in tuple(self._sliders): slider.remove_value_listener(self._slider_value) for button in self._strip_buttons: button.remove_value_listener(self._mixer_button_value) self._preview_button.remove_value_listener(self._preview_value) ControlSurface.disconnect(self) self._encoders = None self._sliders = None self._strip_buttons = None self._master_slider = None self._current_midi_map = None self._shift_button = None self._name_display = None self._prev_bank_button = None self._next_bank_button = None self._encoder_modes = None self._transport_view_modes = None self._send_midi(SYSEX_START + (6, 0, 0, 0, 247)) def build_midi_map(self, midi_map_handle): self._current_midi_map = midi_map_handle ControlSurface.build_midi_map(self, midi_map_handle) def update_display(self): ControlSurface.update_display(self) if self._string_to_display != None: self._name_display_data_source.set_display_string(self._string_to_display) self._string_to_display = None if self._display_reset_delay >= 0: self._display_reset_delay -= 1 if self._display_reset_delay == -1: self._show_current_track_name() def _setup_mixer(self): mute_solo_flip_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 34) self._next_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 37) self._prev_nav_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 38) self._strip_buttons = [] mute_solo_flip_button.name = 'Mute_Solo_Flip_Button' self._next_nav_button.name = 'Next_Track_Button' self._prev_nav_button.name = 'Prev_Track_Button' self._mixer = SpecialMixerComponent(8) self._mixer.name = 'Mixer' self._mixer.set_select_buttons(self._next_nav_button, self._prev_nav_button) self._mixer.selected_strip().name = 'Selected_Channel_Strip' self._mixer.master_strip().name = 'Master_Channel_Strip' self._mixer.master_strip().set_volume_control(self._master_slider) self._sliders = [] for index in range(8): strip = self._mixer.channel_strip(index) strip.name = 'Channel_Strip_' + str(index) strip.set_invert_mute_feedback(True) self._sliders.append(SliderElement(MIDI_CC_TYPE, 0, index)) self._sliders[-1].name = str(index) + '_Volume_Control' self._sliders[-1].set_feedback_delay(-1) self._sliders[-1].add_value_listener(self._slider_value, identify_sender=True) strip.set_volume_control(self._sliders[-1]) self._strip_buttons.append(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 9 + index)) self._strip_buttons[-1].name = str(index) + '_Mute_Button' self._strip_buttons[-1].add_value_listener(self._mixer_button_value, identify_sender=True) self._mixer.master_strip().set_mute_button(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 17)) self._mixer.set_strip_mute_solo_buttons(tuple(self._strip_buttons), mute_solo_flip_button) def _setup_session(self): num_pads = len(PAD_TRANSLATIONS) self._track_left_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 36) self._track_right_button = ButtonElement(not IS_MOMENTARY, MIDI_CC_TYPE, 0, 35) self._session = SessionComponent(8, 0) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.set_mixer(self._mixer) self._session.set_page_left_button(self._track_left_button) self._session.set_page_right_button(self._track_right_button) pads = [] for index in range(num_pads): pads.append(ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 60 + index)) pads[-1].name = 'Pad_' + str(index) clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_triggered_to_play_value(GREEN_BLINK) clip_slot.set_triggered_to_record_value(RED_BLINK) clip_slot.set_stopped_value(AMBER_FULL) clip_slot.set_started_value(GREEN_FULL) clip_slot.set_recording_value(RED_FULL) clip_slot.set_launch_button(pads[-1]) clip_slot.name = str(index) + '_Selected_Clip_Slot' def _setup_transport(self): rwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 27) ffwd_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 28) stop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 29) play_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 30) loop_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 31) rec_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 0, 32) ffwd_button.name = 'FFwd_Button' rwd_button.name = 'Rwd_Button' loop_button.name = 'Loop_Button' play_button.name = 'Play_Button' stop_button.name = 'Stop_Button' rec_button.name = 'Record_Button' transport = ShiftableTransportComponent() transport.name = 'Transport' transport.set_stop_button(stop_button) transport.set_play_button(play_button) transport.set_record_button(rec_button) transport.set_shift_button(self._shift_button) self._transport_view_modes = TransportViewModeSelector(transport, self._session, ffwd_button, rwd_button, loop_button) self._transport_view_modes.name = 'Transport_View_Modes' def _setup_device(self): encoders = [] for index in range(8): encoders.append(PeekableEncoderElement(MIDI_CC_TYPE, 1, index, Live.MidiMap.MapMode.relative_binary_offset)) encoders[-1].set_feedback_delay(-1) encoders[-1].add_value_listener(self._encoder_value, identify_sender=True) encoders[-1].name = 'Device_Control_' + str(index) self._encoders = tuple(encoders) self._prev_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 12) self._next_bank_button = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, 11) self._prev_bank_button.name = 'Device_Bank_Down_Button' self._next_bank_button.name = 'Device_Bank_Up_Button' device = DeviceComponent() device.name = 'Device_Component' self.set_device_component(device) device.set_parameter_controls(self._encoders) device.set_bank_nav_buttons(self._prev_bank_button, self._next_bank_button) def _setup_name_display(self): self._name_display = PhysicalDisplayElement(16, 1) self._name_display.name = 'Display' self._name_display.set_message_parts(SYSEX_START + (8,), (247,)) self._name_display_data_source = DisplayDataSource() self._name_display.segment(0).set_data_source(self._name_display_data_source) def _encoder_value(self, value, sender): if not sender in self._encoders: raise AssertionError if not value in range(128): raise AssertionError display_string = self._device_component.is_enabled() and ' - ' display_string = sender.mapped_parameter() != None and sender.mapped_parameter().name self._set_string_to_display(display_string) def _slider_value(self, value, sender): if not sender in tuple(self._sliders) + (self._master_slider,): raise AssertionError if not value in range(128): raise AssertionError if self._mixer.is_enabled(): display_string = ' - ' if sender.mapped_parameter() != None: master = self.song().master_track tracks = self.song().tracks returns = self.song().return_tracks track = None if sender == self._master_slider: track = self._has_sliders and master else: track = self.song().view.selected_track else: track = self._mixer.channel_strip(self._sliders.index(sender))._track display_string = track == master and 'Master' elif track in tracks: display_string = str(list(tracks).index(track) + 1) elif track in returns: display_string = str(chr(ord('A') + list(returns).index(track))) else: raise False or AssertionError display_string += ' Volume' self._set_string_to_display(display_string) def _mixer_button_value(self, value, sender): if not value in range(128): raise AssertionError if self._mixer.is_enabled() and value > 0: strip = self._mixer.channel_strip(self._strip_buttons.index(sender)) self._string_to_display = strip != None and None self._name_display.segment(0).set_data_source(strip.track_name_data_source()) self._name_display.update() self._display_reset_delay = STANDARD_DISPLAY_DELAY else: self._set_string_to_display(' - ') def _preview_value(self, value): raise value in range(128) or AssertionError for encoder in self._encoders: encoder.set_peek_mode(value > 0) def _show_current_track_name(self): if self._name_display != None and self._mixer != None: self._string_to_display = None self._name_display.segment(0).set_data_source(self._mixer.selected_strip().track_name_data_source()) self._name_display.update() def _show_startup_message(self): self._name_display.display_message('LIVE') self._display_reset_delay = INITIAL_DISPLAY_DELAY def _set_string_to_display(self, string_to_display): raise isinstance(string_to_display, (str, unicode)) or AssertionError self._name_display.segment(0).set_data_source(self._name_display_data_source) self._string_to_display = string_to_display self._display_reset_delay = STANDARD_DISPLAY_DELAY def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._show_current_track_name() all_tracks = self._has_sliders or self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks: track_index = list(all_tracks).index(selected_track) new_offset = track_index - track_index % num_strips if not new_offset / num_strips == int(new_offset / num_strips): raise AssertionError self._session.set_offsets(new_offset, self._session.scene_offset())
class CNTRL_R_LITE(ControlSurface): def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) is_momentary = True self._timer = 0 # Used in FlashingButtonElement (kludge for our purposes) self.flash_status = 1 # Used in FlashingButtonElement (kludge for our purposes) if USE_MIXER_CONTROLS == True: self.mixer_control() if USE_SESSION_VIEW == True: self.session_control() def mixer_control(self): is_momentary = True self.num_tracks = N_TRACKS if(USE_SENDS == True): self.mixer = MixerComponent(N_TRACKS, N_SENDS_PER_TRACK, USE_MIXER_EQ, USE_MIXER_FILTERS) else: self.mixer = MixerComponent(N_TRACKS,0, USE_MIXER_EQ, USE_MIXER_FILTERS) self.mixer.name = 'Mixer' self.mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) for index in range(N_TRACKS): self.mixer.channel_strip(index).name = 'Mixer_ChannelStrip_' + str(index) self.mixer.channel_strip(index)._invert_mute_feedback = True self.song().view.selected_track = self.mixer.channel_strip(0)._track self.log_message(str(len(SOLO_BUTTONS))) self.log_message(str(len(MUTE_BUTTONS))) if(USE_SOLO_BUTTONS == True): self.solobuttons = [None for index in range(N_TRACKS)] for index in range(len(SOLO_BUTTONS)): self.solobuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,SOLO_BUTTONS[index], 'Solo_Button', self) self.mixer.channel_strip(index).set_solo_button(self.solobuttons[index]) self.solobuttons[index].set_on_value(SOLO_BUTTON_ON_COLOR) self.solobuttons[index].set_off_value(SOLO_BUTTON_OFF_COLOR) if(USE_MUTE_BUTTONS == True): self.mutebuttons = [None for index in range(N_TRACKS)] for index in range(len(MUTE_BUTTONS)): self.mutebuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,MUTE_BUTTONS[index], 'Mute_Button', self) self.mixer.channel_strip(index).set_mute_button(self.mutebuttons[index]) self.mutebuttons[index].set_on_value(MUTE_BUTTON_ON_COLOR) self.mutebuttons[index].set_off_value(MUTE_BUTTON_OFF_COLOR) if(USE_SENDS == True): self.sendencoders = [None for index in range(len(SEND_ENCODERS))] for index in range(len(SEND_ENCODERS)): self.sendencoders[index] = EncoderElement(MIDI_CC_TYPE, CHANNEL, SEND_ENCODERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(SEND_ENCODERS)/N_SENDS_PER_TRACK): self.mixer.channel_strip(index).set_send_controls(tuple(self.sendencoders[(index*N_SENDS_PER_TRACK):((index*N_SENDS_PER_TRACK)+N_SENDS_PER_TRACK-1)])) if(USE_VOLUME_CONTROLS == True): self.volencoders = [None for index in range(len(VOLUME_ENCODERS))] for index in range (len(VOLUME_ENCODERS)): self.volencoders[index] = EncoderElement(MIDI_CC_TYPE, CHANNEL, VOLUME_ENCODERS[index], Live.MidiMap.MapMode.absolute) self.mixer.channel_strip(index).set_volume_control(self.volencoders[index]) def session_control(self): is_momentary = True self._timer = 0 self.flash_status = 1 self.grid = [None for index in range(N_TRACKS*N_SCENES)] for index in range(N_TRACKS*N_SCENES): self.grid[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,TRACK_CLIP_BUTTONS[index], 'Grid' + str(index), self) self.matrix = ButtonMatrixElement() for row in range(N_SCENES): button_row = [] for column in range(N_TRACKS): button_row.append(self.grid[row+(column*4)]) self.matrix.add_row(tuple(button_row)) self.session = SessionComponent(N_TRACKS,N_SCENES) self.session.name = "Session" self.session.set_offsets(0,0) self.scene = [None for index in range(N_SCENES)] for row in range(N_SCENES): self.scene[row] = self.session.scene(row) self.scene[row].name = 'Scene_'+str(row) for column in range(N_TRACKS): clip_slot = self.scene[row].clip_slot(column) clip_slot.name = str(column)+'_Clip_Slot'+str(row) self.scene[row].clip_slot(column).set_triggered_to_play_value(CLIP_TRG_PLAY_COLOR) self.scene[row].clip_slot(column).set_stopped_value(CLIP_STOP_COLOR) self.scene[row].clip_slot(column).set_started_value(CLIP_STARTED_COLOR) # Clip trigger on grid assignments for column in range(N_TRACKS): for row in range(N_SCENES): self.scene[row].clip_slot(column).set_launch_button(self.grid[row+(column*4)]) for index in range(N_TRACKS*N_SCENES): self.grid[index].clear_send_cache() if USE_SESSION_NAV == True: self.navleft = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,NAVBOX_LEFT_BUTTON, 'Nav_Left_Button', self) self.navleft.clear_send_cache() self.navleft.set_on_off_values(NAVBOX_LEFT_BUTTON_C, NAVBOX_LEFT_BUTTON_C) self.navright = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,NAVBOX_RIGHT_BUTTON, 'Nav_Right_Button', self) self.navright.clear_send_cache() self.navright.set_on_off_values(NAVBOX_RIGHT_BUTTON_C, NAVBOX_RIGHT_BUTTON_C) self.navup = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,NAVBOX_UP_BUTTON, 'Nav_Up_Button', self) self.navup.clear_send_cache() self.navup.set_on_off_values(NAVBOX_UP_BUTTON_C, NAVBOX_UP_BUTTON_C) self.navdown = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,NAVBOX_DOWN_BUTTON, 'Nav_Down_Button', self) self.navdown.clear_send_cache() self.navdown.set_on_off_values(NAVBOX_DOWN_BUTTON_C, NAVBOX_DOWN_BUTTON_C) self.session.set_track_bank_buttons(self.navright, self.navleft) self.session.set_scene_bank_buttons(self.navdown, self.navup) if USE_MIXER_CONTROLS == True: self.session.set_mixer(self.mixer) self.refresh_state() self.session.set_enabled(True) self.session.update() def update_display(self): ControlSurface.update_display(self) self._timer = (self._timer + 1) % 256 self.flash() def flash(self): if(USE_SESSION_VIEW == True): for index in range(N_TRACKS*N_SCENES): if(self.grid[index]._flash_state > 0): self.grid[index].flash(self._timer) if(USE_SESSION_NAV == True): if(self.navleft._flash_state>0): self.navleft.flash(self._timer) if(self.navright._flash_state>0): self.navright.flash(self._timer) if(self.navup._flash_state>0): self.navup.flash(self._timer) if(self.navdown._flash_state>0): self.navdown.flash(self._timer) if(USE_MIXER_CONTROLS == True): for index in range(N_TRACKS): if(USE_SOLO_BUTTONS == True): if(self.solobuttons[index]._flash_state > 0): self.solobuttons[index].flash(self._timer) if(USE_MUTE_BUTTONS == True): if(self.mutebuttons[index]._flash_state > 0): self.mutebuttons[index].flash(self._timer) def disconnect(self): self._hosts = [] self.log_message("--------------= CNTRLR log closed =--------------") ControlSurface.disconnect(self) return None
def _on_control_surface_offset_changed(self): """ Updates offsets in serato to be the same as in control surface Called whenever control surface offsets are changed. """ SessionComponent.set_offsets(self, self._synced_session.track_offset(), self._synced_session.scene_offset())
def set_offsets(self, track_offset, scene_offset): if self._synced_session != None: self._synced_session.set_offsets(track_offset, scene_offset) else: SessionComponent.set_offsets(self, track_offset, scene_offset)
class DC1(ControlSurface): def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) is_momentary = True self._timer = 0 #used for flashing states, and is incremented by each call from self._update_display() self._touched = 0 self.flash_status = 1 # Used in FlashingButtonElement (kludge for our purposes) self._device_selection_follows_track_selection = True with self.component_guard(): self._setup_transport_control() if USE_MIXER_CONTROLS == True: self.mixer_control() if USE_SESSION_VIEW == True: self.session_control() self.setup_device_control() def _setup_transport_control(self): is_momentary = True # We'll only be using momentary buttons here self.transport = TransportComponent() #Instantiate a Transport Component """set up the buttons""" self.transport.set_play_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 60)) #ButtonElement(is_momentary, msg_type, channel, identifier) Note that the MIDI_NOTE_TYPE constant is defined in the InputControlElement module self.transport.set_stop_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 61)) self.transport.set_record_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 62)) def mixer_control(self): is_momentary = True self.num_tracks = N_TRACKS if(USE_SENDS == True): self.mixer = MixerComponent(N_TRACKS, N_SENDS_PER_TRACK, USE_MIXER_EQ, USE_MIXER_FILTERS) else: self.mixer = MixerComponent(N_TRACKS,0, USE_MIXER_EQ, USE_MIXER_FILTERS) self.mixer.name = 'Mixer' self.mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) for index in range(N_TRACKS): self.mixer.channel_strip(index).name = 'Mixer_ChannelStrip_' + str(index) self.mixer.channel_strip(index)._invert_mute_feedback = True if(USE_SELECT_BUTTONS == True): self.selectbuttons = [None for index in range(N_TRACKS)] for index in range(len(SELECT_BUTTONS)): self.selectbuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,SELECT_BUTTONS[index], 'Select_Button', self) self.mixer.channel_strip(index).set_select_button(self.selectbuttons[index]) self.selectbuttons[index].set_on_value(SELECT_BUTTON_ON_COLOR) self.selectbuttons[index].set_off_value(SELECT_BUTTON_OFF_COLOR) if(USE_SOLO_BUTTONS == True): self.solobuttons = [None for index in range(N_TRACKS)] for index in range(len(SOLO_BUTTONS)): self.solobuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,SOLO_BUTTONS[index], 'Solo_Button', self) self.mixer.channel_strip(index).set_solo_button(self.solobuttons[index]) self.solobuttons[index].set_on_value(SOLO_BUTTON_ON_COLOR) self.solobuttons[index].set_off_value(SOLO_BUTTON_OFF_COLOR) if(USE_ARM_BUTTONS == True): self.armbuttons = [None for index in range(N_TRACKS)] for index in range(len(ARM_BUTTONS)): self.armbuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,ARM_BUTTONS[index], 'Arm_Button', self) self.mixer.channel_strip(index).set_arm_button(self.armbuttons[index]) self.armbuttons[index].set_on_value(ARM_BUTTON_ON_COLOR) self.armbuttons[index].set_off_value(ARM_BUTTON_OFF_COLOR) if(USE_MUTE_BUTTONS == True): self.mutebuttons = [None for index in range(N_TRACKS)] for index in range(len(MUTE_BUTTONS)): self.mutebuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,MUTE_BUTTONS[index], 'Mute_Button', self) self.mixer.channel_strip(index).set_mute_button(self.mutebuttons[index]) self.mutebuttons[index].set_on_value(MUTE_BUTTON_ON_COLOR) self.mutebuttons[index].set_off_value(MUTE_BUTTON_OFF_COLOR) if(USE_SENDS == True): self.sendencoders = [None for index in range(len(SEND_ENCODERS))] for index in range(len(SEND_ENCODERS)): self.sendencoders[index] = EncoderElement(MIDI_CC_TYPE, CHANNEL, SEND_ENCODERS[index], Live.MidiMap.MapMode.absolute) for index in range(len(SEND_ENCODERS)/N_SENDS_PER_TRACK): self.mixer.channel_strip(index).set_send_controls(tuple(self.sendencoders[(index*N_SENDS_PER_TRACK):((index*N_SENDS_PER_TRACK)+N_SENDS_PER_TRACK-1)])) if(USE_VOLUME_CONTROLS == True): self.volencoders = [None for index in range(len(VOLUME_ENCODERS))] for index in range (len(VOLUME_ENCODERS)): self.volencoders[index] = EncoderElement(MIDI_CC_TYPE, CHANNEL, VOLUME_ENCODERS[index], Live.MidiMap.MapMode.absolute) self.mixer.channel_strip(index).set_volume_control(self.volencoders[index]) def session_control(self): is_momentary = True self._timer = 0 self.flash_status = 1 self.grid = [None for index in range(N_TRACKS*N_SCENES)] for index in range(N_TRACKS*N_SCENES): self.grid[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,TRACK_CLIP_BUTTONS[index], 'Grid' + str(index), self) self.grid[index].set_off_value(0) self.grid[index].turn_off() self.matrix = ButtonMatrixElement() for row in range(N_SCENES): button_row = [] for column in range(N_TRACKS): button_row.append(self.grid[row+(column*N_SCENES)]) self.matrix.add_row(tuple(button_row)) self.session = SessionComponent(N_TRACKS,N_SCENES) self.session.name = "Session" self.session.set_offsets(0,0) self.scene = [None for index in range(N_SCENES)] for row in range(N_SCENES): self.scene[row] = self.session.scene(row) self.scene[row].name = 'Scene_'+str(row) for column in range(N_TRACKS): clip_slot = self.scene[row].clip_slot(column) clip_slot.name = str(column)+'_Clip_Slot'+str(row) self.scene[row].clip_slot(column).set_triggered_to_play_value(CLIP_TRG_PLAY_COLOR) self.scene[row].clip_slot(column).set_stopped_value(CLIP_STOP_COLOR) self.scene[row].clip_slot(column).set_started_value(CLIP_STARTED_COLOR) self.set_highlighting_session_component(self.session) self.session_zoom = DeprecatedSessionZoomingComponent(self.session) #this creates the ZoomingComponent that allows navigation when the shift button is pressed self.session_zoom.name = 'Session_Overview' #name it so we can access it in m4l self.session_zoom.set_stopped_value(ZOOM_STOPPED) #set the zooms stopped color self.session_zoom.set_playing_value(ZOOM_PLAYING) #set the zooms playing color self.session_zoom.set_selected_value(ZOOM_SELECTED) #set the zooms selected color self.session_zoom.set_button_matrix(self.matrix) #assign the ButtonMatrixElement that we created in _setup_controls() to the zooming component so that we can control it self._shift_button = ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 63) self.session_zoom.set_zoom_button(self._shift_button) #assign a shift button so that we can switch states between the SessionComponent and the SessionZoomingComponent self.looper = LooperComponent(self) self.log_message(str(len(STOP_BUTTONS))) if(USE_STOP_BUTTONS == True): self.stopbuttons = [None for index in range(N_TRACKS)] for index in range(len(STOP_BUTTONS)): self.stopbuttons[index] = FlashingButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL,STOP_BUTTONS[index], 'Stop_Button', self) self.session.set_stop_track_clip_buttons(self.stopbuttons) self.stopbuttons[index].set_on_value(STOP_BUTTON_ON_COLOR) self.stopbuttons[index].set_off_value(STOP_BUTTON_OFF_COLOR) self.scrollencoder = ScrollEncoderElement(MIDI_CC_TYPE, CHANNEL, 32, Live.MidiMap.MapMode.absolute, self.session, self.transport, self.mixer, self.looper) self.scrollencoder.set_nav_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 0)) self.scrollencoder.set_transport_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 7)) self.scrollencoder.set_scene_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 3)) self.scrollencoder.set_library_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 4)) self.scrollencoder.set_button1(SimpleButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 1)) self.scrollencoder.set_button2(SimpleButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 2)) self.scrollencoder.set_button3(SimpleButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 5)) self.scrollencoder.set_button4(SimpleButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 6)) self.scrollencoder.set_encoder_button(SimpleButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 32)) for column in range(N_TRACKS): for row in range(N_SCENES): self.scene[row].clip_slot(column).set_launch_button(self.grid[row+(column*N_SCENES)]) for index in range(N_TRACKS*N_SCENES): self.grid[index].clear_send_cache() if USE_MIXER_CONTROLS == True: self.session.set_mixer(self.mixer) self.refresh_state() self.session.set_enabled(True) self.session.update() def setup_device_control(self): is_momentary = True device_bank_buttons = [] device_param_controls = [] bank_button_labels = ('Clip_Track_Button', 'Device_On_Off_Button', 'Previous_Device_Button', 'Next_Device_Button') for index in range(4): device_bank_buttons.append(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, 16 + index)) device_bank_buttons[-1].name = bank_button_labels[index] for index in range(8): #ring_mode_button = ButtonElement(not is_momentary, MIDI_CC_TYPE, CHANNEL, 21 + index) ringed_encoder = CMDEncoderElement(MIDI_CC_TYPE, CHANNEL, 16 + index, Live.MidiMap.MapMode.relative_binary_offset, 20) #ringed_encoder.set_ring_mode_button(ring_mode_button) ringed_encoder.name = 'Device_Control_' + str(index) #ring_mode_button.name = ringed_encoder.name + '_Ring_Mode_Button' device_param_controls.append(ringed_encoder) device = ShiftableDeviceComponent() device.name = 'Device_Component' device.set_bank_buttons(tuple(device_bank_buttons)) device.set_shift_button(self._shift_button) device.set_parameter_controls(tuple(device_param_controls)) device.set_on_off_button(device_bank_buttons[1]) self.set_device_component(device) detail_view_toggler = DetailViewControllerComponent(self) detail_view_toggler.name = 'Detail_View_Control' detail_view_toggler.set_shift_button(self._shift_button) detail_view_toggler.set_device_clip_toggle_button(device_bank_buttons[0]) detail_view_toggler.set_device_nav_buttons(device_bank_buttons[2], device_bank_buttons[3]) def update_display(self): ControlSurface.update_display(self) self._timer = (self._timer + 1) % 256 def disconnect(self): self._hosts = [] ControlSurface.disconnect(self) return None
def _on_control_surface_offset_changed(self): SessionComponent.set_offsets(self, self._synced_session.track_offset(), self._synced_session.scene_offset())
class Codec(ControlSurface): __module__ = __name__ __doc__ = " MonoCode controller script " def __init__(self, c_instance, *a, **k): super(Codec, self).__init__(c_instance, *a, **k) self._monomod_version = 'b995' self._version_check = 'b995' self._host_name = 'Codec' self._color_type = 'Monochrome' self._link_mixer = LINK_MIXER self._hosts = [] self._linked_script = None self._local_ring_control = True self._last_device = None self._device_list = [None, None, None, None] self._device_select_buttons = None self._last_device_component = None self._timer = 0 self._touched = 0 self._locked = False self.flash_status = 1 self._shift_button = None self._shift_pressed = 0 self._shift_pressed_timer = 0 self._shift_thresh = SHIFT_THRESH self._use_device_selector = USE_DEVICE_SELECTOR self._device_selection_follows_track_selection=FOLLOW with self.component_guard(): #self.local_ring_control(True) #self.set_absolute_mode(True) self._setup_controls() self._setup_monobridge() self._setup_device_controls() self._setup_special_device_control() self._device.append(self._special_device) #necessary for device browsing to work with special device self._setup_device_chooser() self._setup_mixer_controls() self._setup_monomod() self._setup_modes() self._setup_device_selector() self._setup_send_reset() self._setup_default_buttons() self.set_local_ring_control(1) self.song().view.add_selected_track_listener(self._update_selected_device) self._initialize_code() #self._shift_mode.set_mode(0) #self._monomod_mode.set_mode(0) self.log_message('<<<<<<<<<<<<<<<<<<<<<<<<< Codec ' + str(self._monomod_version) + ' log opened >>>>>>>>>>>>>>>>>>>>>>>>>') self.show_message('Codec Control Surface Loaded') self.request_rebuild_midi_map() """script initialization methods""" def _initialize_code(self): self._send_midi(factoryreset) self._send_midi(btn_channels) self._send_midi(enc_channels) def _setup_monobridge(self): self._monobridge = MonoBridgeElement(self) self._monobridge.name = 'MonoBridge' def _setup_controls(self): is_momentary = True self._livid = CodecMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, LIVID, 'Livid_Button', self) self._dial = [None for index in range(8)] for column in range(8): self._dial[column] = [None for index in range(4)] for row in range(4): self._dial[column][row] = CodecEncoderElement(MIDI_CC_TYPE, CHANNEL, CODE_DIALS[row][column], Live.MidiMap.MapMode.absolute, 'Dial_' + str(column) + '_' + str(row), (column + (row*8)), self) #CODE_DIALS[row][column] self._button = [None for index in range(8)] for column in range(8): self._button[column] = [None for index in range(4)] for row in range(4): self._button[column][row] = CodecMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, CODE_BUTTONS[row][column], 'Button_' + str(column) + '_' + str(row), self) self._column_button = [None for index in range(8)] for index in range(8): self._column_button[index] = CodecMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, CODE_COLUMN_BUTTONS[index], 'Column_Button_' + str(index), self) self._row_button = [None for index in range(4)] for index in range(4): self._row_button[index] = CodecMonoButtonElement(is_momentary, MIDI_NOTE_TYPE, CHANNEL, CODE_ROW_BUTTONS[index], 'Row_Button_' + str(index), self) self._dial_matrix = EncoderMatrixElement(self) self._dial_matrix.name = 'Encoder_Matrix' for row in range(4): dial_row = tuple([self._dial[column][row] for column in range(8)]) self._dial_matrix.add_row(dial_row) self._button_matrix = ButtonMatrixElement() self._button_matrix.name = 'Button_Matrix' for row in range(4): button_row = [self._button[column][row] for column in range(8)] button_row.append(self._row_button[row]) self._button_matrix.add_row(tuple(button_row)) self._button_matrix.add_row(tuple(self._column_button + [self._livid])) def _setup_modes(self): self._monomod_mode = MonomodModeComponent(self._mod_mode_update, self) self._monomod_mode.name = 'Monomod_Mode' self.set_shift_button(self._livid) self._shift_mode = ShiftModeComponent(self._shift_update, self) self._shift_mode.name = 'Shift_Mode' self._shift_mode.set_mode_buttons(tuple([self._row_button[0], self._row_button[1], self._row_button[2], self._row_button[3]])) def _setup_transport_control(self): self._transport = TransportComponent() self._transport.name = 'Transport' def _setup_monomod(self): self._host = CodecMonomodComponent(self) self._host.name = 'Monomod_Host' self._host._set_dial_matrix(self._dial_matrix, self._button_matrix) self.hosts = [self._host] encs = [] for row in range(4): for col in range(8): encs.append(self._dial[col][row]) self._host._set_parameter_controls(encs) def _setup_mixer_controls(self): is_momentary = True self._num_tracks = (8) self._session = SessionComponent(self._num_tracks, 0) self._session.name = 'Session' self._mixer = MixerComponent(self._num_tracks, 0, False, False) self._mixer.name = 'Mixer' self._mixer._next_track_value = self._mixer_next_track_value(self._mixer) self._mixer._prev_track_value = self._mixer_prev_track_value(self._mixer) self._mixer.set_track_offset(0) #Sets start point for mixer strip (offset from left) #for index in range(8): #use the bottom row of encoders for volume, so add 24 to offset the index # self._mixer.channel_strip(index).set_volume_control(self._dial[index+24]) for index in range(8): self._mixer.channel_strip(index).name = 'Mixer_ChannelStrip_' + str(index) self._mixer.channel_strip(index)._invert_mute_feedback = True self._mixer.channel_strip(index)._mute_value = self._channelstrip_mute_value(self._mixer.channel_strip(index)) self._mixer.channel_strip(index)._solo_value = self._channelstrip_solo_value(self._mixer.channel_strip(index)) #mixer.channel_strip(index).set_select_button(ButtonElement(is_momentary, MIDI_NOTE_TYPE, CH, track_select_notes[index])) self.song().view.selected_track = self._mixer.channel_strip(0)._track #set the selected strip to the first track, so that we don't, for example, try to assign a button to arm the master track, which would cause an assertion error self._session.set_mixer(self._mixer) def _setup_device_controls(self): self._device = [None for index in range(4)] for index in range(4): self._device[index] = CodecDeviceComponent(self) self._device[index].name = 'CodecDevice_Component_' + str(index) device_param_controls = [] for control in range(8): device_param_controls.append(self._dial[control][index]) self._device[index].set_on_off_button(self._button[1][index]) self._device[index].set_lock_button(self._button[2][index]) self._device[index].set_bank_nav_buttons(self._button[4][index], self._button[5][index]) self._device[index].set_nav_buttons(self._button[6][index], self._button[7][index]) self._device[index].set_parameter_controls(tuple(device_param_controls)) self.set_device_component(self._device[0]) self._last_device_component = self._device[0] def _setup_special_device_control(self): self._special_device = SpecialCodecDeviceComponent(self) self._special_device.name = 'SpecialCodecDeviceComponent' self._special_device.set_on_off_button(self._button[1][0]) self._special_device.set_lock_button(self._button[2][0]) self._special_device.set_bank_nav_buttons(self._button[4][0], self._button[5][0]) self._special_device.set_nav_buttons(self._button[6][0], self._button[7][0]) device_param_controls = [] for row in range(4): for column in range(8): device_param_controls.append(self._dial[column][row]) self._special_device.set_parameter_controls(tuple(device_param_controls)) def _setup_device_chooser(self): self._selected_device = self._device[0] self._last_selected_device = self._device[0] self._device_select_buttons = [self._button[0][index] for index in range(4)] for button in self._device_select_buttons: button.add_value_listener(self._device_select_value, True) def _setup_device_selector(self): self._device_selector = CodecDeviceSelectorComponent(self, 'c', self._device + [self._special_device]) self._device_selector.name = 'Device_Selector' self._device_selector.set_mode_buttons(self._column_button) #self._device_selector.set_mode_toggle(self._livid) def _setup_send_reset(self): self._send_reset = CodecResetSendsComponent(self) self._send_reset.set_buttons(self._button) def _setup_default_buttons(self): self._value_default = ParameterDefaultComponent(self) buttons = [] dials = [] for column in self._button: for button in column: buttons.append(button) for column in self._dial: for dial in column: dials.append(dial) self._value_default.set_buttons(buttons) self._value_default.set_dials(dials) """multiple device support""" def _device_select_value(self, value, sender): #self.log_message('device_select_value ' + str(value) + ' ' + str(self._device_select_buttons.index(sender))) if not self._shift_pressed: if sender.is_momentary or value > 0: if self._shift_mode._mode_index == 2: self.set_device_component(self._device[self._device_select_buttons.index(sender)]) self._last_device_component = self._device_component if self._device_component != None and isinstance(self._device_component._device, Live.Device.Device): if self._device_component.find_track(self._device_component._device) == self.song().view.selected_track: self._device_component.display_device() """livid double press mechanism""" def set_shift_button(self, button): assert ((button == None) or (isinstance(button, MonoButtonElement))) if self._shift_button != None: self._shift_button.remove_value_listener(self._shift_value) self._shift_button = button if self._shift_button != None: self._shift_button.add_value_listener(self._shift_value) def _shift_value(self, value): self._shift_pressed = int(value != 0) if self._shift_pressed > 0: self._send_midi(SLOWENCODER) if (self._shift_pressed_timer + self._shift_thresh) > self._timer: #if(self._host.is_enabled() != True) self.log_message('mod mode: ' + str(abs(self._monomod_mode._mode_index - 1))) self._monomod_mode.set_mode(max(0, min(1, abs(self._monomod_mode._mode_index - 1)))) #else: # self._monomod_mode.set_mode(0) self._shift_pressed_timer = self._timer % 256 else: self._send_midi(NORMALENCODER) def _mod_mode_update(self): if(self._monomod_mode._mode_index == 0): self._host._set_shift_button(None) self._host.set_enabled(False) self._dial_matrix.reset() self._shift_mode.set_enabled(True) self._shift_update() self.request_rebuild_midi_map() self._livid.turn_off() elif(self._monomod_mode._mode_index == 1): self._shift_mode.set_enabled(False) self._deassign_all() self._dial_matrix.reset() self._button_matrix.reset() self._livid.turn_on() if not self._host._active_client == None: self._host.set_enabled(True) self._host._set_shift_button(self._livid) else: self._assign_alternate_mappings(1) self.request_rebuild_midi_map() """Mode Functions""" def _shift_update(self): if(self._shift_mode.is_enabled()): with self.component_guard(): self.allow_updates(False) #if(not self._in_build_midi_map): # self.set_suppress_rebuild_requests(True) self._deassign_all() if(self._shift_mode._mode_index is 0): self._assign_volume() elif(self._shift_mode._mode_index is 1): self._assign_sends() elif(self._shift_mode._mode_index is 2): self._assign_devices() elif(self._shift_mode._mode_index is 3): self._assign_special_device() for index in range(self._shift_mode.number_of_modes()): if index == self._shift_mode._mode_index: self._shift_mode._modes_buttons[index].turn_on() else: self._shift_mode._modes_buttons[index].turn_off() self.allow_updates(True) #self.set_suppress_rebuild_requests(False) self.request_rebuild_midi_map() def _deassign_all(self): self._assign_alternate_mappings(0) self._device_selector.set_enabled(False) for index in range(8): self._mixer.channel_strip(index).set_volume_control(None) self._mixer.channel_strip(index).set_pan_control(None) self._mixer.channel_strip(index).set_send_controls(tuple([None, None, None, None])) for index in range(4): self._device[index].set_enabled(False) self._device[index]._parameter_controls = None #self._device_navigator[index].set_enabled(False) self._special_device.set_enabled(False) self._special_device._parameter_controls = None self._device_selector.set_enabled(False) self._deassign_buttons() for control in self.controls: control.reset() self.request_rebuild_midi_map() def _deassign_buttons(self): for index in range(8): self._mixer.channel_strip(index).set_select_button(None) self._mixer.channel_strip(index).set_solo_button(None) self._mixer.channel_strip(index).set_mute_button(None) self._mixer.set_select_buttons(None, None) self._send_reset.set_enabled(False) def _assign_volume(self): for index in range(8): self._mixer.channel_strip(index).set_volume_control(self._dial[index][3]) self._mixer.channel_strip(index).set_pan_control(self._dial[index][2]) self._mixer.channel_strip(index).set_send_controls(tuple([self._dial[index][0], self._dial[index][1]])) self._mixer.channel_strip(index).set_select_button(self._column_button[index]) self._mixer.channel_strip(index).set_solo_button(self._button[index][2]) self._mixer.channel_strip(index).set_mute_button(self._button[index][3]) self._mixer.set_select_buttons(self._button[7][0], self._button[6][0]) def _assign_sends(self): for index in range(8): self._mixer.channel_strip(index).set_send_controls(tuple([self._dial[index][0], self._dial[index][1], self._dial[index][2], self._dial[index][3]])) self._mixer.channel_strip(index).set_select_button(self._column_button[index]) self._send_reset.set_enabled(True) def _assign_devices(self): self.set_device_component(self._last_device_component) self._device_select_value(1, self._device_select_buttons[self._device.index(self._device_component)]) for index in range(4): device_param_controls = [] for control in range(8): device_param_controls.append(self._dial[control][index]) self._device[index].set_parameter_controls(tuple(device_param_controls)) self._device[index].set_enabled(True) self._device_selector.set_enabled(self._use_device_selector) if not self._use_device_selector: for index in range(8): self._mixer.channel_strip(index).set_select_button(self._column_button[index]) def _assign_special_device(self): self.set_device_component(self._special_device) device_param_controls = [] for row in range(4): for column in range(8): device_param_controls.append(self._dial[column][row]) self._special_device.set_parameter_controls(tuple(device_param_controls)) self._special_device.set_enabled(True) self._device_selector.set_enabled(self._use_device_selector) if not self._use_device_selector: for index in range(8): self._mixer.channel_strip(index).set_select_button(self._column_button[index]) def _assign_alternate_mappings(self, chan): for column in self._dial: for control in column: control.set_channel(chan) control.set_enabled(chan is 0) for column in self._button: for control in column: control.set_channel(chan) control.set_enabled(chan is 0) for control in self._column_button: control.set_channel(chan) control.set_enabled(chan is 0) for control in self._row_button: control.set_channel(chan) control.set_enabled(chan is 0) """general functionality""" def disconnect(self): """clean things up on disconnect""" if not self._shift_button is None: if self._shift_button.value_has_listener(self._shift_value): self._shift_button.remove_value_listener(self._shift_value) for button in self._device_select_buttons: if button.value_has_listener(self._device_select_value): button.remove_value_listener(self._device_select_value) if self._session._is_linked(): self._session._unlink() self.song().view.remove_selected_track_listener(self._update_selected_device) """for cs in self._control_surfaces(): for host in self._hosts: self.log_message('installed: ' + str(cs) + ' vs. ' + str(host)) if str(type(cs)) == str(type(host)): self.log_message('disconnecting: ' + str(type(cs))) cs.disconnect(cs)""" #self._host._set_parameter_controls(None) self._hosts = [] if self._linked_script != None: self._linked_script._update_linked_device_selection = None self._linked_script = None #self._disconnect_notifier.set_mode(0) self.log_message('<<<<<<<<<<<<<<<<<<<<<<<<< Codec log closed >>>>>>>>>>>>>>>>>>>>>>>>>') ControlSurface.disconnect(self) return None def connect_script_instances(self, instanciated_scripts): found = False for s in instanciated_scripts: if '_codec_version' in dir(s): if s._codec_version == self._version_check: if s._host_name == ('MonOhm'): self.log_message('found codec version ' + str(s._codec_version) + ' in script ' + str(s._host_name)) found = True self._linked_script = s self._linked_script._update_linked_device_selection = self._update_linked_device_selection if not self._session._is_linked() and self._link_mixer is True: self._session.set_offsets(LINK_OFFSET[0], LINK_OFFSET[1]) self._session._link() else: self.log_message('version mismatch: Monomod version ' + str(self._version_check) + ' vs. Host version ' + str(s._codec_version)) if found == False: for s in instanciated_scripts: if '_codec_version' in dir(s): if s._codec_version == self._version_check: if s._host_name == 'BlockMod': self.log_message('found codec version ' + str(s._codec_version) + ' in script ' + str(s._host_name)) self._linked_script = s self._linked_script._update_linked_device_selection = self._update_linked_device_selection if not self._session._is_linked() and self._link_mixer is True: self._session.set_offsets(LINK_OFFSET[0], LINK_OFFSET[1]) self._session._link() else: self.log_message('version mismatch: Monomod version ' + str(self._version_check) + ' vs. Host version ' + str(s._codec_version)) #self.log_message('hosts: ' + str(self._hosts))""" def update_display(self): ControlSurface.update_display(self) #since we are overriding this from the inherited method, we need to call the original routine as well self._timer = (self._timer + 1) % 256 if(self._timer == 0): self._shift_pressed_timer = -12 if(self._local_ring_control is False): self.send_ring_leds() self.flash() def handle_sysex(self, midi_bytes): #self._send_midi(tuple([240, 00, 01, 97, 04, 15, 01, 247])) #response = [long(0),long(0)] #self.log_message(response) pass def flash(self): if(self.flash_status > 0): for control in self.controls: if isinstance(control, MonoButtonElement): control.flash(self._timer) def send_ring_leds(self): leds = [240, 0, 1, 97, 4, 31] for column in range(8): for row in range(4): wheel = self._dial[column][row] bytes = wheel._get_ring() leds.append(bytes[0]) leds.append(int(bytes[1]) + int(bytes[2])) #if(row == 1 and column == 0): # self.log_message(str(leds) + ' ' + str(bytes[0]) + ' ' + str(bytes[1]) + ' ' + str(bytes[2])) leds.append(247) self._send_midi(tuple(leds)) def set_absolute_mode(self, val = 1): self._absolute_mode = (val!=0) if self._absolute_mode is True: self._send_midi(tuple([240, 0, 1, 97, 4, 17, 0, 0, 0, 0, 0, 0, 0, 0, 247])) else: self._send_midi(tuple([240, 0, 1, 97, 4, 17, 127, 127, 127, 127, 127, 127, 127, 127, 247])) def set_local_ring_control(self, val = 1): self._local_ring_control = (val!=0) if(self._local_ring_control is True): #self._send_midi(tuple([240, 0, 1, 97, 4, 32, 0, 247])) self._send_midi(tuple([240, 0, 1, 97, 4, 8, 72, 247])) else: #self._send_midi(tuple([240, 0, 1, 97, 4, 32, 1, 247])) self._send_midi(tuple([240, 0, 1, 97, 4, 8, 64, 247])) def device_follows_track(self, val): self._device_selection_follows_track_selection = (val == 1) return self """m4l bridge""" def generate_strip_string(self, display_string): NUM_CHARS_PER_DISPLAY_STRIP = 12 if (not display_string): return (' ' * NUM_CHARS_PER_DISPLAY_STRIP) if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))): display_string = display_string[:-2] if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)): for um in [' ', 'i', 'o', 'u', 'e', 'a']: while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)): um_pos = display_string.rfind(um, 1) display_string = (display_string[:um_pos] + display_string[(um_pos + 1):]) else: display_string = display_string.center((NUM_CHARS_PER_DISPLAY_STRIP - 1)) ret = u'' for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)): if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)): ret += ' ' else: ret += display_string[i] ret += ' ' assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP) return ret def notification_to_bridge(self, name, value, sender): if(isinstance(sender, CodecEncoderElement)): self._monobridge._send(sender.name, 'lcd_name', str(self.generate_strip_string(name))) self._monobridge._send(sender.name, 'lcd_value', str(self.generate_strip_string(value))) def touched(self): if not self._host.is_enabled(): if self._touched is 0: self._monobridge._send('touch', 'on') self.schedule_message(2, self.check_touch) self._touched +=1 def check_touch(self): if self._touched > 5: self._touched = 5 elif self._touched > 0: self._touched -= 1 if self._touched is 0: self._monobridge._send('touch', 'off') else: self.schedule_message(2, self.check_touch) def get_clip_names(self): clip_names = [] for scene in self._session._scenes: for clip_slot in scene._clip_slots: if clip_slot.has_clip() is True: clip_names.append(clip_slot._clip_slot)##.clip.name) return clip_slot._clip_slot ##self.log_message(str(clip_slot._clip_slot.clip.name)) return clip_names """overrides""" def allow_updates(self, allow_updates): for component in self.components: component.set_allow_update(int(allow_updates!=0)) def set_device_component(self, device_component): if self._device_component != None: self._device_component._lock_callback = None assert (device_component != None) assert isinstance(device_component, DeviceComponent) self._device_component = device_component self._device_component._lock_callback = self._toggle_lock #old: self._device_component.set_lock_callback(self._toggle_lock) if self._device_select_buttons != None: for button in self._device_select_buttons: button.send_value(self._device_select_buttons.index(button) == self._device.index(self._device_component)) self._update_device_selection() return None def _update_selected_device(self): if self._device_selection_follows_track_selection is True: self._update_device_selection() return None def _update_linked_device_selection(self, device): #self.log_message('codec received ' + str(device.name)) if self._device_component != None and device != None: if not self._device_component.is_locked(): self._device_component.set_device(device) def _get_num_tracks(self): return self.num_tracks def _update_device_selection(self): #self.log_message('_update_device_selection') if self._device_component != None: if not self._device_component.is_locked(): track = self.song().view.selected_track device_to_select = track.view.selected_device if ((device_to_select == None) and (len(track.devices) > 0)): device_to_select = track.devices[0] if (device_to_select != None): self.song().view.select_device(device_to_select) self._device_component.set_device(device_to_select) def _channelstrip_mute_value(self, channelstrip): def _mute_value(value): if not self._shift_pressed: self.log_message('shift not pressed') ChannelStripComponent._mute_value(channelstrip, value) return _mute_value def _channelstrip_solo_value(self, channelstrip): def _solo_value(value): if not self._shift_pressed: ChannelStripComponent._solo_value(channelstrip, value) return _solo_value def _mixer_next_track_value(self, mixer): def _next_track_value(value): if not self._shift_pressed: MixerComponent._next_track_value(mixer, value) return _next_track_value def _mixer_prev_track_value(self, mixer): def _prev_track_value(value): if not self._shift_pressed: MixerComponent._prev_track_value(mixer, value) return _prev_track_value
class MPK_mini_hero(ControlSurface): """ Script for Novation's Launchkey 25/49/61 keyboards """ def __init__(self, c_instance, identity_response=SIZE_RESPONSE): ControlSurface.__init__(self, c_instance) self._identity_response = identity_response with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._device_selection_follows_track_selection = True self._suggested_input_port = 'MPK mini' self._suggested_output_port = 'MPK mini' self._setup_buttons() self._setup_components() for component in self.components: component.set_enabled(True) # Puvodne False def refresh_state(self): ControlSurface.refresh_state(self) # for val in range(127): # self.schedule_message(2, self._send_midi, (144, val, 0)) # self.schedule_message(3, self._send_midi, (144, 9, 127)) def handle_sysex(self, midi_bytes): self._send_midi(LED_FLASHING_ON) self._update_mixer_offset() for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) self.request_rebuild_midi_map() def disconnect(self): ControlSurface.disconnect(self) self._encoders = None self._transport_view_modes = None self._send_midi(LED_FLASHING_OFF) self._send_midi(LIVE_MODE_OFF) def _setup_buttons(self): # Pads CC Mode self._scene_launch_button = make_pad_button(PAD_MODE_CC, 1, 'Scene_Launch_Button') self._overdub_button = make_pad_button(PAD_MODE_CC, 2, 'Session_Overdub_Button') self._ffwd_button = make_pad_button(PAD_MODE_CC, 3, 'FFwd_Button') self._clip_undo_button = make_pad_button(PAD_MODE_CC, 4, 'Clip_Undo_Button') self._prev_track_button = make_pad_button(PAD_MODE_CC, 5, 'Prev_Track_Button') self._next_track_button = make_pad_button(PAD_MODE_CC, 6, 'Next_Track_Button') self._rwd_button = make_pad_button(PAD_MODE_CC, 7, 'Rwd_Button') self._scene_stop_button = make_pad_button(PAD_MODE_CC, 9, 'Scene_Stop_Button') self._stop_button = make_pad_button(PAD_MODE_CC, 10, 'Stop_Button') self._play_button = make_pad_button(PAD_MODE_CC, 11, 'Play_Button') self._loop_button = make_pad_button(PAD_MODE_CC, 12, 'Loop_Button') self._rec_button = make_pad_button(PAD_MODE_CC, 13, 'Record_Button') # Pads Notes Mode self._clip_launch_buttons = [ make_pad_button(PAD_MODE_NOTES, index, 'Clip_Launch_%d' % index) for index in xrange(8) ] self._clip_stop_buttons = [ make_pad_button(PAD_MODE_NOTES, 8 + index, 'Clip_Stop_%d' % index) for index in xrange(8) ] # Encoders self._encoders = tuple([ make_encoder(21 + index, 'Device_Control_%d' % index) for index in xrange(8) ]) # Scenes self._scene_launch_buttons = [] for key_no in [0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24]: self._scene_launch_buttons.append( make_scene_button(key_no, 'Scene_Launch_%d' % key_no)) def _setup_components(self): # Session self._session = SessionComponent(8, len(self._scene_launch_buttons)) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.selected_scene().set_launch_button( self._scene_launch_button) self._session.set_stop_all_clips_button(self._scene_stop_button) for index in range(8): clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_launch_button(self._clip_launch_buttons[index]) clip_slot.name = 'Selected_Clip_Slot_' + str(index) self._session.set_stop_track_clip_buttons( tuple(self._clip_stop_buttons)) # Undo self._do_undo.subject = self._clip_undo_button # Transport transport = TransportComponent() transport.name = 'Transport' transport.set_stop_button(self._stop_button) transport.set_play_button(self._play_button) transport.set_record_button(self._rec_button) transport.set_loop_button(self._loop_button) self._transport_view_modes = TransportViewModeSelector( transport, self._session, self._ffwd_button, self._rwd_button) self._transport_view_modes.name = 'Transport_View_Modes' session_recording = SessionRecordingComponent( ClipCreator(), ViewControlComponent(), name='Session_Recording', is_enabled=False, layer=Layer(record_button=self._overdub_button)) # Device # device = DeviceComponent() # device.name = 'Device_Component' # self.set_device_component(device) # device.set_parameter_controls(self._encoders) # Navigation self._session_navigation = SessionNavigationComponent( name='Session_Navigation') self._session_navigation.set_next_track_button(self._next_track_button) self._session_navigation.set_prev_track_button(self._prev_track_button) # Playing # self._session.set_scene_launch_buttons(tuple(self._scene_launch_buttons)) for index in range(len(self._scene_launch_buttons)): scene = self._session.scene(index) scene.set_launch_button(self._scene_launch_buttons[index]) @subject_slot('value') def _do_undo(self, value): if value: if self.song().can_undo == 1: self.song().undo() self.show_message(str('UNDO')) def _dummy_listener(self, value): pass def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._update_mixer_offset() def _update_mixer_offset(self): all_tracks = self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks: track_index = list(all_tracks).index(selected_track) new_offset = track_index - track_index % num_strips self._session.set_offsets(new_offset, self._session.scene_offset())
class Launchkey(ControlSurface): """ Script for Novation's Launchkey 25/49/61 keyboards """ def __init__(self, c_instance, control_factory = LaunchkeyControlFactory(), identity_response = SIZE_RESPONSE): ControlSurface.__init__(self, c_instance) self._control_factory = control_factory self._identity_response = identity_response with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._device_selection_follows_track_selection = True self._suggested_input_port = 'Launchkey InControl' self._suggested_output_port = 'Launchkey InControl' self._has_sliders = True self._current_midi_map = None self._master_slider = make_slider(7, 'Master_Volume_Control') self._modes_buttons = [] for index in range(3): button = ButtonElement(IS_MOMENTARY, MIDI_NOTE_TYPE, 0, 13 + index) self._modes_buttons.append(button) self._modes_buttons[-1].add_value_listener(self._dummy_listener) self._setup_mixer() self._setup_session() self._setup_transport() self._setup_device() self._setup_navigation() for component in self.components: component.set_enabled(False) return def refresh_state(self): ControlSurface.refresh_state(self) self.schedule_message(2, self._send_midi, LIVE_MODE_ON) self.schedule_message(3, self._send_midi, SIZE_QUERY) def handle_sysex(self, midi_bytes): if midi_bytes[0:11] == self._identity_response: self._has_sliders = midi_bytes[11] != 48 self._send_midi(LED_FLASHING_ON) self._update_mixer_offset() for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) if self._has_sliders: self._mixer.master_strip().set_volume_control(self._master_slider) self._mixer.update() else: self._mixer.master_strip().set_volume_control(None) for index in range(len(self._sliders)): self._mixer.channel_strip(index).set_volume_control(None) self._mixer.channel_strip(index).set_mute_button(None) slider = self._sliders[index] slider.release_parameter() self._mixer.selected_strip().set_volume_control(self._master_slider) self.request_rebuild_midi_map() return def disconnect(self): ControlSurface.disconnect(self) for button in self._modes_buttons: if button.value_has_listener(self._dummy_listener): button.remove_value_listener(self._dummy_listener) self._modes_buttons = None self._encoders = None self._sliders = None self._strip_buttons = None self._master_slider = None self._current_midi_map = None self._transport_view_modes = None self._send_midi(LED_FLASHING_OFF) self._send_midi(LIVE_MODE_OFF) return def build_midi_map(self, midi_map_handle): self._current_midi_map = midi_map_handle ControlSurface.build_midi_map(self, midi_map_handle) def _setup_mixer(self): mute_solo_flip_button = make_button(59, 'Master_Button') self._mixer = SpecialMixerComponent(8) self._mixer.name = 'Mixer' self._mixer.selected_strip().name = 'Selected_Channel_Strip' self._mixer.master_strip().name = 'Master_Channel_Strip' self._mixer.master_strip().set_volume_control(self._master_slider) self._sliders = [] self._strip_buttons = [] for index in range(8): strip = self._mixer.channel_strip(index) strip.name = 'Channel_Strip_' + str(index) strip.set_invert_mute_feedback(True) self._sliders.append(make_slider(41 + index, 'Volume_Control_%d' % index)) strip.set_volume_control(self._sliders[-1]) self._strip_buttons.append(make_button(51 + index, 'Mute_Button_%d' % index)) self._mixer.set_strip_mute_solo_buttons(tuple(self._strip_buttons), mute_solo_flip_button) def _setup_session(self): scene_launch_button = self._control_factory.create_scene_launch_button() scene_stop_button = self._control_factory.create_scene_stop_button() self._session = SessionComponent(8, 0) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.selected_scene().set_launch_button(scene_launch_button) self._session.selected_scene().set_triggered_value(GREEN_BLINK) self._session.set_stop_all_clips_button(scene_stop_button) scene_stop_button.set_on_off_values(AMBER_FULL, LED_OFF) self._session.set_mixer(self._mixer) self._session.set_stop_clip_value(AMBER_HALF) self._session.set_stop_clip_triggered_value(GREEN_BLINK) clip_launch_buttons = [] clip_stop_buttons = [] for index in range(8): clip_launch_buttons.append(self._control_factory.create_clip_launch_button(index)) clip_stop_buttons.append(self._control_factory.create_clip_stop_button(index)) clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_triggered_to_play_value(GREEN_BLINK) clip_slot.set_triggered_to_record_value(RED_BLINK) clip_slot.set_stopped_value(AMBER_FULL) clip_slot.set_started_value(GREEN_FULL) clip_slot.set_recording_value(RED_FULL) clip_slot.set_launch_button(clip_launch_buttons[-1]) clip_slot.name = 'Selected_Clip_Slot_' + str(index) self._session.set_stop_track_clip_buttons(tuple(clip_stop_buttons)) def _setup_transport(self): rwd_button = make_button(112, 'Rwd_Button') ffwd_button = make_button(113, 'FFwd_Button') stop_button = make_button(114, 'Stop_Button') play_button = make_button(115, 'Play_Button') loop_button = make_button(116, 'Loop_Button') rec_button = make_button(117, 'Record_Button') transport = TransportComponent() transport.name = 'Transport' transport.set_stop_button(stop_button) transport.set_play_button(play_button) transport.set_record_button(rec_button) transport.set_loop_button(loop_button) self._transport_view_modes = TransportViewModeSelector(transport, self._session, ffwd_button, rwd_button) self._transport_view_modes.name = 'Transport_View_Modes' def _setup_device(self): encoders = [ make_encoder(21 + index, 'Device_Control_%d' % index) for index in xrange(8) ] self._encoders = tuple(encoders) device = DeviceComponent() device.name = 'Device_Component' self.set_device_component(device) device.set_parameter_controls(self._encoders) def _setup_navigation(self): self._next_track_button = self._control_factory.create_next_track_button() self._prev_track_button = self._control_factory.create_prev_track_button() self._session_navigation = SessionNavigationComponent(name='Session_Navigation') self._session_navigation.set_next_track_button(self._next_track_button) self._session_navigation.set_prev_track_button(self._prev_track_button) def _dummy_listener(self, value): pass def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._update_mixer_offset() def _update_mixer_offset(self): all_tracks = self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks: track_index = list(all_tracks).index(selected_track) new_offset = track_index - track_index % num_strips self._session.set_offsets(new_offset, self._session.scene_offset())
class MidiFighterTwister(ControlSurface): __module__ = __name__ __doc__ = "MidiFighterTwister class" def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.__c_instance = c_instance self.show_message('Script initiated') self.init() def init(self): # initialize listeners, caches and colors self.flush_all() self.mf_disable_bank_buttons() self.mf_init_page_config() self.mf_init_light_pages() # Start listeners to call dispatcher self.song().view.add_detail_clip_listener( self.dispatch_detail_clip_listener) self.song().add_current_song_time_listener( self.dispatch_current_song_time_listener) self.song().view.add_selected_track_listener( self.dispatch_selected_track_listener) self.device_listener_wrapper() # Initialize the sequencer buttons self.sequencer_init_buttons() self.sequencer_init_rotaries() self.init_clip_page() self.init_pad_page() self.init_device_params() def flush_all(self): for poti in range(64): for channel in range(4): self._send_midi((175 + channel, poti, 0)) def mf_init_page_config(self): # Initialize configuration parameters # Sequencer configuration self.sequencer_page_default_color = 1 self.sequencer_current_page_color_index = self.sequencer_page_default_color self.sequencer_base_default_note = 36 self.sequencer_current_selected_note = self.sequencer_base_default_note self.sequencer_clip_position_16th = None # Midi Channels self.rotary_midi_channel = 175 + 1 self.ring_midi_channel = 175 + 1 self.switch_midi_channel = 175 + 2 self.light_midi_channel = 175 + 2 # Pages cc map self.clip_page_cc = range(0, 16) self.sequencer_page_cc = range(16, 32) self.note_page_cc = range(32, 48) self.control_page_cc = range(48, 64) # Pages init color self.clip_page_colors = [1] * 16 self.sequencer_page_colors = [self.sequencer_page_default_color] * 16 self.note_page_colors = range(1, 127, 16) * 2 #self.note_page_colors = [0] * 16 self.control_page_colors = [1] * 16 # Status cache for sequencer self.switch_encoder_status_cache = [False] * 64 # List to store ButtonElements in self.switch_encoder_buttons = [False] * 64 # Status cache for rotaries self.rotary_encoder_potis = [False] * 64 def mf_init_light_pages(self): sequencer_page_map = zip(self.sequencer_page_cc, self.sequencer_page_colors) for light_encoder_cc, light_color_cc in sequencer_page_map: self._mf_set_light(light_encoder_cc, light_color_cc, False) note_page_map = zip(self.note_page_cc, self.note_page_colors) for light_encoder_cc, light_color_cc in note_page_map: self._mf_set_light(light_encoder_cc, light_color_cc, False) def _mf_set_light(self, light_encoder_cc, light_color_cc, status): # Sets color on midi channel 2 (177) end updates status cache # for sequencer to remember statuses self._send_midi((self.light_midi_channel, light_encoder_cc, light_color_cc)) self.switch_encoder_status_cache[light_encoder_cc] = status def mf_disable_bank_buttons(self): # Workaround for not sending values to track when pressing bank buttons self.padm0 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 4, 0) self.padm1 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 4, 1) self.padm2 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 4, 2) self.padm3 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 4, 3) self.padm0.add_value_listener(self.bank_buttons_dummy, identify_sender=True) self.padm1.add_value_listener(self.bank_buttons_dummy, identify_sender=True) self.padm2.add_value_listener(self.bank_buttons_dummy, identify_sender=True) self.padm3.add_value_listener(self.bank_buttons_dummy, identify_sender=True) def bank_buttons_dummy(self): pass def dispatch_detail_clip_listener(self): self.current_clip = self.song().view.highlighted_clip_slot.clip self.init_sequencer() try: if self.current_clip.is_midi_clip and not self.current_clip.notes_has_listener: # Update leds when notes are added or removed self.current_clip.add_notes_listener( self._sequencer_update_notes_to_light) self.init_sequencer() else: self.sequencer_reset_colors() except AttributeError: pass def dispatch_current_song_time_listener(self): self.sequencer_light_follows_beat() def dispatch_selected_track_listener(self): self.device_auto_select() self.device_listener_wrapper() def device_listener_wrapper(self): selected_track = self.song().view.selected_track if not selected_track.devices_has_listener(self.device_auto_select): self.song().view.selected_track.add_devices_listener( self.device_auto_select) # Sequencer def init_sequencer(self): self.sequencer_current_selected_note = self.sequencer_base_default_note self.sequencer_current_page_color_index = self.sequencer_page_default_color self._sequencer_update_notes_to_light() def sequencer_init_buttons(self): for switch_encoder_cc in self.sequencer_page_cc: self.switch_encoder_buttons[switch_encoder_cc] = ButtonElement( IS_MOMENTARY, MIDI_CC_TYPE, 1, switch_encoder_cc) self.switch_encoder_buttons[switch_encoder_cc].add_value_listener( self.sequencer_button_press, identify_sender=True) self.padl14 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 14) self.padr17 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 17) self.padl16 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 16) self.padr19 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 19) self.padl14.add_value_listener(self.sequencer_side_button_press, identify_sender=True) self.padr17.add_value_listener(self.sequencer_side_button_press, identify_sender=True) self.padl16.add_value_listener(self.sequencer_side_button_press, identify_sender=True) self.padr19.add_value_listener(self.sequencer_side_button_press, identify_sender=True) def sequencer_init_rotaries(self): for rotary_encoder_cc in self.sequencer_page_cc: self.rotary_encoder_potis[rotary_encoder_cc] = EncoderElement( MIDI_CC_TYPE, 0, rotary_encoder_cc, Live.MidiMap.MapMode.absolute) self.rotary_encoder_potis[rotary_encoder_cc].add_value_listener(self.sequencer_rotary_change, identify_sender=True) def sequencer_rotary_change(self, value, sender): try: self.current_clip except AttributeError: return False if self.current_clip.is_midi_clip: cc_value = sender._msg_identifier if value > 0: if not self.switch_encoder_status_cache[cc_value]: self._send_midi((self.light_midi_channel, cc_value, self.sequencer_current_light_on_color)) self._send_midi(( self.ring_midi_channel, cc_value, 100)) self.switch_encoder_status_cache[cc_value] = True self.current_clip.set_notes(((self.sequencer_current_selected_note, cc_value % 16 * 0.25, 0.25, value, False),)) elif value == 0: self._send_midi((self.light_midi_channel, cc_value, self.sequencer_current_page_color)) self.current_clip.remove_notes( cc_value % 16 * 0.25, self.sequencer_current_selected_note, 0.25, 1) self.switch_encoder_status_cache[cc_value] = False def sequencer_button_press(self, value, sender): try: self.current_clip except AttributeError: return False if self.current_clip.is_midi_clip: cc_value = sender._msg_identifier if value > 0: if not self.switch_encoder_status_cache[cc_value]: self._send_midi((self.light_midi_channel, cc_value, self.sequencer_current_light_on_color)) self.current_clip.set_notes((( self.sequencer_current_selected_note, cc_value % 16 * 0.25, 0.25, 100, False),)) self.switch_encoder_status_cache[cc_value] = True self._send_midi((self.ring_midi_channel, cc_value, 100)) else: self._send_midi((self.light_midi_channel, cc_value, self.sequencer_current_page_color)) self._send_midi((self.ring_midi_channel, cc_value, 0)) self.current_clip.remove_notes( cc_value % 16 * 0.25, self.sequencer_current_selected_note, 0.25, 1) self.switch_encoder_status_cache[cc_value] = False def sequencer_side_button_press(self, value, sender): try: cc_value = sender._msg_identifier if value > 0: # Note/clolor up/down if cc_value == 14 and self.sequencer_current_selected_note > 0: self.sequencer_current_selected_note = self.sequencer_current_selected_note - 1 self.sequencer_current_page_color_index = self.sequencer_current_page_color_index - 16 self._sequencer_update_notes_to_light() self.sequencer_clip_position_16th = None self.show_message("Selected Midi Note: "+str(self.sequencer_current_selected_note)) if cc_value == 17 and self.sequencer_current_selected_note < 127: self.sequencer_current_selected_note = self.sequencer_current_selected_note + 1 self.sequencer_current_page_color_index = self.sequencer_current_page_color_index + 16 self._sequencer_update_notes_to_light() self.sequencer_clip_position_16th = None self.show_message("Selected Midi Note: "+str(self.sequencer_current_selected_note)) # New/duplicate clip if cc_value == 16 and self.sequencer_current_selected_note > 0: self.duplicate_clip() if cc_value == 19 and self.sequencer_current_selected_note > 0: self.session_record() except AttributeError: pass def sequencer_light_follows_beat(self): try: if self.current_clip.is_midi_clip: if self.sequencer_clip_position_16th == None: self.sequencer_clip_position_16th = int(self.current_clip.playing_position / 0.25) if self.switch_encoder_status_cache[self.sequencer_page_cc[self.sequencer_clip_position_16th]]: self._send_midi((177, self.sequencer_page_cc[self.sequencer_clip_position_16th], self.sequencer_current_light_on_color)) else: self._send_midi((177, self.sequencer_page_cc[self.sequencer_clip_position_16th], self.sequencer_current_page_color)) elif self.sequencer_clip_position_16th != int(self.current_clip.playing_position/0.25): if self.switch_encoder_status_cache[self.sequencer_page_cc[self.sequencer_clip_position_16th]]: self._send_midi((177, self.sequencer_page_cc[self.sequencer_clip_position_16th], self.sequencer_current_light_on_color)) else: self._send_midi((177, self.sequencer_page_cc[self.sequencer_clip_position_16th], self.sequencer_current_page_color)) self.sequencer_clip_position_16th = int(self.current_clip.playing_position/0.25) self._send_midi((177, self.sequencer_page_cc[self.sequencer_clip_position_16th], self.sequencer_current_light_beat_color)) except IndexError: pass @property def sequencer_current_light_on_color(self): # light on color to be relative to page color return self.sequencer_current_page_color + 32 % 128 @property def sequencer_current_light_beat_color(self): # light on color to be relative to page color return self.sequencer_current_page_color + 64 % 128 @property def sequencer_current_page_color(self): return self.sequencer_current_page_color_index % 128 def _sequencer_get_midi_notes(self, note): # self.current_clip.get_notes(start, self.sequencer_current_selected_note, # selection_length, hight) try: return self.current_clip.get_notes(0, note, 4, 1) except AttributeError: return [] def _sequencer_update_notes_to_light(self): self.sequencer_reset_colors() notes_for_current_selected_note = self._sequencer_get_midi_notes( self.sequencer_current_selected_note) for note in notes_for_current_selected_note: light_encoder_cc = int(note[1]*4+self.sequencer_page_cc[0]) self._send_midi((self.ring_midi_channel, light_encoder_cc, note[3])) self._mf_set_light(light_encoder_cc, self.sequencer_current_light_on_color, True) def sequencer_reset_colors(self): for light_encoder_cc in self.sequencer_page_cc: self._mf_set_light(light_encoder_cc, self.sequencer_current_page_color, False) self._send_midi((self.ring_midi_channel, light_encoder_cc, 0)) def duplicate_clip(self): self.log_message("duplicate clip") #if self._clip_slot and self._clip_slot.has_clip: # slot_name = self._clip_slot.clip.name # track = self._clip_slot.canonical_parent current_track = self.song().view.selected_track current_clip_slot = self.song().view.highlighted_clip_slot self.song().duplicate_scene(list(current_track.clip_slots).index(current_clip_slot)) #new_clip = current_track.duplicate_clip_slot( # list(current_track.clip_slots).index(current_clip_slot)+1) #self.log_message(new_clip) #selected_track = self.song().view.selected_track #selected_track.duplicate_clip_slot(selected_track) def session_record(self): self.log_message("session record") #self.song().trigger_session_record() # Clip page setion def init_clip_page(self): num_tracks = 4 num_scenes = 3 self.flash_status = 1 self.Mixer = MixerComponent(4, 3) # Volencoder self.volencoders = [None for index in range(num_tracks)] for index in range(num_tracks): self.volencoders[index] = EncoderElement( MIDI_CC_TYPE, 0, index, Live.MidiMap.MapMode.absolute) self.Mixer.channel_strip(index).set_volume_control( self.volencoders[index]) # Sendencoder for index in range(num_tracks): encoder_cc_send_1 = index + num_tracks encoder_cc_send_2 = index + num_tracks * 2 send1 = EncoderElement(MIDI_CC_TYPE, 0, encoder_cc_send_1, Live.MidiMap.MapMode.absolute) send2 = EncoderElement(MIDI_CC_TYPE, 0, encoder_cc_send_2, Live.MidiMap.MapMode.absolute) self.Mixer.channel_strip(index).set_send_controls((send1, send2)) # Panencoder for index in range(num_tracks): encoder_cc_pan = index + num_tracks * 3 pan = EncoderElement(MIDI_CC_TYPE, 0, encoder_cc_pan, Live.MidiMap.MapMode.absolute) self.Mixer.channel_strip(index).set_pan_control(pan) # Arm-/selectbuttons for index in range(num_tracks): armbutton = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 1, index + 12) self.Mixer.channel_strip(index).set_arm_button(armbutton) self.Mixer.channel_strip(index).set_select_button(armbutton) # Navigation buttons self.padl11 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 11) self.padr8 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 8) self.padl10 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 10) self.padr13 = ButtonElement(IS_MOMENTARY, MIDI_CC_TYPE, 3, 13) self.grid = [None for index in range(num_tracks * 3)] for index in range(num_tracks * 3): self.grid[index] = ButtonElement( IS_MOMENTARY, MIDI_CC_TYPE, 1, index) self.matrix = ButtonMatrixElement() for row in range(num_scenes): button_row = [] for column in range(num_tracks): button_row.append(self.grid[column+(row*4)]) self.log_message(str(column+(row*4))) self.matrix.add_row(tuple(button_row)) self.Session = SessionComponent(num_tracks, num_scenes) self.Session.name = "Session" self.Session.set_offsets(0, 0) self.Session.set_mixer(self.Mixer) self.Session._do_show_highlight() self.set_highlighting_session_component(self.Session) self.Session.set_track_bank_buttons(self.padl11, self.padr8) self.Session.set_scene_bank_buttons(self.padr13, self.padl10) self.scene = [None for index in range(num_scenes)] for row in range(num_scenes): self.scene[row] = self.Session.scene(row) self.scene[row].name = 'Scene_'+str(row) for column in range(num_tracks): clip_slot = self.scene[row].clip_slot(column) clip_slot.name = str(column)+'_Clip_Slot'+str(row) self.scene[row].clip_slot(column).set_triggered_to_play_value(35) self.scene[row].clip_slot(column).set_stopped_value(68) self.scene[row].clip_slot(column).set_started_value(45) self.scene[row].clip_slot(column).set_triggered_to_record_value(100) self.scene[row].clip_slot(column).set_recording_value(80) for column in range(num_tracks): for row in range(num_scenes): self.scene[row].clip_slot(column).set_launch_button(self.grid[column+(row*4)]) for index in range(num_tracks*num_scenes): self.grid[index].clear_send_cache() def update_display(self): # Called every 100 ms ControlSurface.update_display(self) self.refresh_state() self.Session.set_enabled(True) self.Session.update() # Sequencer hack try: for light_encoder_cc in self.sequencer_page_cc: self._send_midi((self.ring_midi_channel, light_encoder_cc, 0)) notes_for_current_selected_note = self._sequencer_get_midi_notes( self.sequencer_current_selected_note) for note in notes_for_current_selected_note: light_encoder_cc = int(note[1]*4+self.sequencer_page_cc[0]) self._send_midi((self.ring_midi_channel, light_encoder_cc, note[3])) except AttributeError: pass # Pad Section def init_pad_page(self): self.pad_device_params() PAD_TRANSLATION = ( (0, 0, 32, 1), (1, 0, 33, 1), (2, 0, 34, 1), (3, 0, 35, 1), (0, 1, 36, 1), (1, 1, 37, 1), (2, 1, 38, 1), (3, 1, 39, 1), (0, 2, 40, 1), (1, 2, 41, 1), (2, 2, 42, 1), (3, 2, 43, 1), (0, 3, 44, 1), (1, 3, 45, 1), (2, 3, 46, 1), (3, 3, 47, 1)) self.set_pad_translations(PAD_TRANSLATION) self._device_selection_follows_track_selection = True def pad_device_params(self): device_param_controls = [] for param in self.note_page_cc[:8]: self.rotary_encoder_potis[param] = EncoderElement( MIDI_CC_TYPE, 0, param, Live.MidiMap.MapMode.absolute) self.rotary_encoder_potis[param].release_parameter() self.rotary_encoder_potis[param].send_value(0, True) self.rotary_encoder_potis[param].clear_send_cache() device_param_controls.append(self.rotary_encoder_potis[param]) device = DeviceComponent() device.name = 'Device_Component pad' device.set_parameter_controls(tuple(device_param_controls)) self.set_device_component(device) #def scrolling(self): # self.application().view.scroll_view(ndir, 'Detail/DeviceChain', True) # Live.Song.Song.View.selected_track #Live.Song.Song.View.select_device()[0] # Device parameter section def init_device_params(self): device_param_controls = [] device_bank_buttons = [] for param in self.control_page_cc[:8]: self.rotary_encoder_potis[param] = EncoderElement( MIDI_CC_TYPE, 0, param, Live.MidiMap.MapMode.absolute) self.switch_encoder_buttons[param] = ButtonElement( IS_MOMENTARY, MIDI_CC_TYPE, 1, param) self.rotary_encoder_potis[param].release_parameter() self.rotary_encoder_potis[param].send_value(0, True) self.rotary_encoder_potis[param].clear_send_cache() device_param_controls.append(self.rotary_encoder_potis[param]) device_bank_buttons.append(self.switch_encoder_buttons[param]) device = DeviceComponent() device.name = 'Device_Component' device.set_parameter_controls(tuple(device_param_controls)) device.set_bank_buttons(tuple(device_bank_buttons)) device.set_on_off_button(ButtonElement( IS_MOMENTARY, MIDI_CC_TYPE, 1, 56)) self.set_device_component(device) def device_auto_select(self): # Iterates through devices within a track and assigns the first # DrumPad device to activate the individual drum's device. # Use first device in case none is a DrumPad device. selected_track = self.song().view.selected_track devices = selected_track.devices for device in devices: if device.can_have_drum_pads: self.current_drum_device = device pad_device = self.current_drum_device.view.selected_chain.devices[0] self.song().view.select_device(pad_device) if not self.current_drum_device.view.selected_drum_pad_has_listener( self.device_update_current_note): self.current_drum_device.view.add_selected_drum_pad_listener( self.device_update_current_note) break else: self.song().view.select_device(devices[0]) def device_update_current_note(self): current_note = self.current_drum_device.view.selected_drum_pad.note self.sequencer_current_selected_note = current_note # Update light of active pad #self._send_midi((self.light_midi_channel, light_encoder_cc, 63)) try: self.current_clip = self.song().view.highlighted_clip_slot.clip self.current_clip.is_midi_clip self._sequencer_update_notes_to_light() except AttributeError: pass
class Launchkey(ControlSurface): """ Script for Novation's Launchkey 25/49/61 keyboards """ def __init__(self, c_instance, control_factory=LaunchkeyControlFactory(), identity_response=SIZE_RESPONSE): ControlSurface.__init__(self, c_instance) self._control_factory = control_factory self._identity_response = identity_response with self.component_guard(): self.set_pad_translations(PAD_TRANSLATIONS) self._suggested_input_port = 'Launchkey InControl' self._suggested_output_port = 'Launchkey InControl' self._has_sliders = True self._current_midi_map = None self._master_slider = make_slider(7, 'Master_Volume_Control') self._modes_buttons = [] for index in range(3): button = ButtonElement(IS_MOMENTARY, MIDI_NOTE_TYPE, 0, 13 + index) self._modes_buttons.append(button) self._modes_buttons[-1].add_value_listener( self._dummy_listener) self._setup_mixer() self._setup_session() self._setup_transport() self._setup_device() self._setup_navigation() for component in self.components: component.set_enabled(False) return def refresh_state(self): ControlSurface.refresh_state(self) self.schedule_message(2, self._send_midi, LIVE_MODE_ON) self.schedule_message(3, self._send_midi, SIZE_QUERY) def handle_sysex(self, midi_bytes): if midi_bytes[0:11] == self._identity_response: self._has_sliders = midi_bytes[11] != 48 self._send_midi(LED_FLASHING_ON) self._update_mixer_offset() for control in self.controls: if isinstance(control, InputControlElement): control.clear_send_cache() for component in self.components: component.set_enabled(True) if self._has_sliders: self._mixer.master_strip().set_volume_control( self._master_slider) self._mixer.update() else: self._mixer.master_strip().set_volume_control(None) for index in range(len(self._sliders)): self._mixer.channel_strip(index).set_volume_control(None) self._mixer.channel_strip(index).set_mute_button(None) slider = self._sliders[index] slider.release_parameter() self._mixer.selected_strip().set_volume_control( self._master_slider) self.request_rebuild_midi_map() return def disconnect(self): ControlSurface.disconnect(self) for button in self._modes_buttons: if button.value_has_listener(self._dummy_listener): button.remove_value_listener(self._dummy_listener) self._modes_buttons = None self._encoders = None self._sliders = None self._strip_buttons = None self._master_slider = None self._current_midi_map = None self._transport_view_modes = None self._send_midi(LED_FLASHING_OFF) self._send_midi(LIVE_MODE_OFF) return def build_midi_map(self, midi_map_handle): self._current_midi_map = midi_map_handle ControlSurface.build_midi_map(self, midi_map_handle) def _setup_mixer(self): mute_solo_flip_button = make_button(59, 'Master_Button') self._mixer = SpecialMixerComponent(8) self._mixer.name = 'Mixer' self._mixer.selected_strip().name = 'Selected_Channel_Strip' self._mixer.master_strip().name = 'Master_Channel_Strip' self._mixer.master_strip().set_volume_control(self._master_slider) self._sliders = [] self._strip_buttons = [] for index in range(8): strip = self._mixer.channel_strip(index) strip.name = 'Channel_Strip_' + str(index) strip.set_invert_mute_feedback(True) self._sliders.append( make_slider(41 + index, 'Volume_Control_%d' % index)) strip.set_volume_control(self._sliders[-1]) self._strip_buttons.append( make_button(51 + index, 'Mute_Button_%d' % index)) self._mixer.set_strip_mute_solo_buttons(tuple(self._strip_buttons), mute_solo_flip_button) def _setup_session(self): scene_launch_button = self._control_factory.create_scene_launch_button( ) scene_stop_button = self._control_factory.create_scene_stop_button() self._session = SessionComponent(8, 0) self._session.name = 'Session_Control' self._session.selected_scene().name = 'Selected_Scene' self._session.selected_scene().set_launch_button(scene_launch_button) self._session.selected_scene().set_triggered_value(GREEN_BLINK) self._session.set_stop_all_clips_button(scene_stop_button) scene_stop_button.set_on_off_values(AMBER_FULL, LED_OFF) self._session.set_mixer(self._mixer) self._session.set_stop_clip_value(AMBER_HALF) self._session.set_stop_clip_triggered_value(GREEN_BLINK) clip_launch_buttons = [] clip_stop_buttons = [] for index in range(8): clip_launch_buttons.append( self._control_factory.create_clip_launch_button(index)) clip_stop_buttons.append( self._control_factory.create_clip_stop_button(index)) clip_slot = self._session.selected_scene().clip_slot(index) clip_slot.set_triggered_to_play_value(GREEN_BLINK) clip_slot.set_triggered_to_record_value(RED_BLINK) clip_slot.set_stopped_value(AMBER_FULL) clip_slot.set_started_value(GREEN_FULL) clip_slot.set_recording_value(RED_FULL) clip_slot.set_launch_button(clip_launch_buttons[-1]) clip_slot.name = 'Selected_Clip_Slot_' + str(index) self._session.set_stop_track_clip_buttons(tuple(clip_stop_buttons)) def _setup_transport(self): rwd_button = make_button(112, 'Rwd_Button') ffwd_button = make_button(113, 'FFwd_Button') stop_button = make_button(114, 'Stop_Button') play_button = make_button(115, 'Play_Button') loop_button = make_button(116, 'Loop_Button') rec_button = make_button(117, 'Record_Button') transport = TransportComponent() transport.name = 'Transport' transport.set_stop_button(stop_button) transport.set_play_button(play_button) transport.set_record_button(rec_button) transport.set_loop_button(loop_button) self._transport_view_modes = TransportViewModeSelector( transport, self._session, ffwd_button, rwd_button) self._transport_view_modes.name = 'Transport_View_Modes' def _setup_device(self): encoders = [ make_encoder(21 + index, 'Device_Control_%d' % index) for index in xrange(8) ] self._encoders = tuple(encoders) device = DeviceComponent(device_selection_follows_track_selection=True) device.name = 'Device_Component' self.set_device_component(device) device.set_parameter_controls(self._encoders) def _setup_navigation(self): self._next_track_button = self._control_factory.create_next_track_button( ) self._prev_track_button = self._control_factory.create_prev_track_button( ) self._session_navigation = SessionNavigationComponent( name='Session_Navigation') self._session_navigation.set_next_track_button(self._next_track_button) self._session_navigation.set_prev_track_button(self._prev_track_button) def _dummy_listener(self, value): pass def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._update_mixer_offset() def _update_mixer_offset(self): all_tracks = self._session.tracks_to_use() selected_track = self.song().view.selected_track num_strips = self._session.width() if selected_track in all_tracks: track_index = list(all_tracks).index(selected_track) new_offset = track_index - track_index % num_strips self._session.set_offsets(new_offset, self._session.scene_offset())
class Midi_Fighter_64(ControlSurface): def __init__(self, c_instance): super(Midi_Fighter_64, self).__init__(c_instance) self._color_skin = make_rgb_skin() self._default_skin = make_default_skin() with self.component_guard(): global _map_modes _map_modes = Live.MidiMap.MapMode self.current_track_offset = 0 self.current_scene_offset = 0 # mixer global mixer num_tracks = 128 num_returns = 24 self.mixer = MixerComponent(num_tracks, num_returns) global active_mode #self._mode0() active_mode = "_mode1" self._set_active_mode() self._set_track_select_led() self.show_message("Powered by DJ TechTools") ''' def _mode4(self): self.show_message("_mode4 is active") # mixer global mixer # session global _session num_tracks = 8 num_scenes = 7 self._session = SessionComponent(num_tracks, num_scenes) clip_color_table = colors.LIVE_COLORS_TO_MIDI_VALUES.copy() clip_color_table[16777215] = 119 self._session.set_rgb_mode(colors.LIVE_COLORS_TO_MIDI_VALUES, colors.RGB_COLOR_TABLE) track_offset = self.current_track_offset scene_offset = self.current_scene_offset self._session.set_offsets(track_offset, scene_offset) self._session._reassign_scenes() self.set_highlighting_session_component(self._session) # clip launch buttons session_buttons = [60, 61, 62, 63, 92, 93, 94, 95, 56, 57, 58, 59, 88, 89, 90, 91, 52, 53, 54, 55, 84, 85, 86, 87, 48, 49, 50, 51, 80, 81, 82, 83, 44, 45, 46, 47, 76, 77, 78, 79, 40, 41, 42, 43, 72, 73, 74, 75, 36, 37, 38, 39, 68, 69, 70, 71] session_channels = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] session_types = [MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE] session_is_momentary = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self._pads = [ButtonElement(session_is_momentary[index], session_types[index], session_channels[index], session_buttons[index]) for index in range(num_tracks*num_scenes)] self._grid = ButtonMatrixElement(rows=[self._pads[(index*num_tracks):(index*num_tracks)+num_tracks] for index in range(num_scenes)]) self._session.set_clip_launch_buttons(self._grid) # LED feedback self._session._enable_skinning() for scene_index in range(num_scenes): scene = self._session.scene(scene_index) for track_index in range(num_tracks): clip_slot = scene.clip_slot(track_index) clip_slot.set_triggered_to_play_value(61) clip_slot.set_triggered_to_record_value(13) clip_slot.set_record_button_value(19) #clip_slot.set_stopped_value(49) #clip_slot.set_started_value(127) clip_slot.set_recording_value(13) self.delete_button = ConfigurableButtonElement(0, MIDI_NOTE_TYPE, 1, 67) self.delete_button.set_on_off_values(49, 55) self._session._link() self.refresh_state() self.clip_xtra_back = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 96) self.clip_xtra_back.add_value_listener(self._activate_mode1,identify_sender= False) self.clip_xtra_back.send_value(85) # transport global transport self.transport = TransportComponent() self.transport.name = 'Transport' overdub_button = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 64) overdub_button.set_on_off_values(13, 19) overdub_button.name = 'overdub_button' self.transport.set_overdub_button(overdub_button) if((hasattr(self, 'clip_xtra')) and (self.clip_xtra is not None)): self.clip_xtra.send_value(85) def _remove_mode4(self): # mixer global mixer # session global _session # clip launch buttons self._session.set_clip_launch_buttons(None) self.set_highlighting_session_component(None) self.current_track_offset = self._session._track_offset self.current_scene_offset = self._session._scene_offset self._session._unlink() self._session = None self.clip_xtra_back.send_value(0) self.clip_xtra_back.remove_value_listener(self._activate_mode1) self.clip_xtra_back = None # transport global transport self.transport.set_overdub_button(None) self.transport = None if((hasattr(self, 'clip_xtra')) and (self.clip_xtra is not None)): self.clip_xtra.send_value(91) ''' def _mode1(self): self.show_message("Script Loaded") # mixer global mixer # session global _session num_tracks = 8 num_scenes = 8 # self._session = SessionComponent(auto_name=True, is_enabled=False, enable_skinning=True) self._session = SessionComponent(num_tracks, num_scenes) clip_color_table = colors.LIVE_COLORS_TO_MIDI_VALUES.copy() clip_color_table[16777215] = 119 self._session.set_rgb_mode(colors.LIVE_COLORS_TO_MIDI_VALUES, colors.RGB_COLOR_TABLE) track_offset = self.current_track_offset scene_offset = self.current_scene_offset self._session.set_offsets(track_offset, scene_offset) self._session._reassign_scenes() self.set_highlighting_session_component(self._session) # clip launch buttons session_buttons = [ 64, 65, 66, 67, 96, 97, 98, 99, 60, 61, 62, 63, 92, 93, 94, 95, 56, 57, 58, 59, 88, 89, 90, 91, 52, 53, 54, 55, 84, 85, 86, 87, 48, 49, 50, 51, 80, 81, 82, 83, 44, 45, 46, 47, 76, 77, 78, 79, 40, 41, 42, 43, 72, 73, 74, 75, 36, 37, 38, 39, 68, 69, 70, 71 ] session_channels = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] #change all the session channels to 2 in order to use the first bank. This will potentially allow for blinking/flashing animations in the future. session_types = [ MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE ] session_is_momentary = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] self._pads = [ ButtonElement(session_is_momentary[index], session_types[index], session_channels[index], session_buttons[index]) for index in range(num_tracks * num_scenes) ] self._grid = ButtonMatrixElement(rows=[ self._pads[(index * num_tracks):(index * num_tracks) + num_tracks] for index in range(num_scenes) ]) self._session.set_clip_launch_buttons(self._grid) # LED feedback self._session._enable_skinning() for scene_index in range(num_scenes): scene = self._session.scene(scene_index) for track_index in range(num_tracks): clip_slot = scene.clip_slot(track_index) clip_slot.set_triggered_to_play_value(61) #orange-red clip_slot.set_triggered_to_record_value(13) #yellow clip_slot.set_record_button_value(5) #bright red #clip_slot.set_stopped_value(49) #blue #clip_slot.set_started_value(127) #dark red clip_slot.set_recording_value(13) #yellow # these are written in decimal format, correspond to the RGB_COLOR_TABLE in pushbase/colors.py """ # session navigation self.session_up = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 64) self.session_up.set_on_off_values(25, 31) self._session.set_page_up_button(self.session_up) self.session_down = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 65) self.session_down.set_on_off_values(25, 31) self._session.set_page_down_button(self.session_down) self.session_left = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 66) self.session_left.set_on_off_values(25, 31) self._session.set_page_left_button(self.session_left) self.session_right = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 67) # "ConfigurableButtonElement(1," was originally set to 0, fixed by Jademalo self.session_right.set_on_off_values(25, 31) self._session.set_page_right_button(self.session_right) self._session._link() self.refresh_state() self.clip_xtra = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 96) self.clip_xtra.add_value_listener(self._activate_mode4,identify_sender= False) self.clip_xtra.send_value(91) if((hasattr(self, 'clip_xtra_back')) and (self.clip_xtra_back is not None)): self.clip_xtra_back.send_value(91) """ def _remove_mode1(self): # mixer global mixer # session global _session # clip launch buttons self._session.set_clip_launch_buttons(None) self.set_highlighting_session_component(None) """ # session navigation self._session.set_page_up_button(None) self._session.set_page_down_button(None) self._session.set_page_left_button(None) self._session.set_page_right_button(None) self.current_track_offset = self._session._track_offset self.current_scene_offset = self._session._scene_offset self._session._unlink() self._session = None self.clip_xtra.send_value(0) self.clip_xtra.remove_value_listener(self._activate_mode4) self.clip_xtra = None if((hasattr(self, 'clip_xtra_back')) and (self.clip_xtra_back is not None)): self.clip_xtra_back.send_value(85) """ """ def _mode2(self): self.show_message("_mode2 is active") # mixer global mixer # session global _session num_tracks = 8 num_scenes = 7 self._session = SessionComponent(num_tracks, num_scenes) clip_color_table = colors.LIVE_COLORS_TO_MIDI_VALUES.copy() clip_color_table[16777215] = 119 self._session.set_rgb_mode(colors.LIVE_COLORS_TO_MIDI_VALUES, colors.RGB_COLOR_TABLE) track_offset = self.current_track_offset scene_offset = self.current_scene_offset self._session.set_offsets(track_offset, scene_offset) self._session._reassign_scenes() self.set_highlighting_session_component(self._session) # clip launch buttons session_buttons = [60, 61, 62, 63, 92, 93, 94, 121, 56, 57, 58, 59, 88, 89, 90, 122, 52, 53, 54, 55, 84, 85, 86, 123, 48, 49, 50, 51, 80, 81, 82, 124, 44, 45, 46, 47, 76, 77, 78, 125, 40, 41, 42, 43, 72, 73, 74, 126, 36, 37, 38, 39, 68, 69, 70, 127] # in mode 2, the last buttons in rows aren't used for launching clips and instead are used for launching scenes # because of this, the last clip-launching button in every row is moved out of range (121,122,123,124,125,126,127) so it doesn't interfere. clever! # 121-127 seems arbitrary, 100-107 probably would have worked just as well since the last midi fighter button is 99 anyways session_channels = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] session_types = [MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE] session_is_momentary = [1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0] self._pads = [ButtonElement(session_is_momentary[index], session_types[index], session_channels[index], session_buttons[index]) for index in range(num_tracks*num_scenes)] self._grid = ButtonMatrixElement(rows=[self._pads[(index*num_tracks):(index*num_tracks)+num_tracks] for index in range(num_scenes)]) self._session.set_clip_launch_buttons(self._grid) # session scene launch scene_buttons = [95, 91, 87, 83, 79, 75, 71] #the last buttons in every row, mentioned earlier scene_channels = [1, 1, 1, 1, 1, 1, 1] scene_types = [MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE] scene_momentarys = [1, 1, 1, 1, 1, 1, 1] self._scene_launch_buttons = [ButtonElement(scene_momentarys[index], scene_types[index], scene_channels[index], scene_buttons[index]) for index in range(num_scenes)] self._scene_launch_buttons = ButtonMatrixElement(rows=[self._scene_launch_buttons]) self._session.set_scene_launch_buttons(self._scene_launch_buttons) # LED feedback self._session._enable_skinning() for scene_index in range(num_scenes): scene = self._session.scene(scene_index) scene.set_scene_value(127) scene.set_no_scene_value(0) scene.set_triggered_value(61) for track_index in range(num_tracks): clip_slot = scene.clip_slot(track_index) clip_slot.set_triggered_to_play_value(61) clip_slot.set_triggered_to_record_value(13) clip_slot.set_record_button_value(19) #clip_slot.set_stopped_value(49) #clip_slot.set_started_value(127) clip_slot.set_recording_value(13) self._session._link() self.refresh_state() if((hasattr(self, 'scene_shift')) and (self.scene_shift is not None)): self.scene_shift.send_value(127) def _remove_mode2(self): # mixer global mixer # session global _session # clip launch buttons self._session.set_clip_launch_buttons(None) self.set_highlighting_session_component(None) # session scene launch self._scene_launch_buttons = None self._session.set_scene_launch_buttons(None) self.current_track_offset = self._session._track_offset self.current_scene_offset = self._session._scene_offset self._session._unlink() self._session = None if((hasattr(self, 'scene_shift')) and (self.scene_shift is not None)): self.scene_shift.send_value(66) """ """ def _mode0(self): self.show_message("_mode0 is active") # mixer global mixer self.scene_shift = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 99) self.scene_shift.add_value_listener(self._activate_shift_mode2,identify_sender= False) self.scene_shift.send_value(66) self.shift_mixer = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 98) self.shift_mixer.add_value_listener(self._activate_shift_mode3,identify_sender= False) self.shift_mixer.send_value(37) def _remove_mode0(self): # mixer global mixer self.scene_shift.send_value(0) self.scene_shift.remove_value_listener(self._activate_shift_mode2) self.scene_shift = None self.shift_mixer.send_value(0) self.shift_mixer.remove_value_listener(self._activate_shift_mode3) self.shift_mixer = None """ """ def _mode3(self): self.show_message("_mode3 is active") # mixer # the set_on_off_values were originally completely different, fixed by Jademalo global mixer arm_specific_0 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 40) arm_specific_0.set_on_off_values(5, 7) self.mixer.channel_strip(0).set_arm_button(arm_specific_0) arm_specific_1 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 41) arm_specific_1.set_on_off_values(5, 7) self.mixer.channel_strip(1).set_arm_button(arm_specific_1) arm_specific_2 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 42) arm_specific_2.set_on_off_values(5, 7) self.mixer.channel_strip(2).set_arm_button(arm_specific_2) arm_specific_3 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 43) arm_specific_3.set_on_off_values(5, 7) self.mixer.channel_strip(3).set_arm_button(arm_specific_3) arm_specific_4 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 72) arm_specific_4.set_on_off_values(5, 7) self.mixer.channel_strip(4).set_arm_button(arm_specific_4) arm_specific_5 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 73) arm_specific_5.set_on_off_values(5, 7) self.mixer.channel_strip(5).set_arm_button(arm_specific_5) arm_specific_6 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 74) arm_specific_6.set_on_off_values(5, 7) self.mixer.channel_strip(6).set_arm_button(arm_specific_6) arm_specific_7 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 75) arm_specific_7.set_on_off_values(5, 7) self.mixer.channel_strip(7).set_arm_button(arm_specific_7) solo_specific_0 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 44) solo_specific_0.set_on_off_values(37, 47) self.mixer.channel_strip(0).set_solo_button(solo_specific_0) solo_specific_1 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 45) solo_specific_1.set_on_off_values(37, 47) self.mixer.channel_strip(1).set_solo_button(solo_specific_1) solo_specific_2 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 46) solo_specific_2.set_on_off_values(37, 47) self.mixer.channel_strip(2).set_solo_button(solo_specific_2) solo_specific_3 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 47) solo_specific_3.set_on_off_values(37, 47) self.mixer.channel_strip(3).set_solo_button(solo_specific_3) solo_specific_4 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 76) solo_specific_4.set_on_off_values(37, 47) self.mixer.channel_strip(4).set_solo_button(solo_specific_4) solo_specific_5 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 77) solo_specific_5.set_on_off_values(37, 47) self.mixer.channel_strip(5).set_solo_button(solo_specific_5) solo_specific_6 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 78) solo_specific_6.set_on_off_values(37, 47) self.mixer.channel_strip(6).set_solo_button(solo_specific_6) solo_specific_7 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 79) solo_specific_7.set_on_off_values(37, 47) self.mixer.channel_strip(7).set_solo_button(solo_specific_7) mute_specific_0 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 48) mute_specific_0.set_on_off_values(13, 15) self.mixer.channel_strip(0).set_mute_button(mute_specific_0) self.mixer.channel_strip(0).set_invert_mute_feedback(True) mute_specific_1 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 49) mute_specific_1.set_on_off_values(13, 15) self.mixer.channel_strip(1).set_mute_button(mute_specific_1) self.mixer.channel_strip(1).set_invert_mute_feedback(True) mute_specific_2 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 50) mute_specific_2.set_on_off_values(13, 15) self.mixer.channel_strip(2).set_mute_button(mute_specific_2) self.mixer.channel_strip(2).set_invert_mute_feedback(True) mute_specific_3 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 51) mute_specific_3.set_on_off_values(13, 15) self.mixer.channel_strip(3).set_mute_button(mute_specific_3) self.mixer.channel_strip(3).set_invert_mute_feedback(True) mute_specific_4 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 80) mute_specific_4.set_on_off_values(13, 15) self.mixer.channel_strip(4).set_mute_button(mute_specific_4) self.mixer.channel_strip(4).set_invert_mute_feedback(True) mute_specific_5 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 81) mute_specific_5.set_on_off_values(13, 15) self.mixer.channel_strip(5).set_mute_button(mute_specific_5) self.mixer.channel_strip(5).set_invert_mute_feedback(True) mute_specific_6 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 82) mute_specific_6.set_on_off_values(13, 15) self.mixer.channel_strip(6).set_mute_button(mute_specific_6) self.mixer.channel_strip(6).set_invert_mute_feedback(True) mute_specific_7 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 83) mute_specific_7.set_on_off_values(13, 15) self.mixer.channel_strip(7).set_mute_button(mute_specific_7) self.mixer.channel_strip(7).set_invert_mute_feedback(True) # session global _session num_tracks = 8 num_scenes = 7 self._session = SessionComponent(num_tracks, num_scenes) clip_color_table = colors.LIVE_COLORS_TO_MIDI_VALUES.copy() clip_color_table[16777215] = 119 self._session.set_rgb_mode(colors.LIVE_COLORS_TO_MIDI_VALUES, colors.RGB_COLOR_TABLE) track_offset = self.current_track_offset scene_offset = self.current_scene_offset self._session.set_offsets(track_offset, scene_offset) self._session._reassign_scenes() self.set_highlighting_session_component(self._session) # session track stop stop_track_buttons = [36, 37, 38, 39, 68, 69, 70, 71] stop_track_channels = [1, 1, 1, 1, 1, 1, 1, 1] stop_track_types = [MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE, MIDI_NOTE_TYPE] stop_track_is_momentary = [0, 0, 0, 0, 0, 0, 0, 0] self._track_stop_buttons = [ConfigurableButtonElement(stop_track_is_momentary[index], stop_track_types[index], stop_track_channels[index], stop_track_buttons[index]) for index in range(num_tracks)] self._session.set_stop_track_clip_buttons(tuple(self._track_stop_buttons)) # LED feedback self._session._enable_skinning() self._session.set_stop_clip_triggered_value(61) self._session.set_stop_clip_value(127) for scene_index in range(num_scenes): scene = self._session.scene(scene_index) for track_index in range(num_tracks): clip_slot = scene.clip_slot(track_index) # session navigation # several lines originally missing, added by Jademalo self.session_up = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 64) self.session_up.set_on_off_values(25, 31) self._session.set_page_up_button(self.session_up) self.session_down = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 65) self.session_down.set_on_off_values(25, 31) self._session.set_page_down_button(self.session_down) self.session_left = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 66) self.session_left.set_on_off_values(25, 31) self._session.set_page_left_button(self.session_left) self.session_right = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 67) self.session_right.set_on_off_values(25, 31) self._session.set_page_right_button(self.session_right) self._session._link() self._session.set_mixer(self.mixer) self.refresh_state() # select track 1 button self.select_1 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 52) self.select_1.set_on_off_values(73, 79) self.select_1.add_value_listener(self.track_select_1, identify_sender=False) # select track 2 button self.select_2 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 53) self.select_2.set_on_off_values(73, 79) self.select_2.add_value_listener(self.track_select_2, identify_sender=False) # select track 3 button self.select_3 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 54) self.select_3.set_on_off_values(73, 79) self.select_3.add_value_listener(self.track_select_3, identify_sender=False) # select track 4 button self.select_4 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 55) self.select_4.set_on_off_values(73, 79) self.select_4.add_value_listener(self.track_select_4, identify_sender=False) # select track 5 button self.select_5 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 84) self.select_5.set_on_off_values(73, 79) self.select_5.add_value_listener(self.track_select_5, identify_sender=False) # select track 6 button self.select_6 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 85) self.select_6.set_on_off_values(73, 79) self.select_6.add_value_listener(self.track_select_6, identify_sender=False) # select track 7 button self.select_7 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 86) self.select_7.set_on_off_values(73, 79) self.select_7.add_value_listener(self.track_select_7, identify_sender=False) # select track 8 button self.select_8 = ConfigurableButtonElement(1, MIDI_NOTE_TYPE, 1, 87) self.select_8.set_on_off_values(73, 79) self.select_8.add_value_listener(self.track_select_8, identify_sender=False) if((hasattr(self, 'shift_mixer')) and (self.shift_mixer is not None)): self.shift_mixer.send_value(127) def _remove_mode3(self): # mixer global mixer self.mixer.channel_strip(0).set_arm_button(None) self.mixer.channel_strip(1).set_arm_button(None) self.mixer.channel_strip(2).set_arm_button(None) self.mixer.channel_strip(3).set_arm_button(None) self.mixer.channel_strip(4).set_arm_button(None) self.mixer.channel_strip(5).set_arm_button(None) self.mixer.channel_strip(6).set_arm_button(None) self.mixer.channel_strip(7).set_arm_button(None) self.mixer.channel_strip(0).set_solo_button(None) self.mixer.channel_strip(1).set_solo_button(None) self.mixer.channel_strip(2).set_solo_button(None) self.mixer.channel_strip(3).set_solo_button(None) self.mixer.channel_strip(4).set_solo_button(None) self.mixer.channel_strip(5).set_solo_button(None) self.mixer.channel_strip(6).set_solo_button(None) self.mixer.channel_strip(7).set_solo_button(None) self.mixer.channel_strip(0).set_mute_button(None) self.mixer.channel_strip(1).set_mute_button(None) self.mixer.channel_strip(2).set_mute_button(None) self.mixer.channel_strip(3).set_mute_button(None) self.mixer.channel_strip(4).set_mute_button(None) self.mixer.channel_strip(5).set_mute_button(None) self.mixer.channel_strip(6).set_mute_button(None) self.mixer.channel_strip(7).set_mute_button(None) # session global _session self.set_highlighting_session_component(None) self._session.set_mixer(None) # session track stop self._track_stop_buttons = None self._session.set_stop_track_clip_buttons(None) # session navigation self._session.set_page_left_button(None) self._session.set_page_right_button(None) self.current_track_offset = self._session._track_offset self.current_scene_offset = self._session._scene_offset self._session._unlink() self._session = None self.select_1.send_value(0) self.select_1.remove_value_listener(self.track_select_1) self.select_1 = None self.select_2.send_value(0) self.select_2.remove_value_listener(self.track_select_2) self.select_2 = None self.select_3.send_value(0) self.select_3.remove_value_listener(self.track_select_3) self.select_3 = None self.select_4.send_value(0) self.select_4.remove_value_listener(self.track_select_4) self.select_4 = None self.select_5.send_value(0) self.select_5.remove_value_listener(self.track_select_5) self.select_5 = None self.select_6.send_value(0) self.select_6.remove_value_listener(self.track_select_6) self.select_6 = None self.select_7.send_value(0) self.select_7.remove_value_listener(self.track_select_7) self.select_7 = None self.select_8.send_value(0) self.select_8.remove_value_listener(self.track_select_8) self.select_8 = None if((hasattr(self, 'shift_mixer')) and (self.shift_mixer is not None)): self.shift_mixer.send_value(37) """ def _set_track_select_led(self): self._turn_off_track_select_leds() # take sessionbox into account if its present offset = 0 if (hasattr(self, '_session')): offset = self._session._track_offset num_of_tracks = len(self.song().tracks) # next is each track select item # select_1 pos = offset + 0 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_1')) and (self.select_1 is not None)): self.select_1.send_value(73) # select_2 pos = offset + 1 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_2')) and (self.select_2 is not None)): self.select_2.send_value(73) # select_3 pos = offset + 2 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_3')) and (self.select_3 is not None)): self.select_3.send_value(73) # select_4 pos = offset + 3 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_4')) and (self.select_4 is not None)): self.select_4.send_value(73) # select_5 pos = offset + 4 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_5')) and (self.select_5 is not None)): self.select_5.send_value(73) # select_6 pos = offset + 5 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_6')) and (self.select_6 is not None)): self.select_6.send_value(73) # select_7 pos = offset + 6 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_7')) and (self.select_7 is not None)): self.select_7.send_value(73) # select_8 pos = offset + 7 pos2 = pos + 1 if num_of_tracks >= pos2: if (self.song().view.selected_track == self.song().tracks[pos]): if ((hasattr(self, 'select_8')) and (self.select_8 is not None)): self.select_8.send_value(73) def _turn_off_track_select_leds(self): num_of_tracks = len(self.song().tracks) # take sessionbox into account if its present offset = 0 if (hasattr(self, '_session')): offset = self._session._track_offset # select_1 pos = offset + 0 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_1')) and (self.select_1 is not None)): self.select_1.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_1')) and (self.select_1 is not None)): self.select_1.send_value(0) # select_2 pos = offset + 1 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_2')) and (self.select_2 is not None)): self.select_2.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_2')) and (self.select_2 is not None)): self.select_2.send_value(0) # select_3 pos = offset + 2 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_3')) and (self.select_3 is not None)): self.select_3.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_3')) and (self.select_3 is not None)): self.select_3.send_value(0) # select_4 pos = offset + 3 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_4')) and (self.select_4 is not None)): self.select_4.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_4')) and (self.select_4 is not None)): self.select_4.send_value(0) # select_5 pos = offset + 4 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_5')) and (self.select_5 is not None)): self.select_5.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_5')) and (self.select_5 is not None)): self.select_5.send_value(0) # select_6 pos = offset + 5 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_6')) and (self.select_6 is not None)): self.select_6.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_6')) and (self.select_6 is not None)): self.select_6.send_value(0) # select_7 pos = offset + 6 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_7')) and (self.select_7 is not None)): self.select_7.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_7')) and (self.select_7 is not None)): self.select_7.send_value(0) # select_8 pos = offset + 7 pos2 = pos + 1 if ((num_of_tracks >= pos2) and (hasattr(self, 'select_8')) and (self.select_8 is not None)): self.select_8.send_value(79) elif ((num_of_tracks < pos2) and (hasattr(self, 'select_8')) and (self.select_8 is not None)): self.select_8.send_value(0) def track_select_1(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 1 else: move = 1 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_2(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 2 else: move = 2 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_3(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 3 else: move = 3 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_4(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 4 else: move = 4 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_5(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 5 else: move = 5 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_6(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 6 else: move = 6 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_7(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 7 else: move = 7 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def track_select_8(self, value): if value > 0: if (hasattr(self, '_session')): move = self._session._track_offset + 8 else: move = 8 num_of_tracks = len(self.song().tracks) if num_of_tracks >= move: move = move - 1 self.song().view.selected_track = self.song().tracks[move] def _on_selected_track_changed(self): ControlSurface._on_selected_track_changed(self) self._display_reset_delay = 0 value = "selected track changed" if (hasattr(self, '_set_track_select_led')): self._set_track_select_led() if (hasattr(self, '_reload_active_devices')): self._reload_active_devices(value) if (hasattr(self, 'update_all_ab_select_LEDs')): self.update_all_ab_select_LEDs(1) def _is_prev_device_on_or_off(self): self._device = self.song().view.selected_track.view.selected_device self._device_position = self.selected_device_idx() if (self._device is None) or (self._device_position == 0): on_off = "off" else: on_off = "on" return on_off def _is_nxt_device_on_or_off(self): self._selected_device = self.selected_device_idx( ) + 1 # add one as this starts from zero if (self._device is None) or (self._selected_device == len( self.song().view.selected_track.devices)): on_off = "off" else: on_off = "on" return on_off def _set_active_mode(self): global active_mode # activate mode if active_mode == "_mode4": self._mode4() elif active_mode == "_mode1": self._mode1() elif active_mode == "_mode2": self._mode2() elif active_mode == "_mode0": self._mode0() elif active_mode == "_mode3": self._mode3() if hasattr(self, '_set_track_select_led'): self._set_track_select_led() if hasattr(self, '_turn_on_device_select_leds'): self._turn_off_device_select_leds() self._turn_on_device_select_leds() if hasattr(self, '_all_prev_device_leds'): self._all_prev_device_leds() if hasattr(self, '_all_nxt_device_leds'): self._all_nxt_device_leds() if hasattr(self, 'update_all_ab_select_LEDs'): self.update_all_ab_select_LEDs(1) def _remove_active_mode(self): global active_mode # remove activate mode if active_mode == "_mode4": self._remove_mode4() elif active_mode == "_mode1": self._remove_mode1() elif active_mode == "_mode2": self._remove_mode2() elif active_mode == "_mode0": self._remove_mode0() elif active_mode == "_mode3": self._remove_mode3() """ def _activate_mode4(self,value): global active_mode global shift_previous_is_active if value > 0: shift_previous_is_active = "off" self._remove_active_mode() active_mode = "_mode4" self._set_active_mode() """ def _activate_mode1(self, value): global active_mode global shift_previous_is_active if value > 0: shift_previous_is_active = "off" self._remove_active_mode() active_mode = "_mode1" self._set_active_mode() """ def _activate_mode2(self,value): global active_mode global shift_previous_is_active if value > 0: shift_previous_is_active = "off" self._remove_active_mode() active_mode = "_mode2" self._set_active_mode() def _activate_mode0(self,value): global active_mode global shift_previous_is_active if value > 0: shift_previous_is_active = "off" self._remove_active_mode() active_mode = "_mode0" self._set_active_mode() def _activate_mode3(self,value): global active_mode global shift_previous_is_active if value > 0: shift_previous_is_active = "off" self._remove_active_mode() active_mode = "_mode3" self._set_active_mode() def _activate_shift_mode4(self,value): global active_mode global previous_shift_mode4 global shift_previous_is_active if value > 0: shift_previous_is_active = "on" previous_shift_mode4 = active_mode self._remove_active_mode() active_mode = "_mode4" self._set_active_mode() elif shift_previous_is_active == "on": try: previous_shift_mode4 except NameError: self.log_message("previous shift mode not defined yet") else: self._remove_active_mode() active_mode = previous_shift_mode4 self._set_active_mode() def _activate_shift_mode1(self,value): global active_mode global previous_shift_mode1 global shift_previous_is_active if value > 0: shift_previous_is_active = "on" previous_shift_mode1 = active_mode self._remove_active_mode() active_mode = "_mode1" self._set_active_mode() elif shift_previous_is_active == "on": try: previous_shift_mode1 except NameError: self.log_message("previous shift mode not defined yet") else: self._remove_active_mode() active_mode = previous_shift_mode1 self._set_active_mode() def _activate_shift_mode2(self,value): global active_mode global previous_shift_mode2 global shift_previous_is_active if value > 0: shift_previous_is_active = "on" previous_shift_mode2 = active_mode self._remove_active_mode() active_mode = "_mode2" self._set_active_mode() elif shift_previous_is_active == "on": try: previous_shift_mode2 except NameError: self.log_message("previous shift mode not defined yet") else: self._remove_active_mode() active_mode = previous_shift_mode2 self._set_active_mode() def _activate_shift_mode0(self,value): global active_mode global previous_shift_mode0 global shift_previous_is_active if value > 0: shift_previous_is_active = "on" previous_shift_mode0 = active_mode self._remove_active_mode() active_mode = "_mode0" self._set_active_mode() elif shift_previous_is_active == "on": try: previous_shift_mode0 except NameError: self.log_message("previous shift mode not defined yet") else: self._remove_active_mode() active_mode = previous_shift_mode0 self._set_active_mode() def _activate_shift_mode3(self,value): global active_mode global previous_shift_mode3 global shift_previous_is_active if value > 0: shift_previous_is_active = "on" previous_shift_mode3 = active_mode self._remove_active_mode() active_mode = "_mode3" self._set_active_mode() elif shift_previous_is_active == "on": try: previous_shift_mode3 except NameError: self.log_message("previous shift mode not defined yet") else: self._remove_active_mode() active_mode = previous_shift_mode3 self._set_active_mode() """ def selected_device_idx(self): self._device = self.song().view.selected_track.view.selected_device return self.tuple_index(self.song().view.selected_track.devices, self._device) def selected_track_idx(self): self._track = self.song().view.selected_track self._track_num = self.tuple_index(self.song().tracks, self._track) self._track_num = self._track_num + 1 return self._track_num def tuple_index(self, tuple, obj): for i in xrange(0, len(tuple)): if (tuple[i] == obj): return i return (False) def disconnect(self): super(Midi_Fighter_64, self).disconnect()