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 _get_lilypond_format_bundle(self, leaf): from abjad.tools import lilypondnametools from abjad.tools import schemetools from abjad.tools import systemtools lilypond_format_bundle = self._get_basic_lilypond_format_bundle(leaf) if self._is_my_only_leaf(leaf): context_setting = lilypondnametools.LilyPondContextSetting( context_name='Staff', context_property='pedalSustainStyle', value=schemetools.Scheme(self.style, quoting="'"), ) lilypond_format_bundle.update(context_setting) string = self._kinds[self.kind][0] lilypond_format_bundle.right.spanner_starts.append(string) string = self._kinds[self.kind][1] lilypond_format_bundle.right.spanner_starts.append(string) elif self._is_my_first_leaf(leaf): context_setting = lilypondnametools.LilyPondContextSetting( context_name='Staff', context_property='pedalSustainStyle', value=schemetools.Scheme(self.style, quoting="'"), ) lilypond_format_bundle.update(context_setting) string = self._kinds[self.kind][0] lilypond_format_bundle.right.spanner_starts.append(string) elif self._is_my_last_leaf(leaf): string = self._kinds[self.kind][1] lilypond_format_bundle.right.spanner_stops.append(string) return lilypond_format_bundle
def format_lilypond_value(expr): r'''Formats LilyPond `expr` according to Scheme formatting conventions. Returns string. ''' from abjad.tools import schemetools if '_lilypond_format' in dir(expr) and not isinstance(expr, str): pass elif expr in (True, False): expr = schemetools.Scheme(expr) elif expr in (Up, Down, Left, Right, Center): expr = schemetools.Scheme(repr(expr).lower()) elif isinstance(expr, int) or isinstance(expr, float): expr = schemetools.Scheme(expr) elif expr in LilyPondFormatManager.lilypond_color_constants: expr = schemetools.Scheme(expr) elif isinstance(expr, str) and '::' in expr: expr = schemetools.Scheme(expr) elif isinstance(expr, tuple) and len(expr) == 2: expr = schemetools.SchemePair(expr[0], expr[1]) elif isinstance(expr, str) and ' ' not in expr: expr = schemetools.Scheme(expr, quoting="'") elif isinstance(expr, str) and ' ' in expr: expr = schemetools.Scheme(expr) else: expr = schemetools.Scheme(expr, quoting="'") return format(expr, 'lilypond')
def _make_markup_score_block(selection): from abjad.tools import lilypondfiletools from abjad.tools import schemetools from abjad.tools import scoretools selection = copy.deepcopy(selection) staff = scoretools.Staff(selection) staff.context_name = 'RhythmicStaff' staff.remove_commands.append('Time_signature_engraver') staff.remove_commands.append('Staff_symbol_engraver') override(staff).stem.direction = Up #override(staff).stem.length = 4 override(staff).stem.length = 5 override(staff).tuplet_bracket.bracket_visibility = True override(staff).tuplet_bracket.direction = Up override(staff).tuplet_bracket.padding = 1.25 override(staff).tuplet_bracket.shorten_pair = (-1, -1.5) scheme = schemetools.Scheme('tuplet-number::calc-fraction-text') override(staff).tuplet_number.text = scheme set_(staff).tuplet_full_length = True layout_block = lilypondfiletools.Block(name='layout') layout_block.indent = 0 layout_block.ragged_right = True score = scoretools.Score([staff]) override(score).spacing_spanner.spacing_increment = 0.5 set_(score).proportional_notation_duration = False return score, layout_block
def __init__(self, glyph_name=None): from abjad.ly import music_glyphs glyph_name = glyph_name or 'accidentals.sharp' message = 'not a valid LilyPond glyph name.' assert glyph_name in music_glyphs, message glyph_scheme = schemetools.Scheme(glyph_name, force_quotes=True) MarkupCommand.__init__(self, 'musicglyph', glyph_scheme)
def p_variable__IDENTIFIER(self, p): r'''variable : IDENTIFIER ''' #print 'variable : IDENTIFIER' #print p[1] p.slice[0].cursor_end = p.slice[-1].cursor_end p[0] = schemetools.Scheme(p[1])
def _make_bow_contact_point_overrides( self, bow_contact_point=None, lilypond_format_bundle=None, ): if bow_contact_point is None: return override_ = lilypondnametools.LilyPondGrobOverride( grob_name='NoteHead', is_once=True, property_path='stencil', value=schemetools.Scheme('ly:text-interface::print'), ) string = override_.override_string lilypond_format_bundle.grob_overrides.append(string) override_ = lilypondnametools.LilyPondGrobOverride( grob_name='NoteHead', is_once=True, property_path='text', value=bow_contact_point.markup, ) string = override_.override_string lilypond_format_bundle.grob_overrides.append(string) y_offset = float((4 * bow_contact_point.contact_point) - 2) override_ = lilypondnametools.LilyPondGrobOverride( grob_name='NoteHead', is_once=True, property_path='Y-offset', value=y_offset, ) string = override_.override_string lilypond_format_bundle.grob_overrides.append(string)
def make_page(direc, main_staff, drone_staff, inst): mfn = inst['name'] + '_main.ly' dfn = inst['name'] + '_drone.ly' main_group = st.StaffGroup([main_staff]) drone_group = st.StaffGroup([drone_staff]) for group in [main_group, drone_group]: tlt.override(group).system_start_bracket.collapse_height = 2000 score1 = st.Score([main_group]) score2 = st.Score([drone_group]) for score in [score1, score2]: tlt.override(score).staff_grouper.staffgroup_staff_spacing = \ scht.SchemeAssociativeList(('basic-distance', 30), ('padding', 1)) tlt.override(score).bar_line.allow_span_bar = False tlt.override(score).system_start_bar.collapse_height = 2000 mf = lyft.make_basic_lilypond_file(score1) df = lyft.make_basic_lilypond_file(score2) for fn, lf in zip([mfn, dfn], [mf, df]): lf.header_block.composer = "Danny Clarke" lf.header_block.instrument = scht.Scheme(inst['name'], quoting="'") with open(direc + '/' + fn, 'w+') as f: f.write(format(lf)) return mfn, dfn
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 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 p_list__L_PAREN__data__datum__PERIOD__datum__R_PAREN(self, p): r'''list : L_PAREN data datum PERIOD datum R_PAREN ''' p.slice[0].cursor_end = p.slice[-1].cursor_end result = p[2] + [p[3]] + [p[5]] if len(result) == 2: p[0] = schemetools.SchemePair(*result) else: p[0] = schemetools.Scheme(*result) self.expression_depth -= 1
def __call__(self): '''Calls woodwind fingering. Returns markup command. ''' key_groups_as_scheme = [] cc_scheme_pair = schemetools.SchemePair('cc', self._center_column) key_groups_as_scheme.append(cc_scheme_pair) lh_scheme_pair = schemetools.SchemePair('lh', self._left_hand) key_groups_as_scheme.append(lh_scheme_pair) rh_scheme_pair = schemetools.SchemePair('rh', self._right_hand) key_groups_as_scheme.append(rh_scheme_pair) key_groups_as_scheme = schemetools.Scheme(key_groups_as_scheme[:], quoting="'") instrument_as_scheme = schemetools.Scheme(self._instrument_name, quoting="'") return markuptools.MarkupCommand( 'woodwind-diagram', instrument_as_scheme, key_groups_as_scheme, )
def general_align(self, axis, direction): r'''LilyPond ``\general-align`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.general_align('Y', Up) >>> print(format(markup)) \markup { \general-align #Y #UP "Allegro assai" } Returns new markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) axis = schemetools.Scheme(axis) # TODO: make schemetools.Scheme(direction) work if direction == Up: direction = schemetools.Scheme('UP') elif direction == Down: direction = schemetools.Scheme('DOWN') elif direction == Center: direction = schemetools.Scheme('CENTER') else: message = 'unknown direction: {!r}.' message = message.format(direction) raise ValueError(message) command = markuptools.MarkupCommand( 'general-align', axis, direction, contents, ) return new(self, contents=command)
def p_expression__QUOTE__datum(self, p): r'''expression : QUOTE datum ''' #print 'expression : QUOTE datum' #print p[2] p.slice[0].cursor_end = p.slice[-1].cursor_end datum = p[2] if isinstance(datum, schemetools.Scheme): if datum._quoting: datum._quoting = "'" + datum._quoting else: datum._quoting = "'" p[0] = datum else: p[0] = schemetools.Scheme(datum, quoting="'")
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 _get_formatted_user_attributes(self): from abjad.tools import indicatortools from abjad.tools import lilypondfiletools from abjad.tools import markuptools from abjad.tools import schemetools result = [] for value in self.items: acceptable_types = ( schemetools.Scheme, indicatortools.LilyPondCommand, ) if isinstance(value, acceptable_types): result.append(format(value, 'lilypond')) for key, value in sorted(vars(self).items()): if not key.startswith('_'): # format subkeys via double underscore formatted_key = key.split('__') for i, k in enumerate(formatted_key): formatted_key[i] = k.replace('_', '-') if 0 < i: string = "#'{}".format(formatted_key[i]) formatted_key[i] = string formatted_key = ' '.join(formatted_key) # format value accetable_types = ( schemetools.Scheme, lilypondfiletools.LilyPondDimension, indicatortools.LilyPondCommand, ) if isinstance(value, markuptools.Markup): formatted_value = value._get_format_pieces() elif isinstance(value, accetable_types): formatted_value = [format(value, 'lilypond')] else: formatted_value = schemetools.Scheme(value) formatted_value = format(formatted_value, 'lilypond') formatted_value = [formatted_value] setting = '{!s} = {!s}' setting = setting.format( formatted_key, formatted_value[0], ) result.append(setting) result.extend(formatted_value[1:]) return result
def make_mozart_lilypond_file(): r'''Makes Mozart LilyPond file. ''' score = abjad.demos.mozart.make_mozart_score() lily = lilypondfiletools.make_basic_lilypond_file( music=score, global_staff_size=12, ) title = markuptools.Markup(r'\bold \sans "Ein Musikalisches Wuerfelspiel"') composer = schemetools.Scheme("W. A. Mozart (maybe?)") lily.header_block.title = title lily.header_block.composer = composer lily.layout_block.ragged_right = True lily.paper_block.markup_system_spacing = schemetools.SchemeAssociativeList( ('basic_distance', 8), ) lily.paper_block.paper_width = 180 return lily
def _make_glissando_overrides( self, bow_pressure=None, bow_motion_technique=None, lilypond_format_bundle=None, string_contact_point=None, ): if bow_motion_technique is not None: style = schemetools.Scheme( bow_motion_technique.glissando_style, quoting="'", ) override_ = lilypondnametools.LilyPondGrobOverride( grob_name='Glissando', is_once=True, property_path='style', value=style, ) string = '\n'.join(override_._override_format_pieces) lilypond_format_bundle.grob_overrides.append(string)
def with_color(self, color): r'''LilyPond ``\with-color`` markup command. .. container:: example :: >>> markup = Markup('Allegro assai') >>> markup = markup.with_color('blue') :: >>> print(format(markup)) \markup { \with-color #blue "Allegro assai" } :: >>> show(markup) # doctest: +SKIP Returns markup. ''' from abjad.tools import markuptools contents = self._parse_markup_command_argument(self) color = schemetools.Scheme(color) command = markuptools.MarkupCommand( 'with-color', color, contents, ) return new( self, contents=command, )
def _get_lilypond_grob_overrides(self): overrides = [] if self.arrow_width is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=('arrow-width', ), value=self.arrow_width, ) overrides.append(override_) if self.dash_fraction is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=('dash-fraction', ), value=self.dash_fraction, ) overrides.append(override_) if self.dash_period is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=('dash-period', ), value=self.dash_period, ) overrides.append(override_) if self.left_broken_padding is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'left-broken', 'padding', ), value=self.left_broken_padding, ) overrides.append(override_) if self.left_broken_text is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'left-broken', 'text', ), value=self.left_broken_text, ) overrides.append(override_) if self.left_padding is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'left', 'padding', ), value=self.left_padding, ) overrides.append(override_) if self.left_stencil_align_direction_y is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'left', 'stencil-align-dir-y', ), value=self.left_stencil_align_direction_y, ) overrides.append(override_) if self.right_arrow is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'right', 'arrow', ), value=self.right_arrow, ) overrides.append(override_) if self.right_broken_arrow is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'right-broken', 'arrow', ), value=self.right_broken_arrow, ) overrides.append(override_) if self.right_broken_padding is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'right-broken', 'padding', ), value=self.right_broken_padding, ) overrides.append(override_) if self.right_padding is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'right', 'padding', ), value=self.right_padding, ) overrides.append(override_) if self.right_stencil_align_direction_y is not None: override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=( 'bound-details', 'right', 'stencil-align-dir-y', ), value=self.right_stencil_align_direction_y, ) overrides.append(override_) if self.style is not None: style = schemetools.Scheme(self.style, quoting="'") override_ = lilypondnametools.LilyPondGrobOverride( grob_name='TextSpanner', is_once=True, property_path=('style', ), value=style, ) overrides.append(override_) return overrides
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_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_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_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
def __call__(self, logical_ties): r'''Calls hairpin handler on `logical_ties`. Passes silently when `logical_ties` is empty. Returns none. ''' if not logical_ties: return if not isinstance(logical_ties[0], selectiontools.LogicalTie): assert isinstance(logical_ties[0], scoretools.Leaf) logical_ties = [selectiontools.LogicalTie(_) for _ in logical_ties] if (self.span == 'contiguous notes and chords' or isinstance(self.span, (tuple, list))): groups = self._group_contiguous_logical_ties(logical_ties) elif self.span == 'nontrivial ties': groups = [[_] for _ in logical_ties] else: raise ValueError(self.span) if isinstance(self.span, (tuple, list)): if not self.enchain_hairpins: groups = self._partition_groups(groups) else: groups = self._partition_enchained_groups(groups) hairpin_tokens = self.hairpin_tokens for group_index, group in enumerate(groups): notes = [] for logical_tie in group: for note in logical_tie: notes.append(note) if len(notes) == 0: continue total_notes = len(notes) notes_to_span = [] for note_index, note in enumerate(notes): if self._index_matches_patterns(note_index, total_notes): notes_to_span.append(note) if not notes_to_span: continue if self.include_following_rests: last_note = notes_to_span[-1] next_leaf = inspect_(last_note).get_leaf(1) prototype = (scoretools.Rest, scoretools.MultimeasureRest) if isinstance(next_leaf, prototype): notes_to_span.append(next_leaf) if len(notes_to_span) == 1 and self.omit_lone_note_dynamic: continue if len(notes_to_span) == 1 and not self.omit_lone_note_dynamic: hairpin_token = hairpin_tokens[group_index] start_dynamic = hairpin_token[0] if start_dynamic == 'niente': message = 'can not attach niente dynamics to components.' raise Exception(message) dynamic = indicatortools.Dynamic(start_dynamic) attach(dynamic, notes[0]) continue hairpin_token = hairpin_tokens[group_index] if hairpin_token is None: continue if isinstance(hairpin_token, tuple): descriptor = ' '.join([_ for _ in hairpin_token if _]) include_rests = bool(self.include_following_rests) hairpin = spannertools.Hairpin( descriptor=descriptor, include_rests=include_rests, ) attach(hairpin, notes_to_span) # hook to allow callable custom classes like SwellSpecifier else: hairpin_token(notes_to_span) if self.flare: first_note = notes_to_span[0] prototype = scoretools.Note assert isinstance(first_note, prototype), repr(first_note) stencil = schemetools.Scheme('flared-hairpin') override(first_note).hairpin.stencil = stencil
# -*- encoding: utf-8 -*- import consort from abjad.tools import markuptools from abjad.tools import schemetools from abjad.tools import selectortools from abjad.tools import spannertools harmonic_fourth_trill = consort.ConsortTrillSpanner( interval='+P4', overrides={ 'trill_pitch_head__stencil': schemetools.Scheme('ly:text-interface::print', ), 'trill_pitch_head__text': markuptools.Markup.musicglyph( 'noteheads.s0harmonic', direction=None, ), }, ) harmonic_third_trill = consort.ConsortTrillSpanner( interval='+m3', overrides={ 'trill_pitch_head__stencil': schemetools.Scheme('ly:text-interface::print', ), 'trill_pitch_head__text': markuptools.Markup.musicglyph( 'noteheads.s0harmonic', direction=None, ), },