def check_misrepresented_flags(expr=None): r'''Checks to make sure there are no misrepresented flags in score. Returns violators and total. ''' from abjad.tools import scoretools from abjad.tools.topleveltools import iterate from abjad.tools.topleveltools import set_ violators = [] total = 0 for leaf in iterate(expr).by_class(scoretools.Leaf): total += 1 flags = leaf.written_duration.flag_count left = getattr(set_(leaf), 'stem_left_beam_count', None) right = getattr(set_(leaf), 'stem_right_beam_count', None) if left is not None: if flags < left or \ (left < flags and right not in (flags, None)): if leaf not in violators: violators.append(leaf) if right is not None: if flags < right or \ (right < flags and left not in (flags, None)): if leaf not in violators: violators.append(leaf) return violators, total
def check_misrepresented_flags(self): r'''Checks to make sure there are no misrepresented flags in score. Returns violators and total. ''' from abjad.tools import scoretools from abjad.tools.topleveltools import iterate from abjad.tools.topleveltools import set_ violators = [] total = 0 for leaf in iterate(self.expr).by_class(scoretools.Leaf): total += 1 flags = leaf.written_duration.flag_count left = getattr(set_(leaf), 'stem_left_beam_count', None) right = getattr(set_(leaf), 'stem_right_beam_count', None) if left is not None: if flags < left or \ (left < flags and right not in (flags, None)): if leaf not in violators: violators.append(leaf) if right is not None: if flags < right or \ (right < flags and left not in (flags, None)): if leaf not in violators: violators.append(leaf) return violators, total
def _populate_context_setting_format_contributions(component, bundle): result = [] from abjad.tools.topleveltools import set_ from abjad.tools import scoretools manager = LilyPondFormatManager if isinstance(component, (scoretools.Leaf, scoretools.Measure)): contextualizer = set_(component) variables = vars(contextualizer) for name, value in variables.items(): # if we've found a leaf context namespace if name.startswith('_'): for x, y in vars(value).items(): if not x.startswith('_'): string = \ manager.format_lilypond_context_setting_inline( x, y, name) result.append(string) # otherwise we've found a default leaf context setting else: # parse default context setting string = manager.format_lilypond_context_setting_inline( name, value) result.append(string) else: for name, value in vars(set_(component)).items(): string = manager.format_lilypond_context_setting_in_with_block( name, value) result.append(string) result.sort() bundle.context_settings.extend(result)
def _populate_context_setting_format_contributions(component, bundle): result = [] from abjad.tools.topleveltools import set_ from abjad.tools import scoretools manager = LilyPondFormatManager if isinstance(component, scoretools.Context): for name, value in vars(set_(component)).items(): string = manager.format_lilypond_context_setting_in_with_block( name, value) result.append(string) #if isinstance(component, (scoretools.Leaf, scoretools.Measure)): else: contextualizer = set_(component) variables = vars(contextualizer) for name, value in variables.items(): # if we've found a leaf context namespace if name.startswith('_'): for x, y in vars(value).items(): if not x.startswith('_'): string = \ manager.format_lilypond_context_setting_inline( x, y, name) result.append(string) # otherwise we've found a default leaf context setting else: # parse default context setting string = manager.format_lilypond_context_setting_inline( name, value) result.append(string) result.sort() bundle.context_settings.extend(result)
def prep_instruments(instrument_dicts): insts = deepcopy(instrument_dicts) for inst in insts: abj.attach(abj.Clef(inst['clef']), inst['voice']) inst['voice'].remove_commands.append('Note_heads_engraver') inst['voice'].consists_commands.append('Completion_heads_engraver') inst['voice'].remove_commands.append('Rest_engraver') inst['voice'].consists_commands.append('Completion_rest_engraver') set_(inst['voice']).beam_exceptions = scht.SchemeVector() set_(inst['voice']).base_moment = scht.SchemeMoment(1, 4) set_(inst['voice']).beat_structure = scht.SchemeVector(1, 1) set_(inst['voice']).completion_unit = scht.SchemeMoment(1, 4) return insts
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_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, **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_score( self, rhythm_maker, division_list, score_number_markup, ): lists = rhythm_maker(division_list) selections = sequencetools.flatten_sequence(lists) measures = scoretools.make_spacer_skip_measures(division_list) time_signature_context = scoretools.Context( measures, context_name='TimeSignatureContext', name='TimeSignatureContext', ) measures = scoretools.make_spacer_skip_measures(division_list) staff = scoretools.Staff(measures) set_(staff).instrument_name = score_number_markup staff.context_name = 'RhythmicStaff' staff.name = 'Note-entry staff' measures = mutate(staff).replace_measure_contents(selections) score = scoretools.Score() score.append(time_signature_context) score.append(staff) self._add_final_bar_line(score) self._check_score(score) return score
def _make_score( self, rhythm_maker, division_list, score_number_markup, ): lists = rhythm_maker(division_list) music = sequencetools.flatten_sequence(lists) measures = scoretools.make_spacer_skip_measures(division_list) time_signature_context = scoretools.Context( measures, context_name='TimeSignatureContext', name='TimeSignatureContext', ) measures = scoretools.make_spacer_skip_measures(division_list) staff = scoretools.Staff(measures) set_(staff).instrument_name = score_number_markup staff.context_name = 'RhythmicStaff' staff.name = 'Note-entry staff' measures = mutate(staff).replace_measure_contents(music) score = scoretools.Score() score.append(time_signature_context) score.append(staff) self._add_final_bar_line(score) self._check_score(score) return score
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 _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 _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 _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 _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 make_score(self): r'''Make MIDI playback score from scale: :: >>> scale = tonalanalysistools.Scale('E', 'major') >>> score = scale.make_score() .. doctest:: >>> print(format(score)) \new Score \with { tempoWholesPerMinute = #(ly:make-moment 30 1) } << \new Staff { \key e \major e'8 fs'8 gs'8 a'8 b'8 cs''8 ds''8 e''8 ds''8 cs''8 b'8 a'8 gs'8 fs'8 e'4 } >> :: >>> show(score) # doctest: +SKIP Returns score. ''' ascending_notes = self.make_notes(8, durationtools.Duration(1, 8)) descending_notes = copy.deepcopy(ascending_notes[:-1]) descending_notes = list(descending_notes) descending_notes.reverse() descending_notes = selectiontools.Selection(descending_notes) notes = ascending_notes + descending_notes notes[-1].written_duration = durationtools.Duration(1, 4) staff = scoretools.Staff(notes) key_signature = copy.copy(self.key_signature) attach(key_signature, staff) score = scoretools.Score([staff]) set_(score).tempo_wholes_per_minute = schemetools.SchemeMoment(30) return score
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 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 make_ligeti_example_lilypond_file(music=None): r'''Makes Ligeti example LilyPond file. Returns LilyPond file. ''' lilypond_file = lilypondfiletools.make_basic_lilypond_file(music=music) lilypond_file.default_paper_size = 'a4', 'letter' lilypond_file.global_staff_size = 14 lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True lilypond_file.layout_block.merge_differently_dotted = True lilypond_file.layout_block.merge_differently_headed = True context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Bar_number_engraver') context_block.remove_commands.append('Default_bar_line_engraver') context_block.remove_commands.append('Timing_translator') override(context_block).beam.breakable = True override(context_block).glissando.breakable = True override(context_block).note_column.ignore_collision = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).text_script.staff_padding = 4 override(context_block).text_spanner.breakable = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.minimum_length = 3 override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme set_(context_block).autoBeaming = False moment = schemetools.SchemeMoment((1, 12)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True context_block = lilypondfiletools.ContextBlock( source_context_name='Staff', ) lilypond_file.layout_block.items.append(context_block) # LilyPond CAUTION: Timing_translator must appear # before Default_bar_line_engraver! context_block.consists_commands.append('Timing_translator') context_block.consists_commands.append('Default_bar_line_engraver') scheme = schemetools.Scheme("'numbered") override(context_block).time_signature.style = scheme context_block = lilypondfiletools.ContextBlock( source_context_name='RhythmicStaff', ) lilypond_file.layout_block.items.append(context_block) # LilyPond CAUTION: Timing_translator must appear # before Default_bar_line_engraver! context_block.consists_commands.append('Timing_translator') context_block.consists_commands.append('Default_bar_line_engraver') scheme = schemetools.Scheme("'numbered") override(context_block).time_signature.style = scheme override(context_block).vertical_axis_group.minimum_Y_extent = (-2, 4) context_block = lilypondfiletools.ContextBlock( source_context_name='Voice', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Forbid_line_break_engraver') return lilypond_file
def make_text_alignment_example_lilypond_file(music=None): r'''Makes text-alignment example LilyPond file. >>> score = Score([Staff('c d e f')]) >>> lilypond_file = documentationtools.make_text_alignment_example_lilypond_file(score) .. doctest:: >>> print(format(lilypond_file)) # doctest: +SKIP % Abjad revision 5651 % 2012-05-19 10:04 \version "2.15.37" \language "english" #(set-global-staff-size 18) \layout { indent = #0 ragged-right = ##t \context { \Score \remove Bar_number_engraver \remove Default_bar_line_engraver \override Clef #'transparent = ##t \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TextScript #'staff-padding = #4 proportionalNotationDuration = #(ly:make-moment 1 32) } } \paper { bottom-margin = #10 left-margin = #10 line-width = #150 system-system-spacing = #'( (basic-distance . 0) (minimum-distance . 0) (padding . 15) (stretchability . 0)) } \score { \new Score << \new Staff { c4 d4 e4 f4 } >> } Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import schemetools lilypond_file = lilypondfiletools.make_basic_lilypond_file( music=music, global_staff_size=18, ) lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Bar_number_engraver') context_block.remove_commands.append('Default_bar_line_engraver') override(context_block).clef.transparent = True override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).text_script.staff_padding = 4 override(context_block).time_signature.transparent = True moment = schemetools.SchemeMoment((1, 32)) set_(context_block).proportionalNotationDuration = moment lilypond_file.paper_block.bottom_margin = 10 lilypond_file.paper_block.left_margin = 10 lilypond_file.paper_block.line_width = 150 vector = schemetools.make_spacing_vector(0, 0, 15, 0) lilypond_file.paper_block.system_system_spacing = vector return lilypond_file
def make_floating_time_signature_lilypond_file(music=None): r'''Makes floating time signature LilyPond file. .. container:: example :: >>> score = Score() >>> time_signature_context = scoretools.Context( ... context_name='TimeSignatureContext', ... ) >>> durations = [(2, 8), (3, 8), (4, 8)] >>> measures = scoretools.make_spacer_skip_measures(durations) >>> time_signature_context.extend(measures) >>> score.append(time_signature_context) >>> staff = Staff() >>> staff.append(Measure((2, 8), "c'8 ( d'8 )")) >>> staff.append(Measure((3, 8), "e'8 ( f'8 g'8 )")) >>> staff.append(Measure((4, 8), "fs'4 ( e'8 d'8 )")) >>> score.append(staff) >>> lilypond_file = \ ... lilypondfiletools.make_floating_time_signature_lilypond_file( ... score ... ) :: >>> print format(lilypond_file) # doctest: +SKIP % 2014-01-07 18:22 \version "2.19.0" \language "english" #(set-default-paper-size "letter" 'portrait) #(set-global-staff-size 12) \header {} \layout { \accidentalStyle forget indent = #0 ragged-right = ##t \context { \name TimeSignatureContext \type Engraver_group \consists Axis_group_engraver \consists Time_signature_engraver \override TimeSignature #'X-extent = #'(0 . 0) \override TimeSignature #'X-offset = #ly:self-alignment-interface::x-aligned-on-self \override TimeSignature #'Y-extent = #'(0 . 0) \override TimeSignature #'break-align-symbol = ##f \override TimeSignature #'break-visibility = #end-of-line-invisible \override TimeSignature #'font-size = #1 \override TimeSignature #'self-alignment-X = #center \override VerticalAxisGroup #'default-staff-staff-spacing = #'((basic-distance . 0) (minimum-distance . 12) (padding . 6) (stretchability . 0)) } \context { \Score \remove Bar_number_engraver \accepts TimeSignatureContext \override Beam #'breakable = ##t \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TupletBracket #'bracket-visibility = ##t \override TupletBracket #'minimum-length = #3 \override TupletBracket #'padding = #2 \override TupletBracket #'springs-and-rods = #ly:spanner::set-spacing-rods \override TupletNumber #'text = #tuplet-number::calc-fraction-text autoBeaming = ##f proportionalNotationDuration = #(ly:make-moment 1 32) tupletFullLength = ##t } \context { \StaffGroup } \context { \Staff \remove Time_signature_engraver } \context { \RhythmicStaff \remove Time_signature_engraver } } \paper { left-margin = #20 system-system-spacing = #'((basic-distance . 0) (minimum-distance . 0) (padding . 12) (stretchability . 0)) } \score { \new Score << \new TimeSignatureContext { { \time 2/8 s1 * 1/4 } { \time 3/8 s1 * 3/8 } { \time 4/8 s1 * 1/2 } } \new Staff { { \time 2/8 c'8 ( d'8 ) } { \time 3/8 e'8 ( f'8 g'8 ) } { \time 4/8 fs'4 ( e'8 d'8 ) } } >> } :: >>> show(lilypond_file) # doctest: +SKIP Makes LilyPond file. Wraps `music` in LilyPond ``\score`` block. Adds LilyPond ``\header``, ``\layout``, ``\paper`` and ``\score`` blocks to LilyPond file. Defines layout settings for custom ``\TimeSignatureContext``. (Note that you must create and populate an Abjad context with name equal to ``'TimeSignatureContext'`` in order for ``\TimeSignatureContext`` layout settings to apply.) Applies many file, layout and paper settings. Returns LilyPond file. ''' from abjad.tools import layouttools from abjad.tools import lilypondfiletools lilypond_file = lilypondfiletools.make_basic_lilypond_file(music=music) lilypond_file.default_paper_size = 'letter', 'portrait' lilypond_file.global_staff_size = 12 lilypond_file.paper_block.left_margin = 20 vector = layouttools.make_spacing_vector(0, 0, 12, 0) lilypond_file.paper_block.system_system_spacing = vector lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True command = indicatortools.LilyPondCommand('accidentalStyle forget') lilypond_file.layout_block.items.append(command) block = _make_time_signature_context_block(font_size=1, padding=6) lilypond_file.layout_block.items.append(block) context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) lilypond_file.layout_block.items.append(context_block) context_block.accepts_commands.append('TimeSignatureContext') context_block.remove_commands.append('Bar_number_engraver') override(context_block).beam.breakable = True override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme override(context_block).tuplet_bracket.minimum_length = 3 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme set_(context_block).autoBeaming = False moment = schemetools.SchemeMoment((1, 32)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True # provided as a stub position for user customization context_block = lilypondfiletools.ContextBlock( source_context_name='StaffGroup', ) lilypond_file.layout_block.items.append(context_block) context_block = lilypondfiletools.ContextBlock( source_context_name='Staff', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Time_signature_engraver') context_block = lilypondfiletools.ContextBlock( source_context_name='RhythmicStaff', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Time_signature_engraver') return lilypond_file
def make_reference_manual_lilypond_file(music=None, **kwargs): r'''Makes reference manual LilyPond file. >>> score = Score([Staff('c d e f')]) >>> lilypond_file = \ ... documentationtools.make_reference_manual_lilypond_file(score) .. doctest:: >>> print(format(lilypond_file)) # doctest: +SKIP \version "2.19.15" \language "english" <BLANKLINE> #(set-global-staff-size 12) <BLANKLINE> \header { tagline = \markup {} } <BLANKLINE> \layout { indent = #0 ragged-right = ##t \context { \Score \remove Bar_number_engraver \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TupletBracket #'bracket-visibility = ##t \override TupletBracket #'minimum-length = #3 \override TupletBracket #'padding = #2 \override TupletBracket #'springs-and-rods = #ly:spanner::set-spacing-rods \override TupletNumber #'text = #tuplet-number::calc-fraction-text proportionalNotationDuration = #(ly:make-moment 1 24) tupletFullLength = ##t } } <BLANKLINE> \paper { left-margin = 1\in } <BLANKLINE> \score { \new Score << \new Staff { c4 d4 e4 f4 } >> } Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import schemetools assert hasattr(music, '__illustrate__') lilypond_file = music.__illustrate__(**kwargs) blocks = [_ for _ in lilypond_file.items if isinstance(_, lilypondfiletools.Block) ] header_block, layout_block, paper_block = None, None, None for block in blocks: if block.name == 'header': header_block = block elif block.name == 'layout': layout_block = block elif block.name == 'paper': paper_block = block # paper if paper_block is None: paper_block = lilypondfiletools.Block(name='paper') lilypond_file.items.insert(0, paper_block) paper_block.left_margin = lilypondfiletools.LilyPondDimension(1, 'in') # layout if layout_block is None: layout_block = lilypondfiletools.Block(name='layout') lilypond_file.items.insert(0, layout_block) lilypond_file.line_width = lilypondfiletools.LilyPondDimension(6, 'in') layout_block.indent = 0 layout_block.ragged_right = True # score context context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) context_block.remove_commands.append('Bar_number_engraver') override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme override(context_block).tuplet_bracket.minimum_length = 3 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme moment = schemetools.SchemeMoment((1, 24)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True layout_block.items.append(context_block) # header if header_block is None: header_block = lilypondfiletools.Block(name='header') lilypond_file.items.insert(0, header_block) header_block.tagline = markuptools.Markup('""') # etc lilypond_file.file_initial_system_comments[:] = [] lilypond_file.global_staff_size = 12 return lilypond_file
def make_reference_manual_lilypond_file(music=None, **kwargs): r'''Makes reference manual LilyPond file. >>> score = Score([Staff('c d e f')]) >>> lilypond_file = \ ... documentationtools.make_reference_manual_lilypond_file(score) .. doctest:: >>> print(format(lilypond_file)) # doctest: +SKIP \version "2.19.15" \language "english" <BLANKLINE> #(set-global-staff-size 12) <BLANKLINE> \header { tagline = \markup {} } <BLANKLINE> \layout { indent = #0 ragged-right = ##t \context { \Score \remove Bar_number_engraver \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TupletBracket #'bracket-visibility = ##t \override TupletBracket #'minimum-length = #3 \override TupletBracket #'padding = #2 \override TupletBracket #'springs-and-rods = #ly:spanner::set-spacing-rods \override TupletNumber #'text = #tuplet-number::calc-fraction-text proportionalNotationDuration = #(ly:make-moment 1 24) tupletFullLength = ##t } } <BLANKLINE> \paper { left-margin = 1\in } <BLANKLINE> \score { \new Score << \new Staff { c4 d4 e4 f4 } >> } Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import schemetools assert '__illustrate__' in dir(music) lilypond_file = music.__illustrate__(**kwargs) # header lilypond_file.header_block.tagline = markuptools.Markup('""') # layout lilypond_file.layout_block.indent = 0 lilypond_file.line_width = lilypondfiletools.LilyPondDimension(6, 'in') lilypond_file.layout_block.ragged_right = True # paper lilypond_file.paper_block.left_margin = \ lilypondfiletools.LilyPondDimension(1, 'in') # score context context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) context_block.remove_commands.append('Bar_number_engraver') override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme override(context_block).tuplet_bracket.minimum_length = 3 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme moment = schemetools.SchemeMoment((1, 24)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True lilypond_file.layout_block.items.append(context_block) # etc lilypond_file.file_initial_system_comments[:] = [] lilypond_file.global_staff_size = 12 return lilypond_file
def make_floating_time_signature_lilypond_file(music=None): r'''Makes floating time signature LilyPond file. .. container:: example :: >>> score = Score() >>> time_signature_context = scoretools.Context( ... context_name='TimeSignatureContext', ... ) >>> durations = [(2, 8), (3, 8), (4, 8)] >>> measures = scoretools.make_spacer_skip_measures(durations) >>> time_signature_context.extend(measures) >>> score.append(time_signature_context) >>> staff = Staff() >>> staff.append(Measure((2, 8), "c'8 ( d'8 )")) >>> staff.append(Measure((3, 8), "e'8 ( f'8 g'8 )")) >>> staff.append(Measure((4, 8), "fs'4 ( e'8 d'8 )")) >>> score.append(staff) >>> lilypond_file = \ ... lilypondfiletools.make_floating_time_signature_lilypond_file( ... score ... ) :: >>> print(format(lilypond_file)) # doctest: +SKIP % 2014-01-07 18:22 \version "2.19.0" \language "english" #(set-default-paper-size "letter" 'portrait) #(set-global-staff-size 12) \header {} \layout { \accidentalStyle forget indent = #0 ragged-right = ##t \context { \name TimeSignatureContext \type Engraver_group \consists Axis_group_engraver \consists Time_signature_engraver \override TimeSignature #'X-extent = #'(0 . 0) \override TimeSignature #'X-offset = #ly:self-alignment-interface::x-aligned-on-self \override TimeSignature #'Y-extent = #'(0 . 0) \override TimeSignature #'break-align-symbol = ##f \override TimeSignature #'break-visibility = #end-of-line-invisible \override TimeSignature #'font-size = #1 \override TimeSignature #'self-alignment-X = #center \override VerticalAxisGroup #'default-staff-staff-spacing = #'((basic-distance . 0) (minimum-distance . 12) (padding . 6) (stretchability . 0)) } \context { \Score \remove Bar_number_engraver \accepts TimeSignatureContext \override Beam #'breakable = ##t \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TupletBracket #'bracket-visibility = ##t \override TupletBracket #'minimum-length = #3 \override TupletBracket #'padding = #2 \override TupletBracket #'springs-and-rods = #ly:spanner::set-spacing-rods \override TupletNumber #'text = #tuplet-number::calc-fraction-text autoBeaming = ##f proportionalNotationDuration = #(ly:make-moment 1 32) tupletFullLength = ##t } \context { \StaffGroup } \context { \Staff \remove Time_signature_engraver } \context { \RhythmicStaff \remove Time_signature_engraver } } \paper { left-margin = #20 system-system-spacing = #'((basic-distance . 0) (minimum-distance . 0) (padding . 12) (stretchability . 0)) } \score { \new Score << \new TimeSignatureContext { { \time 2/8 s1 * 1/4 } { \time 3/8 s1 * 3/8 } { \time 4/8 s1 * 1/2 } } \new Staff { { \time 2/8 c'8 ( d'8 ) } { \time 3/8 e'8 ( f'8 g'8 ) } { \time 4/8 fs'4 ( e'8 d'8 ) } } >> } :: >>> show(lilypond_file) # doctest: +SKIP Makes LilyPond file. Wraps `music` in LilyPond ``\score`` block. Adds LilyPond ``\header``, ``\layout``, ``\paper`` and ``\score`` blocks to LilyPond file. Defines layout settings for custom ``\TimeSignatureContext``. (Note that you must create and populate an Abjad context with name equal to ``'TimeSignatureContext'`` in order for ``\TimeSignatureContext`` layout settings to apply.) Applies many file, layout and paper settings. Returns LilyPond file. ''' from abjad.tools import layouttools from abjad.tools import lilypondfiletools lilypond_file = lilypondfiletools.make_basic_lilypond_file(music=music) lilypond_file.default_paper_size = 'letter', 'portrait' lilypond_file.global_staff_size = 12 lilypond_file.paper_block.left_margin = 20 vector = layouttools.make_spacing_vector(0, 0, 12, 0) lilypond_file.paper_block.system_system_spacing = vector #lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True command = indicatortools.LilyPondCommand('accidentalStyle forget') lilypond_file.layout_block.items.append(command) block = _make_time_signature_context_block(font_size=1, padding=6) lilypond_file.layout_block.items.append(block) context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) lilypond_file.layout_block.items.append(context_block) context_block.accepts_commands.append('TimeSignatureContext') context_block.remove_commands.append('Bar_number_engraver') override(context_block).beam.breakable = True override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme override(context_block).tuplet_bracket.minimum_length = 3 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme set_(context_block).autoBeaming = False moment = schemetools.SchemeMoment((1, 24)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True # provided as a stub position for user customization context_block = lilypondfiletools.ContextBlock( source_context_name='StaffGroup', ) lilypond_file.layout_block.items.append(context_block) context_block = lilypondfiletools.ContextBlock( source_context_name='Staff', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Time_signature_engraver') context_block = lilypondfiletools.ContextBlock( source_context_name='RhythmicStaff', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Time_signature_engraver') return lilypond_file
def make_text_alignment_example_lilypond_file(music=None): r'''Makes text-alignment example LilyPond file. >>> score = Score([Staff('c d e f')]) >>> lilypond_file = documentationtools.make_text_alignment_example_lilypond_file(score) .. doctest:: >>> print(format(lilypond_file)) # doctest: +SKIP % Abjad revision 5651 % 2012-05-19 10:04 \version "2.15.37" \language "english" #(set-global-staff-size 18) \layout { indent = #0 ragged-right = ##t \context { \Score \remove Bar_number_engraver \remove Default_bar_line_engraver \override Clef #'transparent = ##t \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TextScript #'staff-padding = #4 proportionalNotationDuration = #(ly:make-moment 1 32) } } \paper { bottom-margin = #10 left-margin = #10 line-width = #150 system-system-spacing = #'( (basic-distance . 0) (minimum-distance . 0) (padding . 15) (stretchability . 0)) } \score { \new Score << \new Staff { c4 d4 e4 f4 } >> } Returns LilyPond file. ''' from abjad.tools import layouttools from abjad.tools import lilypondfiletools from abjad.tools import schemetools lilypond_file = lilypondfiletools.make_basic_lilypond_file(music=music) lilypond_file.global_staff_size = 18 lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Bar_number_engraver') context_block.remove_commands.append('Default_bar_line_engraver') override(context_block).clef.transparent = True override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).text_script.staff_padding = 4 override(context_block).time_signature.transparent = True moment = schemetools.SchemeMoment((1, 32)) set_(context_block).proportionalNotationDuration = moment lilypond_file.paper_block.bottom_margin = 10 lilypond_file.paper_block.left_margin = 10 lilypond_file.paper_block.line_width = 150 vector = layouttools.make_spacing_vector(0, 0, 15, 0) lilypond_file.paper_block.system_system_spacing = vector return lilypond_file
def make_reference_manual_lilypond_file(music=None, **kwargs): r'''Makes reference manual LilyPond file. >>> score = Score([Staff('c d e f')]) >>> lilypond_file = \ ... documentationtools.make_reference_manual_lilypond_file(score) .. doctest:: >>> print(format(lilypond_file)) # doctest: +SKIP \version "2.19.15" \language "english" <BLANKLINE> #(set-global-staff-size 12) <BLANKLINE> \header { tagline = ##f } <BLANKLINE> \layout { indent = #0 ragged-right = ##t \context { \Score \remove Bar_number_engraver \override SpacingSpanner.strict-grace-spacing = ##t \override SpacingSpanner.strict-note-spacing = ##t \override SpacingSpanner.uniform-stretching = ##t \override TupletBracket.bracket-visibility = ##t \override TupletBracket.minimum-length = #3 \override TupletBracket.padding = #2 \override TupletBracket.springs-and-rods = #ly:spanner::set-spacing-rods \override TupletNumber.text = #tuplet-number::calc-fraction-text proportionalNotationDuration = #(ly:make-moment 1 24) tupletFullLength = ##t } } <BLANKLINE> \paper { left-margin = 1\in } <BLANKLINE> \score { \new Score << \new Staff { c4 d4 e4 f4 } >> } Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import schemetools assert hasattr(music, '__illustrate__') lilypond_file = music.__illustrate__(**kwargs) blocks = [ _ for _ in lilypond_file.items if isinstance(_, lilypondfiletools.Block) ] header_block, layout_block, paper_block = None, None, None for block in blocks: if block.name == 'header': header_block = block elif block.name == 'layout': layout_block = block elif block.name == 'paper': paper_block = block # paper if paper_block is None: paper_block = lilypondfiletools.Block(name='paper') lilypond_file.items.insert(0, paper_block) paper_block.left_margin = lilypondfiletools.LilyPondDimension(1, 'in') # layout if layout_block is None: layout_block = lilypondfiletools.Block(name='layout') lilypond_file.items.insert(0, layout_block) # TODO: following line does nothing; must assign to paper_block instead #lilypond_file.line_width = lilypondfiletools.LilyPondDimension(6, 'in') layout_block.indent = 0 layout_block.ragged_right = True # score context context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) context_block.remove_commands.append('Bar_number_engraver') override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme override(context_block).tuplet_bracket.minimum_length = 3 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme moment = schemetools.SchemeMoment((1, 24)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True layout_block.items.append(context_block) # header if header_block is None: header_block = lilypondfiletools.Block(name='header') lilypond_file.items.insert(0, header_block) header_block.tagline = markuptools.Markup('""') # etc lilypond_file._date_time_token = None lilypond_file._global_staff_size = 12 return lilypond_file
def make_reference_manual_lilypond_file(music=None): r'''Makes reference manual LilyPond file. >>> score = Score([Staff('c d e f')]) >>> lilypond_file = \ ... documentationtools.make_reference_manual_lilypond_file(score) .. doctest:: >>> print(format(lilypond_file)) # doctest: +SKIP \version "2.15.37" \language "english" \layout { indent = #0 ragged-right = ##t \context { \Score \remove Bar_number_engraver \override SpacingSpanner #'strict-grace-spacing = ##t \override SpacingSpanner #'strict-note-spacing = ##t \override SpacingSpanner #'uniform-stretching = ##t \override TupletBracket #'bracket-visibility = ##t \override TupletBracket #'minimum-length = #3 \override TupletBracket #'padding = #2 \override TupletBracket #'springs-and-rods = #ly:spanner::set-spacing-rods \override TupletNumber #'text = #tuplet-number::calc-fraction-text proportionalNotationDuration = #(ly:make-moment 1 32) tupletFullLength = True } } \paper { left-margin = 1.0\in } \score { \new Score << \new Staff { c4 d4 e4 f4 } >> } Returns LilyPond file. ''' from abjad.tools import lilypondfiletools from abjad.tools import schemetools assert '__illustrate__' in dir(music) lilypond_file = music.__illustrate__() # header lilypond_file.header_block.tagline = markuptools.Markup('""') # layout lilypond_file.layout_block.indent = 0 lilypond_file.line_width = lilypondfiletools.LilyPondDimension(6, 'in') lilypond_file.layout_block.ragged_right = True # paper lilypond_file.paper_block.left_margin = \ lilypondfiletools.LilyPondDimension(1, 'in') # score context context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) context_block.remove_commands.append('Bar_number_engraver') override(context_block).spacing_spanner.strict_grace_spacing = True override(context_block).spacing_spanner.strict_note_spacing = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme override(context_block).tuplet_bracket.minimum_length = 3 scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme moment = schemetools.SchemeMoment((1, 32)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True lilypond_file.layout_block.items.append(context_block) # etc lilypond_file.file_initial_system_comments[:] = [] lilypond_file.global_staff_size = 12 return lilypond_file
def make_ligeti_example_lilypond_file(music=None): r'''Makes Ligeti example LilyPond file. Returns LilyPond file. ''' lilypond_file = lilypondfiletools.make_basic_lilypond_file( music=music, default_paper_size=('a4', 'letter'), global_staff_size=14, ) lilypond_file.layout_block.indent = 0 lilypond_file.layout_block.ragged_right = True lilypond_file.layout_block.merge_differently_dotted = True lilypond_file.layout_block.merge_differently_headed = True context_block = lilypondfiletools.ContextBlock( source_context_name='Score', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Bar_number_engraver') context_block.remove_commands.append('Default_bar_line_engraver') context_block.remove_commands.append('Timing_translator') override(context_block).beam.breakable = True override(context_block).glissando.breakable = True override(context_block).note_column.ignore_collision = True override(context_block).spacing_spanner.uniform_stretching = True override(context_block).text_script.staff_padding = 4 override(context_block).text_spanner.breakable = True override(context_block).tuplet_bracket.bracket_visibility = True override(context_block).tuplet_bracket.minimum_length = 3 override(context_block).tuplet_bracket.padding = 2 scheme = schemetools.Scheme('ly:spanner::set-spacing-rods') override(context_block).tuplet_bracket.springs_and_rods = scheme scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(context_block).tuplet_number.text = scheme set_(context_block).autoBeaming = False moment = schemetools.SchemeMoment((1, 12)) set_(context_block).proportionalNotationDuration = moment set_(context_block).tupletFullLength = True context_block = lilypondfiletools.ContextBlock( source_context_name='Staff', ) lilypond_file.layout_block.items.append(context_block) # LilyPond CAUTION: Timing_translator must appear # before Default_bar_line_engraver! context_block.consists_commands.append('Timing_translator') context_block.consists_commands.append('Default_bar_line_engraver') scheme = schemetools.Scheme("'numbered") override(context_block).time_signature.style = scheme context_block = lilypondfiletools.ContextBlock( source_context_name='RhythmicStaff', ) lilypond_file.layout_block.items.append(context_block) # LilyPond CAUTION: Timing_translator must appear # before Default_bar_line_engraver! context_block.consists_commands.append('Timing_translator') context_block.consists_commands.append('Default_bar_line_engraver') scheme = schemetools.Scheme("'numbered") override(context_block).time_signature.style = scheme override(context_block).vertical_axis_group.minimum_Y_extent = (-2, 4) context_block = lilypondfiletools.ContextBlock( source_context_name='Voice', ) lilypond_file.layout_block.items.append(context_block) context_block.remove_commands.append('Forbid_line_break_engraver') return lilypond_file