def set_control_element(self, control_elements): dimensions = (None, None) if old_hasattr(control_elements, 'width') and old_hasattr( control_elements, 'height'): dimensions = (control_elements.height(), control_elements.width()) if not self._dynamic_create: control_elements = [ control_elements.get_button(col, row) for row, col in product(range(self.height), range(self.width)) ] elif is_matrix(control_elements): dimensions = (len(control_elements), len(first(control_elements))) if not self._dynamic_create: control_elements = [ row[0:self.width] for row in control_elements ] control_elements = [_ for _ in flatten(control_elements)] elif control_elements is not None: raise RuntimeError('Control Elements must be a matrix') if self._dynamic_create: if None not in dimensions: self._dimensions = dimensions self._create_controls( first(dimensions) * second(dimensions)) self._update_controls() super(MatrixControl.State, self).set_control_element(control_elements)
def _get_chain_nesting_level(self, chain): parent_chain_or_track = chain.canonical_parent.canonical_parent if old_hasattr(parent_chain_or_track, 'group_track'): return self._get_nesting_level(parent_chain_or_track) + 1 if old_hasattr(parent_chain_or_track, 'canonical_parent'): if old_hasattr(parent_chain_or_track.canonical_parent, 'canonical_parent'): return self._get_chain_nesting_level(parent_chain_or_track) + 1 return 0
def map_track_params(self, script_handle, midi_map_handle): for idx in range(0, 16): tracks = tuple(self.parent.song().tracks) + tuple( self.parent.song().return_tracks) if len(tracks) > idx: track = tracks[idx] mixer_device = track.mixer_device parameter = mixer_device.volume ParamMap.map_with_feedback(midi_map_handle, CHANNEL_SETUP2, VOLUME_CCS[idx], parameter, Live.MidiMap.MapMode.absolute) sends = mixer_device.sends for send_idx in range(0, 4): if len(sends) > send_idx: parameter = sends[send_idx] ParamMap.map_with_feedback( midi_map_handle, TRACK_CHANNEL_SETUP2, SEND_CCS[idx][send_idx], parameter, Live.MidiMap.MapMode.absolute) parameter = mixer_device.panning ParamMap.map_with_feedback(midi_map_handle, TRACK_CHANNEL_SETUP2, PAN_X_CC[idx], parameter, Live.MidiMap.MapMode.absolute) track = self.parent.song().master_track parameter = track.mixer_device.panning ParamMap.map_with_feedback(midi_map_handle, TRACK_CHANNEL_SETUP2, PAN_X_MASTER_CC, parameter, Live.MidiMap.MapMode.absolute) parameter = track.mixer_device.volume cc = MAIN_VOLUME_CC if self.parent.is_lv1: cc = LV1_MAIN_VOLUME_CC ParamMap.map_with_feedback(midi_map_handle, CHANNEL_SETUP2, cc, parameter, Live.MidiMap.MapMode.absolute) if old_hasattr(track.mixer_device, u'cue_volume'): parameter = track.mixer_device.cue_volume cc = CUE_VOLUME_CC if self.parent.is_lv1: cc = LV1_CUE_VOLUME_CC ParamMap.map_with_feedback(midi_map_handle, CHANNEL_SETUP2, cc, parameter, Live.MidiMap.MapMode.absolute) if old_hasattr(track.mixer_device, u'crossfader'): parameter = track.mixer_device.crossfader cc = CROSSFADER_CC ParamMap.map_with_feedback(midi_map_handle, CHANNEL_SETUP2, cc, parameter, Live.MidiMap.MapMode.absolute) if self.parent.is_lv1: cc = LV1_CROSSFADER_CC ParamMap.map_with_feedback(midi_map_handle, CHANNEL_SETUP2, cc, parameter, Live.MidiMap.MapMode.absolute)
def __setattr__(self, name, value): obj = self.proxied_object interface = self.proxied_interface if obj and old_hasattr(interface, name): if self.proxy_old_hasattr(name): raise_(AttributeError, 'Ambiguous set attribute: %s proxied: %s' % (name, obj)) setattr(obj, name, value) else: if old_hasattr(interface, name): raise_(AttributeError, 'Ambiguous set attribute: %s proxied: %s' % (name, obj)) self.__dict__[name] = value
def _toggle_track_fold(self, track): if old_hasattr(track, 'is_foldable') and track.is_foldable: track.fold_state = not track.fold_state elif old_hasattr(track, 'is_showing_chains') and track.can_show_chains: track.is_showing_chains = not track.is_showing_chains else: instruments = list(find_instrument_devices(track)) if instruments: instrument = instruments[0] if old_hasattr(instrument, 'is_showing_chains'): if instrument.can_show_chains: instrument.is_showing_chains = not instrument.is_showing_chains
def get_chains_recursive(track_or_chain): instruments = list(find_instrument_devices(track_or_chain)) chains = [] if instruments and old_hasattr(instruments[0], u'chains'): for chain in instruments[0].chains: chains.append(chain) instruments = list(find_instrument_devices(chain)) if instruments and old_hasattr(instruments[0], u'chains'): if instruments[0].is_showing_chains: nested_chains = get_chains_recursive(chain) chains.extend(nested_chains) return chains
def get_racks_recursive(track_or_chain): instruments = list(find_instrument_devices(track_or_chain)) racks = [] if instruments and old_hasattr(instruments[0], u'chains'): racks.append(instruments[0]) for chain in instruments[0].chains: instruments = list(find_instrument_devices(chain)) if instruments and old_hasattr(instruments[0], u'chains'): if instruments[0].can_have_chains: nested_racks = get_racks_recursive(chain) racks.extend(nested_racks) return racks
def create_lom_doc_string(lom_object): description = u'' if old_hasattr(lom_object, u'__doc__') and isinstance( lom_object.__doc__, basestring) and len(lom_object.__doc__) > 0: description = u'description %s' % lom_object.__doc__.replace( u'\n', u' ').replace(u',', u'\\,') return description
def unlock_from_device(self, device): if device: if device == self.device: self.device_locked = False if old_hasattr(self.parent.song(), 'appointed_device'): if not self.parent.song().appointed_device == self.device: self.parent.request_rebuild_midi_map()
def add_mode(self, name, mode_or_component, toggle_value = False, groups = set(), behaviour = None): u""" Adds a mode of the given name into the component. The mode object should be a Mode or ControlSurfaceComponent instance. The 'toggle_value' is the light value the toggle_botton will be set to when the component is on this mode. If 'group' is not None, the mode will be put in the group identified by the passed object. When several modes are grouped: * All the buttons in the group will light up when any of the modes withing the group is selected. * Any of the group buttons will cancel the current mode when the current mode belongs to the group. """ assert name not in list(self._mode_map.keys()) if not isinstance(groups, set): groups = set(groups) mode = tomode(mode_or_component) task = self._tasks.add(Task.sequence(Task.wait(Defaults.MOMENTARY_DELAY), Task.run(lambda : self._get_mode_behaviour(name).press_delayed(self, name)))) task.kill() slot = self.register_slot(listener=partial(self._on_mode_button_value, name), event=u'value', extra_kws=dict(identify_sender=True)) self._mode_list.append(name) self._mode_map[name] = _ModeEntry(mode=mode, toggle_value=toggle_value, behaviour=behaviour, subject_slot=slot, momentary_task=task, groups=groups) button_setter = u'set_' + name + u'_button' if not old_hasattr(self, button_setter): setattr(self, button_setter, partial(self.set_mode_button, name))
def device_name(self, device): if old_hasattr(device, u'class_name'): return device.class_name elif device.name in FIVETOSIX_DICT: return FIVETOSIX_DICT[device.name] else: return device.name
def set_light(self, value): color = None if old_hasattr(value, u'draw'): color = value else: color = self._skin[value] color.draw(self)
def _playing_clip_slot(self): if old_hasattr(self._adaptee, 'playing_slot_index'): try: if self._adaptee.playing_slot_index >= 0: return self._adaptee.clip_slots[self._adaptee.playing_slot_index] except RuntimeError: pass
def __getattr__(self, name): if not self._skip_wrapper_lookup: obj = self.proxied_object interface = self.proxied_interface if obj and old_hasattr(interface, name): return getattr(obj, name) return getattr(interface, name) raise_(AttributeError, u'Does not have attribute %s' % name)
def __init__(self, *a, **k): (super(EditModeOptionAdapter, self).__init__)(*a, **k) if old_hasattr(self._adaptee, 'active_index'): self._alias_observable_property('active_index', 'activeIndex', getter=(lambda self_: getattr(self_._adaptee, 'active_index', 0))) self._alias_observable_property('default_label', 'choices', getter=(lambda self_: self_._choices))
def __new__(cls, name, bases, dct): events = dct.get(u'__subject_events__', []) if events and u'disconnect' not in dct: dct[u'disconnect'] = lambda self: super(cls, self).disconnect() cls = super(SubjectMeta, cls).__new__(cls, name, bases, dct) assert not events or old_hasattr(cls, u'disconnect') setup_subject(cls, events) return cls
def _make_control(self, index): control = super(MatrixControl.State, self)._make_control(index) control_state = control._get_state(self._manager) if not old_hasattr(control_state, u'coordinate'): control_state.coordinate = (int(old_div(index, self.width)), index % self.width) else: raise RuntimeError(u"Cannot set 'coordinate' attribute. Attribute already set.") return control
def set_control_element(self, control_element): if self._control_element != control_element: self._release_encoder() super(EncoderControl.State, self).set_control_element(control_element) if self._touch_value_slot: self._touch_value_slot.subject = control_element if control_element and old_hasattr(control_element, u'is_pressed') and control_element.is_pressed(): self._touch_encoder()
def get_control_surfaces(): if isinstance(__builtins__, dict): if CS_LIST_KEY not in list(__builtins__.keys()): __builtins__[CS_LIST_KEY] = [] return __builtins__[CS_LIST_KEY] if not old_hasattr(__builtins__, CS_LIST_KEY): setattr(__builtins__, CS_LIST_KEY, []) return getattr(__builtins__, CS_LIST_KEY)
def _make_control(self, index): control = self._control_type(*self._extra_args, **self._extra_kws) control._event_listeners = self._event_listeners control_state = control._get_state(self._manager) if not old_hasattr(control_state, u'index'): control_state.index = index else: raise RuntimeError(u"Cannot set 'index' attribute. Attribute already set.") return control
def _get_playing_clip(self): playing_clip = None song = self.song selected_track = song.view.selected_track if old_hasattr(selected_track, u'playing_slot_index'): playing_slot_index = selected_track.playing_slot_index if playing_slot_index >= 0: playing_clip = selected_track.clip_slots[playing_slot_index].clip return playing_clip
def parse_string(self, string): self._arguments = [] self._sub_string = u'' self._state = STATE_NEUTRAL self._open_quote_index = -1 for index in range(len(string)): char = string[index] handle_selector = u'_' + str(self._state) + u'_handle_char' if old_hasattr(self, handle_selector): getattr(self, handle_selector)(char, index) else: logger.info(u'Unknown state ' + str(self._state)) assert False finalize_selector = u'_finalize_' + str(self._state) if len(self._sub_string) > 0 and old_hasattr(self, finalize_selector): getattr(self, finalize_selector)() return self._arguments
def get_control_surfaces(): result = [] cs_list_key = u'control_surfaces' if isinstance(__builtins__, dict): if cs_list_key in list(__builtins__.keys()): result = __builtins__[cs_list_key] elif old_hasattr(__builtins__, cs_list_key): result = getattr(__builtins__, cs_list_key) return tuple(result)
def object_grab_control(self, device_id, object_id, lom_object, parameters): cs = lom_object control_or_name = parameters[1] control = self._get_control_or_raise(cs, control_or_name, u'grab_control') if cs not in self._grabbed_controls_per_cs: self._grabbed_controls_per_cs[cs] = [] cs.add_disconnect_listener(self._disconnect_control_surface) grabbed_controls = self._grabbed_controls_per_cs[cs] if control not in grabbed_controls: with cs.component_guard(): priority = cs.mxd_grab_control_priority() if old_hasattr( cs, u'mxd_grab_control_priority') else 1 control.resource.grab(self, priority=priority) if old_hasattr(control, u'suppress_script_forwarding'): control.suppress_script_forwarding = False grabbed_controls.append(control)
def __init__(self, *a, **k): super(TrackAdapter, self).__init__(*a, **k) if old_hasattr(self._adaptee, u'mute'): self.__on_mute_changed.subject = self._adaptee self.__on_solo_changed.subject = self._adaptee self.__on_muted_via_solo_changed.subject = self._adaptee self.has_playing_clip = False self._update_has_playing_clip() if old_hasattr(self._adaptee, u'playing_slot_index'): self.__on_playing_slot_index_changed.subject = self._adaptee try: if old_hasattr(self._adaptee.parent_track, u'is_frozen'): self.__on_is_frozen_changed.subject = self._adaptee.parent_track except AttributeError: pass try: self.register_slot(self._adaptee, self.notify_colorIndex, u'color_index') except EventError: pass try: self.register_slot(self._adaptee.parent_track, self.notify_parentColorIndex, u'color_index') except AttributeError: pass try: self.register_slot(self._adaptee, self.notify_isFrozen, u'is_frozen') except EventError: pass try: self.register_slot(self._adaptee, self.notify_arm, u'arm') except EventError: pass try: self.register_slot(self._adaptee, self.notify_outputRouting, u'output_routing_type') except EventError: pass
def __init__(self, *a, **k): from ..device_util import is_drum_pad, find_chain_or_track, find_rack from ..device_navigation import is_bank_rack_2 super(DeviceAdapter, self).__init__(*a, **k) item = self._unwrapped_item() if old_hasattr(item, u'is_active'): if is_bank_rack_2(item): self.__on_is_active_changed.subject = item.rack_device else: self.__on_is_active_changed.subject = item elif is_drum_pad(item): self.__on_is_active_changed.subject = item.canonical_parent self.__on_mute_changed.subject = item if old_hasattr(item, u'name'): self.__on_name_changed.subject = item self._chain = find_chain_or_track(item) self._rack_chain = find_chain_or_track(find_rack(item)) self.__on_chain_color_index_changed.subject = self._chain self.__on_rack_color_index_changed.subject = self._rack_chain
def playing_clip(track): if old_hasattr(track, u'playing_slot_index'): try: if track.playing_slot_index >= 0: playing_clip_slot = track.clip_slots[track.playing_slot_index] if liveobj_valid(playing_clip_slot): return playing_clip_slot.clip return None except RuntimeError: pass
def _find_property_object_path(self, lom_object, parent): component = None for key in list(PROPERTY_TYPES.keys()): if isinstance(lom_object, PROPERTY_TYPES[key]) and old_hasattr( parent, key): if lom_object == getattr(parent, key): component = key break return component
def _find_tuple_element_object_path(self, lom_object, parent): component = None for key in sorted(list(TUPLE_TYPES.keys())): if old_hasattr(parent, key): property = getattr(parent, key) if lom_object in property: index = list(property).index(lom_object) component = u'%s %d' % (key, index) break return component
def verify_object_property(lom_object, property_name, epii_version): raise_error = False if isinstance(lom_object, cs_base_classes()): if not old_hasattr(lom_object, property_name): raise_error = True elif not is_property_exposed_for_type(property_name, type(lom_object), epii_version): raise_error = True if raise_error: raise LomAttributeError(u"'%s' object has no attribute '%s'" % (lom_object.__class__.__name__, property_name))