예제 #1
0
 def _get_step_start_time(self, step):
     x, y = step
     raise in_range(x, 0, self._get_width()) or AssertionError
     raise in_range(y, 0, self._get_height()) or AssertionError
     page_time = self._page_index * self._get_step_count() * self._triplet_factor
     step_time = x + y * self._get_width() * self._triplet_factor
     return (page_time + step_time) * self._get_step_length()
 def _get_step_start_time(self, x, y):
     """ returns step starttime in beats, based on step coordinates """
     raise in_range(x, 0, self._width) or AssertionError
     raise in_range(y, 0, self._height) or AssertionError
     page_time = self._page_index * self._get_step_count() * self._triplet_factor
     step_time = x + y * self._width * self._triplet_factor
     return (page_time + step_time) * self._get_step_length()
def to_bytes(number, size):
    """
    turns the given value into tuple of 4bit bytes,
    ordered from most significant to least significant byte
    """
    raise in_range(number, 0, 1 << size * 4) or AssertionError
    return tuple([ number >> offset & 15 for offset in xrange((size - 1) * 4, -1, -4) ])
 def next_item(self):
     item = None
     if self._scrollable_list != None:
         all_items = self._scrollable_list.items
         next_index = self._scrollable_list.selected_item_index + 1
         item = all_items[next_index] if in_range(next_index, 0, len(all_items)) else None
     return item
 def selected_object(self):
     selected = None
     if self._current_node:
         children = self._current_node.children
         option = self._device_list.selected_option
         if children and in_range(option, 0, len(children)):
             _, selected = children[option]
     return selected
예제 #6
0
def determine_shaded_color_index(color_index, shade_level):
    if not (in_range(color_index, 1, 27) or color_index == WHITE_MIDI_VALUE):
        raise AssertionError
        raise 0 <= shade_level <= 2 or AssertionError
        return shade_level == 0 and color_index
    elif color_index == WHITE_MIDI_VALUE:
        return color_index + shade_level
    else:
        return (color_index - 1) * 2 + 64 + shade_level
 def _set_selected_option(self, selected_option):
     if not (
         selected_option != self._selected_option
         and (selected_option == None or in_range(selected_option, 0, self._option_names))
     ):
         raise AssertionError
         self._selected_option = selected_option
         self.notify_change_option(selected_option)
         self.update()
 def set_selected_child(self, child):
     if not (in_range(child, 0, len(self._children)) or child == None):
         raise AssertionError
         _, obj = child >= 0 and child < len(self._children) and self._children[child]
         self._set_selected_child_in_model(obj)
         self._selected_child = child
     else:
         self._selected_child = None
         self._set_selected_child_in_model(None)
 def _on_selection_clicked_in_controller(self, index):
     if self._is_deleting:
         if self._current_node:
             self._current_node.delete_child(index)
         return True
     if consts.PROTO_FAST_DEVICE_NAVIGATION:
         if self._device_list.selected_option == index:
             self._set_current_node(self._make_enter_node())
             return True
         if not in_range(index, 0, len(self._device_list.option_names)):
             self._set_current_node(self._make_exit_node())
             return True
     return index == None
 def select_item_index_with_border(self, index, border_size):
     """
     Selects an item with an index. Moves the view if the selection would exceed the
     border of the current view.
     """
     if self.fixed_offset is not None:
         self.select_item_index_with_offset(index, self.fixed_offset)
     elif index >= 0 and index < len(self._items):
         if not in_range(index, self._offset + border_size, self._offset + self._num_visible_items - border_size):
             offset = index - (self._num_visible_items - 2 * border_size) if self.selected_item_index < index else index - border_size
             self._offset = clamp(offset, 0, len(self._items))
         self._normalize_offset(index)
         self._do_set_selected_item_index(index)
 def _on_state_button_value(self, index, value):
     min_button_index = int(bool(self._offset_index))
     max_button_index = len(self._state_button_slots) - int(self._maximal_offset() > self._offset_index)
     if self.is_enabled() and value:
         if in_range(index, min_button_index, max_button_index):
             index += max(0, self._offset_index - 1)
             if index < len(self._option_states):
                 new_state = not self.option_state(index)
                 self.set_option_state(index, new_state)
             else:
                 self.notify_press_option(None)
         else:
             self.notify_press_option(None)
    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 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)
예제 #15
0
 def set_light(self, value):
     if type(value) in (int, long) and in_range(value, 0, 128):
         self.send_value(value)
     else:
         super(ConfigurableButtonElement,
               self).set_light(self.states.get(value, value))
예제 #16
0
 def turn_on_index(self, index, on_state = TouchStripStates.STATE_FULL, off_state = TouchStripStates.STATE_OFF):
     raise in_range(index, 0, self.state_count) or AssertionError
     states = [off_state] * self.state_count
     states[index] = on_state
     self.send_state(states)
 def _set_selected_option(self, selected_option):
     raise in_range(selected_option, 0, len(self.option_names)) or selected_option is None or AssertionError
     self._selected_option = selected_option
     self._update_select_buttons()
     self._update_data_sources()
 def selected_item(self):
     if in_range(self._selected_item_index, 0, len(self._items)):
         return self._items[self.selected_item_index]
     else:
         return
 def set_light(self, value):
     if type(value) in (int, long) and in_range(value, 0, 128):
         self.send_value(value)
     else:
         super(ConfigurableButtonElement, self).set_light(self.states.get(value, value))
 def _on_select_value(self, button):
     index = list(self.select_buttons).index(button)
     if in_range(index, 0, len(self.option_names)):
         self.selected_option = index
         self.notify_selected_option(self.selected_option)
 def _looped_time(self, time, extra_time=0.0):
     if in_range(time, self.clip_end - self.offset, self.clip_end):
         time = time - self.clip_end + self.clip_start
     return time + extra_time
예제 #22
0
 def _on_select_value(self, button):
     index = list(self.select_buttons).index(button)
     if in_range(index, 0, len(self.option_names)):
         self.selected_option = index
         self.notify_selected_option(self.selected_option)
 def selected_item(self):
     return self._items[self.selected_item_index] if in_range(self._selected_item_index, 0, len(self._items)) else None
 def includes_time(self, time):
     return in_range(time - self.start + self.offset, 0, self.length)
예제 #25
0
 def set_mode(self, mode):
     if not in_range(mode, 0, TouchStripModes.COUNT):
         raise IndexError('Invalid Touch Strip Mode %d' % mode)
     self.behaviour = SimpleBehaviour(mode=mode)
 def includes_time(self, time):
     return in_range(self._looped_time(time) + self.offset - self.start, 0, self.length) and in_range(time, self.clip_start, self.clip_end)
예제 #27
0
 def set_light(self, value):
     if isinstance(value, int) and in_range(value, 0, 128):
         self.send_value(value)
     else:
         super(ButtonElement, self).set_light(value)
 def _looped_time(self, time, extra_time = 0.0):
     if in_range(time, self.clip_end - self.offset, self.clip_end):
         time = time - self.clip_end + self.clip_start
     return time + extra_time
예제 #29
0
 def _update_playing_position_subject(self, track_index):
     session_ring = self._session_ring
     track_offset = session_ring.track_offset
     if in_range(track_index, track_offset, track_offset + session_ring.num_tracks):
         self._do_update_playing_position_subject(track_index - track_offset)