def _get_start_and_stop_pieces( self, leaf, previous_leaf, next_leaf, leaf_ids, ): start_piece = None stop_piece = None direction_string = '' if self.vertical_direction is not None: direction_string = \ stringtools.expr_to_tridirectional_lilypond_symbol( self.vertical_direction) previous_leaf_is_beamable = \ self._is_beamable_component(previous_leaf) and \ id(previous_leaf) in leaf_ids next_leaf_is_beamable = \ self._is_beamable_component(next_leaf) and \ id(next_leaf) in leaf_ids if not previous_leaf_is_beamable: if not next_leaf_is_beamable: if self.isolated_nib_direction is not None: start_piece = '{}['.format(direction_string) stop_piece = ']' else: start_piece = '{}['.format(direction_string) elif not next_leaf_is_beamable: stop_piece = ']' return start_piece, stop_piece
def __init__( self, descriptor='<', direction=None, include_rests=False, overrides=None, ): Spanner.__init__( self, overrides=overrides, ) direction = stringtools.expr_to_tridirectional_lilypond_symbol( direction) self._direction = direction self._include_rests = include_rests start_dynamic, shape_string, stop_dynamic = \ self._parse_descriptor(descriptor) self._descriptor = descriptor assert shape_string in ('<', '>') self._shape_string = shape_string if start_dynamic is not None: start_dynamic = indicatortools.Dynamic(start_dynamic) self._start_dynamic = start_dynamic if stop_dynamic is not None: stop_dynamic = indicatortools.Dynamic(stop_dynamic) self._stop_dynamic = stop_dynamic
def __init__( self, direction=None, overrides=None, ): Spanner.__init__( self, overrides=overrides, ) direction = stringtools.expr_to_tridirectional_lilypond_symbol( direction) self._direction = direction
def __init__( self, direction=None, overrides=None, use_messiaen_style_ties=None, ): Spanner.__init__( self, overrides=overrides, ) direction = stringtools.expr_to_tridirectional_lilypond_symbol( direction) self._direction = direction self._use_messiaen_style_ties = use_messiaen_style_ties
def __str__(self): r'''Gets string representation of articulation. Returns string. ''' if self.name: string = self._shortcut_to_word.get(self.name) if not string: string = self.name if self.direction is None: direction = '-' else: direction = stringtools.expr_to_tridirectional_lilypond_symbol( self.direction) return '{}\{}'.format(direction, string) else: return ''
def _get_lilypond_format_bundle(self, leaf): from abjad.tools import systemtools lilypond_format_bundle = systemtools.LilyPondFormatBundle() if self._is_my_first_leaf(leaf): contributions = override(self)._list_format_contributions( 'override', is_once=False, ) lilypond_format_bundle.grob_overrides.extend(contributions) if self._is_my_last_leaf(leaf): contributions = override(self)._list_format_contributions( 'revert', ) lilypond_format_bundle.grob_reverts.extend(contributions) direction_string = '' if self.direction is not None: direction_string = \ stringtools.expr_to_tridirectional_lilypond_symbol( self.direction) direction_string = '{} '.format(direction_string) if (self._is_my_first_leaf(leaf) and (self.start_dynamic and self.start_dynamic.name == 'niente' or self.stop_dynamic and self.stop_dynamic.name == 'niente')): override(leaf).hairpin.circled_tip = True if self.include_rests: if self._is_my_first_leaf(leaf): string = r'{}\{}'.format(direction_string, self.shape_string) lilypond_format_bundle.right.spanner_starts.append(string) if (self.start_dynamic and not self.start_dynamic.name == 'niente'): string = r'{}\{}'.format( direction_string, self.start_dynamic.name, ) lilypond_format_bundle.right.spanner_starts.append( string) if self._is_my_last_leaf(leaf): if (self.stop_dynamic and not self.stop_dynamic.name == 'niente'): string = r'{}\{}'.format( direction_string, self.stop_dynamic.name, ) lilypond_format_bundle.right.spanner_stops.append( string) else: effective_dynamic = leaf._get_effective( indicatortools.Dynamic) if effective_dynamic is None: string = r'\!' lilypond_format_bundle.right.spanner_stops.append( string) elif effective_dynamic not in leaf._indicator_expressions: found_match = False for indicator in \ leaf._get_indicators(indicatortools.Dynamic): if indicator == effective_dynamic: found_match = True if not found_match: string = r'\!' lilypond_format_bundle.right.spanner_stops.append( string) else: if self._is_my_first(leaf, (scoretools.Chord, scoretools.Note)): string = r'{}\{}'.format( direction_string, self.shape_string, ) lilypond_format_bundle.right.spanner_starts.append(string) if (self.start_dynamic and not self.start_dynamic.name == 'niente'): string = r'{}\{}'.format( direction_string, self.start_dynamic.name, ) lilypond_format_bundle.right.spanner_starts.append( string) if self._is_my_last(leaf, (scoretools.Chord, scoretools.Note)): if (self.stop_dynamic and not self.stop_dynamic.name == 'niente'): string = r'{}\{}'.format( direction_string, self.stop_dynamic.name, ) lilypond_format_bundle.right.spanner_stops.append( string) else: effective_dynamic = leaf._get_effective( indicatortools.Dynamic) if effective_dynamic is None: string = r'\!' lilypond_format_bundle.right.spanner_stops.append( string) elif effective_dynamic not in leaf._indicator_expressions: found_match = False for indicator in \ leaf._get_indicators(indicatortools.Dynamic): if indicator == effective_dynamic: found_match = True if not found_match: string = r'\!' lilypond_format_bundle.right.spanner_stops.append( string) if self._is_my_only_leaf(leaf): lilypond_format_bundle.right.spanner_starts.extend( lilypond_format_bundle.right.spanner_stops) lilypond_format_bundle.right.spanner_stops[:] = [] return lilypond_format_bundle
def test_expr_to_tridirectional_lilypond_symbol_01(): assert stringtools.expr_to_tridirectional_lilypond_symbol('^') == '^' assert stringtools.expr_to_tridirectional_lilypond_symbol('-') == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol('_') == '_' assert stringtools.expr_to_tridirectional_lilypond_symbol(Up) == '^' assert stringtools.expr_to_tridirectional_lilypond_symbol('default') == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol('neutral') == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol(Down) == '_' assert stringtools.expr_to_tridirectional_lilypond_symbol(1) == '^' assert stringtools.expr_to_tridirectional_lilypond_symbol(0) == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol(-1) == '_' assert stringtools.expr_to_tridirectional_lilypond_symbol(None) == None assert pytest.raises( ValueError, "stringtools.expr_to_tridirectional_lilypond_symbol('foo')")
def test_expr_to_tridirectional_lilypond_symbol_01(): assert stringtools.expr_to_tridirectional_lilypond_symbol('^') == '^' assert stringtools.expr_to_tridirectional_lilypond_symbol('-') == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol('_') == '_' assert stringtools.expr_to_tridirectional_lilypond_symbol(Up) == '^' assert stringtools.expr_to_tridirectional_lilypond_symbol('default') == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol('neutral') == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol(Down) == '_' assert stringtools.expr_to_tridirectional_lilypond_symbol(1) == '^' assert stringtools.expr_to_tridirectional_lilypond_symbol(0) == '-' assert stringtools.expr_to_tridirectional_lilypond_symbol(-1) == '_' assert stringtools.expr_to_tridirectional_lilypond_symbol(None) == None assert pytest.raises(ValueError, "stringtools.expr_to_tridirectional_lilypond_symbol('foo')")