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 set_line_breaks_by_line_duration( expr, line_duration, line_break_class=None, kind='prolated', add_empty_bars=False, ): r'''Iterate `line_break_class` instances in `expr` and accumulate `kind` duration. Add line break after every total less than or equal to `line_duration`. Set `line_break_class` to measure when `line_break_class` is none. ''' if line_break_class is None: line_break_class = scoretools.Measure previous = None cumulative_duration = durationtools.Duration(0) for current in iterate(expr).by_class(line_break_class): # TODO: compress these 4 lines to only the 4th line # after duration migration if kind == 'seconds': current_duration = current._get_duration(in_seconds=True) elif kind == 'prolated': current_duration = current._get_duration() elif kind == 'preprolated': current_duration = current._preprolated_duration else: current_duration = getattr(current._get_duration(), kind) candidate_duration = cumulative_duration + current_duration if candidate_duration < line_duration: cumulative_duration += current_duration elif candidate_duration == line_duration: command = indicatortools.LilyPondCommand('break', 'closing') attach(command, current) if add_empty_bars: if current.bar_line.kind is None: current.bar_line.kind = '' cumulative_duration = durationtools.Duration(0) else: if previous is not None: command = indicatortools.LilyPondCommand('break', 'closing') attach(command, previous) if add_empty_bars: if current.bar_line.kind is None: current.bar_line.kind = '' cumulative_duration = current_duration previous = current
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 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_page_breaks(score): r'''Applies page breaks to score. ''' bell_voice = score['Bell Voice'] measure_indices = [ 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 72, 79, 86, 93, 100, ] for measure_index in measure_indices: command = indicatortools.LilyPondCommand('break', 'after') attach(command, bell_voice[measure_index])
def _add_final_bar_line(score): score.add_final_bar_line() selection = score.select_leaves(start=-1) last_leaf = selection[0] string = "override Staff.BarLine #'extra-offset = #'(1.6 . 0)" command = indicatortools.LilyPondCommand( string, 'after', ) attach(command, last_leaf)
def make_desordre_cell(pitches): '''The function constructs and returns a *Désordre cell*. `pitches` is a list of numbers or, more generally, pitch tokens. ''' notes = [scoretools.Note(pitch, (1, 8)) for pitch in pitches] beam = spannertools.Beam() attach(beam, notes) slur = spannertools.Slur() attach(slur, notes) clef = indicatortools.Dynamic('f') attach(clef, notes[0]) dynamic = indicatortools.Dynamic('p') attach(dynamic, notes[1]) # make the lower voice lower_voice = scoretools.Voice(notes) lower_voice.name = 'RH Lower Voice' command = indicatortools.LilyPondCommand('voiceTwo') attach(command, lower_voice) n = int(math.ceil(len(pitches) / 2.)) chord = scoretools.Chord([pitches[0], pitches[0] + 12], (n, 8)) articulation = indicatortools.Articulation('>') attach(articulation, chord) # make the upper voice upper_voice = scoretools.Voice([chord]) upper_voice.name = 'RH Upper Voice' command = indicatortools.LilyPondCommand('voiceOne') attach(command, upper_voice) # combine them together container = scoretools.Container([lower_voice, upper_voice]) container.is_simultaneous = True # make all 1/8 beats breakable leaves = select(lower_voice).by_leaf() for leaf in leaves[:-1]: bar_line = indicatortools.BarLine('') attach(bar_line, leaf) return container
def _add_final_bar_line(score): score.add_final_bar_line() selector = select().by_leaf(flatten=True) leaves = selector(score) leaves = leaves[-1:] last_leaf = leaves[0] string = "override Staff.BarLine.extra-offset = #'(1.6 . 0)" command = indicatortools.LilyPondCommand( string, 'after', ) attach(command, last_leaf)
def apply_rehearsal_marks(score): r'''Applies rehearsal marks to score. ''' bell_voice = score['Bell Voice'] measure_indices = [ 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, ] for measure_index in measure_indices: command = indicatortools.LilyPondCommand(r'mark \default', 'before') attach(command, bell_voice[measure_index])
def __call__(self, expr, timespan=None): r'''Calls handler on `expr`. Returns none. ''' prototype = (scoretools.Note, scoretools.Chord) for note_or_chord in iterate(expr).by_class(prototype): #indicatortools.Dynamic(self.dynamic_name)(note_or_chord) command = indicatortools.LilyPondCommand( self.dynamic_name, 'right', ) attach(command, note_or_chord) return expr
def _resolve_event_identifier(self, identifier): from abjad.tools import lilypondparsertools # without any leading slash lookup = self._current_module[identifier] name = lookup['name'] if name == 'ArticulationEvent': return indicatortools.Articulation(lookup['articulation-type']) elif name == 'AbsoluteDynamicEvent': return indicatortools.Dynamic(lookup['text']) elif name == 'LaissezVibrerEvent': return indicatortools.LilyPondCommand('laissezVibrer', 'after') event = lilypondparsertools.LilyPondEvent(name) if 'span-direction' in lookup: if lookup['span-direction'] == -1: event.span_direction = 'start' else: event.span_direction = 'stop' return event
def __call__(self, logical_ties, timespan=None, offset=0): r'''Calls handler on `expr` with keywords. Returns none. ''' dynamics = datastructuretools.CyclicTuple(self.dynamics) for i, logical_tie in enumerate(logical_ties): dynamic_name = dynamics[offset + i] if i == 0 and self.always_first_note: pass elif self.minimum_duration is not None: written_duration = durationtools.Duration(0) for note in logical_tie: written_duration += note.written_duration if written_duration < self.minimum_duration: continue #indicatortools.Dynamic(dynamic_name)(note_or_chord) command = indicatortools.LilyPondCommand(dynamic_name, 'right') attach(command, logical_tie.head)
def __call__(self, expr): r'''Calls handler on `expr`. Returns none. ''' note_or_chords = [] prototype = (scoretools.Note, scoretools.Chord) logical_ties = iterate(expr).by_logical_tie() logical_ties = [ _ for _ in logical_ties if isinstance(_.head, prototype) ] for i, logical_tie in enumerate(logical_ties): #indicatortools.Dynamic(self.dynamic_name)(note_or_chord) dynamic_name = self._dynamic_names[i] command = indicatortools.LilyPondCommand( dynamic_name, 'right', ) attach(command, logical_tie.head) return expr
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 breathe(self): r'''Handles LilyPond ``\breathe`` command. ''' return indicatortools.LilyPondCommand('breathe', 'after')
def __call__(self, expr): r'''Calls handler on `expr`. Returns none. ''' assert len(self.swell_dynamics) == 5, repr(self.swell_dynamics) assert scoretools.all_are_leaves(expr), repr(expr) start_dynamic, left_hairpin, peak_dynamic, right_hairpin, stop_dynamic = self.swell_dynamics #leaves = list(iterate(expr).by_class(scoretools.Leaf)) #leaves = scoretools.remove_outer_rests_from_sequence(leaves) leaves = expr for leaf in iterate(leaves).by_class(): spanners = leaf._get_spanners(spannertools.Hairpin) for spanner in spanners: spanner.detach() # TODO: this should eventually be changed to remove dynamics only for leaf in leaves: indicatortools.detach_lilypond_commands_attached_to_component(leaf) if 3 <= len(leaves): #indicatortools.Dynamic(start_dynamic)(leaves[0]) #indicatortools.Dynamic(stop_dynamic)(leaves[-1]) indicatortools.LilyPondCommand(start_dynamic, 'right')(leaves[0]) indicatortools.LilyPondCommand(stop_dynamic, 'right')(leaves[-1]) middle_index = int(len(leaves) / 2.0) middle_leaf = leaves[middle_index] #indicatortools.Dynamic(peak_dynamic)(middle_leaf) indicatortools.LilyPondCommand(peak_dynamic, 'right')(middle_leaf) half_count = middle_index + 1 left_leaves = leaves[:half_count] if len(leaves) % 2 == 0: right_leaves = leaves[-middle_index:] else: right_leaves = leaves[-(middle_index + 1):] if left_hairpin == '<': crescendo = spannertools.Crescendo() attach(crescendo, left_leaves) else: decrescendo = spannertools.Decrescendo() attach(decrescendo, left_leaves) if right_hairpin == '<': crescendo = spannertools.Crescendo() attach(crescendo, right_leaves) else: decrescendo = spannertools.Decrescendo() attach(decrescendo, right_leaves) return leaves elif len(leaves) == 2: command = indicatortools.LilyPondCommand(start_dynamic, 'right') attach(command, leaves[0]) command = indicatortools.LilyPondCommand(peak_dynamic, 'right') attach(command, leaves[-1]) if left_hairpin == '<': crescendo = spannertools.Crescendo() attach(crescendo, leaves) else: decrescendo = spannertools.Decrescendo() attach(decrescendo, leaves) elif len(leaves) == 1: command = indicatortools.LilyPondCommand(peak_dynamic, 'right') attach(command, leaves[0]) else: raise ValueError(len(leaves))
def mark(self, label): r'''Handles LilyPond ``\mark`` command. ''' if label is None: label = '\default' return indicatortools.LilyPondCommand('mark %s' % label)
def __call__(self): r'''Calls string orchestra template. Returns score. ''' ### TAGS ### tag_names = [] ### SCORE ### staff_group = scoretools.StaffGroup(name='Outer Staff Group', ) score = scoretools.Score( [staff_group], name='Score', ) ### VIOLINS ### if self.violin_count: clef_name = 'treble' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Violin() instrument_count = self.violin_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### VIOLAS ### if self.viola_count: clef_name = 'alto' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Viola() instrument_count = self.viola_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### CELLOS ### if self.cello_count: clef_name = 'bass' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Cello() instrument_count = self.cello_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### BASSES ### if self.contrabass_count: clef_name = 'bass_8' if self.use_percussion_clefs: clef_name = 'percussion' instrument = instrumenttools.Contrabass() instrument_count = self.contrabass_count instrument_staff_group, instrument_tag_names = \ self._make_instrument_staff_group( clef_name=clef_name, count=instrument_count, instrument=instrument, ) staff_group.append(instrument_staff_group) tag_names.extend(instrument_tag_names) ### TIME SIGNATURE CONTEXT ### time_signature_context = scoretools.Context( name='TimeSignatureContext', context_name='TimeSignatureContext', ) instrument_tags = ' '.join(tag_names) tag_string = "tag #'({})".format(instrument_tags) tag_command = indicatortools.LilyPondCommand(tag_string, 'before') attach(tag_command, time_signature_context) score.insert(0, time_signature_context) return score
def _make_performer_staff_group( self, clef_name=None, instrument=None, number=None, ): if number is not None: name = '{} {}'.format( instrument.instrument_name.title(), number, ) else: name = instrument.instrument_name.title() pitch_range = instrument.pitch_range staff_group = scoretools.StaffGroup( context_name='StringPerformerStaffGroup', name='{} Staff Group'.format(name), ) tag_name = name.replace(' ', '') tag_string = "tag #'{}".format(tag_name) tag_command = indicatortools.LilyPondCommand( tag_string, 'before', ) attach(tag_command, staff_group) if self.split_hands: lh_voice = scoretools.Voice( context_name='FingeringVoice', name='{} Fingering Voice'.format(name), ) abbreviation = lh_voice.name.lower().replace(' ', '_') self.voice_name_abbreviations[abbreviation] = lh_voice.name lh_staff = scoretools.Staff( [lh_voice], context_name='FingeringStaff', name='{} Fingering Staff'.format(name), ) lh_staff.is_simultaneous = True attach(pitch_range, lh_staff) attach(indicatortools.Clef(clef_name), lh_staff) rh_voice = scoretools.Voice( context_name='BowingVoice', name='{} Bowing Voice'.format(name), ) abbreviation = rh_voice.name.lower().replace(' ', '_') self.voice_name_abbreviations[abbreviation] = rh_voice.name rh_staff = scoretools.Staff( [rh_voice], context_name='BowingStaff', name='{} Bowing Staff'.format(name), ) rh_staff.is_simultaneous = True staff_group.extend([rh_staff, lh_staff]) else: lh_voice = scoretools.Voice( context_name='FingeringVoice', name='{} Voice'.format(name), ) lh_staff = scoretools.Staff( [lh_voice], context_name='FingeringStaff', name='{} Staff'.format(name), ) lh_staff.is_simultaneous = True attach(pitch_range, lh_staff) attach(indicatortools.Clef(clef_name), lh_staff) staff_group.append(lh_staff) return staff_group, tag_name
def __call__(self): r'''Calls string quartet score template. Returns score. ''' # make first violin voice and staff first_violin_voice = scoretools.Voice(name='First Violin Voice') first_violin_staff = scoretools.Staff([first_violin_voice], name='First Violin Staff') clef = indicatortools.Clef('treble') attach(clef, first_violin_staff) violin = instrumenttools.Violin() attach(violin, first_violin_staff) tag = indicatortools.LilyPondCommand("tag #'first-violin", 'before') attach(tag, first_violin_staff) # make second violin voice and staff second_violin_voice = scoretools.Voice(name='Second Violin Voice') second_violin_staff = scoretools.Staff([second_violin_voice], name='Second Violin Staff') clef = indicatortools.Clef('treble') attach(clef, second_violin_staff) violin = instrumenttools.Violin() attach(violin, second_violin_staff) tag = indicatortools.LilyPondCommand("tag #'second-violin", 'before') attach(tag, second_violin_staff) # make viola voice and staff viola_voice = scoretools.Voice(name='Viola Voice') viola_staff = scoretools.Staff([viola_voice], name='Viola Staff') clef = indicatortools.Clef('alto') attach(clef, viola_staff) viola = instrumenttools.Viola() attach(viola, viola_staff) tag = indicatortools.LilyPondCommand("tag #'viola", 'before') attach(tag, viola_staff) # make cello voice and staff cello_voice = scoretools.Voice(name='Cello Voice') cello_staff = scoretools.Staff([cello_voice], name='Cello Staff') clef = indicatortools.Clef('bass') attach(clef, cello_staff) cello = instrumenttools.Cello() attach(cello, cello_staff) tag = indicatortools.LilyPondCommand("tag #'cello", 'before') attach(tag, cello_staff) # make string quartet staff group string_quartet_staff_group = scoretools.StaffGroup( [ first_violin_staff, second_violin_staff, viola_staff, cello_staff, ], name='String Quartet Staff Group', ) # make string quartet score string_quartet_score = scoretools.Score( [string_quartet_staff_group], name='String Quartet Score', ) # return string quartet score return string_quartet_score
def one_voice(self): r'''Handles LilyPond ``\oneVoice`` command. ''' return indicatortools.LilyPondCommand('oneVoice')
def voiceOne(self): r'''Handles LilyPond ``\voiceOnce`` command. ''' return indicatortools.LilyPondCommand('voiceOne')
def voiceTwo(self): r'''Handles LilyPond ``\voiceTwo`` command. ''' return indicatortools.LilyPondCommand('voiceTwo')
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_mozart_score(): r'''Makes Mozart score. ''' score_template = templatetools.TwoStaffPianoScoreTemplate() score = score_template() # select the measures to use choices = abjad.demos.mozart.choose_mozart_measures() # create and populate the volta containers treble_volta = scoretools.Container() bass_volta = scoretools.Container() for choice in choices[:7]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) treble_volta.append(treble) bass_volta.append(bass) # attach indicators to the volta containers command = indicatortools.LilyPondCommand('repeat volta 2', 'before') attach(command, treble_volta) command = indicatortools.LilyPondCommand('repeat volta 2', 'before') attach(command, bass_volta) # append the volta containers to our staves score['RH Voice'].append(treble_volta) score['LH Voice'].append(bass_volta) # create and populate the alternative ending containers treble_alternative = scoretools.Container() bass_alternative = scoretools.Container() for choice in choices[7:9]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) treble_alternative.append(treble) bass_alternative.append(bass) # attach indicators to the alternative containers command = indicatortools.LilyPondCommand('alternative', 'before') attach(command, treble_alternative) command = indicatortools.LilyPondCommand('alternative', 'before') attach(command, bass_alternative) # append the alternative containers to our staves score['RH Voice'].append(treble_alternative) score['LH Voice'].append(bass_alternative) # create the remaining measures for choice in choices[9:]: treble, bass = abjad.demos.mozart.make_mozart_measure(choice) score['RH Voice'].append(treble) score['LH Voice'].append(bass) # attach indicators time_signature = indicatortools.TimeSignature((3, 8)) attach(time_signature, score['RH Staff']) bar_line = indicatortools.BarLine('|.') attach(bar_line, score['RH Voice'][-1]) bar_line = indicatortools.BarLine('|.') attach(bar_line, score['LH Voice'][-1]) # remove the old, default piano instrument attached to the piano staff # and attach a custom instrument mark detach(instrumenttools.Instrument, score['Piano Staff']) klavier = instrumenttools.Piano( instrument_name='Katzenklavier', short_instrument_name='kk.', ) attach(klavier, score['Piano Staff']) return score