def color_for_note(note, velocity_range_thresholds=None): thresholds = velocity_range_thresholds or DEFAULT_VELOCITY_RANGE_THRESHOLDS if not note_muted(note): velocity_range_index = index_if(lambda threshold: note_velocity(note) >= threshold, thresholds) return VELOCITY_RANGE_INDEX_TO_COLOR[velocity_range_index] else: return 'Muted'
def insert_scene_button(self, _): try: song = self.song scenes = song.scenes song.create_scene(clamp(index_if(lambda s: s == song.view.selected_scene, scenes) + 1, 0, len(scenes))) except Live.Base.LimitationError: pass
def color_for_note(note, velocity_range_thresholds = None): thresholds = velocity_range_thresholds or DEFAULT_VELOCITY_RANGE_THRESHOLDS if not note_muted(note): velocity_range_index = index_if(lambda threshold: note_velocity(note) >= threshold, thresholds) return VELOCITY_RANGE_INDEX_TO_COLOR[velocity_range_index] else: return 'Muted'
def _first_scale_note_offset(self): if not self._note_layout.is_in_key: return self._note_layout.notes[0] if self._note_layout.notes[0] == 0: return 0 return len(self._note_layout.notes) - index_if(lambda n: n >= 12, self._note_layout.notes)
def _update_button_selection(self): selected_item = self._item_provider.selected_item items = self.items selected_index = index_if(lambda item: item == selected_item, items) if selected_index >= len(items): selected_index = -1 self.select_buttons.checked_index = selected_index
def _do_update_playing_position_subject(self, index): session_ring = self._session_ring tracks = session_ring.tracks_to_use() track_index = session_ring.track_offset + index new_subject = None if track_index < len(tracks): track = tracks[track_index] if self._can_have_playing_slots(track): if liveobj_valid(track.group_track): group_track_index = index_if( lambda t: t == track.group_track, tracks) if group_track_index < len(tracks): subject_index = index - track_index + group_track_index if in_range(subject_index, 0, session_ring.num_tracks): self._do_update_playing_position_subject( subject_index) if track.is_foldable: track = find_first_playing_grouped_track( track, self.song.tracks) if liveobj_valid(track): playing_slot_index = track.playing_slot_index if playing_slot_index >= 0: clip_slot = track.clip_slots[playing_slot_index] if clip_slot.has_clip: new_subject = clip_slot.clip self._playing_position_subjects[index] = new_subject self._SessionComponent__on_playing_position_changed.replace_subjects( (self._playing_position_subjects), identifiers=(count())) self._SessionComponent__on_playing_position_changed(index)
def _first_scale_note_offset(self): if not self._note_layout.is_in_key: return self._note_layout.notes[0] elif self._note_layout.notes[0] == 0: return 0 else: return len(self._note_layout.notes) - index_if(lambda n: n >= 12, self._note_layout.notes)
def preselect(self): old_selected_child_index = self.selected_child if old_selected_child_index == None: devices = map(second, self.children) instrument = index_if( lambda d: isinstance(d, Live.Device.Device) and d.type == DeviceType.instrument, devices) if in_range(instrument, 0, len(devices)): if devices[instrument].can_have_drum_pads and devices[ instrument].drum_pads and instrument + 1 < len( devices): self.selected_child = instrument + 1 else: self.selected_child = instrument super(ChainNode, self).preselect() new_selected_child_index = self.selected_child track = self._get_track() if new_selected_child_index == old_selected_child_index and new_selected_child_index != None: _, selected_object = self.children[new_selected_child_index] if isinstance( selected_object, Live.Device.Device ) and track and track.view.selected_device != selected_object: select_and_appoint_device(self._get_song(), selected_object) self._device_bank_registry.set_device_bank(track.view.selected_device, 0) return
def _selected_track_clip_is_above_playing_clip(self): song_view = self.song.view track = song_view.selected_track playing_slot_index = track.playing_slot_index selected_index = index_if( lambda slot: slot == song_view.highlighted_clip_slot, track.clip_slots) return playing_slot_index <= selected_index
def _do_scroll(self, delta): selected_track = self._song.view.selected_track tracks = all_tracks(self._song) selected_track_index = index_if(lambda t: t == selected_track, tracks) len_tracks = len(tracks) new_index = selected_track_index + delta * self._track_provider.num_tracks self._song.view.selected_track = tracks[clamp(new_index, 0, len_tracks - 1)] self.notify_scrolled()
def _update_selected_item_index(self): new_index = None if not self.has_invalid_selection: items = self.items index = index_if(lambda i: get_item(i) == self.selected_item, items) if index < len(items): new_index = index self._selected_index = new_index
def find_first_playing_grouped_track(group_track, all_tracks): def is_playing_and_grouped(track): return is_child_of_group_track( group_track, track) and not track.is_foldable and track.playing_slot_index >= 0 return find_if( is_playing_and_grouped, all_tracks[index_if(lambda t: t == group_track, all_tracks):])
def color_for_note(note, velocity_range_thresholds = None): thresholds = velocity_range_thresholds or DEFAULT_VELOCITY_RANGE_THRESHOLDS velocity = note[3] muted = note[4] if not muted: velocity_range_index = index_if(lambda threshold: velocity >= threshold, thresholds) return VELOCITY_RANGE_INDEX_TO_COLOR[velocity_range_index] else: return 'Muted'
def _show_selected_item(self): selected_item = self.item_provider.selected_item if selected_item is not None: items = self.item_provider.items if len(items) > self._num_visible_items: selected_index = index_if(lambda i: i[0] == selected_item, items) if selected_index >= self._num_visible_items + self.item_offset - 1 and selected_index < len(items) - 1: self.item_offset = selected_index - self._num_visible_items + 2 elif selected_index > 0 and selected_index <= self.item_offset: self.item_offset = selected_index - 1
def color_for_note(note, velocity_range_thresholds=None): thresholds = velocity_range_thresholds or DEFAULT_VELOCITY_RANGE_THRESHOLDS velocity = note[3] muted = note[4] if not muted: velocity_range_index = index_if( lambda threshold: velocity >= threshold, thresholds) return VELOCITY_RANGE_INDEX_TO_COLOR[velocity_range_index] else: return 'Muted'
def _select_reached_region(self, zoom_in): rois = self._get_unique_regions_of_interest() i = index_if(lambda roi: self.visible_region == roi.region_with_margin, rois) if i != len(rois): if zoom_in: if i < len(rois) - 1: self._set_source_and_target_roi(rois[i], rois[(i + 1)]) elif i > 0: self._set_source_and_target_roi(rois[(i - 1)], rois[i]) return True return False
def _select_hotswap_target(self, list_index = 0): if list_index < len(self._lists): l = self._lists[list_index] l.access_all = True children = l.items i = index_if(lambda i: i.is_selected, children) if i < len(children): self._focused_list_index = list_index l.selected_index = i self._replace_preview_list() self._select_hotswap_target(list_index + 1)
def _select_reached_region(self, zoom_in): rois = self._get_unique_regions_of_interest() i = index_if(lambda roi: self.visible_region == roi.region_with_margin, rois) if i != len(rois): if zoom_in: if i < len(rois) - 1: self._set_source_and_target_roi(rois[i], rois[i + 1]) elif i > 0: self._set_source_and_target_roi(rois[i - 1], rois[i]) return True return False
def _show_selected_item(self): selected_item = self.item_provider.selected_item if selected_item is not None: items = self.item_provider.items if len(items) > self._num_visible_items: selected_index = index_if(lambda i: i[0] == selected_item, items) if selected_index >= self._num_visible_items + self.item_offset - 1 and selected_index < len( items) - 1: self.item_offset = selected_index - self._num_visible_items + 2 elif selected_index > 0 and selected_index <= self.item_offset: self.item_offset = selected_index - 1
def _select_reached_region(self, zoom_in): region_getters = self._get_unique_region_getters() i = index_if(self._visible_region_reaches, imap(apply, region_getters)) if i != len(region_getters): if zoom_in: if i < len(region_getters) - 1: self._source_region_getter = region_getters[i] self._target_region_getter = region_getters[i + 1] elif i > 0: self._source_region_getter = region_getters[i - 1] self._target_region_getter = region_getters[i] return True return False
def get_filter_type(self): selected = self.get_selection_for_insert() chain = selected.canonical_parent if selected else self._selection.selected_track chain_len = len(chain.devices) index = index_if(lambda device: device == selected, chain.devices) is_drum_pad = isinstance(chain.canonical_parent, Live.DrumPad.DrumPad) midi_support = chain.has_midi_input if not is_drum_pad: supports_instrument = chain.has_midi_input and (chain.has_audio_output or isinstance(chain, Live.Track.Track)) left = self.insert_left and (chain.devices[index - 1] if index > 0 else None) return filter_type_between(left, selected, midi_support, is_drum_pad, supports_instrument) else: right = chain.devices[index + 1] if index < chain_len - 1 else None return filter_type_between(selected, right, midi_support, is_drum_pad, supports_instrument)
def update_selection(self): last_seleced_list_index = None if self._browser.hotswap_target != None: list_index = 0 while list_index < self._num_contents: content_list, _ = self._contents[list_index] items = content_list.items index = index_if(lambda x: x.content.is_selected, items) if in_range(index, 0, len(items)): content_list.select_item_index_with_offset(index, 2) last_seleced_list_index = list_index list_index += 1 if last_seleced_list_index != None: self.notify_selection_updated(last_seleced_list_index)
def assign_items(self, items): old_selection = unicode(self.selected_item) for item in self._items: item._scrollable_list = None self._items = tuple([ self.item_type(index=index, content=item, scrollable_list=self) for index, item in enumerate(items) ]) if self._items: new_selection = index_if(lambda item: unicode(item) == old_selection, self._items) self._selected_item_index = new_selection if in_range(new_selection, 0, len(self._items)) else 0 self._normalize_offset(self._selected_item_index) else: self._offset = 0 self._selected_item_index = -1 self._last_activated_item_index = None self.notify_selected_item() self.request_notify_item_activated()
def assign_items(self, items): old_selection = str(self.selected_item) for item in self._items: item._scrollable_list = None self._items = tuple([ self.item_type(index=index, content=item, scrollable_list=self) for index, item in enumerate(items) ]) if self._items: new_selection = index_if(lambda item: str(item) == old_selection, self._items) self._selected_item_index = new_selection if in_range(new_selection, 0, len(self._items)) else 0 self._normalize_offset(self._selected_item_index) else: self._offset = 0 self._selected_item_index = -1 self._last_activated_item_index = None self.notify_selected_item() self.request_notify_item_activated()
def preselect(self): old_selected_child_index = self.selected_child if old_selected_child_index == None: devices = map(second, self.children) instrument = index_if(lambda d: isinstance(d, Live.Device.Device) and d.type == DeviceType.instrument, devices) if in_range(instrument, 0, len(devices)): if devices[instrument].can_have_drum_pads and devices[instrument].drum_pads and instrument + 1 < len(devices): self.selected_child = instrument + 1 else: self.selected_child = instrument super(ChainNode, self).preselect() new_selected_child_index = self.selected_child track = self._get_track() if new_selected_child_index == old_selected_child_index and new_selected_child_index != None: _, selected_object = self.children[new_selected_child_index] if isinstance(selected_object, Live.Device.Device) and track and track.view.selected_device != selected_object: select_and_appoint_device(self._get_song(), selected_object) self._device_bank_registry.set_device_bank(track.view.selected_device, 0)
def __on_interval_changed(self, interval): index = index_if(lambda layout: layout.interval == interval, self._layouts) self.selected_layout_index = index
def _track_index(self, track): return index_if(lambda t: t == track, self._session_ring.tracks_to_use())
def is_track_in_session_ring(track): controlled_tracks = self._session_ring.controlled_tracks() return index_if(lambda t: t == track, controlled_tracks) < len(controlled_tracks)
def force_to_live_crossfade_assign_value(value): return index_if(lambda v: v == value, LIVE_CROSSFADE_ASSIGN_VALUES)
def _selected_track_clip_is_above_playing_clip(self): song_view = self.song.view track = song_view.selected_track playing_slot_index = track.playing_slot_index selected_index = index_if(lambda slot: slot == song_view.highlighted_clip_slot, track.clip_slots) return playing_slot_index <= selected_index