def connect_push2(self, log=False): # type: (bool) -> None """ object modification, push2 registers itself after protocol0 instantiation """ push2 = find_if(lambda cs: isinstance(cs, Push2), get_control_surfaces()) if not push2 or not hasattr(push2, "_session_ring"): if log: self.parent.log_warning("Cannot connect to push2") return if not self.push2: self.parent.log_info("Push2 connected") self.push2 = push2 with push2.component_guard(): self.push2._session_ring.set_enabled(False) self.push2._matrix_modes.selected_mode = "session" self._session_pad_press_listener.subject = self.push2.elements.matrix self._track_select_button_press_listener.subject = self.push2.elements.select_buttons self._nav_button_press_listener.replace_subjects([ self.push2.elements.nav_left_button, self.push2.elements.nav_right_button ]) if not self.push2: self.parent.log_info("Push2 connected to Protocol0")
def computed_base_name(self): # type: () -> str # tracks have all the same name unique_sub_track_names = list( set([sub_track.name for sub_track in self.sub_tracks])) if len(unique_sub_track_names) == 1: return unique_sub_track_names[0] # tracks have all the same instrument common_subtracks_instrument_class = self._common_subtracks_instrument_class if common_subtracks_instrument_class == InstrumentSimpler and \ find_if(lambda t: "kick" in t.name.lower(), self.sub_tracks): return "Drums" if common_subtracks_instrument_class: return common_subtracks_instrument_class.NAME def _name_prefix(track): # type: (AbstractTrack) -> str return track.base_track.name.split(" ")[0] # checking if all sub tracks have the same prefix unique_sub_tracks_name_prefixes = list( set([_name_prefix(sub_track) for sub_track in self.sub_tracks])) if len(unique_sub_tracks_name_prefixes ) == 1 and unique_sub_tracks_name_prefixes[0]: return unique_sub_tracks_name_prefixes[0] return self.DEFAULT_NAME
def _check_protocol_midi_is_up(self): # type: () -> None from protocol0_midi import Protocol0Midi protocol0_midi = find_if(lambda cs: isinstance(cs, Protocol0Midi), get_control_surfaces()) if protocol0_midi is None: self.log_error("Protocol0Midi is not loaded")
def _get_selected_preset(self): # type: () -> Optional[InstrumentPreset] """ Checking first the track name (Serum or Minitaur) then the device name (e.g. simpler) """ preset = None if len(self.presets) == 0: return None if self.instrument.device and self.instrument.device.preset_name: preset = find_if(lambda p: p.name == self.instrument.device.preset_name, self.presets) elif self.instrument.PRESET_DISPLAY_OPTION == PresetDisplayOptionEnum.NAME: preset = find_if(lambda p: p.name == self.instrument.track.abstract_track.name, self.presets) return preset
def _get_method_from_method_name_and_class(cls, class_instance, method_name): # type: (Any, str) -> Any from protocol0 import Protocol0 component = find_if(lambda c: c.__class__ == class_instance, Protocol0.SELF.components) if component: return getattr(component, method_name) else: raise Protocol0Error("You should create the method mapping after the components instantiation")
def _get_audio_effect_preset_item(self, preset_name): # type: (str) -> Optional[Live.Browser.BrowserItem] if preset_name in self._audio_effect_rack_cache: return self._audio_effect_rack_cache[preset_name] else: audio_effect_rack_item = find_if( lambda i: i.name == "Audio Effect Rack", self._browser.audio_effects.iter_children) if not audio_effect_rack_item: self.parent.log_info( "Couldn't access preset items for Audio Effect Rack") return None else: preset = find_if(lambda i: i.name == "%s.adg" % preset_name, audio_effect_rack_item.iter_children) self._audio_effect_rack_cache[preset_name] = preset return preset
def _update_device_params(self, track, device_name, parameters): # type: (SimpleTrack, str, Dict[str, float]) -> None device = find_if(lambda d: d.name == device_name, track.devices) if not device: self.parent.log_error("Couldn't find device with name %s in %s" % (device_name, track)) for param_name, param_value in parameters.items(): device.update_param_value(param_name=param_name, param_value=param_value)
def selected_parameter(self): # type: () -> Optional[DeviceParameter] all_parameters = [ param for track in self.simple_tracks for param in track.device_parameters ] return find_if( lambda p: p._device_parameter == self._view.selected_parameter, all_parameters)
def output_routing_track(self, track): # type: (SimpleTrack) -> None if self._track is None: return output_routing_type = find_if( lambda r: r.attached_object == track._track, self.available_output_routing_types) if not output_routing_type: output_routing_type = find_if( lambda r: r.display_name == track.name, self.available_output_routing_types) if not output_routing_type: raise Protocol0Error( "Couldn't find the output routing type %s for %s" % (track, self)) self._track.output_routing_type = output_routing_type
def scroll_chain_selector(self, go_next): # type: (bool) -> None if not self.chain_selector: self.chain_selector = find_if( lambda p: p.original_name.startswith("Chain Selector") and p. is_enabled, self.parameters) increment = 1 if go_next else -1 self.chain_selector.value = (self.chain_selector.value + increment) % len(self.chains) self.selected_chain = self.chains[int(self.chain_selector.value)]
def selected_device(self): # type: (SimpleTrack) -> Optional[Device] if self._track and self._track.view.selected_device: device = find_if( lambda d: d._device == self._track.view.selected_device, self.base_track.all_devices) # type: Optional[Device] assert device return device else: return None
def input_routing_channel(self, input_routing_channel): # type: (InputRoutingChannelEnum) -> None if self._track is None: return channel = find_if( lambda r: r.display_name == input_routing_channel.label, self.available_input_routing_channels) if not channel: raise Protocol0Error("couldn't find channel matching %s for %s" % (input_routing_channel, self)) self._track.input_routing_channel = channel
def __init__(self, *a, **k): # type: (Any, Any) -> None super(AbstractObject, self).__init__(*a, **k) from protocol0 import Protocol0 if Protocol0.SELF: parent = Protocol0.SELF # type: Optional[Protocol0] else: parent = find_if(lambda cs: isinstance(cs, Protocol0), get_control_surfaces()) assert parent self._parent = parent # type: Protocol0
def input_routing_type(self, input_routing_type_enum): # type: (InputRoutingTypeEnum) -> None if self._track is None: return input_routing_type = find_if( lambda i: i.display_name == input_routing_type_enum.label, self.available_input_routing_types) if input_routing_type is None: raise Protocol0Error( "Couldn't find input routing type from %s for %s" % (input_routing_type_enum, self)) self._track.input_routing_type = input_routing_type
def input_routing_track(self, track): # type: (Optional[SimpleTrack]) -> None if self._track is None: return if track is None: input_routing_type = self.available_input_routing_types[-1] else: input_routing_type = find_if( lambda r: r.attached_object == track._track, self.available_input_routing_types) if not input_routing_type: raise Protocol0Error( "Couldn't find the output routing type %s for %s" % (track, self)) self._track.input_routing_type = input_routing_type
def make_instrument_from_simple_track(self, track): # type: (SimpleTrack) -> Optional[AbstractInstrument] """ If the instrument didn't change we keep the same instrument and don't instantiate a new one to keep instrument state """ instrument_device = find_if( lambda d: AbstractInstrument.get_instrument_class( d), # type: ignore track.all_devices) if not instrument_device: return None instrument_class = cast( Type[AbstractInstrument], AbstractInstrument.get_instrument_class(instrument_device)) if isinstance(track.instrument, instrument_class): return track.instrument # maintaining state else: return instrument_class(track=track, device=instrument_device)
def selected_chain(self): # type: () -> Optional[DeviceChain] return find_if(lambda c: c._chain == self._view.selected_chain, self.chains)
def _devices_listener(self): # type: () -> None self._external_device = find_if(lambda d: d.is_external_device, self.midi_track.devices)
def get_device_from_enum(self, device_enum): # type: (SimpleTrack, DeviceEnum) -> Optional[Device] return find_if(lambda d: d.name == device_enum.device_name, self.base_track.all_devices)
def get_parameter_by_name(self, device_parameter_name): # type: (Union[DeviceParameterEnum, str]) -> Optional[DeviceParameter] if isinstance(device_parameter_name, DeviceParameterEnum): device_parameter_name = device_parameter_name.label return find_if(lambda d: d.name == device_parameter_name, self.parameters)