Exemple #1
0
def test_LilyPondParser__indicators__Articulation_03():

    maker = abjad.NoteMaker()
    target = abjad.Container(
        maker(["c''", "c''", "b'", "c''"], [(1, 4), (1, 4), (1, 2), (1, 1)]))

    articulation = abjad.Articulation("staccato")
    abjad.attach(articulation, target[0])
    articulation = abjad.Articulation("mordent")
    abjad.attach(articulation, target[1])
    articulation = abjad.Articulation("turn")
    abjad.attach(articulation, target[2])
    articulation = abjad.Articulation("fermata")
    abjad.attach(articulation, target[3])

    assert format(target) == abjad.String.normalize(r"""
        {
            c''4
            - \staccato
            c''4
            - \mordent
            b'2
            - \turn
            c''1
            - \fermata
        }
        """)

    string = r"""{ c''4\staccato c''\mordent b'2\turn c''1\fermata }"""

    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
    for x in result:
        assert 1 == len(abjad.inspect(x).indicators(abjad.Articulation))
Exemple #2
0
def test_LilyPondParser__spanners__Beam_05():
    """
    With direction.
    """

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 8)]))
    start_beam = abjad.StartBeam(direction=abjad.Up)
    abjad.beam(target[0:3], start_beam=start_beam)
    start_beam = abjad.StartBeam(direction=abjad.Down)
    abjad.beam(target[3:], start_beam=start_beam, beam_lone_notes=True)

    assert format(target) == abjad.String.normalize(
        r"""
        {
            c'8
            ^ [
            c'8
            c'8
            ]
            c'8
            _ [
            ]
        }
        """
        )

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Exemple #3
0
def test_LilyPondParser__spanners__PhrasingSlur_02():
    """
    Swapped start and stop.
    """

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    abjad.phrasing_slur(target[2:])
    abjad.phrasing_slur(target[:3])

    assert format(target) == abjad.String.normalize(
        r"""
        {
            c'4
            \(
            c'4
            c'4
            \)
            \(
            c'4
            \)
        }
        """
    )

    string = r"\relative c' { c \( c c \( \) c \) }"

    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Beam_04():

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    beam = abjad.Beam()
    abjad.attach(beam, target[:3])
    beam = abjad.Beam()
    abjad.attach(beam, target[2:])

    assert format(target) == abjad.String.normalize(
        r'''
        {
            c'4
            [
            c'4
            c'4
            ]
            [
            c'4
            ]
        }
        '''
        )

    assert pytest.raises(Exception, "LilyPondParser()(format(target))")
Exemple #5
0
def test_LilyPondParser__spanners__HorizontalBracket_01():

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    abjad.horizontal_bracket(target[:])
    abjad.horizontal_bracket(target[:2])
    abjad.horizontal_bracket(target[2:])

    assert format(target) == abjad.String.normalize(r"""
        {
            c'4
            \startGroup
            \startGroup
            c'4
            \stopGroup
            c'4
            \startGroup
            c'4
            \stopGroup
            \stopGroup
        }
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Slur_01():
    r'''Successful slurs, showing single leaf overlap.
    '''

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    slur = abjad.Slur()
    abjad.attach(slur, target[2:])
    slur = abjad.Slur()
    abjad.attach(slur, target[:3])

    assert format(target) == abjad.String.normalize(r'''
        {
            c'4
            (
            c'4
            c'4
            )
            (
            c'4
            )
        }
        ''')

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Beam_02():
    r'''With start and stop reversed.
    '''

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    beam = abjad.Beam()
    abjad.attach(beam, target[0:3])
    beam = abjad.Beam()
    abjad.attach(beam, target[3:])

    assert format(target) == abjad.String.normalize(
        r'''
        {
            c'4
            [
            c'4
            c'4
            ]
            c'4
            [
            ]
        }
        '''
        )

    string = r'''\relative c' { c [ c c ] c ] [ }'''
    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
def test_LilyPondParser__spanners__Text_02():
    """
    Swapped start and stop.
    """

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    abjad.text_spanner(target[2:])
    abjad.text_spanner(target[:3])

    assert abjad.lilypond(target) == abjad.String.normalize(r"""
        {
            c'4
            \startTextSpan
            c'4
            c'4
            \stopTextSpan
            \startTextSpan
            c'4
            \stopTextSpan
        }
        """)

    string = (
        r"\relative c' { c \startTextSpan c c \startTextSpan \stopTextSpan c"
        r" \stopTextSpan }")

    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert abjad.lilypond(target) == abjad.lilypond(
        result) and target is not result
def test_LilyPondParser__spanners__Text_01():
    """
    Successful text spanners, showing single leaf overlap.
    """

    maker = abjad.NoteMaker()
    container = abjad.Container(maker([0] * 4, [(1, 4)]))
    abjad.text_spanner(container[2:])
    abjad.text_spanner(container[:3])

    assert abjad.lilypond(container) == abjad.String.normalize(r"""
        {
            c'4
            \startTextSpan
            c'4
            c'4
            \stopTextSpan
            \startTextSpan
            c'4
            \stopTextSpan
        }
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(abjad.lilypond(container))
    assert (abjad.lilypond(container) == abjad.lilypond(result)
            and container is not result)
Exemple #10
0
def test_lilypondparsertools_LilyPondParser__spanners__Trill_01():
    r'''Successful trills, showing single leaf overlap.
    '''

    maker = abjad.NoteMaker()
    notes = maker(4 * [0], [(1, 4)])
    target = abjad.Container(notes)
    trill = abjad.TrillSpanner()
    abjad.attach(trill, target[2:])
    trill = abjad.TrillSpanner()
    abjad.attach(trill, target[:3])

    assert format(target) == abjad.String.normalize(
        r'''
        {
            c'4
            \startTrillSpan
            c'4
            c'4
            \stopTrillSpan
            \startTrillSpan
            c'4
            \stopTrillSpan
        }
        '''
        )

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_LilyPondParser__functions__relative_09():

    # http://lilypond.org/doc/v2.15/Documentation/c6/lily-8d84e2b9.ly
    pitches = ["c''", "fs''", "c''", "gf'", "b'", "ess''", "b'", "fff'"]
    maker = abjad.NoteMaker()
    target = abjad.Container(maker(pitches, [(1, 2)]))

    assert abjad.lilypond(target) == abjad.String.normalize(r"""
        {
            c''2
            fs''2
            c''2
            gf'2
            b'2
            ess''2
            b'2
            fff'2
        }
        """)

    string = r"""\relative c'' { c2 fs c2 gf b2 ess b2 fff }"""
    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert abjad.lilypond(target) == abjad.lilypond(
        result) and target is not result
Exemple #12
0
def test_lilypondparsertools_LilyPondParser__spanners__Trill_02():
    r'''Swapped start and stop.
    '''

    maker = abjad.NoteMaker()
    notes = maker(4 * [0], [(1, 4)])
    target = abjad.Container(notes)
    trill = abjad.TrillSpanner()
    abjad.attach(trill, target[2:])
    trill = abjad.TrillSpanner()
    abjad.attach(trill, target[:3])

    assert format(target) == abjad.String.normalize(
        r'''
        {
            c'4
            \startTrillSpan
            c'4
            c'4
            \stopTrillSpan
            \startTrillSpan
            c'4
            \stopTrillSpan
        }
        '''
        )

    string = r"\relative c' { c \startTrillSpan c c \startTrillSpan \stopTrillSpan c \stopTrillSpan }"

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
Exemple #13
0
 def _make_container(self, division):
     import abjad
     duration_specifier = self._get_duration_specifier()
     forbidden_duration = \
         duration_specifier.forbidden_duration
     time_signature = abjad.TimeSignature(division)
     implied_prolation = time_signature.implied_prolation
     numerator, denominator = division.pair
     denominator = abjad.mathtools.greatest_power_of_two_less_equal(
         denominator)
     assert abjad.mathtools.is_positive_integer_power_of_two(denominator)
     exponent = self.exponent or 0
     denominator_multiplier = 2 ** exponent
     denominator *= denominator_multiplier
     unit_duration = abjad.Duration(1, denominator)
     if forbidden_duration is not None:
         multiplier = 1
         while forbidden_duration <= unit_duration:
             unit_duration /= 2
             multiplier *= 2
         numerator *= multiplier
     numerator *= denominator_multiplier
     maker = abjad.NoteMaker()
     notes = maker(numerator * [0], [unit_duration])
     if implied_prolation == 1:
         result = abjad.Container(notes)
     else:
         multiplier = implied_prolation
         result = abjad.Tuplet(multiplier, notes)
     return result
Exemple #14
0
    def make_notes(self, n, written_duration=(1, 8)):
        r'''Makes first `n` notes in ascending scale.

        ..  container:: example

            >>> scale = abjad.tonalanalysistools.Scale(('c', 'major'))
            >>> notes = scale.make_notes(8)
            >>> staff = abjad.Staff(notes)
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                {
                    c'8
                    d'8
                    e'8
                    f'8
                    g'8
                    a'8
                    b'8
                    c''8
                }

        Returns selection of notes.
        '''
        import abjad
        written_duration = written_duration or abjad.Duration(1, 8)
        maker = abjad.NoteMaker()
        result = maker(n * [0], [written_duration])
        self._set_ascending_named_diatonic_pitches_on_logical_ties(result)
        return result
Exemple #15
0
def edit_viola_voice(score, durated_reservoir):
    """
    Edits viola voice.
    """
    voice = score['Viola Voice']
    descents = durated_reservoir['Viola']
    for leaf in descents[-1]:
        articulation = abjad.Articulation('accent')
        abjad.attach(articulation, leaf)
        articulation = abjad.Articulation('tenuto')
        abjad.attach(articulation, leaf)
    last_descent = abjad.Selection(descents[-1])
    copied_descent = abjad.mutate(last_descent).copy()
    for leaf in copied_descent:
        if leaf.written_duration == abjad.Duration(4, 4):
            leaf.written_duration = abjad.Duration(8, 4)
        else:
            leaf.written_duration = abjad.Duration(4, 4)
    voice.extend(copied_descent)
    bridge = abjad.Note('e1')
    articulation = abjad.Articulation('tenuto')
    abjad.attach(articulation, bridge)
    articulation = abjad.Articulation('accent')
    abjad.attach(articulation, bridge)
    voice.append(bridge)
    final_sustain_rhythm = [(6, 4)] * 21 + [(1, 2)]
    maker = abjad.NoteMaker()
    final_sustain_notes = maker(['e'], final_sustain_rhythm)
    articulation = abjad.Articulation('accent')
    abjad.attach(articulation, final_sustain_notes[0])
    articulation = abjad.Articulation('tenuto')
    abjad.attach(articulation, final_sustain_notes[0])
    voice.extend(final_sustain_notes)
    abjad.tie(final_sustain_notes)
    voice.extend('r4 r2.')
Exemple #16
0
def test_LilyPondParser__spanners__Hairpin_06():
    """
    With direction.
    """

    maker = abjad.NoteMaker()
    target = abjad.Staff(maker([0] * 5, [(1, 4)]))
    start_hairpin = abjad.StartHairpin("<", direction=abjad.Up)
    abjad.attach(start_hairpin, target[0])
    stop_hairpin = abjad.StopHairpin()
    abjad.attach(stop_hairpin, target[2])
    hairpin = abjad.StartHairpin(">", direction=abjad.Down)
    abjad.attach(hairpin, target[2])
    dynamic = abjad.Dynamic("ppp")
    abjad.attach(dynamic, target[-1])

    assert format(target) == abjad.String.normalize(r"""
        \new Staff
        {
            c'4
            ^ \<
            c'4
            c'4
            \!
            _ \>
            c'4
            c'4
            \ppp
        }
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Slur_02():
    r'''Swapped start and stop.
    '''

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    slur = abjad.Slur()
    abjad.attach(slur, target[2:])
    slur = abjad.Slur()
    abjad.attach(slur, target[:3])

    assert format(target) == abjad.String.normalize(r'''
        {
            c'4
            (
            c'4
            c'4
            )
            (
            c'4
            )
        }
        ''')

    string = r"\relative c' { c ( c c () c ) }"

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
Exemple #18
0
def test_LilyPondParser__spanners__Hairpin_01():

    maker = abjad.NoteMaker()
    target = abjad.Staff(maker([0] * 5, [(1, 4)]))
    abjad.hairpin("< !", target[:3])
    abjad.hairpin("> ppp", target[2:])

    assert format(target) == abjad.String.normalize(r"""
        \new Staff
        {
            c'4
            \<
            c'4
            c'4
            \!
            \>
            c'4
            c'4
            \ppp
        }
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Slur_07():
    r'''With direction.
    '''

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    slur = abjad.Slur(direction=abjad.Down)
    abjad.attach(slur, target[:3])
    slur = abjad.Slur(direction=abjad.Up)
    abjad.attach(slur, target[2:])

    assert format(target) == abjad.String.normalize(r'''
        {
            c'4
            _ (
            c'4
            c'4
            )
            ^ (
            c'4
            )
        }
        ''')

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Exemple #20
0
def test_LilyPondParser__spanners__Hairpin_02():
    """
    Dynamics can terminate hairpins.
    """

    maker = abjad.NoteMaker()
    target = abjad.Staff(maker([0] * 3, [(1, 4)]))
    abjad.hairpin("<", target[0:2])
    abjad.hairpin("p > f", target[1:])

    assert format(target) == abjad.String.normalize(r"""
        \new Staff
        {
            c'4
            \<
            c'4
            \p
            \>
            c'4
            \f
        }
        """)

    string = r"\new Staff \relative c' { c \< c \p \> c \f }"
    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Beam_01():

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    beam = abjad.Beam()
    abjad.attach(beam, target[0:3])
    beam = abjad.Beam()
    abjad.attach(beam, target[3:])

    assert format(target) == abjad.String.normalize(
        r'''
        {
            c'4
            [
            c'4
            c'4
            ]
            c'4
            [
            ]
        }
        '''
        )

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_LilyPondParser__spanners__Slur_07():
    """
    With direction.
    """

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    start_slur = abjad.StartSlur(direction=abjad.Down)
    abjad.slur(target[:3], start_slur=start_slur)
    start_slur = abjad.StartSlur(direction=abjad.Up)
    abjad.slur(target[2:], start_slur=start_slur)

    assert format(target) == abjad.String.normalize(r"""
        {
            c'4
            _ (
            c'4
            c'4
            )
            ^ (
            c'4
            )
        }
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
def test_Container_extend_10():
    """
    Selections are stripped out.
    """

    maker = abjad.NoteMaker()
    selection_1 = maker([0, 2], [abjad.Duration(1, 4)])
    selection_2 = maker([4, 5], [abjad.Duration(1, 4)])
    selection_3 = maker([7, 9], [abjad.Duration(1, 4)])
    selection_4 = maker([11, 12], [abjad.Duration(1, 4)])
    selections = [selection_1, selection_2, selection_3, selection_4]
    container = abjad.Container()
    container.extend(selections)

    assert format(container) == abjad.String.normalize(r"""
        {
            c'4
            d'4
            e'4
            f'4
            g'4
            a'4
            b'4
            c''4
        }
        """), print(format(container))

    assert abjad.inspect(container).wellformed()
def test_lilypondparsertools_LilyPondParser__functions__relative_02():

    maker = abjad.NoteMaker()
    pitches = [11, 12, 11, 14, 11, 16, 11, 9, 11, 7, 11, 5]
    target = abjad.Container(maker(pitches, (1, 4)))

    assert format(target) == abjad.String.normalize(r'''
        {
            b'4
            c''4
            b'4
            d''4
            b'4
            e''4
            b'4
            a'4
            b'4
            g'4
            b'4
            f'4
        }
        ''')

    string = r"\relative c'' { b c b d b e b a b g b f }"
    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
Exemple #25
0
def test_LilyPondParser__spanners__Beam_01():

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 8)]))
    abjad.beam(target[0:3])
    abjad.beam(target[3:], beam_lone_notes=True)

    assert format(target) == abjad.String.normalize(
        r"""
        {
            c'8
            [
            c'8
            c'8
            ]
            c'8
            [
            ]
        }
        """
        )

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Exemple #26
0
def test_LilyPondParser__spanners__Trill_02():
    """
    Swapped start and stop.
    """

    maker = abjad.NoteMaker()
    notes = maker(4 * [0], [(1, 4)])
    target = abjad.Container(notes)
    abjad.trill_spanner(target[2:])
    abjad.trill_spanner(target[:3])

    assert format(target) == abjad.String.normalize(r"""
        {
            c'4
            \startTrillSpan
            c'4
            c'4
            \stopTrillSpan
            \startTrillSpan
            c'4
            \stopTrillSpan
        }
        """)

    string = r"\relative c' { c \startTrillSpan c c \startTrillSpan \stopTrillSpan c \stopTrillSpan }"

    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert format(target) == format(result) and target is not result
Exemple #27
0
def test_scoretools_Container_extend_10():
    r'''Selections are stripped out.
    '''

    maker = abjad.NoteMaker()
    selection_1 = maker([0, 2], [abjad.Duration(1, 4)])
    selection_2 = maker([4, 5], [abjad.Duration(1, 4)])
    selection_3 = maker([7, 9], [abjad.Duration(1, 4)])
    selection_4 = maker([11, 12], [abjad.Duration(1, 4)])
    selections = [selection_1, selection_2, selection_3, selection_4]
    container = abjad.Container()
    container.extend(selections)

    assert format(container) == abjad.String.normalize(r'''
        {
            c'4
            d'4
            e'4
            f'4
            g'4
            a'4
            b'4
            c''4
        }
        ''')

    assert abjad.inspect(container).is_well_formed()
Exemple #28
0
def test_LilyPondParser__spanners__Trill_01():
    """
    Successful trills, showing single leaf overlap.
    """

    maker = abjad.NoteMaker()
    notes = maker(4 * [0], [(1, 4)])
    target = abjad.Container(notes)
    abjad.trill_spanner(target[2:])
    abjad.trill_spanner(target[:3])

    assert format(target) == abjad.String.normalize(r"""
        {
            c'4
            \startTrillSpan
            c'4
            c'4
            \stopTrillSpan
            \startTrillSpan
            c'4
            \stopTrillSpan
        }
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Exemple #29
0
def test_LilyPondParser__spanners__PhrasingSlur_01():
    """
    Successful slurs, showing single leaf overlap.
    """

    maker = abjad.NoteMaker()
    target = abjad.Container(maker([0] * 4, [(1, 4)]))
    abjad.phrasing_slur(target[2:])
    abjad.phrasing_slur(target[:3])

    assert format(target) == abjad.String.normalize(
        r"""
        {
            c'4
            \(
            c'4
            c'4
            \)
            \(
            c'4
            \)
        }
        """
    )

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Exemple #30
0
def test_LilyPondParser__contexts__PianoStaff_01():

    maker = abjad.NoteMaker()
    target = abjad.StaffGroup([
        abjad.Staff(maker([0, 2, 4, 5, 7], (1, 8))),
        abjad.Staff(maker([0, 2, 4, 5, 7], (1, 8)))
    ])
    target.lilypond_type = 'PianoStaff'

    assert format(target) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \new Staff
            {
                c'8
                d'8
                e'8
                f'8
                g'8
            }
            \new Staff
            {
                c'8
                d'8
                e'8
                f'8
                g'8
            }
        >>
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result