def _notate_glissando(name: str) -> None: staff = abjad.Staff([ abjad.Note("a'", 3 / 16), abjad.Note("a'", 1 / 16), abjad.Note("a'", 1 / 8), abjad.Note("a'", 1 / 8), ]) abjad.attach( abjad.LilyPondLiteral("#(define afterGraceFraction (cons 15 16))"), staff[0]) abjad.attach( abjad.LilyPondLiteral('\\override Flag.stroke-style = #"grace"'), staff[0], ) for n in (0, 2): attachments._GlissandoAttachment._set_glissando_layout( staff[n + 1], minimum_length=3) abjad.attach(abjad.AfterGraceContainer([abjad.Note("f'", 1 / 8)]), staff[n + 1]) abjad.attach(abjad.Tie(), staff[n]) abjad.attach(abjad.StartBeam(), staff[n]) abjad.attach(abjad.StopBeam(), staff[n + 1]) abjad.attach(abjad.GlissandoIndicator(), staff[n + 1]) abjad.attach(lily.mk_no_time_signature(), staff[0]) abjad.attach(abjad.TimeSignature((len(staff), 1)), staff[0]) abjad.attach(abjad.Clef("treble"), staff[0]) sco = abjad.Score([staff]) lily.make_small_example(sco, name, ragged_last=True, ragged_right=True)
def beam_score(target): global_skips = [ _ for _ in abjad.select(target["Global Context"]).leaves() ] sigs = [] for skip in global_skips: for indicator in abjad.get.indicators(skip): if isinstance(indicator, abjad.TimeSignature): sigs.append(indicator) print("Beaming meter ...") for voice in abjad.iterate(target["Staff Group"]).components( abjad.Voice): for i, shard in enumerate(abjad.mutate.split(voice[:], sigs)): met = abjad.Meter(sigs[i].pair) inventories = [ x for x in enumerate( abjad.Meter(sigs[i].pair).depthwise_offset_inventory) ] if sigs[i].denominator == 4: beam_meter( components=shard[:], meter=met, offset_depth=inventories[-1][0], include_rests=SegmentMaker.beaming, # include_rests=False, ) else: beam_meter( components=shard[:], meter=met, offset_depth=inventories[-2][0], include_rests=SegmentMaker.beaming, # include_rests=False, ) for trem in abjad.select(target).components(abjad.TremoloContainer): if abjad.StartBeam() in abjad.get.indicators(trem[0]): abjad.detach(abjad.StartBeam(), trem[0]) if abjad.StopBeam() in abjad.get.indicators(trem[-1]): abjad.detach(abjad.StopBeam(), trem[-1])
def test_mutate__fuse_leaves_by_immediate_parent_09(): """ Fuse leaves in logical tie with same immediate parent, with an indicator at the end of the logical tie after fusing. """ staff = abjad.Staff(r"d'8 c'8 ~ c'32 r16 r16 r16 r4") indicators = (abjad.TimeSignature((3, 4)), abjad.StartBeam()) for indicator in indicators: abjad.attach(indicator, staff[0]) indicators = ( abjad.BeforeGraceContainer("b'16"), abjad.Articulation("staccato"), abjad.Articulation("accent"), abjad.StopBeam(), ) for indicator in indicators: abjad.attach(indicator, staff[1]) logical_tie = abjad.get.logical_tie(staff[1]) result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie) assert abjad.lilypond(staff) == abjad.String.normalize( r""" \new Staff { \time 3/4 d'8 [ \grace { b'16 } c'8 - \staccato - \accent ~ c'32 ] r16 r16 r16 r4 } """ ), print(abjad.lilypond(staff)) assert abjad.wf.wellformed(staff) assert len(result) == 1
def beam( *tweaks: abjad.TweakInterface, direction: abjad.VerticalAlignment = None, selector: abjad.Expression = classes.select().tleaves(), start_beam: abjad.StartBeam = None, stop_beam: abjad.StopBeam = None, ) -> SpannerIndicatorCommand: r""" Attaches beam. .. container:: example Beams everything and sets beam direction down: >>> maker = baca.SegmentMaker( ... score_template=baca.SingleStaffScoreTemplate(), ... spacing=baca.minimum_duration((1, 12)), ... time_signatures=[(4, 8), (3, 8), (4, 8), (3, 8)], ... ) >>> maker( ... 'Music_Voice', ... baca.beam( ... direction=abjad.Down, ... ), ... baca.make_even_divisions(), ... baca.pitch('C4'), ... ) >>> lilypond_file = maker.run(environment='docs') >>> abjad.show(lilypond_file) # doctest: +SKIP .. docs:: >>> string = abjad.lilypond(lilypond_file[abjad.Score]) >>> print(string) <BLANKLINE> \context Score = "Score" << <BLANKLINE> \context GlobalContext = "Global_Context" << <BLANKLINE> \context GlobalSkips = "Global_Skips" { <BLANKLINE> % [Global_Skips measure 1] \baca-new-spacing-section #1 #12 \time 4/8 \baca-time-signature-color #'blue s1 * 1/2 <BLANKLINE> % [Global_Skips measure 2] \baca-new-spacing-section #1 #12 \time 3/8 \baca-time-signature-color #'blue s1 * 3/8 <BLANKLINE> % [Global_Skips measure 3] \baca-new-spacing-section #1 #12 \time 4/8 \baca-time-signature-color #'blue s1 * 1/2 <BLANKLINE> % [Global_Skips measure 4] \baca-new-spacing-section #1 #12 \time 3/8 \baca-time-signature-color #'blue s1 * 3/8 <BLANKLINE> % [Global_Skips measure 5] \baca-new-spacing-section #1 #4 \time 1/4 \baca-time-signature-transparent s1 * 1/4 \once \override Score.BarLine.transparent = ##t \once \override Score.SpanBar.transparent = ##t <BLANKLINE> } <BLANKLINE> >> <BLANKLINE> \context MusicContext = "Music_Context" << <BLANKLINE> \context Staff = "Music_Staff" { <BLANKLINE> \context Voice = "Music_Voice" { <BLANKLINE> % [Music_Voice measure 1] c'8 - \abjad-dashed-line-with-hook - \baca-text-spanner-left-text "make_even_divisions()" - \tweak bound-details.right.padding 2.75 - \tweak color #darkcyan - \tweak staff-padding 8 \bacaStartTextSpanRhythmAnnotation _ [ <BLANKLINE> c'8 <BLANKLINE> c'8 <BLANKLINE> c'8 <BLANKLINE> % [Music_Voice measure 2] c'8 <BLANKLINE> c'8 <BLANKLINE> c'8 <BLANKLINE> % [Music_Voice measure 3] c'8 <BLANKLINE> c'8 <BLANKLINE> c'8 <BLANKLINE> c'8 <BLANKLINE> % [Music_Voice measure 4] c'8 <BLANKLINE> c'8 <BLANKLINE> c'8 ] <> \bacaStopTextSpanRhythmAnnotation <BLANKLINE> << <BLANKLINE> \context Voice = "Music_Voice" { <BLANKLINE> % [Music_Voice measure 5] \abjad-invisible-music-coloring %@% \abjad-invisible-music \baca-not-yet-pitched-coloring b'1 * 1/4 %@% ^ \baca-duration-multiplier-markup #"1" #"4" <BLANKLINE> } <BLANKLINE> \context Voice = "Rest_Voice" { <BLANKLINE> % [Rest_Voice measure 5] \once \override Score.TimeSignature.X-extent = ##f \once \override MultiMeasureRest.transparent = ##t \stopStaff \once \override Staff.StaffSymbol.transparent = ##t \startStaff R1 * 1/4 %@% ^ \baca-duration-multiplier-markup #"1" #"4" <BLANKLINE> } <BLANKLINE> >> <BLANKLINE> } <BLANKLINE> } <BLANKLINE> >> <BLANKLINE> >> """ start_beam = start_beam or abjad.StartBeam(direction=direction) stop_beam = stop_beam or abjad.StopBeam() return SpannerIndicatorCommand( detach_first=True, selector=selector, start_indicator=start_beam, stop_indicator=stop_beam, tags=[_site(inspect.currentframe())], tweaks=tweaks, )
for i, shard in enumerate(abjad.mutate(voice[:]).split(time_signatures)): time_signature = time_signatures[i] abjad.mutate(shard).rewrite_meter(time_signature) print("Beaming runs ...") for voice in abjad.select(score).components(abjad.Voice): for run in abjad.select(voice).runs(): if 1 < len(run): # use a beam_specifier to remove beam indicators from run specifier = abjadext.rmakers.BeamSpecifier( beam_each_division=False) specifier(run) # then attach new indicators at the 0 and -1 of run abjad.attach(abjad.StartBeam(), run[0]) abjad.attach(abjad.StopBeam(), run[-1]) for leaf in run: # continue if leaf can't be beamed if abjad.Duration(1, 4) <= leaf.written_duration: continue previous_leaf = abjad.inspect(leaf).leaf(-1) next_leaf = abjad.inspect(leaf).leaf(1) # if next leaf is quarter note (or greater) ... if (isinstance(next_leaf, (abjad.Chord, abjad.Note)) and abjad.Duration(1, 4) <= next_leaf.written_duration): left = previous_leaf.written_duration.flag_count right = leaf.written_duration.flag_count # right-pointing nib beam_count = abjad.BeamCount(left=left, right=right) abjad.attach(beam_count, leaf) continue # if previous leaf is quarter note (or greater) ...
), baca.selectors.leaf(0), ), evans.call("Voice 1", clefs[0], lambda _: abjad.Selection(_)), evans.call("Voice 2", clefs[1], lambda _: abjad.Selection(_)), evans.call("Voice 3", clefs[2], lambda _: abjad.Selection(_)), evans.call("Voice 4", clefs[3], lambda _: abjad.Selection(_)), evans.call( "Global Context", tempo_handler, baca.selectors.leaves().get([2, 3]) ), evans.call( "Global Context", tempo_handler, baca.selectors.leaves().get([5, 6]) ), evans.attach( "Voice 1", abjad.StopBeam(), baca.selectors.leaf(9), ), evans.detach( "Voice 1", abjad.StopBeam(), baca.selectors.leaf(11), ), evans.detach( "Voice 1", abjad.StartBeam(), baca.selectors.leaf(14), ), evans.attach( "Voice 1", abjad.StartBeam(),
evans.attach( "Global Context", abjad.MetronomeMark((1, 4), 63), baca.selectors.leaf(4), ), evans.call( "Global Context", tempo_handler, lambda _: abjad.Selection(_).leaves().get([8, 9, 10]), ), evans.call( "Global Context", tempo_handler, lambda _: abjad.Selection(_).leaves().get([13, 14]), ), evans.attach("Voice 2", abjad.StopBeam(), baca.selectors.leaf(18, pitched=True)), evans.detach("Voice 2", abjad.StopBeam(), baca.selectors.leaf(19, pitched=True)), evans.detach("Voice 3", abjad.StartBeam(), baca.selectors.leaf(11, pitched=True)), evans.detach("Voice 3", abjad.StopBeam(), baca.selectors.leaf(21)), evans.attach( "Voice 1", abjad.Markup(r"\markup ½clt.", direction=abjad.Up), baca.selectors.leaf(1, pitched=True), ), evans.attach( "Voice 2", abjad.Markup(r"\markup ½clt.", direction=abjad.Up), baca.selectors.leaf(15, pitched=True),
evans.attach( "Voice 3", abjad.Dynamic("p"), baca.selectors.leaf(5, pitched=True), ), evans.attach( "Voice 3", abjad.Dynamic("f"), baca.selectors.leaf(8, pitched=True), ), evans.attach( "Voice 3", abjad.Dynamic("mp"), baca.selectors.leaf(13, pitched=True), ), evans.attach("Voice 3", abjad.StopBeam(), baca.selectors.leaf(4, pitched=True)), evans.detach("Voice 3", abjad.StopBeam(), baca.selectors.leaf(5, pitched=True)), ], score_template=score, time_signatures=time_signatures, clef_handlers=clef_handlers, tuplet_bracket_noteheads=False, add_final_grand_pause=False, score_includes=[ "/Users/gregoryevans/abjad/docs/source/_stylesheets/abjad.ily", "/Users/gregoryevans/Scores/adumbration/adumbration/build/first_stylesheet.ily", ], segment_name="segment_10", current_directory=pathlib.Path(__file__).resolve().parent,