def _get_annotations(self, leaf): import consort leaves = self._get_leaves() index = leaves.index(leaf) prototype = indicatortools.StringContactPoint agent = inspect_(leaf) pizzicato = indicatortools.StringContactPoint('pizzicato') next_attached = None for i in range(index + 1, len(leaves)): next_leaf = leaves[i] indicators = next_leaf._get_indicators( indicatortools.StringContactPoint, ) if indicators: next_attached = indicators[0] break actually_attached = current_attached = None indicators = inspect_(leaf).get_indicators(prototype) if indicators: actually_attached = current_attached = indicators[0] if self._is_my_first_leaf(leaf) and current_attached is None: current_attached = next_attached next_different = None next_after_different = None next_next_different = None for i in range(index + 1, len(leaves)): next_leaf = leaves[i] indicators = next_leaf._get_indicators( indicatortools.StringContactPoint, ) if indicators: indicator = indicators[0] if next_different is not None: if next_after_different is None: next_after_different = indicator if indicator != next_different: next_next_different = indicator break if indicator != current_attached and next_different is None: next_different = indicator n = -1 if actually_attached is None: n = 0 previous_effective = agent.get_effective(prototype, n=n) previous_attached = None for i in reversed(range(index)): previous_leaf = leaves[i] indicators = previous_leaf._get_indicators( indicatortools.StringContactPoint, ) if indicators: previous_attached = indicators[0] break if current_attached is not None and \ not self._is_my_first_leaf(leaf) and \ previous_attached is None: previous_attached = current_attached previous_different = None for i in reversed(range(index)): previous_leaf = leaves[i] indicators = previous_leaf._get_indicators( indicatortools.StringContactPoint, ) if indicators: indicator = indicators[0] if indicator != current_attached: previous_different = indicator has_start_markup = False if current_attached is not None and \ next_attached is not None and \ current_attached != pizzicato and \ next_different != pizzicato and \ current_attached != next_attached: has_start_markup = True has_stop_markup = False if current_attached is not None and \ current_attached != pizzicato and \ (next_next_different == pizzicato or next_next_different is None): has_stop_markup = True elif current_attached is not None and \ next_different == next_after_different: has_stop_markup = True stops_text_spanner = False if current_attached is not None and \ previous_different is not None and \ current_attached != pizzicato and \ previous_different != pizzicato and \ current_attached != previous_attached: stops_text_spanner = True if self._is_my_first_leaf(leaf) and \ current_attached is None and \ previous_effective is not None: current_attached = previous_effective is_cautionary = False if current_attached and current_attached == previous_attached: is_cautionary = True elif current_attached and current_attached == previous_effective: is_cautionary = True current_markup = None if current_attached is not None: current_markup = current_attached.markup if current_attached == previous_attached == next_attached and \ current_attached != pizzicato: current_markup = None if current_attached == previous_effective and \ next_attached is None and \ current_attached != pizzicato and \ not self._is_my_first_leaf(leaf): current_markup = None if current_markup is not None: if is_cautionary: current_markup = current_markup.parenthesize() results = ( current_attached, current_markup, has_start_markup, has_stop_markup, is_cautionary, next_attached, next_different, previous_attached, previous_effective, stops_text_spanner, ) consort.debug(leaf) consort.debug('\t', 'actually_attached', actually_attached) consort.debug('\t', 'current_attached', current_attached) consort.debug('\t', 'current_markup', current_markup) consort.debug('\t', 'has_start_markup', has_start_markup) consort.debug('\t', 'has_stop_markup', has_stop_markup) consort.debug('\t', 'is_cautionary', is_cautionary) consort.debug('\t', 'next_attached', next_attached) consort.debug('\t', 'next_different', next_different) consort.debug('\t', 'next_after_different', next_after_different) consort.debug('\t', 'next_next_different', next_next_different) consort.debug('\t', 'previous_attached', previous_attached) consort.debug('\t', 'previous_effective', previous_effective) consort.debug('\t', 'stops_text_spanner', stops_text_spanner) return results
def _get_lilypond_format_bundle(self, leaf): import consort lilypond_format_bundle = self._get_basic_lilypond_format_bundle(leaf) if not isinstance(leaf, scoretools.Leaf): return lilypond_format_bundle ( current_attached, current_markup, has_start_markup, has_stop_markup, is_cautionary, next_attached, next_different, previous_attached, previous_effective, stops_text_spanner, ) = self._get_annotations(leaf) if current_markup is None: consort.debug('\tRETURNING+++++++++++++++') consort.debug() return lilypond_format_bundle if has_start_markup and has_stop_markup: self._add_segment_start_contributions( lilypond_format_bundle, start_markup=current_markup, stop_markup=next_different.markup, ) elif has_start_markup: self._add_segment_start_contributions( lilypond_format_bundle, start_markup=current_markup, ) if stops_text_spanner: self._add_segment_stop_contributions(lilypond_format_bundle) should_attach_markup = False if current_markup and \ not has_start_markup and \ not has_stop_markup: should_attach_markup = True if current_markup and \ previous_attached is None and \ not has_start_markup: should_attach_markup = True if current_markup and \ current_attached == indicatortools.StringContactPoint('pizzicato'): should_attach_markup = True if current_attached is not None and \ current_attached == next_attached and \ previous_attached != current_attached and \ previous_attached is not None: should_attach_markup = False consort.debug('Attaching???', should_attach_markup) if should_attach_markup: current_markup = markuptools.Markup(current_markup, Up) current_markup = current_markup.italic() current_markup = current_markup.vcenter() lilypond_format_bundle.right.markup.append(current_markup) consort.debug(format(lilypond_format_bundle)) consort.debug() return lilypond_format_bundle
def _get_lilypond_format_bundle(self, leaf): import consort lilypond_format_bundle = self._get_basic_lilypond_format_bundle(leaf) prototype = (abjad.Note, abjad.Chord, type(None)) first_leaf = self._get_leaves()[0] current_clef = abjad.inspect(first_leaf).get_effective(abjad.Clef) set_clef = False reset_clef = False if self._is_my_only_leaf(leaf): consort.debug('ONLY', leaf) if self.clef != current_clef: set_clef = True reset_clef = True previous_leaf = abjad.inspect(leaf).get_leaf(-1) consort.debug('\tP', previous_leaf) while not isinstance(previous_leaf, prototype): previous_leaf = abjad.inspect(previous_leaf).get_leaf(-1) consort.debug('\tP', previous_leaf) if previous_leaf is not None: spanners = abjad.inspect(previous_leaf).get_spanners( type(self)) spanners = tuple(spanners) if spanners: consort.debug('\tPREV?', spanners) if spanners[0].clef == self.clef: set_clef = False next_leaf = abjad.inspect(leaf).get_leaf(1) consort.debug('\tN', next_leaf) while not isinstance(next_leaf, prototype): next_leaf = abjad.inspect(next_leaf).get_leaf(1) consort.debug('\tN', next_leaf) if next_leaf is not None: spanners = abjad.inspect(next_leaf).get_spanners(type(self)) spanners = tuple(spanners) if spanners: consort.debug('\tNEXT?', spanners) if spanners[0].clef == self.clef: reset_clef = False elif self._is_my_first_leaf(leaf): consort.debug('FIRST', leaf) if self.clef != current_clef: set_clef = True previous_leaf = abjad.inspect(leaf).get_leaf(-1) consort.debug('\tP', previous_leaf) while not isinstance(previous_leaf, prototype): previous_leaf = abjad.inspect(previous_leaf).get_leaf(-1) consort.debug('\tP', previous_leaf) if previous_leaf is not None: spanners = abjad.inspect(previous_leaf).get_spanners(type(self)) spanners = tuple(spanners) if spanners: consort.debug('\tPREV?', spanners) if spanners[0].clef == self.clef: set_clef = False elif self._is_my_last_leaf(leaf): consort.debug('LAST', leaf) if self.clef != current_clef and current_clef is not None: reset_clef = True next_leaf = abjad.inspect(leaf).get_leaf(1) consort.debug('\tN', next_leaf) while not isinstance(next_leaf, prototype): next_leaf = abjad.inspect(next_leaf).get_leaf(1) consort.debug('\tN', next_leaf) if next_leaf is not None: spanners = abjad.inspect(next_leaf).get_spanners(type(self)) spanners = tuple(spanners) if spanners: consort.debug('\tNEXT?', spanners) if spanners[0].clef == self.clef: reset_clef = False if set_clef: string = format(self.clef, 'lilypond') lilypond_format_bundle.before.indicators.append(string) if reset_clef and current_clef is not None: string = format(current_clef, 'lilypond') lilypond_format_bundle.after.indicators.append(string) return lilypond_format_bundle