How to use the abjad.Note 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_GraceContainer_parentage.py View on Github external
def test_GraceContainer_parentage_03():
    """
    Grace containers bound to leaf have their correct main leaf after
    assignment.
    """

    note = abjad.Note(1, (1, 4))
    after_grace = abjad.AfterGraceContainer([abjad.Note("e'16")])
    abjad.attach(after_grace, note)
    grace = abjad.GraceContainer([abjad.Note("e'16")])
    abjad.attach(grace, note)
    assert after_grace._main_leaf is note
    assert grace._main_leaf is note
    after_grace[:] = []
    notes = [abjad.Note("c'8"), abjad.Note("d'8")]
    after_grace.extend(notes)
    grace[:] = []
    notes = [abjad.Note("c'8"), abjad.Note("d'8")]
    grace.extend(notes)
    assert after_grace._main_leaf is note
    assert grace._main_leaf is note
    after_grace[:] = []
    grace[:] = []
    assert after_grace._main_leaf is note
    assert grace._main_leaf is note
github Abjad / abjad / tests / test_Selection_are_logical_voice.py View on Github external
def test_Selection_are_logical_voice_30():
    """
    Logical voice can not extend across differently named implicit voices.
    """

    voice_1 = abjad.Voice([abjad.Note(n, (1, 8)) for n in range(4)])
    voice_2 = abjad.Voice([voice_1])
    notes = [abjad.Note(n, (1, 8)) for n in range(4, 8)]
    container = abjad.Container([voice_2] + notes)

    assert format(container) == abjad.String.normalize(
        r"""
        {
            \new Voice
            {
                \new Voice
                {
                    c'8
                    cs'8
                    d'8
                    ef'8
                }
github Abjad / abjad / tests / test_Selection_wellformed.py View on Github external
def test_Selection_wellformed_02():
    """
    Well-formedness checking runs correctly against containers.
    """
    staff = abjad.Staff([abjad.Note(n, (1, 8)) for n in range(8)])
    assert abjad.inspect(staff).wellformed()
github Abjad / abjad / tests / test_Container___contains__.py View on Github external
def test_Container___contains___01():

    note = abjad.Note("c'4")
    voice = abjad.Voice([abjad.Note("c'4")])

    assert note not in voice
github Abjad / abjad / tests / test_Staff___delitem__.py View on Github external
def test_Staff___delitem___01():

    staff = abjad.Staff(
        [
            abjad.Note("c'4"),
            abjad.Rest((1, 4)),
            abjad.Chord([2, 3, 4], (1, 4)),
            abjad.Skip((1, 4)),
            abjad.Tuplet((4, 5), 4 * abjad.Note(0, (1, 16))),
        ]
    )

    assert len(staff) == 5
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    assert isinstance(staff[2], abjad.Chord)
    assert isinstance(staff[3], abjad.Skip)
    assert isinstance(staff[4], abjad.Tuplet)
    del staff[0]
    assert len(staff) == 4
    assert isinstance(staff[0], abjad.Rest)
    assert isinstance(staff[1], abjad.Chord)
    assert isinstance(staff[2], abjad.Skip)
    assert isinstance(staff[3], abjad.Tuplet)
    del staff[0]
    assert len(staff) == 3
    assert isinstance(staff[0], abjad.Chord)
    assert isinstance(staff[1], abjad.Skip)
    assert isinstance(staff[2], abjad.Tuplet)
    del staff[0]
github Abjad / abjad / tests / test_Mutation_replace.py View on Github external
\new Staff
        {
            c'8
            [
            d'8
            ]
            e'8
            [
            f'8
            ]
        }
        """
    ), print(format(staff))

    old_notes = staff[:]
    new_notes = 5 * abjad.Note("c''16")
    abjad.mutate(old_notes).replace(new_notes)

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            c''16
            c''16
            c''16
            c''16
            c''16
        }
        """
    ), print(format(staff))

    assert abjad.inspect(staff).wellformed()
github Abjad / abjad / tests / test_Note___init__.py View on Github external
def test_Note___init___03():
    """
    Initializes note with non-assignable duration.
    """

    with pytest.raises(abjad.AssignabilityError):
        abjad.Note(0, (5, 8))
github Abjad / abjad / abjad / demos / part.py View on Github external
descents = durated_reservoir["Second Violin"]
    last_descent = abjad.Selection(descents[-1])
    copied_descent = abjad.mutate(last_descent).copy()
    copied_descent = list(copied_descent)
    copied_descent[-1].written_duration = abjad.Duration(1, 1)
    copied_descent.append(abjad.Note("a2"))
    for leaf in copied_descent:
        articulation = abjad.Articulation("accent")
        abjad.attach(articulation, leaf)
        articulation = abjad.Articulation("tenuto")
        abjad.attach(articulation, leaf)
    voice.extend(copied_descent)
    final_sustain = []
    for _ in range(32):
        final_sustain.append(abjad.Note("a1."))
    final_sustain.append(abjad.Note("a2"))
    final_sustain = abjad.Selection(final_sustain)
    articulation = abjad.Articulation("accent")
    abjad.attach(articulation, final_sustain[0])
    articulation = abjad.Articulation("tenuto")
    abjad.attach(articulation, final_sustain[0])
    voice.extend(final_sustain)
    abjad.tie(final_sustain)
    voice.extend("r4 r2.")
github josiah-wolf-oberholtzer / consort / consort / tools / LeafExpression.py View on Github external
def _make_new_leaf(self, old_leaf):
        duration = old_leaf.written_duration
        if isinstance(self.leaf, abjad.Note):
            new_leaf = abjad.Note(self.leaf.written_pitch, duration)
        elif isinstance(self.leaf, abjad.Chord):
            new_leaf = abjad.Chord(self.leaf.written_pitches, duration)
        elif isinstance(self.leaf, abjad.Rest):
            new_leaf = abjad.Rest(duration)
        elif isinstance(self.leaf, abjad.Skip):
            new_leaf = abjad.Skip(duration)
        prototype = abjad.Multiplier
        if inspect(old_leaf).has_indicator(prototype):
            multiplier = abjad.inspect(old_leaf).get_indicator(prototype)
            attach(multiplier, new_leaf)
        return new_leaf
github Abjad / abjad / abjad / core / Score.py View on Github external
if pitch < lowest_treble_pitch:
                    bass_pitches.append(pitch)
                else:
                    treble_pitches.append(pitch)
            written_duration = leaf.written_duration
            if not treble_pitches:
                treble_leaf = abjad.Rest(written_duration)
            elif len(treble_pitches) == 1:
                treble_leaf = abjad.Note(treble_pitches[0], written_duration)
            else:
                treble_leaf = abjad.Chord(treble_pitches, written_duration)
            treble_staff.append(treble_leaf)
            if not bass_pitches:
                bass_leaf = abjad.Rest(written_duration)
            elif len(bass_pitches) == 1:
                bass_leaf = abjad.Note(bass_pitches[0], written_duration)
            else:
                bass_leaf = abjad.Chord(bass_pitches, written_duration)
            bass_staff.append(bass_leaf)
        if 0 < len(treble_staff):
            abjad.attach(abjad.Clef("treble"), treble_staff[0])
        if 0 < len(bass_staff):
            abjad.attach(abjad.Clef("bass"), bass_staff[0])
        if sketch:
            abjad.override(score).time_signature.stencil = False
            abjad.override(score).bar_number.transparent = True
            abjad.override(score).bar_line.stencil = False
            abjad.override(score).span_bar.stencil = False
        return score, treble_staff, bass_staff