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) string = r'\startTrillSpan' lilypond_format_bundle.right.spanner_starts.append(string) if self.pitch is not None or self.interval is not None: string = r'\pitchedTrill' lilypond_format_bundle.opening.spanners.append(string) if self.pitch is not None: string = str(self.pitch) lilypond_format_bundle.right.trill_pitches.append(string) elif self.interval is not None: pitch = leaf.written_pitch + self.interval string = str(pitch) lilypond_format_bundle.right.trill_pitches.append(string) if self.is_harmonic: string = '(lambda (grob) (grob-interpret-markup grob' string += r' #{ \markup \musicglyph #"noteheads.s0harmonic" #}))' scheme = schemetools.Scheme(string, verbatim=True) override(leaf).trill_pitch_head.stencil = scheme if self._is_my_last_leaf(leaf): contributions = override(self)._list_format_contributions( 'revert', ) lilypond_format_bundle.grob_reverts.extend(contributions) string = r'\stopTrillSpan' lilypond_format_bundle.right.spanner_stops.append(string) return lilypond_format_bundle
def _apply(self, selections): if self.beam_divisions_together: durations = [] for selection in selections: if isinstance(selection, selectiontools.Selection): duration = selection.get_duration() else: duration = selection._get_duration() durations.append(duration) beam = spannertools.DuratedComplexBeam( durations=durations, span_beam_count=1, ) components = [] for selection in selections: if isinstance(selection, selectiontools.Selection): components.extend(selection) elif isinstance(selection, scoretools.Tuplet): components.append(selection) else: raise TypeError(selection) if self.stemlet_length is not None: grob_proxy = override(beam).staff.stem grob_proxy.stemlet_length = self.stemlet_length attach(beam, components) elif self.beam_each_division: for selection in selections: beam = spannertools.MultipartBeam(beam_rests=self.beam_rests) if self.stemlet_length is not None: grob_proxy = override(beam).staff.stem grob_proxy.stemlet_length = self.stemlet_length attach(beam, selection)
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.direction is not None: string = '{} ['.format(self.direction) else: string = '[' lilypond_format_bundle.right.spanner_starts.append(string) if self._is_my_last_leaf(leaf): contributions = override(self)._list_format_contributions( 'revert', ) lilypond_format_bundle.grob_reverts.extend(contributions) string = ']' if self._is_my_first_leaf(leaf): lilypond_format_bundle.right.spanner_starts.append(string) else: lilypond_format_bundle.right.spanner_stops.append(string) return lilypond_format_bundle
def _get_lilypond_format_bundle(self, component=None): lilypond_format_bundle = self._get_basic_lilypond_format_bundle( component, ) current_annotations = self._get_annotations(component) current_markups = current_annotations[0] current_markup = bool(current_markups) current_line_segment = current_annotations[1] start_spanner = self._spanner_starts_on_leaf(component) stop_spanner = self._spanner_stops_on_leaf(component) if start_spanner: contributions = override(self)._list_format_contributions( 'override', is_once=False, ) lilypond_format_bundle.grob_overrides.extend(contributions) string = r'\startTextSpan' lilypond_format_bundle.right.spanner_starts.append(string) if stop_spanner: contributions = override(self)._list_format_contributions( 'revert', ) lilypond_format_bundle.grob_reverts.extend(contributions) string = r'\stopTextSpan' lilypond_format_bundle.right.spanner_stops.append(string) if current_markups is not None: # assign markup to spanner left text if start_spanner: markup = current_markups[0] if current_line_segment: if current_line_segment.left_hspace is not None: hspace = current_line_segment.left_hspace hspace = markuptools.Markup.hspace(hspace) markup = markuptools.Markup.concat([markup, hspace]) override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'left', 'text', ), value=markup, ) override_string = override_.override_string lilypond_format_bundle.grob_overrides.append(override_string) # format markup normally else: current_markup = current_markups[0] markup = new(current_markup, direction=Up) string = format(markup, 'lilypond') lilypond_format_bundle.right.markup.append(string) if current_line_segment is not None: overrides = current_line_segment._get_lilypond_grob_overrides() for override_ in overrides: override_string = override_.override_string lilypond_format_bundle.grob_overrides.append(override_string) return lilypond_format_bundle
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 configure_score(score): r'''Configures score. ''' spacing_vector = schemetools.make_spacing_vector(0, 0, 8, 0) override(score).vertical_axis_group.staff_staff_spacing = spacing_vector override(score).staff_grouper.staff_staff_spacing = spacing_vector override(score).staff_symbol.thickness = 0.5 set_(score).mark_formatter = schemetools.Scheme('format-mark-box-numbers')
def execute_against_score(self, score): r'''Execute note head color set expression against `score`. ''' color = self.source_expression.payload for leaf in self._iterate_selected_leaves_in_score(score): labeltools.color_leaf(leaf, color) override(leaf).beam.color = color override(leaf).flag.color = color override(leaf).stem.color = color
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 make_rhythmic_sketch_staff(music): r'''Make rhythmic staff with transparent time_signature and transparent bar lines. ''' from abjad.tools import scoretools staff = scoretools.Staff(music) staff.context_name = 'RhythmicStaff' override(staff).time_signature.transparent = True override(staff).bar_line.transparent = True return staff
def _get_basic_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) return lilypond_format_bundle
def _make_time_signature_context_block( font_size=3, minimum_distance=12, padding=4, ): from abjad.tools import layouttools from abjad.tools import lilypondfiletools assert isinstance(font_size, (int, float)) assert isinstance(padding, (int, float)) context_block = lilypondfiletools.ContextBlock( type_='Engraver_group', name='TimeSignatureContext', ) context_block.consists_commands.append('Axis_group_engraver') context_block.consists_commands.append('Time_signature_engraver') override(context_block).time_signature.X_extent = (0, 0) override(context_block).time_signature.X_offset = schemetools.Scheme( 'ly:self-alignment-interface::x-aligned-on-self') override(context_block).time_signature.Y_extent = (0, 0) override(context_block).time_signature.break_align_symbol = False override(context_block).time_signature.break_visibility = \ schemetools.Scheme('end-of-line-invisible') override(context_block).time_signature.font_size = font_size override(context_block).time_signature.self_alignment_X = \ schemetools.Scheme('center') spacing_vector = layouttools.make_spacing_vector( 0, minimum_distance, padding, 0, ) override(context_block).vertical_axis_group.default_staff_staff_spacing = \ spacing_vector return context_block
def _make_time_signature_context_block( font_size=3, minimum_distance=10, padding=4, ): from abjad.tools import layouttools from abjad.tools import lilypondfiletools assert isinstance(font_size, (int, float)) assert isinstance(padding, (int, float)) context_block = lilypondfiletools.ContextBlock( type_='Engraver_group', name='TimeSignatureContext', ) context_block.consists_commands.append('Axis_group_engraver') context_block.consists_commands.append('Time_signature_engraver') override(context_block).time_signature.X_extent = (0, 0) override(context_block).time_signature.X_offset = schemetools.Scheme( 'ly:self-alignment-interface::x-aligned-on-self') override(context_block).time_signature.Y_extent = (0, 0) override(context_block).time_signature.break_align_symbol = False override(context_block).time_signature.break_visibility = \ schemetools.Scheme('end-of-line-invisible') override(context_block).time_signature.font_size = font_size override(context_block).time_signature.self_alignment_X = \ schemetools.Scheme('center') spacing_vector = layouttools.make_spacing_vector( 0, minimum_distance, padding, 0, ) override(context_block).vertical_axis_group.default_staff_staff_spacing = \ spacing_vector return context_block
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 __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 import spannertools 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 _format_pieces(self): from abjad.tools import systemtools indent = systemtools.LilyPondFormatManager.indent result = [] string = '{} {{'.format(self._escaped_name) result.append(string) manager = systemtools.LilyPondFormatManager # CAUTION: source context name must come before type_ to allow # context redefinition. if self.source_context_name is not None: string = indent + r'\{}'.format(self.source_context_name) result.append(string) if self.name is not None: string = indent + r'\name {}'.format(self.name) result.append(string) if self.type_ is not None: string = indent + r'\type {}'.format(self.type_) result.append(string) if self.alias is not None: string = indent + r'\alias {}'.format(self.alias) result.append(string) for statement in self.remove_commands: string = indent + r'\remove {}'.format(statement) result.append(string) # CAUTION: LilyPond \consists statements are order-significant! for statement in self.consists_commands: string = indent + r'\consists {}'.format(statement) result.append(string) for statement in self.accepts_commands: string = indent + r'\accepts {}'.format(statement) result.append(string) overrides = override(self)._list_format_contributions('override') for statement in overrides: string = indent + statement result.append(string) setting_contributions = [] for key, value in set_(self)._get_attribute_tuples(): setting_contribution = \ manager.format_lilypond_context_setting_in_with_block( key, value) setting_contributions.append(setting_contribution) for setting_contribution in sorted(setting_contributions): string = indent + setting_contribution result.append(string) for item in self.items: if isinstance(item, str): string = indent + '{}'.format(item) result.append(string) elif '_get_format_pieces' in dir(item): pieces = item._get_format_pieces() pieces = [indent + item for item in pieces] result.extend(pieces) elif '_format_pieces' in dir(item): pieces = item._format_pieces pieces = [indent + item for item in pieces] result.extend(pieces) else: pass result.append('}') return result
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 apply_overrides(self): if len(self.voices) > 1: topleveltools.override(self.voices[0]).stem.direction = 'up' topleveltools.override(self.voices[1]).stem.direction = 'down' topleveltools.override(self.voices[0]).tuplet_bracket.direction = 'up' topleveltools.override(self.voices[1]).tuplet_bracket.direction = 'down' topleveltools.override(self.voices[0]).tie.direction = 'up' topleveltools.override(self.voices[1]).tie.direction = 'down' topleveltools.override(self.voices[0]).rest.staff_position = 6 topleveltools.override(self.voices[1]).rest.staff_position = -8
def color_contents_of_container(container, color): r'''Color contents of `container`: :: >>> measure = Measure((2, 8), "c'8 d'8") :: >>> labeltools.color_contents_of_container(measure, 'red') Measure((2, 8), "c'8 d'8") .. doctest:: >>> print(format(measure)) { \override Accidental #'color = #red \override Beam #'color = #red \override Dots #'color = #red \override NoteHead #'color = #red \override Rest #'color = #red \override Stem #'color = #red \override TupletBracket #'color = #red \override TupletNumber #'color = #red \time 2/8 c'8 d'8 \revert Accidental #'color \revert Beam #'color \revert Dots #'color \revert NoteHead #'color \revert Rest #'color \revert Stem #'color \revert TupletBracket #'color \revert TupletNumber #'color } :: >>> show(measure) # doctest: +SKIP Returns none. ''' override(container).accidental.color = color override(container).beam.color = color override(container).dots.color = color override(container).note_head.color = color override(container).rest.color = color override(container).stem.color = color override(container).tuplet_bracket.color = color override(container).tuplet_number.color = color return container
def color_note_head_by_numbered_pitch_class_color_map(pitch_carrier): r'''Color `pitch_carrier` note head: :: >>> note = Note("c'4") :: >>> labeltools.color_note_head_by_numbered_pitch_class_color_map(note) Note("c'4") .. doctest:: >>> print format(note) \once \override NoteHead #'color = #(x11-color 'red) c'4 :: >>> show(note) # doctest: +SKIP Numbered pitch-class color map: :: 0: red 1: MediumBlue 2: orange 3: LightSlateBlue 4: ForestGreen 5: MediumOrchid 6: firebrick 7: DeepPink 8: DarkOrange 9: IndianRed 10: CadetBlue 11: SeaGreen 12: LimeGreen Numbered pitch-class color map can not be changed. Raise type error when `pitch_carrier` is not a pitch carrier. Raise extra pitch error when `pitch_carrier` carries more than 1 note head. Raise missing pitch error when `pitch_carrier` carries no note head. Return `pitch_carrier`. ''' pitch = pitchtools.get_named_pitch_from_pitch_carrier(pitch_carrier) color = _pc_number_to_color(abs(pitch.numbered_pitch_class)) if color is not None: override(pitch_carrier).note_head.color = color return pitch_carrier
def color_note_head_by_numbered_pitch_class_color_map(pitch_carrier): r'''Color `pitch_carrier` note head: :: >>> note = Note("c'4") :: >>> labeltools.color_note_head_by_numbered_pitch_class_color_map(note) Note("c'4") .. doctest:: >>> print(format(note)) \once \override NoteHead #'color = #(x11-color 'red) c'4 :: >>> show(note) # doctest: +SKIP Numbered pitch-class color map: :: 0: red 1: MediumBlue 2: orange 3: LightSlateBlue 4: ForestGreen 5: MediumOrchid 6: firebrick 7: DeepPink 8: DarkOrange 9: IndianRed 10: CadetBlue 11: SeaGreen 12: LimeGreen Numbered pitch-class color map can not be changed. Raise type error when `pitch_carrier` is not a pitch carrier. Raise extra pitch error when `pitch_carrier` carries more than 1 note head. Raise missing pitch error when `pitch_carrier` carries no note head. Return `pitch_carrier`. ''' pitch = pitchtools.get_named_pitch_from_pitch_carrier(pitch_carrier) color = _pc_number_to_color(pitch.numbered_pitch_class.pitch_class_number) if color is not None: override(pitch_carrier).note_head.color = color return pitch_carrier
def _copy_with_indicators_but_without_children_or_spanners(self): new = type(self)(*self.__getnewargs__()) if getattr(self, '_lilypond_grob_name_manager', None) is not None: new._lilypond_grob_name_manager = copy.copy(override(self)) if getattr(self, '_lilypond_setting_name_manager', None) is not None: new._lilypond_setting_name_manager = copy.copy(set_(self)) for indicator in self._get_indicators(unwrap=False): new_indicator = copy.copy(indicator) attach(new_indicator, new) return new
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) string = r'\startTextSpan' lilypond_format_bundle.right.spanner_starts.append(string) if self._is_my_last_leaf(leaf): contributions = override(self)._list_format_contributions( 'revert', ) lilypond_format_bundle.grob_reverts.extend(contributions) string = r'\stopTextSpan' lilypond_format_bundle.right.spanner_stops.append(string) return lilypond_format_bundle
def _copy_with_indicators_but_without_children_or_spanners(self): new = type(self)(*self.__getnewargs__()) if getattr(self, '_lilypond_grob_name_manager', None) is not None: new._lilypond_grob_name_manager = copy.copy(override(self)) if getattr(self, '_lilypond_setting_name_manager', None) is not None: new._lilypond_setting_name_manager = copy.copy(set_(self)) for indicator in self._get_indicators(): new_indicator = copy.copy(indicator) attach(new_indicator, new) return new
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 _copy_override_and_set_from_leaf(self, leaf): if getattr(leaf, '_lilypond_grob_name_manager', None) is not None: self._lilypond_grob_name_manager = copy.copy(override(leaf)) if getattr(leaf, '_lilypond_setting_name_manager', None) is not None: self._lilypond_setting_name_manager = copy.copy(set_(leaf)) new_indicators = [] for indicator in leaf._indicator_expressions: new_indicator = copy.copy(indicator) new_indicators.append(new_indicator) for new_indicator in new_indicators: attach(new_indicator, self)
def _apply_overrides(self, overrides): import abjad namespace = abjad.__dict__.copy() manager = override(self) for key, value in overrides.items(): grob_name, attribute = key.split('__', 1) grob_manager = getattr(manager, grob_name) if isinstance(value, str): if 'markuptools' in value or 'schemetools' in value: value = eval(value, namespace, namespace) setattr(grob_manager, attribute, value)
def _apply_overrides(self, overrides): from abjad.tools import markuptools from abjad.tools import schemetools manager = override(self) for key, value in overrides.items(): grob_name, attribute = key.split('__', 1) grob_manager = getattr(manager, grob_name) if isinstance(value, str): if 'markuptools' in value or 'schemetools' in value: value = eval(value) setattr(grob_manager, attribute, value)
def _copy_override_and_set_from_leaf(self, leaf): if getattr(leaf, "_lilypond_grob_name_manager", None) is not None: self._lilypond_grob_name_manager = copy.copy(override(leaf)) if getattr(leaf, "_lilypond_setting_name_manager", None) is not None: self._lilypond_setting_name_manager = copy.copy(set_(leaf)) new_indicators = [] for indicator in leaf._indicator_expressions: new_indicator = copy.copy(indicator) new_indicators.append(new_indicator) for new_indicator in new_indicators: attach(new_indicator, self)
def __illustrate__(self, **kwargs): r'''Illustrates pitch-class tree. Returns LilyPond file. ''' from abjad import abjad_configuration from abjad.tools import indicatortools from abjad.tools import lilypondfiletools from abjad.tools import markuptools from abjad.tools import scoretools from abjad.tools.topleveltools import override voice = scoretools.Voice() staff = scoretools.Staff([voice]) score = scoretools.Score([staff]) stylesheet = os.path.join( abjad_configuration.abjad_directory, 'stylesheets', 'rhythm-letter-16.ily', ) lilypond_file = lilypondfiletools.make_basic_lilypond_file( music=score, includes=[stylesheet], ) voice.consists_commands.append('Horizontal_bracket_engraver') leaf_list_stack = [] self._bracket_inner_nodes(leaf_list_stack, self, voice) score.add_final_bar_line() override(score).bar_line.stencil = False override(score).flag.stencil = False override(score).stem.stencil = False override(score).text_script.staff_padding = 3 override(score).time_signature.stencil = False if 'title' in kwargs: markup = markuptools.Markup(kwargs.get('title')) lilypond_file.header_block.title = markup 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) return lilypond_file
def overrides(self): r'''Gets overrides. Returns dict. ''' manager = override(self) overrides = {} for attribute_tuple in manager._get_attribute_tuples(): attribute = '__'.join(attribute_tuple[:-1]) value = attribute_tuple[-1] overrides[attribute] = value return overrides
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 __illustrate__(self): r'''Illustrates tempo inventory. :: >>> show(inventory) # 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 from abjad.tools.topleveltools import new staff = scoretools.Staff() score = scoretools.Score([staff]) time_signature = indicatortools.TimeSignature((2, 4)) attach(time_signature, staff) # the zero note avoids a lilypond spacing problem: # score-initial tempo indications slip to the left zero_note = scoretools.Note("c'2") staff.append(zero_note) command = indicatortools.LilyPondCommand('break') attach(command, zero_note) for tempo in self.items: note = scoretools.Note("c'2") attach(tempo, note) staff.append(note) command = indicatortools.LilyPondCommand('break') attach(command, note) override(score).bar_line.transparent = True override(score).bar_number.stencil = False override(score).clef.stencil = False override(score).note_head.no_ledgers = True override(score).note_head.transparent = True override(score).staff_symbol.transparent = True override(score).stem.transparent = True override(score).time_signature.stencil = False lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True lilypond_file.items.remove(lilypond_file['paper']) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file
def __call__(self, selections): r'''Calls beam specifier on `selections`. Returns none. ''' if self.beam_divisions_together: durations = [] for selection in selections: if isinstance(selection, selectiontools.Selection): duration = selection.get_duration() else: duration = selection._get_duration() durations.append(duration) beam = spannertools.DuratedComplexBeam( durations=durations, span_beam_count=1, ) components = [] for selection in selections: if isinstance(selection, selectiontools.Selection): components.extend(selection) elif isinstance(selection, scoretools.Tuplet): components.append(selection) else: raise TypeError(selection) if self.stemlet_length is not None: grob_proxy = override(beam).staff.stem grob_proxy.stemlet_length = self.stemlet_length leaves = select(components).by_leaf() #attach(beam, components) attach(beam, leaves) elif self.beam_each_division: for selection in selections: beam = spannertools.MultipartBeam(beam_rests=self.beam_rests) if self.stemlet_length is not None: grob_proxy = override(beam).staff.stem grob_proxy.stemlet_length = self.stemlet_length leaves = select(selection).by_leaf() attach(beam, leaves)
def __illustrate__(self, **kwargs): r'''Illustrates pitch-class tree. Returns LilyPond file. ''' from abjad import abjad_configuration from abjad.tools import indicatortools from abjad.tools import lilypondfiletools from abjad.tools import markuptools from abjad.tools import scoretools from abjad.tools.topleveltools import override voice = scoretools.Voice() staff = scoretools.Staff([voice]) score = scoretools.Score([staff]) lilypond_file = lilypondfiletools.make_basic_lilypond_file(score) stylesheet = os.path.join( abjad_configuration.abjad_directory, 'stylesheets', 'rhythm-letter-16.ily', ) lilypond_file.file_initial_user_includes.append(stylesheet) voice.consists_commands.append('Horizontal_bracket_engraver') leaf_list_stack = [] self._bracket_inner_nodes(leaf_list_stack, self, voice) score.add_final_bar_line() override(score).bar_line.stencil = False override(score).flag.stencil = False override(score).stem.stencil = False override(score).text_script.staff_padding = 3 override(score).time_signature.stencil = False if 'title' in kwargs: markup = markuptools.Markup(kwargs.get('title')) lilypond_file.header_block.title = markup 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) return lilypond_file
def configure_score(score): r'''Configured score. ''' moment = schemetools.SchemeMoment(1, 56) set_(score).proportional_notation_duration = moment set_(score).tuplet_full_length = True override(score).bar_line.stencil = False override(score).bar_number.transparent = True override(score).spacing_spanner.uniform_stretching = True override(score).spacing_spanner.strict_note_spacing = True override(score).time_signature.stencil = False override(score).tuplet_bracket.padding = 2 override(score).tuplet_bracket.staff_padding = 4 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(score).tuplet_number.text = scheme
def __illustrate__(self): r'''Illustrates clef inventory. :: >>> show(inventory) # doctest: +SKIP Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import scoretools staff = scoretools.Staff() for clef in self: rest = scoretools.Rest((1, 8)) clef = copy.copy(clef) attach(clef, rest) staff.append(rest) override(staff).clef.full_size_change = True override(staff).rest.transparent = True override(staff).time_signature.stencil = False lilypond_file = lilypondfiletools.make_basic_lilypond_file(staff) lilypond_file.header_block.tagline = False return lilypond_file
def _copy_with_indicators_but_without_children_or_spanners(self): from abjad.tools import indicatortools new = type(self)(*self.__getnewargs__()) # only the following line differs from Container detach(indicatortools.TimeSignature, new) if getattr(self, '_lilypond_grob_name_manager', None) is not None: new._lilypond_grob_name_manager = copy.copy(override(self)) if getattr(self, '_lilypond_setting_name_manager', None) is not None: new._lilypond_setting_name_manager = copy.copy(set_(self)) for indicator in self._get_indicators(): new_indicator = copy.copy(indicator) attach(new_indicator, new) new.is_simultaneous = self.is_simultaneous return new
def __copy__(self, *args): r'''Copies spanner. Does not copy spanner components. Returns new spanner. ''' new = type(self)(*self.__getnewargs__()) if getattr(self, '_lilypond_grob_name_manager', None) is not None: new._lilypond_grob_name_manager = copy.copy(override(self)) if getattr(self, '_lilypond_setting_name_manager', None) is not None: new._lilypond_setting_name_manager = copy.copy(set_(self)) self._copy_keyword_args(new) return new
def _copy_with_indicators_but_without_children_or_spanners(self): from abjad.tools import indicatortools new = type(self)(*self.__getnewargs__()) # only the following line differs from Container detach(indicatortools.TimeSignature, new) if getattr(self, '_lilypond_grob_name_manager', None) is not None: new._lilypond_grob_name_manager = copy.copy(override(self)) if getattr(self, '_lilypond_setting_name_manager', None) is not None: new._lilypond_setting_name_manager = copy.copy(set_(self)) for indicator in self._get_indicators(): new_indicator = copy.copy(indicator) attach(new_indicator, new) new.is_simultaneous = self.is_simultaneous new.implicit_scaling = self.implicit_scaling return new
def __illustrate__(self): r'''Illustrates pitch. 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 override pitch = pitchtools.NamedPitch(self) note = scoretools.Note(pitch, 1) attach(durationtools.Multiplier(1, 4), note) clef = pitchtools.suggest_clef_for_named_pitches([pitch]) staff = scoretools.Staff() attach(clef, staff) staff.append(note) override(staff).time_signature.stencil = False lilypond_file = lilypondfiletools.make_basic_lilypond_file(staff) lilypond_file.header_block.tagline = markuptools.Markup('""') return lilypond_file