def _get_format_pieces(self): indent = '\t' direction = '' if self.direction is not None: direction = stringtools.arg_to_tridirectional_lilypond_symbol( self.direction) # None if self.contents is None: return [r'\markup { }'] # a single string if len(self.contents) == 1 and isinstance(self.contents[0], str): content = self.contents[0] if '"' in content: content = schemetools.Scheme.format_scheme_value(content) if content: content = '{{ {} }}'.format(content) else: content = '{ }' if direction: return [r'{} \markup {}'.format(direction, content)] return [r'\markup {}'.format(content)] # multiple strings or markup commands if direction: pieces = [r'{} \markup {{'.format(direction)] else: pieces = [r'\markup {'] for content in self.contents: if isinstance(content, str): content = schemetools.Scheme.format_scheme_value(content) pieces.append('{}{}'.format(indent, content)) else: pieces.extend(['{}{}'.format(indent, x) for x in content._get_format_pieces()]) pieces.append('{}}}'.format(indent)) return pieces
def __init__( self, descriptor='<', direction=None, include_rests=False, overrides=None, ): Spanner.__init__( self, overrides=overrides, ) direction = stringtools.arg_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 _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.arg_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 _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.arg_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.arg_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 _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.arg_to_tridirectional_lilypond_symbol(self.direction) direction_string = "{} ".format(direction_string) 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: 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: 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: 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: 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) 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 _format_right_of_leaf(self, leaf): result = [] if not self._is_my_last_leaf(leaf): if self.direction is not None: result.append('{} ~'.format( stringtools.arg_to_tridirectional_lilypond_symbol( self.direction))) else: result.append('~') return result
def __init__( self, direction=None, overrides=None, ): Spanner.__init__( self, overrides=overrides, ) direction = stringtools.arg_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.arg_to_tridirectional_lilypond_symbol( direction) self._direction = direction self._use_messiaen_style_ties = use_messiaen_style_ties
def __init__( self, direction=None, overrides=None, use_messiaen_style_ties=None, ): Spanner.__init__( self, overrides=overrides, ) direction = stringtools.arg_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.arg_to_tridirectional_lilypond_symbol( self.direction) return '{}\{}'.format(direction, string) else: return ''
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.arg_to_tridirectional_lilypond_symbol( self.direction) return '{}\{}'.format(direction, string) else: return ''
def _format_right_of_leaf(self, leaf): result = [] direction_string = '' if self.direction is not None: direction_string = \ stringtools.arg_to_tridirectional_lilypond_symbol( self.direction) direction_string = '{} '.format(direction_string) if self.include_rests: if self._is_my_first_leaf(leaf): result.append('%s\\%s' % (direction_string, self.shape_string)) if self.start_dynamic_string: result.append('%s\\%s' % ( direction_string, self.start_dynamic_string)) if self._is_my_last_leaf(leaf): if self.stop_dynamic_string: result.append('%s\\%s' % ( direction_string, self.stop_dynamic_string)) else: effective_dynamic = leaf._get_effective_context_mark( contexttools.DynamicMark) if effective_dynamic is None or \ effective_dynamic not in \ leaf._start_marks: result.append('\\!') else: if self._is_my_first(leaf, (scoretools.Chord, notetools.Note)): result.append('%s\\%s' % (direction_string, self.shape_string)) if self.start_dynamic_string: result.append('%s\\%s' % ( direction_string, self.start_dynamic_string)) if self._is_my_last(leaf, (scoretools.Chord, notetools.Note)): if self.stop_dynamic_string: result.append('%s\\%s' % ( direction_string, self.stop_dynamic_string)) else: effective_dynamic = leaf._get_effective_context_mark( contexttools.DynamicMark) if effective_dynamic is None: result.append('\\!') return result
def _get_format_pieces(self): indent = '\t' direction = '' if self.direction is not None: direction = stringtools.arg_to_tridirectional_lilypond_symbol( self.direction) # none if self.contents is None: return [r'\markup {}'] # a single string if len(self.contents) == 1 and isinstance(self.contents[0], str): content = self.contents[0] if '"' in content: content = schemetools.Scheme.format_scheme_value(content) if content: content = '{{ {} }}'.format(content) else: content = '{}' if direction: return [r'{} \markup {}'.format(direction, content)] return [r'\markup {}'.format(content)] # multiple strings or markup commands if direction: pieces = [r'{} \markup {{'.format(direction)] else: pieces = [r'\markup {'] for content in self.contents: if isinstance(content, str): content = schemetools.Scheme.format_scheme_value(content) pieces.append('{}{}'.format(indent, content)) else: pieces.extend([ '{}{}'.format(indent, x) for x in content._get_format_pieces() ]) pieces.append('{}}}'.format(indent)) return pieces
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.arg_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_arg_to_tridirectional_lilypond_symbol_01(): assert stringtools.arg_to_tridirectional_lilypond_symbol('^') == '^' assert stringtools.arg_to_tridirectional_lilypond_symbol('-') == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol('_') == '_' assert stringtools.arg_to_tridirectional_lilypond_symbol(Up) == '^' assert stringtools.arg_to_tridirectional_lilypond_symbol('default') == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol('neutral') == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol(Down) == '_' assert stringtools.arg_to_tridirectional_lilypond_symbol(1) == '^' assert stringtools.arg_to_tridirectional_lilypond_symbol(0) == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol(-1) == '_' assert stringtools.arg_to_tridirectional_lilypond_symbol(None) == None assert pytest.raises(ValueError, "stringtools.arg_to_tridirectional_lilypond_symbol('foo')")
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.arg_to_tridirectional_lilypond_symbol( self.direction) direction_string = '{} '.format(direction_string) 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: 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: 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: 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: 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) 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_arg_to_tridirectional_lilypond_symbol_01(): assert stringtools.arg_to_tridirectional_lilypond_symbol('^') == '^' assert stringtools.arg_to_tridirectional_lilypond_symbol('-') == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol('_') == '_' assert stringtools.arg_to_tridirectional_lilypond_symbol(Up) == '^' assert stringtools.arg_to_tridirectional_lilypond_symbol('default') == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol('neutral') == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol(Down) == '_' assert stringtools.arg_to_tridirectional_lilypond_symbol(1) == '^' assert stringtools.arg_to_tridirectional_lilypond_symbol(0) == '-' assert stringtools.arg_to_tridirectional_lilypond_symbol(-1) == '_' assert stringtools.arg_to_tridirectional_lilypond_symbol(None) == None assert pytest.raises(ValueError, "stringtools.arg_to_tridirectional_lilypond_symbol('foo')")
def fset(self, arg): self._direction = \ stringtools.arg_to_tridirectional_lilypond_symbol(arg)