def _run(self): from abjad.tools import instrumenttools from ide import idetools controller = idetools.ControllerContext(controller=self) with controller: items = instrumenttools.Instrument._list_instrument_names() selector = idetools.Selector( session=self._session, items=items, is_ranged=self._is_ranged, ) result = selector._run() if self._session.is_backtracking or not result: return if isinstance(result, list): instrument_names = result else: instrument_names = [result] instruments = [] class_ = InstrumentInventory to_instrument = \ class_._change_instrument_name_to_instrument name_percussion = class_._name_percussion for instrument_name in instrument_names: instrument = to_instrument(instrument_name) instrument = name_percussion(instrument, self._session) if instrument is not None: instruments.append(instrument) if self._is_ranged: result = instruments[:] else: result = instruments[0] self._target = result return self.target
def _run(self): from abjad.tools import instrumenttools from ide import idetools try_again = False performers = [] controller = idetools.ControllerContext(controller=self) selector = idetools.Selector(session=self._session) selector = selector.make_score_tools_performer_name_selector( is_ranged=self._is_ranged, ) with controller: while True: result = selector._run() if self._session.is_backtracking: break if isinstance(result, list): performer_names = result else: performer_names = [result] performers = [] Performer = instrumenttools.Performer for performer_name in performer_names: performer = Performer(performer_name) PerformerInventory._initialize_performer( performer, self._session, ) was_backtracking_locally = \ self._session.is_backtracking_locally if self._session.is_backtracking: if was_backtracking_locally: try_again = True else: try_again = False performers = [] break performers.append(performer) if not try_again: break else: try_again = False if self._is_ranged and performers: final_result = performers[:] elif self._is_ranged and not performers: final_result = [] elif not self._is_ranged and performers: final_result = performers[0] elif not self._is_ranged and not performers: final_result = None else: raise ValueError self._target = final_result return self.target
def _name_percussion(instrument, session): from abjad.tools import instrumenttools from ide import idetools if isinstance(instrument, instrumenttools.Percussion): Percussion = instrumenttools.Percussion items = Percussion.known_percussion[:] selector = idetools.Selector(session=session, items=items) instrument_name = selector._run() if selector._session.is_backtracking or instrument_name is None: return instrument = new( instrument, instrument_name=instrument_name, short_instrument_name=instrument_name, ) return instrument