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 _get_markup(self, direction=None): from abjad.tools import markuptools operator = markuptools.Markup('r', direction=direction) subscript = markuptools.Markup(self.n).sub() hspace = markuptools.Markup.hspace(-0.25) markup = markuptools.Markup.concat([operator, hspace, subscript]) return markup
def configure_lilypond_file(lilypond_file): r'''Configures LilyPond file. ''' lilypond_file._global_staff_size = 8 context_block = lilypondfiletools.ContextBlock( source_context_name=r'Staff \RemoveEmptyStaves', ) override(context_block).vertical_axis_group.remove_first = True lilypond_file.layout_block.items.append(context_block) slash_separator = indicatortools.LilyPondCommand('slashSeparator') lilypond_file.paper_block.system_separator_markup = slash_separator bottom_margin = lilypondfiletools.LilyPondDimension(0.5, 'in') lilypond_file.paper_block.bottom_margin = bottom_margin top_margin = lilypondfiletools.LilyPondDimension(0.5, 'in') lilypond_file.paper_block.top_margin = top_margin left_margin = lilypondfiletools.LilyPondDimension(0.75, 'in') lilypond_file.paper_block.left_margin = left_margin right_margin = lilypondfiletools.LilyPondDimension(0.5, 'in') lilypond_file.paper_block.right_margin = right_margin paper_width = lilypondfiletools.LilyPondDimension(5.25, 'in') lilypond_file.paper_block.paper_width = paper_width paper_height = lilypondfiletools.LilyPondDimension(7.25, 'in') lilypond_file.paper_block.paper_height = paper_height lilypond_file.header_block.composer = markuptools.Markup('Arvo Pärt') title = 'Cantus in Memory of Benjamin Britten (1980)' lilypond_file.header_block.title = markuptools.Markup(title)
def __illustrate__(self, **kwargs): r'''Illustrates segment. Returns LilyPond file. ''' from abjad.tools import durationtools from abjad.tools import indicatortools from abjad.tools import lilypondfiletools from abjad.tools import markuptools from abjad.tools import scoretools from abjad.tools import schemetools from abjad.tools.topleveltools import attach from abjad.tools.topleveltools import override from abjad.tools.topleveltools import select from abjad.tools.topleveltools import set_ notes = [] for item in self: note = scoretools.Note(item, durationtools.Duration(1, 8)) notes.append(note) voice = scoretools.Voice(notes) staff = scoretools.Staff([voice]) score = scoretools.Score([staff]) score.add_final_bar_line() override(score).bar_line.transparent = True override(score).bar_number.stencil = False override(score).beam.stencil = False override(score).flag.stencil = False override(score).stem.stencil = False override(score).time_signature.stencil = False string = 'override Score.BarLine.transparent = ##f' command = indicatortools.LilyPondCommand(string, format_slot='after') last_leaf = select().by_leaf()(score)[-1][-1] attach(command, last_leaf) moment = schemetools.SchemeMoment((1, 12)) set_(score).proportional_notation_duration = moment lilypond_file = lilypondfiletools.make_basic_lilypond_file( global_staff_size=12, music=score, ) if 'title' in kwargs: title = kwargs.get('title') if not isinstance(title, markuptools.Markup): title = markuptools.Markup(title) lilypond_file.header_block.title = title if 'subtitle' in kwargs: markup = markuptools.Markup(kwargs.get('subtitle')) lilypond_file.header_block.subtitle = markup command = indicatortools.LilyPondCommand('accidentalStyle forget') lilypond_file.layout_block.items.append(command) lilypond_file.layout_block.indent = 0 string = 'markup-system-spacing.padding = 8' command = indicatortools.LilyPondCommand(string, prefix='') lilypond_file.paper_block.items.append(command) string = 'system-system-spacing.padding = 10' command = indicatortools.LilyPondCommand(string, prefix='') lilypond_file.paper_block.items.append(command) string = 'top-markup-spacing.padding = 4' command = indicatortools.LilyPondCommand(string, prefix='') lilypond_file.paper_block.items.append(command) return lilypond_file
def make_text_markup(text): markup = markuptools.Markup.concat([ markuptools.Markup(r'\vstrut'), markuptools.Markup(text), ]) markup = markup.smaller().italic().pad_around(0.5).whiteout().box() markup = markuptools.Markup(markup, Up) return markup
def _get_markup(self, direction=None): from abjad.tools import markuptools markup = markuptools.Markup('I', direction=direction) if self.axis is not None: axis = self.axis.get_name(locale='us') subscript = markuptools.Markup(axis).sub() markup = markuptools.Markup.concat([markup, subscript]) return markup
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 final_markup(self): portland = markuptools.Markup('Portland, OR') date = markuptools.Markup('January 2015 - April 2015') null = markuptools.Markup.null() contents = [ null, null, null, portland, date, ] markup = markuptools.Markup.right_column(contents) markup = markup.italic() return markup
def _initialize_default_name_markups(self): if self.instrument_name: string = self.instrument_name string = stringtools.capitalize_start(string) markup = markuptools.Markup(contents=string) self._instrument_name_markup = markup else: self._instrument_name_markup = None if self.short_instrument_name: string = self.short_instrument_name string = stringtools.capitalize_start(string) markup = markuptools.Markup(contents=string) self._short_instrument_name_markup = markup else: self._short_instrument_name_markup = None
def _bracket_inner_nodes(self, leaf_list_stack, node, voice): from abjad.tools import durationtools from abjad.tools import markuptools from abjad.tools import scoretools from abjad.tools import spannertools from abjad.tools.topleveltools import attach if len(node): if node.level: leaf_list_stack.append([]) for child_node in node: self._bracket_inner_nodes( leaf_list_stack, child_node, voice, ) if node.level: bracket = spannertools.HorizontalBracketSpanner() attach(bracket, leaf_list_stack[-1]) if node.level == 1: node_index = node.parent.index(node) level_one_first_leaf = leaf_list_stack[-1][0] string = r'\bold {{ {} }}'.format(node_index) markup = markuptools.Markup(string, Up) attach(markup, level_one_first_leaf) leaf_list_stack.pop() elif node.payload: note = scoretools.Note( node.payload, durationtools.Duration(1, 8), ) voice.append(note) for leaf_list in leaf_list_stack: leaf_list.append(note)
def __illustrate__(self): r'''Illustrates pitch segment. :: >>> named_pitch_segment = pitchtools.PitchSegment( ... ['bf,', 'aqs', "fs'", "g'", 'bqf', "g'"], ... item_class=NamedPitch, ... ) >>> show(named_pitch_segment) # doctest: +SKIP Returns LilyPond file. ''' from abjad.tools import durationtools from abjad.tools import lilypondfiletools from abjad.tools import markuptools from abjad.tools import pitchtools from abjad.tools import scoretools from abjad.tools.topleveltools import attach from abjad.tools.topleveltools import iterate from abjad.tools.topleveltools import override named_pitches = [pitchtools.NamedPitch(x) for x in self] notes = scoretools.make_notes(named_pitches, [1]) score, treble_staff, bass_staff = \ scoretools.make_piano_sketch_score_from_leaves(notes) for leaf in iterate(score).by_class(scoretools.Leaf): attach(durationtools.Multiplier(1, 8), leaf) override(score).rest.transparent = True lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
def __init__( self, payload, image_layout_specifier=None, image_render_specifier=None, ): from abjad.tools import abjadbooktools from abjad.tools import lilypondfiletools from abjad.tools import markuptools ImageOutputProxy.__init__( self, image_layout_specifier=image_layout_specifier, image_render_specifier=image_render_specifier, ) payload = copy.deepcopy(payload) if image_render_specifier is None: image_render_specifier = abjadbooktools.ImageRenderSpecifier() if (not image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet): payload = documentationtools.make_reference_manual_lilypond_file( payload) lilypond_file = payload assert isinstance(lilypond_file, lilypondfiletools.LilyPondFile) lilypond_file.header_block.tagline = markuptools.Markup('""') lilypond_file._date_time_token = None token = lilypondfiletools.LilyPondVersionToken("2.19.0", ) lilypond_file._lilypond_version_token = token if (image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet): if not lilypond_file.includes: lilypond_file._use_relative_includes = True includes = [image_render_specifier.stylesheet] lilypond_file._includes = tuple(includes) self._payload = lilypond_file
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 execute_against_score(self, score): r'''Execute markup set expression against `score`. ''' markup = self.source_expression.payload for leaf in self._iterate_selected_leaves_in_score(score): new_markup = markuptools.Markup(markup) attach(new_markup, leaf)
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 __illustrate__(self): r'''Attempts to illustrate selection. Evaluates the storage format of the selection (to sever any references to the source score from which the selection was taken). Then tries to wrap the result in a staff; in the case that notes of only C4 are found then sets the staff context name to ``'RhythmicStaff'``. If this works then the staff is wrapped in a LilyPond file and the file is returned. If this doesn't work then the method raises an exception. The idea is that the illustration should work for simple selections of that represent an essentially contiguous snippet of a single voice of music. Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import markuptools from abjad.tools import pitchtools from abjad.tools import scoretools from abjad.tools.topleveltools import mutate music = mutate(self).copy() staff = scoretools.Staff(music) found_different_pitch = False for pitch in pitchtools.list_named_pitches_in_expr(staff): if pitch != pitchtools.NamedPitch("c'"): found_different_pitch = True break if not found_different_pitch: staff.context_name = 'RhythmicStaff' score = scoretools.Score([staff]) lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
def markup(self): r'''Markup of rooted chord-class. :: >>> show(chord_class.markup) # doctest: +SKIP Returns markup. ''' markup = [self._markup_root, self._markup_symbol, self.figured_bass] markup = ''.join(markup) markup = r'\fontsize #1 {} \hspace #-0.5'.format(self._markup_root) symbol = self._markup_symbol if symbol: markup += r' \hspace #0.5 \raise #1 \fontsize #-3 {}'.format( symbol) if 'circle' in symbol: if 'sharp' in self._markup_root: markup += r' \hspace #0' else: markup += r' \hspace #-1.2' inversion = self.figured_bass if inversion: inv = r" \raise #1 \fontsize #-3 \override #'(baseline-skip . 1.5)" inv += r' \column {{ {} }}'.format(' '.join(inversion.split('/'))) markup += inv return markuptools.Markup(markup, Down)
def __illustrate__(self): r'''Illustrates markup. .. container:: example :: >>> string = r'\bold { allegro ma non troppo }' >>> markup = Markup(string) >>> show(markup) # doctest: +SKIP .. doctest:: >>> lilypond_file = markup.__illustrate__() >>> markup = lilypond_file.items[-1] >>> print(format(markup)) \markup { \bold { allegro ma non troppo } } Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import markuptools lilypond_file = lilypondfiletools.make_basic_lilypond_file() lilypond_file.header_block.tagline = markuptools.Markup('""') lilypond_file.items.append(self) return lilypond_file
def _populate_markup_format_contributions( component, bundle, up_markup, down_markup, neutral_markup, ): from abjad.tools import markuptools for markup_list in (up_markup, down_markup, neutral_markup): if not markup_list: continue elif 1 < len(markup_list): direction = markup_list[0].direction if direction is None: direction = '-' markup_list = markup_list[:] markup_list.sort(key=lambda x: -x.stack_priority) markup = markuptools.Markup.column( markup_list, direction=direction, ) format_pieces = markup._get_format_pieces() bundle.right.markup.extend(format_pieces) else: if markup_list[0].direction is None: markup = markuptools.Markup(markup_list[0], direction='-') format_pieces = markup._get_format_pieces() bundle.right.markup.extend(format_pieces) else: format_pieces = markup_list[0]._get_format_pieces() bundle.right.markup.extend(format_pieces)
def _get_lilypond_format_bundle(self, component=None): from abjad.tools import markuptools from abjad.tools import systemtools lilypond_format_bundle = systemtools.LilyPondFormatBundle() lilypond_format_bundle.grob_overrides.append( '\\once \\override Accidental.stencil = ##f\n' '\\once \\override AccidentalCautionary.stencil = ##f\n' '\\once \\override Arpeggio.X-offset = #-2\n' '\\once \\override NoteHead.stencil = #ly:text-interface::print\n' '\\once \\override NoteHead.text = \markup {\n' "\t\\filled-box #'(-0.6 . 0.6) #'(-0.7 . 0.7) #0.25\n" '}') if not self.suppress_markup: if self.include_black_keys and self.include_white_keys: string = r'\center-align \concat { \natural \flat }' elif self.include_black_keys: string = r'\center-align \flat' else: string = r'\center-align \natural' markup = markuptools.Markup( string, direction=self.markup_direction, ) markup_format_pieces = markup._get_format_pieces() lilypond_format_bundle.right.markup.extend(markup_format_pieces) return lilypond_format_bundle
def markup(self): r'''Gets markup of color fingering. .. container:: example :: >>> fingering = indicatortools.ColorFingering(1) >>> print(format(fingering.markup, 'lilypond')) \markup { \override #'(circle-padding . 0.25) \circle \finger 1 } Returns markup. ''' if self.number is None: return markup = markuptools.Markup(str(self.number)) markup = markup.finger() markup = markup.circle() markup = markup.override(('circle-padding', 0.25)) return markup
def final_markup(self): portland = markuptools.Markup('Portland, OR') queens = markuptools.Markup('Fresh Meadows, NY') date = markuptools.Markup('September 2014 - January 2015') null = markuptools.Markup.null() contents = [ null, null, null, portland, queens, date, ] markup = markuptools.Markup.right_column(contents) markup = markup.italic() return markup
def markup(self): r'''Markup of roman numeral. Returns markup. ''' symbolic_string = self.symbolic_string symbolic_string = symbolic_string.replace('#', r'\sharp ') return markuptools.Markup(symbolic_string, Down)
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 __illustrate__(self): r'''Illustrates component. Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import markuptools lilypond_file = lilypondfiletools.make_basic_lilypond_file(self) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
def __call__(self, logical_ties): r'''Calls handler on `logical_ties`. Returns none. ''' markups = datastructuretools.CyclicTuple(self.markups) for i, logical_tie in enumerate(logical_ties): markup = markups[i] markup = markuptools.Markup(markup) attach(markup, logical_tie.head)
def __illustrate__(self): r'''Illustrates pitch range. :: >>> show(pitch_range) # doctest: +SKIP Returns LilyPond file. ''' from abjad.tools import durationtools from abjad.tools import lilypondfiletools from abjad.tools import indicatortools from abjad.tools import markuptools from abjad.tools import pitchtools from abjad.tools import scoretools from abjad.tools import spannertools from abjad.tools.topleveltools import attach from abjad.tools.topleveltools import iterate from abjad.tools.topleveltools import override start_pitch_clef = pitchtools.suggest_clef_for_named_pitches( self.start_pitch) stop_pitch_clef = pitchtools.suggest_clef_for_named_pitches( self.stop_pitch) start_note = scoretools.Note(self.start_pitch, 1) stop_note = scoretools.Note(self.stop_pitch, 1) glissando = spannertools.Glissando() if start_pitch_clef == stop_pitch_clef: if start_pitch_clef == indicatortools.Clef('bass'): bass_staff = scoretools.Staff() attach(indicatortools.Clef('bass'), bass_staff) bass_staff.extend([start_note, stop_note]) attach(glissando, bass_staff.select_leaves()) score = scoretools.Score([bass_staff]) else: treble_staff = scoretools.Staff() attach(indicatortools.Clef('treble'), treble_staff) treble_staff.extend([start_note, stop_note]) attach(glissando, treble_staff.select_leaves()) score = scoretools.Score([treble_staff]) else: result = scoretools.make_empty_piano_score() score, treble_staff, bass_staff = result bass_staff.extend([start_note, stop_note]) treble_staff.extend(scoretools.Skip(1) * 2) attach(glissando, bass_staff.select_leaves()) attach(indicatortools.StaffChange(treble_staff), bass_staff[1]) for leaf in iterate(score).by_class(scoretools.Leaf): attach(durationtools.Multiplier(1, 4), leaf) override(score).bar_line.stencil = False override(score).span_bar.stencil = False override(score).glissando.thickness = 2 override(score).time_signature.stencil = False lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
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