How to use the abjad.attach function in abjad

To help you get started, we’ve selected a few abjad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Abjad / abjad / tests / test_PianoPedalSpanner.py View on Github external
def test_PianoPedalSpanner_01():

    staff = abjad.Staff([abjad.Note("c'8"), abjad.Note("c'8"), abjad.Note("c'8"), abjad.Note("c'8")])
    piano_pedal_spanner = abjad.PianoPedalSpanner()
    abjad.attach(piano_pedal_spanner, staff[:])

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \set Staff.pedalSustainStyle = #'mixed
            c'8
            \sustainOn
            c'8
            c'8
            c'8
            \sustainOff
        }
        """
        )
github Abjad / abjad / tests / test_Inspection_indicators.py View on Github external
def test_Inspection_indicators_04():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    comment_1 = abjad.LilyPondComment("comment 1")
    abjad.attach(comment_1, staff[0])
    comment_2 = abjad.LilyPondComment("comment 2")
    abjad.attach(comment_2, staff[0])

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            % comment 1
            % comment 2
            c'8
            d'8
            e'8
            f'8
        }
        """
    ), format(staff)

    indicators = abjad.inspect(staff[0]).indicators(abjad.LilyPondComment)
github Abjad / abjad / abjad / demos / part / apply_expressive_marks.py View on Github external
markup = abjad.Markup('div.', direction=abjad.Up)
    abjad.attach(markup, voice[10][0])
    markup = abjad.Markup('uniti', direction=abjad.Up)
    abjad.attach(markup, voice[74][0])
    markup = abjad.Markup('uniti', direction=abjad.Up)
    abjad.attach(markup, voice[84][1])
    markup = abjad.Markup(r'\italic { espr. }', direction=abjad.Down)
    abjad.attach(markup, voice[86][0])
    markup = abjad.Markup(r'\italic { molto espr. }', direction=abjad.Down)
    abjad.attach(markup, voice[88][1])

    voice = score['Bass Voice']
    markup = abjad.Markup('div.', direction=abjad.Up)
    abjad.attach(markup, voice[14][0])
    markup = abjad.Markup(r'\italic { espr. }', direction=abjad.Down)
    abjad.attach(markup, voice[86][0])
    abjad.mutate(voice[88][:]).split(
        [abjad.Duration(1, 1), abjad.Duration(1, 2)]
        )
    markup = abjad.Markup(r'\italic { molto espr. }', direction=abjad.Down)
    abjad.attach(markup, voice[88][1])
    markup = abjad.Markup('uniti', direction=abjad.Up)
    abjad.attach(markup, voice[99][1])

    strings_staff_group = score['Strings Staff Group']
    for voice in abjad.iterate(strings_staff_group).components(abjad.Voice):
        markup = abjad.Markup(r'\italic { (non dim.) }', direction=abjad.Down)
        abjad.attach(markup, voice[102][0])
github josiah-wolf-oberholtzer / consort / consort / tools / annotate.py View on Github external
def make_empty_phrase_divisions(phrase):
    inner_container = abjad.Container()
    outer_container = abjad.Container()
    for division in phrase:
        duration = abjad.inspect(division).get_duration()
        multiplier = abjad.Multiplier(duration)
        inner_skip = abjad.Skip(1)
        outer_skip = abjad.Skip(1)
        attach(multiplier, inner_skip)
        attach(multiplier, outer_skip)
        inner_container.append(inner_skip)
        outer_container.append(outer_skip)
    return inner_container, outer_container
github josiah-wolf-oberholtzer / consort / consort / tools / SegmentMaker.py View on Github external
stop_offset=meter_offsets[-1],
                    voice_name=voice_name,
                    )
                ])
            silences = SegmentMaker.subtract_timespan_inventories(
                silences, timespans)
            silences = SegmentMaker.split_timespans(meter_offsets, silences)
            for group in silences.partition(include_tangent_timespans=True):
                start_offset = group.start_offset
                stop_offset = group.stop_offset
                durations = [_.duration for _ in group]
                silence = SegmentMaker.make_music(
                    rhythm_maker,
                    durations,
                    )
                abjad.attach(silent_music_specifier, silence, scope=abjad.Voice)
                silent_timespan = consort.PerformedTimespan(
                    music=silence,
                    start_offset=start_offset,
                    stop_offset=stop_offset,
                    voice_name=voice_name,
                    )
                timespans.append(silent_timespan)
            timespans.sort()
        return demultiplexed_maquette
github Abjad / abjad / abjad / demos / part / apply_bowing_marks.py View on Github external
def apply_bowing_marks(score):
    """
    Applies bowing marks to score.
    """

    # apply alternating upbow and downbow for first two sounding bars
    # of the first violin
    for measure in score['First Violin Voice'][6:8]:
        for i, chord in enumerate(abjad.iterate(measure).components(abjad.Chord)):
            if i % 2 == 0:
                articulation = abjad.Articulation('downbow')
                abjad.attach(articulation, chord)
            else:
                articulation = abjad.Articulation('upbow')
                abjad.attach(articulation, chord)

    # create and apply rebowing markup
    rebow_markup = abjad.Markup.concat([
        abjad.Markup.musicglyph('scripts.downbow'),
        abjad.Markup.hspace(1),
        abjad.Markup.musicglyph('scripts.upbow'),
        ])
    markup = copy.copy(rebow_markup)
    abjad.attach(markup, score['First Violin Voice'][64][0])
    markup = copy.copy(rebow_markup)
    abjad.attach(markup, score['Second Violin Voice'][75][0])
    markup = copy.copy(rebow_markup)
    abjad.attach(markup, score['Viola Voice'][86][0])
github Abjad / abjad / abjad / demos / part / apply_bowing_marks.py View on Github external
else:
                articulation = abjad.Articulation('upbow')
                abjad.attach(articulation, chord)

    # create and apply rebowing markup
    rebow_markup = abjad.Markup.concat([
        abjad.Markup.musicglyph('scripts.downbow'),
        abjad.Markup.hspace(1),
        abjad.Markup.musicglyph('scripts.upbow'),
        ])
    markup = copy.copy(rebow_markup)
    abjad.attach(markup, score['First Violin Voice'][64][0])
    markup = copy.copy(rebow_markup)
    abjad.attach(markup, score['Second Violin Voice'][75][0])
    markup = copy.copy(rebow_markup)
    abjad.attach(markup, score['Viola Voice'][86][0])
github Abjad / abjad / abjad / rmakers / TieSpecifier.py View on Github external
continue
            pitched_prototype = (abjad.Note, abjad.Chord)
            if not all(isinstance(_, pitched_prototype) for _ in leaves):
                continue
            logical_tie_one = abjad.inspect(leaf_one).get_logical_tie()
            logical_tie_two = abjad.inspect(leaf_two).get_logical_tie()
            if logical_tie_one == logical_tie_two:
                continue
            combined_logical_tie = logical_tie_one + logical_tie_two
            for leaf in combined_logical_tie:
                abjad.detach(abjad.Tie, leaf)
            tie = abjad.Tie(repeat=self.repeat_ties)
            tie._unconstrain_contiguity()
            if tie._attachment_test_all(combined_logical_tie) is True:
                try:
                    abjad.attach(tie, combined_logical_tie)
                except:
                    raise Exception(tie, combined_logical_tie)
            tie._constrain_contiguity()
github Abjad / abjad / abjad / demos / mozart.py View on Github external
command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.attach(command, treble_alternative)
    command = abjad.LilyPondLiteral(r"\alternative", "before")
    abjad.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)
    # abjad.attach indicators
    time_signature = abjad.TimeSignature((3, 8))
    leaf = abjad.inspect(score["RH_Staff"]).leaf(0)
    abjad.attach(time_signature, leaf)
    bar_line = abjad.BarLine("|.")
    leaf = abjad.inspect(score["RH_Staff"]).leaf(-1)
    abjad.attach(bar_line, leaf)
    # remove the default piano instrument and add a custom one:
    abjad.detach(abjad.Instrument, score["Piano_Staff"])
    klavier = abjad.Piano(name="Katzenklavier", short_name="kk.")
    leaf = abjad.inspect(score["Piano_Staff"]).leaf(0)
    abjad.attach(klavier, leaf)
    return score
github josiah-wolf-oberholtzer / consort / consort / tools / SegmentMaker.py View on Github external
#                include_long_duration_notes=False,
#                include_long_duration_rests=False,
#                isolated_nib_direction=None,
#                use_stemlets=False,
#                )
#            abjad.attach(beam, container, name='beam')
            for division in container:
                durations = [division._get_duration()]
                beam = spannertools.GeneralizedBeam(
                    durations=durations,
                    include_long_duration_notes=False,
                    include_long_duration_rests=False,
                    isolated_nib_direction=None,
                    use_stemlets=True,
                    )
                abjad.attach(beam, division)
            abjad.attach(timespan.music_specifier, container, scope=abjad.Voice)
            inscribed_timespan = abjad.new(
                timespan,
                divisions=None,
                music=container,
                start_offset=start_offset,
                stop_offset=stop_offset,
                )
            assert abjad.inspect(container).get_duration() == \
                inscribed_timespan.duration
            assert abjad.inspect(container).get_timespan().start_offset == 0
            assert abjad.inspect(container[0]).get_timespan().start_offset == 0
            inscribed_timespans.append(inscribed_timespan)
        inscribed_timespans.sort()
        return inscribed_timespans