def test_scoretools_Container_extend_02(): r'''Extend container with contents of other container. ''' voice_1 = abjad.Voice("c'8 d'8") beam = abjad.Beam() abjad.attach(beam, voice_1[:]) voice_2 = abjad.Voice("e'8 f'8") beam = abjad.Beam() abjad.attach(beam, voice_2[:]) voice_1.extend(voice_2) assert format(voice_1) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 ] e'8 [ f'8 ] } ''') assert abjad.inspect(voice_1).is_well_formed()
def test_scoretools_Container__get_spanners_that_dominate_component_pair_01(): '''Get spanners in proper parentage. ''' container = abjad.Container("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(abjad.Beam(), container[:]) slur = abjad.Slur() abjad.attach(slur, container[:]) trill = abjad.TrillSpanner() abjad.attach(trill, container[:]) assert format(container) == abjad.String.normalize(r''' { c'8 [ ( \startTrillSpan d'8 e'8 f'8 ] ) \stopTrillSpan } ''') parentage = abjad.inspect(container[0]).get_parentage() spanners = abjad.inspect(parentage).get_spanners() spanners == [beam, slur, trill] parentage = abjad.inspect(container).get_parentage() spanners = abjad.inspect(parentage).get_spanners() spanners == [trill]
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_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_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))")
def test_spannertools_Beam___eq___01(): r'''Spanner is strict comparator. ''' spanner_1 = abjad.Beam() spanner_2 = abjad.Beam() assert not spanner_1 == spanner_2
def test_scoretools_Container_extend_08(): r'''Extend container with partial and spanned contents of other container. Covered span comes with components from donor container. ''' voice_1 = abjad.Voice("c'8 d'8") beam = abjad.Beam() abjad.attach(beam, voice_1[:]) voice_2 = abjad.Voice("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, voice_2[:]) slur = abjad.Slur() abjad.attach(slur, voice_2[-2:]) assert format(voice_2) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 e'8 ( f'8 ] ) } ''') voice_1.extend(voice_2[-2:]) assert format(voice_1) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 ] e'8 ( f'8 ) } ''') assert abjad.inspect(voice_1).is_well_formed() assert format(voice_2) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 ] } ''') assert abjad.inspect(voice_2).is_well_formed()
def test_scoretools_Parentage_logical_voice_06(): r'''Returns logical voice giving the root and first voice, staff and score in parentage of component. ''' container = abjad.Container([ abjad.Staff([abjad.Voice("c'8 d'8")]), abjad.Staff([abjad.Voice("e'8 f'8")]), ]) container[0].name = 'staff1' container[1].name = 'staff2' container[0][0].name = 'voicefoo' container[1][0].name = 'voicefoo' beam = abjad.Beam() leaves = abjad.select(container).leaves() statement = 'attach(beam, leaves)' assert pytest.raises(Exception, statement) beam = abjad.Beam() abjad.attach(beam, leaves[:2]) beam = abjad.Beam() abjad.attach(beam, leaves[2:]) assert format(container) == abjad.String.normalize(r''' { \context Staff = "staff1" { \context Voice = "voicefoo" { c'8 [ d'8 ] } } \context Staff = "staff2" { \context Voice = "voicefoo" { e'8 [ f'8 ] } } } ''') signatures = [ abjad.inspect(leaf).get_parentage().logical_voice for leaf in leaves ] signatures[0] == signatures[1] signatures[0] != signatures[2] signatures[2] != signatures[2] signatures[2] == signatures[3]
def test_scoretools_Mutation_replace_02(): r'''Moves parentage and spanners from one old note to five new notes. Equivalent to staff[:1] = new_notes. ''' staff = abjad.Staff("c'8 d'8 e'8 f'8") beam_1 = abjad.Beam() abjad.attach(beam_1, staff[:2]) beam_2 = abjad.Beam() abjad.attach(beam_2, staff[2:]) crescendo = abjad.Hairpin('<') abjad.attach(crescendo, staff[:]) assert format(staff) == abjad.String.normalize(r''' \new Staff { c'8 [ \< d'8 ] e'8 [ f'8 ] \! } '''), format(staff) old_notes = staff[:1] 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 d'8 ] e'8 [ f'8 ] \! } '''), format(staff) assert abjad.inspect(staff).is_well_formed()
def test_spannertools_Spanner___getitem___04(): r'''Get all spanner components. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves) assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } ''') assert beam[:] == leaves[:]
def test_spannertools_Spanner___getitem___02(): r'''Get at negative index in spanner. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves) assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } ''') assert beam[-1] is leaves[-1]
def test_spannertools_Spanner_start_offset_01(): r'''Returns start time of spanner in score. ''' container = abjad.Container("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, container[1:3]) glissando = abjad.Glissando() abjad.attach(glissando, container[:]) assert format(container) == abjad.String.normalize( r''' { c'8 \glissando d'8 [ \glissando e'8 ] \glissando f'8 } ''' ) assert abjad.inspect(beam).get_timespan().start_offset == abjad.Duration(1, 8) assert abjad.inspect(glissando).get_timespan().start_offset == abjad.Duration(0)
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___35(): r'''Override LilyPond SpacingSpanner grob. ''' staff = abjad.Staff("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, staff[:]) abjad.override(beam).score.spacing_spanner.strict_grace_spacing = True abjad.override(beam).score.spacing_spanner.strict_note_spacing = True abjad.override(beam).score.spacing_spanner.uniform_stretching = True assert format(staff) == abjad.String.normalize(r''' \new Staff { \override Score.SpacingSpanner.strict-grace-spacing = ##t \override Score.SpacingSpanner.strict-note-spacing = ##t \override Score.SpacingSpanner.uniform-stretching = ##t c'8 [ d'8 e'8 \revert Score.SpacingSpanner.strict-grace-spacing \revert Score.SpacingSpanner.strict-note-spacing \revert Score.SpacingSpanner.uniform-stretching f'8 ] } ''') assert abjad.inspect(staff).is_well_formed()
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___12(): r'''Override LilyPond abjad.DynamicText grob. ''' staff = abjad.Staff("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, staff[:]) dynamic = abjad.Dynamic('f') abjad.attach(dynamic, staff[0]) spanner = abjad.Spanner() abjad.override(spanner).dynamic_text.thickness = 3 abjad.attach(spanner, staff[:]) assert format(staff) == abjad.String.normalize(r''' \new Staff { \override DynamicText.thickness = #3 c'8 \f [ d'8 e'8 \revert DynamicText.thickness f'8 ] } ''') assert abjad.inspect(staff).is_well_formed()
def test_scoretools_Mutation_splice_11(): r'''Extends leaves leftwards of leaf. Do not extend edge spanners. ''' voice = abjad.Voice("c'8 d'8 e'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) notes = [abjad.Note("c'16"), abjad.Note("d'16"), abjad.Note("e'16")] result = abjad.mutate(voice[0]).splice( notes, direction=abjad.Left, grow_spanners=False, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { c'16 d'16 e'16 c'8 [ d'8 e'8 ] } ''') assert abjad.inspect(voice).is_well_formed() assert result == voice[:4]
def test_spannertools_Spanner___len___01(): r'''Spanner length equals length of components. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") beam = abjad.Beam() abjad.attach(beam, voice[1][:]) assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 d'8 } { e'8 [ f'8 ] } { g'8 a'8 } } ''') assert len(beam) == 2
def test_scoretools_Mutation_splice_05(): r'''Extends leaves rightwards after leaf. ''' voice = abjad.Voice("c'8 d'8 e'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) result = abjad.mutate(voice[-1]).splice( [abjad.Note("c'8"), abjad.Note("d'8"), abjad.Note("e'8")], grow_spanners=False, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 e'8 ] c'8 d'8 e'8 } ''') assert abjad.inspect(voice).is_well_formed() assert result == voice[-4:]
def test_scoretools_Mutation_splice_10(): r'''Splices left of container with underspanners. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 }") leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves) result = abjad.mutate(voice[1]).splice( [abjad.Note("dqs'8")], direction=abjad.Left, grow_spanners=True, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 [ d'8 } dqs'8 { e'8 f'8 ] } } ''') assert result == voice[1:] assert abjad.inspect(voice).is_well_formed()
def test_scoretools_Mutation_splice_04(): r'''Splices after container with underspanners. ''' voice = abjad.Voice(abjad.Container("c'8 c'8") * 2) leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves) result = abjad.mutate(voice[0]).splice( [abjad.Note("dqs'8")], grow_spanners=True, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 [ c'8 } dqs'8 { c'8 c'8 ] } } ''') assert abjad.inspect(voice).is_well_formed() assert result == voice[0:2]
def test_scoretools_Mutation_splice_03(): r'''Splices tuplet after tuplet. ''' tuplet = abjad.Tuplet((2, 3), "c'8 d'8 e'8") voice = abjad.Voice([tuplet]) beam = abjad.Beam() abjad.attach(beam, tuplet[:]) tuplet = abjad.Tuplet((2, 3), "c'8 d'8 e'8") result = abjad.mutate(voice[-1]).splice( [tuplet], grow_spanners=True, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { \times 2/3 { c'8 [ d'8 e'8 } \times 2/3 { c'8 d'8 e'8 ] } } ''') assert abjad.inspect(voice).is_well_formed() assert result == voice[:]
def test_scoretools_Mutation_splice_12(): r'''Extends leaf leftwards of interior leaf. Does extend interior spanners. ''' voice = abjad.Voice("c'8 d'8 e'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) result = abjad.mutate(voice[1]).splice( [abjad.Note("dqf'8")], direction=abjad.Left, grow_spanners=False, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ dqf'8 d'8 e'8 ] } ''') assert result == voice[1:3] assert abjad.inspect(voice).is_well_formed()
def test_scoretools_Mutation_splice_02(): r'''Splices leaf after interior leaf. ''' voice = abjad.Voice("c'8 d'8 e'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) result = abjad.mutate(voice[1]).splice( [abjad.Note("dqs'8")], grow_spanners=True, ) assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 dqs'8 e'8 ] } ''') assert result == voice[1:3] assert abjad.inspect(voice).is_well_formed()
def test_spannertools_Spanner_extend_left_01(): r'''Extend spanner to the left. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves[2:4]) beam._extend_left(leaves[:2]) assert format(voice) == abjad.String.normalize( r''' \new Voice { { c'8 [ d'8 } { e'8 f'8 ] } { g'8 a'8 } } ''' ) assert abjad.inspect(voice).is_well_formed()
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___53(): r'''Override LilyPond abjad.TupletBracket grob. ''' voice = abjad.Voice("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) abjad.override(voice).tuplet_bracket.direction = abjad.Down assert format(voice) == abjad.String.normalize(r''' \new Voice \with { \override TupletBracket.direction = #down } { c'8 [ d'8 e'8 f'8 ] } ''') assert abjad.inspect(voice).is_well_formed()
def test_spannertools_Spanner___len___02(): r'''Spanner length equals length of components. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves) assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } ''') assert len(beam) == 6
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___58(): r'''Override LilyPond abjad.TupletNumber grob. ''' voice = abjad.Voice("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) abjad.override(voice).tuplet_number.text = abjad.Markup('6:4') assert format(voice) == abjad.String.normalize(r''' \new Voice \with { \override TupletNumber.text = \markup { 6:4 } } { c'8 [ d'8 e'8 f'8 ] } ''') assert abjad.inspect(voice).is_well_formed()
def test_scoretools_Selection__get_crossing_spanners_02(): r'''Helper gets spanners that cross in from above. ''' voice = abjad.Voice("abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 || 2/8 g'8 a'8 |") leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves[2:5]) assert format(voice) == abjad.String.normalize( r''' \new Voice { { % measure \time 2/8 c'8 d'8 } % measure { % measure e'8 [ f'8 } % measure { % measure g'8 ] a'8 } % measure } ''' ) spanners = abjad.select(leaves)._get_crossing_spanners() assert len(spanners) == 0
def test_scoretools_Mutation_splice_01(): voice = abjad.Voice("c'8 d'8 e'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) result = abjad.mutate(voice[-1]).splice( [abjad.Note("c'8"), abjad.Note("d'8"), abjad.Note("e'8")], grow_spanners=True, ) assert abjad.inspect(voice).is_well_formed() assert result == voice[-4:] assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 e'8 c'8 d'8 e'8 ] } ''')
def test_spannertools_Spanner___in___01(): r'''Spanner containment tests components. ''' voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") beam = abjad.Beam() abjad.attach(beam, voice[1][:]) assert format(voice) == abjad.String.normalize( r''' \new Voice { { c'8 d'8 } { e'8 [ f'8 ] } { g'8 a'8 } } ''' ) assert voice[1] not in beam assert voice[1][0] in beam assert voice[1][1] in beam
def test_scoretools_Measure___add___01(): r'''Add outside-of-score measures. ''' measure_1 = abjad.Measure((1, 8), "c'16 d'16") beam = abjad.Beam() abjad.attach(beam, measure_1[:]) measure_2 = abjad.Measure((2, 16), "c'16 d'16") slur = abjad.Slur() abjad.attach(slur, measure_2[:]) new = measure_1 + measure_2 assert format(new) == abjad.String.normalize(r''' { \time 2/8 c'16 [ d'16 ] c'16 ( d'16 ) } ''') assert new is not measure_1 and new is not measure_2 assert len(measure_1) == 0 assert len(measure_2) == 0 assert abjad.inspect(new).is_well_formed()