def __call__(self, expr): r'''Calls handler on `expr`. Returns none. ''' assert self.dynamics_talea, repr(self.dynamics_talea) groups = [] classes = (scoretools.Note, scoretools.Chord) for i, group in enumerate(iterate(expr).by_run(classes)): spanner = spannertools.TextSpanner() attach(spanner, group) override(spanner).text_spanner.dash_fraction = 1 dynamic_string = self.dynamics_talea[i] dynamicup = markuptools.Markup([ markuptools.MarkupCommand('dynamic', dynamic_string), markuptools.MarkupCommand('hspace', 0.75)]) override(spanner).text_spanner.bound_details__left__text = \ dynamicup nib_markup = markuptools.Markup( markuptools.MarkupCommand( 'draw-line', schemetools.SchemePair(0, 1))) override(spanner).text_spanner.bound_details__right__text = \ nib_markup override(spanner).text_spanner.bound_details__right__padding = \ -0.2 override(spanner).text_spanner.bound_details__left__stencil_align_dir_y = 0 return groups
def _make_class_name_markup(rhythm_maker): class_ = type(rhythm_maker) string = class_.__name__ string = stringtools.capitalize_start(string) pair = schemetools.SchemePair('font-name', 'Times') command = markuptools.MarkupCommand('override', pair, string) command = markuptools.MarkupCommand('fontsize', 4.5, command) markup = markuptools.Markup(command) return markup
def _make_configuration_markup(rhythm_maker): string = format(rhythm_maker, 'storage') string = string.replace('rhythmmakertools.', '') lines = string.split('\n') command = markuptools.MarkupCommand('column', lines) command.force_quotes = True pair = schemetools.SchemePair('font-name', 'Courier') command = markuptools.MarkupCommand('override', pair, command) markup = markuptools.Markup(command, direction=Up) return markup
def _to_markup(self, class_): instance = class_(**self.arguments) string = format(instance, 'storage') string = string.replace('rhythmmakertools.', '') lines = string.split('\n') command = markuptools.MarkupCommand('column', lines) command.force_quotes = True pair = schemetools.SchemePair('font-name', 'Courier') command = markuptools.MarkupCommand('override', pair, command) markup = markuptools.Markup(command, direction=Up) return markup
def _get_markup(self): left_markup = self._get_left_markup() right_markup = self._get_right_markup() commands = [] commands.extend(left_markup.contents) commands.append(markuptools.MarkupCommand('hspace', -0.5)) commands.append(' = ') commands.append(markuptools.MarkupCommand('hspace', -1)) commands.extend(right_markup.contents) markup = markuptools.Markup(contents=commands) return markup
def label_leaves_in_expr_with_leaf_indices(expr, markup_direction=Down): r'''Label leaves in `expr` with leaf indices: :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> labeltools.label_leaves_in_expr_with_leaf_indices(staff) >>> print(format(staff)) \new Staff { c'8 _ \markup { \small 0 } d'8 _ \markup { \small 1 } e'8 _ \markup { \small 2 } f'8 _ \markup { \small 3 } } :: >>> show(staff) # doctest: +SKIP Returns none. ''' for i, leaf in enumerate(iterate(expr).by_class(scoretools.Leaf)): label = markuptools.MarkupCommand('small', str(i)) markup = markuptools.Markup(label, markup_direction) attach(markup, leaf)
def larger(self): r'''LilyPond ``\larger`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.larger() :: >>> print(format(markup)) \markup { \larger "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) command = markuptools.MarkupCommand( 'larger', contents, ) return new(self, contents=command)
def hspace(amount): r'''LilyPond ``\hspace`` markup command. .. container:: example :: >>> markup = Markup.hspace(0.75) :: >>> f(markup) \markup { \hspace #0.75 } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools command = markuptools.MarkupCommand( 'hspace', amount, ) return Markup(contents=command)
def fraction(numerator, denominator): r'''LilyPond ``\fraction`` markup command. .. container:: example :: >>> markup = Markup.fraction(3, 5) :: >>> print(format(markup)) \markup { \fraction 3 5 } :: >>> show(markup) # doctest: +SKIP Returns new markup ''' from abjad.tools import markuptools command = markuptools.MarkupCommand( 'fraction', str(numerator), str(denominator), ) return Markup(contents=command)
def triangle(is_filled=True): r'''LilyPond ``\triangle`` markup command. .. container:: example :: >>> markup = Markup.triangle() :: >>> print(format(markup)) \markup { \triangle ##t } :: >>> show(markup) # doctest: +SKIP Returns new markup ''' from abjad.tools import markuptools command = markuptools.MarkupCommand( 'triangle', bool(is_filled), ) return Markup(contents=command)
def translate(self, offset_pair): r'''LilyPond ``translate`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.translate((2, 1)) :: >>> print(format(markup)) \markup { \translate #'(2 . 1) "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) offset_pair = schemetools.SchemePair(offset_pair) command = markuptools.MarkupCommand( 'translate', offset_pair, contents, ) return new(self, contents=command)
def scale(self, factor_pair): r'''LilyPond ``\scale`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.scale((0.75, 0.75)) :: >>> print(format(markup)) \markup { \scale #'(0.75 . 0.75) "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) factor_pair = schemetools.SchemePair(factor_pair) command = markuptools.MarkupCommand( 'scale', factor_pair, contents, ) return new(self, contents=command)
def rotate(self, angle): r'''LilyPond ``\rotate`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.rotate(45) :: >>> print(format(markup)) \markup { \rotate #45 "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) command = markuptools.MarkupCommand( 'rotate', angle, contents, ) return new(self, contents=command)
def parenthesize(self): r'''LilyPond ``\parenthesie`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.parenthesize() :: >>> f(markup) \markup { \parenthesize "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) command = markuptools.MarkupCommand( 'parenthesize', contents, ) return new(self, contents=command)
def dynamic(self): r'''LilyPond ``\dynamic`` markup command. .. container:: example :: >>> markup = Markup('sffz') >>> markup = markup.dynamic() :: >>> print(format(markup)) \markup { \dynamic sffz } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) command = markuptools.MarkupCommand( 'dynamic', contents, ) return new(self, contents=command)
def center_column(self, direction=None): r'''LilyPond ``\center-column`` markup command. .. container:: example .. container:: example >>> city = abjad.Markup('Los Angeles') >>> date = abjad.Markup('May - August 2014') >>> markups = [city, date] >>> markup_list = abjad.MarkupList(markups) >>> markup = markup_list.center_column(direction=abjad.Up) >>> abjad.f(markup) ^ \markup { \center-column { "Los Angeles" "May - August 2014" } } >>> abjad.show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = [] for markup in self: string = markuptools.Markup._parse_markup_command_argument(markup) contents.append(string) command = markuptools.MarkupCommand('center-column', contents) return markuptools.Markup(contents=command, direction=direction)
def label_leaves_in_expr_with_pitch_numbers(expr, markup_direction=Down): r'''Label leaves in `expr` with pitch numbers: :: >>> staff = Staff(scoretools.make_leaves([None, 12, [13, 14, 15], None], [(1, 4)])) >>> labeltools.label_leaves_in_expr_with_pitch_numbers(staff) >>> print(format(staff)) \new Staff { r4 c''4 _ \markup { \small 12 } <cs'' d'' ef''>4 _ \markup { \column { \small 15 \small 14 \small 13 } } r4 } :: >>> show(staff) # doctest: +SKIP Returns none. ''' for leaf in iterate(expr).by_class(scoretools.Leaf): for pitch in reversed(pitchtools.PitchSegment.from_selection(leaf)): if pitch is not None: label = markuptools.MarkupCommand('small', str(pitch.pitch_number)) markup = markuptools.Markup(label, markup_direction) attach(markup, leaf)
def pad_around(self, padding): r'''LilyPond ``\pad-around`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.pad_around(10) >>> markup = markup.box() :: >>> print(format(markup)) \markup { \box \pad-around #10 "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) command = markuptools.MarkupCommand( 'pad-around', padding, contents, ) return new(self, contents=command)
def box(self): r'''LilyPond ``\box`` markup command. .. container:: example **Example 1.** Default box: :: >>> markup = Markup('Allegro assai') >>> markup = markup.box() :: >>> print(format(markup)) \markup { \box "Allegro assai" } :: >>> show(markup) # doctest: +SKIP .. container:: example **Example 2.** Customized box: :: >>> markup = Markup('Allegro assai') >>> markup = markup.box() >>> markup = markup.override(('box-padding', 0.5)) :: >>> print(format(markup)) \markup { \override #'(box-padding . 0.5) \box "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) command = markuptools.MarkupCommand( 'box', contents, ) return new(self, contents=command)
def _make_score_number_markup( configuration_number, score_number, ): assert mathtools.is_nonnegative_integer(configuration_number) assert mathtools.is_nonnegative_integer(score_number) number_string = '{}-{}'.format( configuration_number, score_number, ) command = markuptools.MarkupCommand('fontsize', 2, number_string) command = markuptools.MarkupCommand('italic', command) command = markuptools.MarkupCommand('box', command) pair = schemetools.SchemePair('box-padding', 0.75) command = markuptools.MarkupCommand('override', pair, command) width = 9 command = markuptools.MarkupCommand('hcenter-in', width, command) markup = markuptools.Markup(command) return markup
def combine_markup_commands(*commands): r'''Combine MarkupCommand and/or string objects. LilyPond's '\combine' markup command can only take two arguments, so in order to combine more than two stencils, a cascade of '\combine' commands must be employed. `combine_markup_commands` simplifies this process. :: >>> markup_a = markuptools.MarkupCommand('draw-circle', 4, 0.4, False) >>> markup_b = markuptools.MarkupCommand( ... 'filled-box', ... schemetools.SchemePair(-4, 4), ... schemetools.SchemePair(-0.5, 0.5), 1) >>> markup_c = "some text" :: >>> markup = markuptools.combine_markup_commands(markup_a, markup_b, markup_c) >>> result = format(markup, 'lilypond') :: >>> print(result) \combine \combine \draw-circle #4 #0.4 ##f \filled-box #'(-4 . 4) #'(-0.5 . 0.5) #1 "some text" Returns a markup command instance, or a string if that was the only argument. ''' from abjad.tools import markuptools assert len(commands) assert all( isinstance(command, (markuptools.MarkupCommand, str)) for command in commands) if 1 == len(commands): return commands[0] combined = markuptools.MarkupCommand('combine', commands[0], commands[1]) for command in commands[2:]: combined = markuptools.MarkupCommand('combine', combined, command) return combined
def make_dynamic_spanner_below_with_nib_at_right(dynamic_text): r'''Makes dynamic spanner below with nib at right. .. container:: example :: >>> staff = Staff("c'8 d'8 e'8 f'8") >>> spanner = spannertools.make_dynamic_spanner_below_with_nib_at_right('mp') >>> attach(spanner, staff[:]) >>> show(staff) # doctest: +SKIP .. doctest:: >>> print(format(staff)) \new Staff { \override TextSpanner.bound-details.left.text = \markup { \dynamic { mp } } \override TextSpanner.bound-details.right-broken.text = ##f \override TextSpanner.bound-details.right.text = \markup { \draw-line #'(0 . 1) } \override TextSpanner.dash-fraction = #1 \override TextSpanner.direction = #down c'8 \startTextSpan d'8 e'8 f'8 \stopTextSpan \revert TextSpanner.bound-details \revert TextSpanner.dash-fraction \revert TextSpanner.direction } Returns text spanner. ''' from abjad.tools import spannertools text_spanner = spannertools.TextSpanner() string = r'\dynamic {{ {} }}'.format(dynamic_text) left_markup = markuptools.Markup(string) pair = schemetools.SchemePair(0, 1) markup_command = markuptools.MarkupCommand('draw-line', pair) right_markup = markuptools.Markup(markup_command) grob = override(text_spanner).text_spanner grob.bound_details__left__text = left_markup grob.bound_details__right__text = right_markup grob.bound_details__right_broken__text = False grob.dash_fraction = 1 grob.direction = Down return text_spanner
def __call__(self): '''Calls woodwind fingering. Returns markup command. ''' key_groups_as_scheme = [] cc_scheme_pair = schemetools.SchemePair('cc', self._center_column) key_groups_as_scheme.append(cc_scheme_pair) lh_scheme_pair = schemetools.SchemePair('lh', self._left_hand) key_groups_as_scheme.append(lh_scheme_pair) rh_scheme_pair = schemetools.SchemePair('rh', self._right_hand) key_groups_as_scheme.append(rh_scheme_pair) key_groups_as_scheme = schemetools.Scheme(key_groups_as_scheme[:], quoting="'") instrument_as_scheme = schemetools.Scheme(self._instrument_name, quoting="'") return markuptools.MarkupCommand( 'woodwind-diagram', instrument_as_scheme, key_groups_as_scheme, )
def general_align(self, axis, direction): r'''LilyPond ``\general-align`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.general_align('Y', Up) >>> print(format(markup)) \markup { \general-align #Y #UP "Allegro assai" } Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) axis = schemetools.Scheme(axis) # TODO: make schemetools.Scheme(direction) work if direction == Up: direction = schemetools.Scheme('UP') elif direction == Down: direction = schemetools.Scheme('DOWN') elif direction == Center: direction = schemetools.Scheme('CENTER') else: message = 'unknown direction: {!r}.' message = message.format(direction) raise ValueError(message) command = markuptools.MarkupCommand( 'general-align', axis, direction, contents, ) return new(self, contents=command)
def line(self, *markups): r'''LilyPond ``\line`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.line(Markup('ma'), Markup('non troppo')) :: >>> print(format(markup)) \markup { \line { "Allegro assai" ma "non troppo" } } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = [] contents.extend(self.contents) for markup in markups: contents.extend(markup.contents) command = markuptools.MarkupCommand( 'line', contents, ) return new(self, contents=command)
def concat(self, direction=None): r'''LilyPond ``\concat`` markup command. .. container:: example .. container:: example >>> downbow = abjad.Markup.musicglyph('scripts.downbow') >>> hspace = abjad.Markup.hspace(1) >>> upbow = abjad.Markup.musicglyph('scripts.upbow') >>> markups = [downbow, hspace, upbow] >>> markup_list = abjad.MarkupList(markups) >>> markup = markup_list.concat(direction=abjad.Up) >>> abjad.f(markup) ^ \markup { \concat { \musicglyph #"scripts.downbow" \hspace #1 \musicglyph #"scripts.upbow" } } >>> abjad.show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools result = [] for markup in self: contents = markuptools.Markup._parse_markup_command_argument( markup) result.append(contents) command = markuptools.MarkupCommand('concat', result) return markuptools.Markup(contents=command, direction=direction)
def with_color(self, color): r'''LilyPond ``\with-color`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.with_color('blue') :: >>> print(format(markup)) \markup { \with-color #blue "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) color = schemetools.Scheme(color) command = markuptools.MarkupCommand( 'with-color', color, contents, ) return new( self, contents=command, )
def column(markups, direction=Up): r'''LilyPond ``\column`` markup command. .. container:: example :: >>> city = Markup('Los Angeles') >>> date = Markup('May - August 2014') >>> markup = Markup.column([city, date]) :: >>> print(format(markup)) ^ \markup { \column { "Los Angeles" "May - August 2014" } } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = [] for markup in markups: contents.extend(markup.contents) command = markuptools.MarkupCommand( 'column', contents, ) return Markup(contents=command, direction=direction)
def override(self, new_property): r'''LilyPond ``\override`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.parenthesize() >>> markup = markup.override(('padding', 0.75)) :: >>> f(markup) \markup { \override #'(padding . 0.75) \parenthesize "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) new_property = schemetools.SchemePair(new_property) command = markuptools.MarkupCommand( 'override', new_property, contents, ) return new(self, contents=command)
def label_leaves_in_expr_with_tuplet_depth(expr, markup_direction=Down): r'''Label leaves in `expr` with tuplet depth: :: >>> staff = Staff("c'8 d'8 e'8 f'8 g'8") >>> scoretools.FixedDurationTuplet(Duration(2, 8), staff[-3:]) FixedDurationTuplet(Duration(1, 4), "e'8 f'8 g'8") >>> labeltools.label_leaves_in_expr_with_tuplet_depth(staff) >>> show(staff) # doctest: +SKIP :: >>> print(format(staff)) \new Staff { c'8 _ \markup { \small 0 } d'8 _ \markup { \small 0 } \times 2/3 { e'8 _ \markup { \small 1 } f'8 _ \markup { \small 1 } g'8 _ \markup { \small 1 } } } :: >>> show(staff) # doctest: +SKIP Returns none. ''' for leaf in iterate(expr).by_class(scoretools.Leaf): label = markuptools.MarkupCommand( 'small', str(leaf._get_parentage().tuplet_depth)) markup = markuptools.Markup(label, markup_direction) attach(markup, leaf)