def test_lilypondparsertools_LilyPondParser__functions__relative_05(): pitches = ["c", "f", "b", "e'", "a'", "d''", "g''", "c'''"] target = Container(scoretools.make_notes(pitches, [(1, 4)])) assert format(target) == stringtools.normalize(r""" { c4 f4 b4 e'4 a'4 d''4 g''4 c'''4 } """) string = r'''\relative c { c f b e a d g c }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__relative_08(): target = Container([ Note("c'", (1, 4)), Chord(["c'", "e'", "g'"], (1, 4)), Chord(["c''", "e''", "g'''"], (1, 4)), Chord(["e", "c'", "g''"], (1, 4)), ]) assert format(target) == stringtools.normalize(r""" { c'4 <c' e' g'>4 <c'' e'' g'''>4 <e c' g''>4 } """) string = r'''\relative c' { c <c e g> <c' e g'> <c, e, g''> }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__indicators__TimeSignature_01(): target = Score([Staff([Note(0, 1)])]) time_signature = TimeSignature((8, 8)) attach(time_signature, target[0]) assert format(target) == stringtools.normalize(r''' \new Score << \new Staff { \time 8/8 c'1 } >> ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result leaves = select(result).by_leaf() leaf = leaves[0] time_signatures = inspect_(leaf).get_indicators(TimeSignature) assert len(time_signatures) == 1
def test_lilypondparsertools_LilyPondParser__spanners__HorizontalBracket_01(): target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) bracket = spannertools.HorizontalBracketSpanner() attach(bracket, target[:]) bracket = spannertools.HorizontalBracketSpanner() attach(bracket, target[:2]) bracket = spannertools.HorizontalBracketSpanner() attach(bracket, target[2:]) assert format(target) == stringtools.normalize(r''' { c'4 \startGroup \startGroup c'4 \stopGroup c'4 \startGroup c'4 \stopGroup \stopGroup } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Beam_01(): target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) beam = Beam() attach(beam, target[0:3]) beam = Beam() attach(beam, target[3:]) assert format(target) == stringtools.normalize( r''' { c'4 [ c'4 c'4 ] c'4 [ ] } ''' ) parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Text_01(): r'''Successful text spanners, showing single leaf overlap. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) text_spanner = spannertools.TextSpanner() attach(text_spanner, target[2:]) text_spanner = spannertools.TextSpanner() attach(text_spanner, target[:3]) assert format(target) == stringtools.normalize(r''' { c'4 \startTextSpan c'4 c'4 \stopTextSpan \startTextSpan c'4 \stopTextSpan } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__relative_03(): pitches = [9, -3, 12, 5, 7, 31, 9, 17] target = Container(scoretools.make_notes(pitches, (1, 4))) assert format(target) == stringtools.normalize(r""" { a'4 a4 c''4 f'4 g'4 g'''4 a'4 f''4 } """) string = r"\relative c'' { a a, c' f, g g'' a,, f' }" parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__misc__chord_repetition_01(): target = Container([ Chord([0, 4, 7], (1, 4)), Chord([0, 4, 7], (1, 4)), Chord([0, 4, 7], (1, 4)), Chord([0, 4, 7], (1, 4)), ]) assert format(target) == stringtools.normalize(r''' { <c' e' g'>4 <c' e' g'>4 <c' e' g'>4 <c' e' g'>4 } ''') string = r'''{ <c' e' g'> q q q }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__indicators__Tempo_01(): target = Score([Staff([Note(0, 1)])]) tempo = Tempo(textual_indication="As fast as possible") attach(tempo, target.select_leaves()[0], scope=Staff) assert systemtools.TestManager.compare( target, r''' \new Score << \new Staff { \tempo "As fast as possible" c'1 } >> ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result leaf = result.select_leaves()[0] tempos = inspect_(leaf).get_indicators(Tempo) assert len(tempos) == 1
def test_lilypondparsertools_LilyPondParser__spanners__PhrasingSlur_01(): r'''Successful slurs, showing single leaf overlap. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) slur = spannertools.PhrasingSlur() attach(slur, target[2:]) slur = spannertools.PhrasingSlur() attach(slur, target[:3]) assert format(target) == stringtools.normalize(r''' { c'4 \( c'4 c'4 \) \( c'4 \) } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__relative_01(): pitches = [2, 5, 9, 7, 12, 11, 5, 2] target = Container(scoretools.make_notes(pitches, (1, 4))) assert format(target) == stringtools.normalize(r''' { d'4 f'4 a'4 g'4 c''4 b'4 f'4 d'4 } ''') string = r"\relative c' { d f a g c b f d }" parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__transpose_02(): pitches = ["ef'", "f'", "g'", "bf'"] target = Staff(scoretools.make_notes(pitches, (1, 4))) key_signature = KeySignature('ef', 'major') attach(key_signature, target[0]) assert systemtools.TestManager.compare( target, r''' \new Staff { \key ef \major ef'4 f'4 g'4 bf'4 } ''') string = r"\transpose a c' \relative c' \new Staff { \key c \major c4 d e g }" parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__transpose_01(): pitches = ["e'", "gs'", "b'", "e''"] target = Staff(scoretools.make_notes(pitches, (1, 4))) key_signature = KeySignature('e', 'major') attach(key_signature, target[0]) assert systemtools.TestManager.compare( target, r''' \new Staff { \key e \major e'4 gs'4 b'4 e''4 } ''') string = r"\transpose d e \relative c' \new Staff { \key d \major d4 fs a d }" parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__indicators__BarLine_01(): target = Staff( scoretools.make_notes(["e'", "d'", "c'"], [(1, 4), (1, 4), (1, 2)])) bar_line = indicatortools.BarLine('|.') attach(bar_line, target[-1]) assert systemtools.TestManager.compare( target, r''' \new Staff { e'4 d'4 c'2 \bar "|." } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result items = inspect_(result[2]).get_indicators() assert 1 == len(items) and isinstance(items[0], indicatortools.BarLine)
def test_lilypondparsertools_LilyPondParser__indicators__Articulation_01(): target = Staff(scoretools.make_notes(["c''"], [(1, 4)] * 6 + [(1, 2)])) articulation = Articulation('marcato', Up) attach(articulation, target[0]) articulation = Articulation('stopped', Down) attach(articulation, target[1]) articulation = Articulation('tenuto') attach(articulation, target[2]) articulation = Articulation('staccatissimo') attach(articulation, target[3]) articulation = Articulation('accent') attach(articulation, target[4]) articulation = Articulation('staccato') attach(articulation, target[5]) articulation = Articulation('portato') attach(articulation, target[6]) assert systemtools.TestManager.compare( target, r''' \new Staff { c''4 ^\marcato c''4 _\stopped c''4 -\tenuto c''4 -\staccatissimo c''4 -\accent c''4 -\staccato c''2 -\portato } ''') string = r'''\new Staff { c''4^^ c''_+ c''-- c''-| c''4-> c''-. c''2-_ }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and \ target is not result for x in result: assert 1 == len(inspect_(x).get_indicators(Articulation))
def test_lilypondparsertools_LilyPondParser__contexts__Staff_02(): target = Staff([]) target.is_simultaneous = True target.append( Voice(scoretools.make_notes([0, 2, 4, 5, 7, 9, 11, 12], (1, 8)))) target.append( Voice(scoretools.make_notes([0, 2, 4, 5, 7, 9, 11, 12], (1, 8)))) assert systemtools.TestManager.compare( target, r''' \new Staff << \new Voice { c'8 d'8 e'8 f'8 g'8 a'8 b'8 c''8 } \new Voice { c'8 d'8 e'8 f'8 g'8 a'8 b'8 c''8 } >> ''') 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. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) slur = Slur(direction=Down) attach(slur, target[:3]) slur = Slur(direction=Up) attach(slur, target[2:]) assert systemtools.TestManager.compare( target, r''' { c'4 _ ( c'4 c'4 ) ^ ( c'4 ) } ''') 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. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) slur = Slur() attach(slur, target[2:]) slur = Slur() attach(slur, target[:3]) assert systemtools.TestManager.compare( target, r''' { c'4 ( c'4 c'4 ) ( c'4 ) } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Trill_01(): r'''Successful trills, showing single leaf overlap. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) trill = spannertools.TrillSpanner() attach(trill, target[2:]) trill = spannertools.TrillSpanner() attach(trill, target[:3]) assert systemtools.TestManager.compare( target, r''' { c'4 \startTrillSpan c'4 c'4 \stopTrillSpan \startTrillSpan c'4 \stopTrillSpan } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__relative_09(): # http://lilypond.org/doc/v2.15/Documentation/c6/lily-8d84e2b9.ly pitches = ["c''", "fs''", "c''", "gf'", "b'", "ess''", "b'", "fff'"] target = Container(scoretools.make_notes(pitches, [(1, 2)])) assert format(target) == stringtools.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 = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Beam_07(): r'''With direction. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) beam = Beam(direction=Up) attach(beam, target[0:3]) beam = Beam(direction=Down) attach(beam, target[3:]) assert systemtools.TestManager.compare( target, r''' { c'4 ^ [ c'4 c'4 ] c'4 _ [ ] } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__indicators__Tempo_01(): target = Score([Staff([Note(0, 1)])]) tempo = Tempo(textual_indication="As fast as possible") attach(tempo, target[0], scope=Staff) assert format(target) == stringtools.normalize( r''' \new Score << \new Staff { \tempo "As fast as possible" c'1 } >> ''' ) parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result leaves = select(result).by_leaf() leaf = leaves[0] tempos = inspect_(leaf).get_indicators(Tempo) assert len(tempos) == 1
def test_lilypondparsertools_LilyPondParser__spanners__Beam_02(): r'''With start and stop reversed. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) beam = Beam() attach(beam, target[0:3]) beam = Beam() attach(beam, target[3:]) assert systemtools.TestManager.compare( target, r''' { c'4 [ c'4 c'4 ] c'4 [ ] } ''') string = r'''\relative c' { c [ c c ] c ] [ }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__functions__transpose_03(): target = Staff([ Container(scoretools.make_notes(["cs'", "ds'", "es'", "fs'"], (1, 4))), Container(scoretools.make_notes(["df'", "ef'", "f'", "gf'"], (1, 4))) ]) assert format(target) == stringtools.normalize( r''' \new Staff { { cs'4 ds'4 es'4 fs'4 } { df'4 ef'4 f'4 gf'4 } } ''' ) string = r'''music = \relative c' { c d e f } \new Staff { \transpose c cs \music \transpose c df \music } ''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Hairpin_01(): target = Staff(scoretools.make_notes([0] * 5, [(1, 4)])) hairpin = Hairpin(descriptor='<') attach(hairpin, target[:3]) hairpin = Hairpin(descriptor='>') attach(hairpin, target[2:]) dynamic = Dynamic('ppp') attach(dynamic, target[-1]) assert systemtools.TestManager.compare( target, r''' \new Staff { c'4 \< c'4 c'4 \! \> c'4 c'4 \ppp } ''') parser = LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Hairpin_02(): target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) hairpin = Hairpin(descriptor='<') attach(hairpin, target[0:2]) hairpin = Hairpin(descriptor='<') attach(hairpin, target[1:3]) hairpin = Hairpin(descriptor='<') attach(hairpin, target[2:]) assert systemtools.TestManager.compare( target, r''' { c'4 \< c'4 \! \< c'4 \! \< c'4 \! } ''') string = r'''\relative c' { c \< c \< c \< c \! }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__spanners__Trill_02(): r'''Swapped start and stop. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) trill = spannertools.TrillSpanner() attach(trill, target[2:]) trill = spannertools.TrillSpanner() attach(trill, target[:3]) assert format(target) == stringtools.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 = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__indicators__Dynamic_01(): target = Staff(Note(-12, (1, 2)) * 6) dynamic = Dynamic('ppp') attach(dynamic, target[0]) dynamic = Dynamic('mp') attach(dynamic, target[1]) dynamic = Dynamic('rfz') attach(dynamic, target[2]) dynamic = Dynamic('mf') attach(dynamic, target[3]) dynamic = Dynamic('spp') attach(dynamic, target[4]) dynamic = Dynamic('ff') attach(dynamic, target[5]) string = r'''\new Staff { c2\ppp c\mp c2\rfz c\mf c2\spp c\ff }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result for x in result: dynamics = inspect_(x).get_indicators(Dynamic) assert len(dynamics) == 1
def test_lilypondparsertools_LilyPondParser__spanners__Slur_02(): r'''Swapped start and stop. ''' target = Container(scoretools.make_notes([0] * 4, [(1, 4)])) slur = Slur() attach(slur, target[2:]) slur = Slur() attach(slur, target[:3]) assert format(target) == stringtools.normalize(r''' { c'4 ( c'4 c'4 ) ( c'4 ) } ''') string = r"\relative c' { c ( c c () c ) }" parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_lilypondparsertools_LilyPondParser__misc__chord_repetition_02(): target = Staff([ Chord([0, 4, 7], (1, 8)), Chord([0, 4, 7], (1, 8)), Chord([0, 4, 7], (1, 4)), Chord([0, 4, 7], (3, 16)), Chord([0, 4, 7], (1, 16)), Chord([0, 4, 7], (1, 4)) ]) dynamic = Dynamic('p') attach(dynamic, target[0]) articulation = Articulation('staccatissimo') attach(articulation, target[2]) markup = markuptools.Markup('text', Up) attach(markup, target[3]) articulation = Articulation('staccatissimo') attach(articulation, target[-1]) assert systemtools.TestManager.compare( target, r''' \new Staff { <c' e' g'>8 \p <c' e' g'>8 <c' e' g'>4 -\staccatissimo <c' e' g'>8. ^ \markup { text } <c' e' g'>16 <c' e' g'>4 -\staccatissimo } ''') string = r'''\new Staff { <c' e' g'>8\p q q4-| q8.^"text" q16 q4-| }''' parser = LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result