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
def test_Selection_are_contiguous_logical_voice_07(): """ False when components belonging to same logical voice are ommitted. """ voice = abjad.Voice("c'8 d'8 e'8 f'8 g'8 a'8") abjad.beam(voice[:]) assert format(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ d'8 e'8 f'8 g'8 a'8 ] } """ ) selection = voice[:2] + voice[-2:] assert not selection.are_contiguous_logical_voice()
def test_Mutation_swap_02(): """ Moves parentage, children from container to empty voice. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() voice.name = "foo" abjad.beam(leaves) assert format(voice) == abjad.String.normalize( r""" \context Voice = "foo" { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } """ ) new_voice = abjad.Voice() new_voice.name = "foo" abjad.mutate(voice[1:2]).swap(new_voice) assert format(voice) == abjad.String.normalize( r""" \context Voice = "foo" { { c'8 [ d'8 } \context Voice = "foo" { e'8 f'8 } { g'8 a'8 ] } } """ ) assert abjad.inspect(voice).wellformed()
def test_Mutation_swap_06(): """ Trying to move parentage, children from components that are not parent-contiguous raises exception. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } """ ) tuplet = abjad.Tuplet((2, 3), []) with pytest.raises(Exception): abjad.mutate([voice[0], voice[2]]).swap(tuplet)
def test_LilyPondGrobNameManager___setattr___46(): """ Override LilyPond abjad.TupletNumber grob. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.override(voice[1]).tuplet_number.fraction = True assert format(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ \once \override TupletNumber.fraction = ##t d'8 e'8 f'8 ] } """ ) assert abjad.inspect(voice).wellformed()
def test_Container_extend_02(): """ Extend container with contents of other container. """ voice_1 = abjad.Voice("c'8 d'8") abjad.beam(voice_1[:]) voice_2 = abjad.Voice("e'8 f'8") abjad.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 ] } """ ), print(format(voice_1)) assert abjad.inspect(voice_1).wellformed()
def test_Container___delitem___01(): """ Deletes in-score container. """ voice = abjad.Voice("{ c'8 ( d'8 ) } { e'8 ( f'8 ) }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { { c'8 ( [ d'8 ) } { e'8 ( f'8 ) ] } } """) container = voice[0] del voice[0] # container no longer appears in score assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { { e'8 ( f'8 ) ] } } """), print(abjad.lilypond(voice)) assert abjad.wf.wellformed(voice) # container leaves are still slurred assert abjad.lilypond(container) == abjad.String.normalize(r""" { c'8 ( [ d'8 ) } """), print(abjad.lilypond(container)) assert abjad.wf.wellformed(container)
def test_Selection_are_contiguous_logical_voice_07(): """ False when components belonging to same logical voice are ommitted. """ voice = abjad.Voice("c'8 d'8 e'8 f'8 g'8 a'8") abjad.beam(voice[:]) assert abjad.lilypond(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ d'8 e'8 f'8 g'8 a'8 ] } """ ) selection = voice[:2] + voice[-2:] assert not selection.are_contiguous_logical_voice()
def test_LilyPondGrobNameManager___setattr___42(): """ Override LilyPond abjad.TupletBracket grob. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.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).wellformed()
def test_Mutation_split_13(): """ Splits in-score measure with power-of-two denominator. """ voice = abjad.Voice() voice.append(abjad.Container("c'8 d'8 e'8")) voice.append(abjad.Container("f'8 g'8 a'8")) leaves = abjad.select(voice).leaves() abjad.beam(leaves) measures = voice[1:2] result = abjad.mutate(measures).split([abjad.Duration(1, 8)], ) assert format(voice) == abjad.String.normalize(r""" \new Voice { { c'8 [ d'8 e'8 } { f'8 } { g'8 a'8 ] } } """), print(format(voice)) assert abjad.inspect(voice).wellformed()
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
def test_Container___setitem___10(): r"""Sets leaf between spanned compoennts. """ staff = abjad.Staff("c'8 d'8 e'8 f'8") abjad.beam(staff[:]) note = abjad.Note("g'8") staff[2:2] = [note] assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 [ d'8 g'8 e'8 f'8 ] } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_Container___setitem___13(): r"""Replaces three spanned leaves with three different leaves. """ staff = abjad.Staff("c'8 d'8 e'8 f'8") abjad.beam(staff[:]) notes = [abjad.Note("b'8"), abjad.Note("a'8"), abjad.Note("g'8")] staff[1:3] = notes assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 [ b'8 a'8 g'8 f'8 ] } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_mutate_split_08(): """ Splits in-score measure with power-of-two denominator. """ voice = abjad.Voice() voice.append(abjad.Container("c'8 d'8 e'8")) voice.append(abjad.Container("f'8 g'8 a'8")) leaves = abjad.select(voice).leaves() abjad.beam(leaves) measures = voice[1:2] abjad.mutate.split(measures, [abjad.Duration(1, 8)]) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { { c'8 [ d'8 e'8 } { f'8 } { g'8 a'8 ] } } """), print(abjad.lilypond(voice)) assert abjad.wf.wellformed(voice)
def test_Leaf__split_by_durations_17(): """ Split one leaf in score. Ties after split. """ staff = abjad.Staff() staff.append(abjad.Container("c'8 d'8")) staff.append(abjad.Container("e'8 f'8")) leaves = abjad.select(staff).leaves() abjad.beam(leaves[:2]) abjad.beam(leaves[-2:]) abjad.slur(leaves) assert format(staff) == abjad.String.normalize(r""" \new Staff { { c'8 [ ( d'8 ] } { e'8 [ f'8 ) ] } } """), print(format(staff)) new_leaves = leaves[0]._split_by_durations([abjad.Duration(1, 32)], tie_split_notes=True) assert format(staff) == abjad.String.normalize(r""" \new Staff { { c'32 [ ( ~ c'16. d'8 ] } { e'8 [ f'8 ) ] } } """), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_Container_append_01(): """ Append sequential to voice. """ voice = abjad.Voice("c'8 d'8") abjad.beam(voice[:]) voice.append(abjad.Container("e'8 f'8")) assert format(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ d'8 ] { e'8 f'8 } } """ ), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Mutation_swap_02(): """ Moves parentage, children from container to empty voice. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() voice.name = 'foo' abjad.beam(leaves) assert format(voice) == abjad.String.normalize( r""" \context Voice = "foo" { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } """ ) new_voice = abjad.Voice() new_voice.name = 'foo' abjad.mutate(voice[1:2]).swap(new_voice) assert format(voice) == abjad.String.normalize( r""" \context Voice = "foo" { { c'8 [ d'8 } \context Voice = "foo" { e'8 f'8 } { g'8 a'8 ] } } """ ) assert abjad.inspect(voice).wellformed()
def test_LilyPondGrobNameManager___setattr___47(): """ Override LilyPond abjad.TupletNumber grob. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.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).wellformed()
def test_LilyPondGrobNameManager___setattr___47(): """ Override LilyPond abjad.TupletNumber grob. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.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).wellformed()
def test_Mutation_swap_06(): """ Trying to move parentage, children from components that are not parent-contiguous raises exception. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) assert format(voice) == abjad.String.normalize(r""" \new Voice { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } """) tuplet = abjad.Tuplet((2, 3), []) with pytest.raises(Exception): abjad.mutate([voice[0], voice[2]]).swap(tuplet)
def test_LilyPondGrobNameManager___setattr___43(): """ Override LilyPond abjad.TupletBracket grob. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.override(voice[1]).tuplet_bracket.direction = abjad.Down assert format(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ \once \override TupletBracket.direction = #down d'8 e'8 f'8 ] } """ ) assert abjad.inspect(voice).wellformed()
def test_Mutation_copy_06(): staff = abjad.Staff("abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |" "| 2/8 g'8 a'8 || 2/8 b'8 c''8 |") leaves = abjad.select(staff).leaves() abjad.beam(leaves) abjad.slur(leaves) assert format(staff) == abjad.String.normalize(r""" \new Staff { { \time 2/8 c'8 [ ( d'8 } { \time 2/8 e'8 f'8 } { \time 2/8 g'8 a'8 } { \time 2/8 b'8 c''8 ) ] } } """), print(format(staff)) result = abjad.mutate(leaves[:6]).copy() new_staff = abjad.Staff(result) assert format(new_staff) == abjad.String.normalize(r""" \new Staff { \time 2/8 c'8 [ ( d'8 \time 2/8 e'8 f'8 \time 2/8 g'8 a'8 } """), print(format(new_staff)) assert abjad.inspect(staff).wellformed() assert abjad.inspect(new_staff).wellformed()
def test_Container_extend_02(): """ Extend container with contents of other container. """ voice_1 = abjad.Voice("c'8 d'8") abjad.beam(voice_1[:]) voice_2 = abjad.Voice("e'8 f'8") abjad.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 ] } """), print(format(voice_1)) assert abjad.inspect(voice_1).wellformed()
def test_LilyPondGrobNameManager___setattr___45(): """ Override LilyPond abjad.TupletNumber grob. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.override(voice).tuplet_number.fraction = True assert format(voice) == abjad.String.normalize(r""" \new Voice \with { \override TupletNumber.fraction = ##t } { c'8 [ d'8 e'8 f'8 ] } """) assert abjad.inspect(voice).wellformed()
def test_Leaf__split_by_durations_16(): staff = abjad.Staff() staff.append(abjad.Container("c'8 d'8")) staff.append(abjad.Container("e'8 f'8")) leaves = abjad.select(staff).leaves() abjad.beam(leaves[:2]) abjad.beam(leaves[-2:]) abjad.slur(leaves) assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'8 [ ( d'8 ] } { e'8 [ f'8 ) ] } } """ ), print(format(staff)) new_leaves = leaves[0]._split_by_durations( [abjad.Duration(1, 32)], tie_split_notes=False ) assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'32 [ ( c'16. d'8 ] } { e'8 [ f'8 ) ] } } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_Mutation_swap_03(): """ Moves parentage, children from container to empty tuplet. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ d'8 } { e'8 f'8 } { g'8 a'8 ] } } """ ) tuplet = abjad.Tuplet((3, 4), []) abjad.mutate(voice[1:2]).swap(tuplet) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ d'8 } \tweak text #tuplet-number::calc-fraction-text \times 3/4 { e'8 f'8 } { g'8 a'8 ] } } """ ) assert abjad.inspect(voice).wellformed()
def test_mutate__split_leaf_by_durations_10(): """ Split one leaf in score. Ties after split. """ staff = abjad.Staff() staff.append(abjad.Container("c'8 d'8")) staff.append(abjad.Container("e'8 f'8")) leaves = abjad.select(staff).leaves() abjad.beam(leaves[:2]) abjad.beam(leaves[-2:]) abjad.slur(leaves) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { { c'8 [ ( d'8 ] } { e'8 [ f'8 ) ] } } """), print(abjad.lilypond(staff)) abjad.mutate._split_leaf_by_durations(leaves[0], [abjad.Duration(1, 32)]) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { { c'32 [ ( ~ c'16. d'8 ] } { e'8 [ f'8 ) ] } } """), print(abjad.lilypond(staff)) assert abjad.wf.wellformed(staff)
def test_Mutation_fuse_08(): """ Fuses fixed-multiplier tuplets with same multiplier in score. """ tuplet_1 = abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8") abjad.beam(tuplet_1[:]) tuplet_2 = abjad.Tuplet(abjad.Multiplier(2, 3), "c'8 d'8 e'8 f'8 g'8") abjad.slur(tuplet_2[:]) voice = abjad.Voice([tuplet_1, tuplet_2]) assert format(voice) == abjad.String.normalize(r""" \new Voice { \times 2/3 { c'8 [ d'8 e'8 ] } \tweak edge-height #'(0.7 . 0) \times 2/3 { c'8 ( d'8 e'8 f'8 g'8 ) } } """), print(format(voice)) tuplets = voice[:] abjad.mutate(tuplets).fuse() assert format(voice) == abjad.String.normalize(r""" \new Voice { \tweak edge-height #'(0.7 . 0) \times 2/3 { c'8 [ d'8 e'8 ] c'8 ( d'8 e'8 f'8 g'8 ) } } """), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Container__split_by_duration_01(): staff = abjad.Staff() staff.append(abjad.Container("c'8 d'8")) staff.append(abjad.Container("e'8 f'8")) leaves = abjad.select(staff).leaves() abjad.beam(leaves[:2]) abjad.beam(leaves[-2:]) abjad.slur(leaves) assert format(staff) == abjad.String.normalize(r""" \new Staff { { c'8 [ ( d'8 ] } { e'8 [ f'8 ) ] } } """), print(format(staff)) halves = staff[0]._split_by_duration( abjad.Duration(1, 32), tie_split_notes=False, ) assert format(staff) == abjad.String.normalize(r""" \new Staff { { c'32 [ ( } { c'16. d'8 ] } { e'8 [ f'8 ) ] } } """), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_Container_remove_02(): """ Containers remove nested containers correctly. abjad.Container abjad.detaches from parentage. abjad.Container returns after removal. """ staff = abjad.Staff("{ c'8 d'8 } { e'8 f'8 }") leaves = abjad.select(staff).leaves() sequential = staff[0] abjad.beam(leaves) assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'8 [ d'8 } { e'8 f'8 ] } } """ ) staff.remove(sequential) assert format(staff) == abjad.String.normalize( r""" \new Staff { { e'8 f'8 ] } } """ ) assert abjad.inspect(staff).wellformed() assert format(sequential) == abjad.String.normalize( r""" { c'8 [ d'8 } """ ) assert abjad.inspect(sequential).wellformed()
def test_Mutation_fuse_06(): """ Fuses two unincorporated tuplets with same multiplier. """ tuplet_1 = abjad.Tuplet((2, 3), "c'8 d'8 e'8") abjad.beam(tuplet_1[:]) tuplet_2 = abjad.Tuplet((2, 3), "c'16 d'16 e'16") abjad.slur(tuplet_2[:]) assert format(tuplet_1) == abjad.String.normalize( r""" \times 2/3 { c'8 [ d'8 e'8 ] } """ ), print(format(tuplet_1)) assert format(tuplet_2) == abjad.String.normalize( r""" \times 2/3 { c'16 ( d'16 e'16 ) } """ ), print(format(tuplet_2)) tuplets = abjad.select([tuplet_1, tuplet_2]) new = abjad.mutate(tuplets).fuse() assert format(new) == abjad.String.normalize( r""" \times 2/3 { c'8 [ d'8 e'8 ] c'16 ( d'16 e'16 ) } """ ), print(format(new)) assert len(tuplet_1) == 0 assert len(tuplet_2) == 0 assert new is not tuplet_1 and new is not tuplet_2 assert abjad.inspect(new).wellformed()
def test_Mutation_fuse_07(): """ Fuses tuplets with same multiplier in score. """ tuplet_1 = abjad.Tuplet((2, 3), "c'8 d'8 e'8") abjad.beam(tuplet_1[:]) tuplet_2 = abjad.Tuplet((2, 3), "c'16 d'16 e'16") abjad.slur(tuplet_2[:]) voice = abjad.Voice([tuplet_1, tuplet_2]) assert format(voice) == abjad.String.normalize( r""" \new Voice { \times 2/3 { c'8 [ d'8 e'8 ] } \times 2/3 { c'16 ( d'16 e'16 ) } } """ ), print(format(voice)) tuplets = voice[:] abjad.mutate(tuplets).fuse() assert format(voice) == abjad.String.normalize( r""" \new Voice { \times 2/3 { c'8 [ d'8 e'8 ] c'16 ( d'16 e'16 ) } } """ ), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Mutation_split_19(): """ Cyclically splits all components in container. """ voice = abjad.Voice([abjad.Container("c'8 d'8 e'8 f'8")]) leaves = abjad.select(voice).leaves() abjad.beam(leaves) abjad.slur(leaves) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ ( d'8 e'8 f'8 ) ] } } """ ), print(format(voice)) container = voice[0] result = abjad.mutate(container).split([abjad.Duration(1, 8)], cyclic=True) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ ( } { d'8 } { e'8 } { f'8 ) ] } } """ ), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Mutation_split_05(): """ Cyclically splits orphan measures. """ measures = [ abjad.Container("c'8 d'8"), abjad.Container("e'8 f'8"), ] leaves = abjad.select(measures).leaves() abjad.beam(leaves[:2]) abjad.beam(leaves[-2:]) result = abjad.mutate(measures).split( [abjad.Duration(3, 32)], cyclic=True, tie_split_notes=False, ) components = abjad.sequence(result).flatten(depth=-1) staff = abjad.Staff(components) assert format(staff) == abjad.String.normalize(r""" \new Staff { { c'16. [ } { c'32 d'16 } { d'16 ] } { e'32 [ } { e'16. } { f'16. } { f'32 ] } } """), print(format(staff)) assert abjad.inspect(staff).wellformed() assert len(result) == 6
def test_Mutation_split_14(): """ Cyclically splits all components in container. """ voice = abjad.Voice([abjad.Container("c'8 d'8 e'8 f'8")]) leaves = abjad.select(voice).leaves() abjad.beam(leaves) abjad.slur(leaves) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ ( d'8 e'8 f'8 ) ] } } """ ), print(format(voice)) container = voice[0] abjad.mutate(container).split([abjad.Duration(1, 8)], cyclic=True) assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ ( } { d'8 } { e'8 } { f'8 ) ] } } """ ), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Mutation_copy_03(): """ Three notes crossing measure boundaries. """ staff = abjad.Staff("abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 || 2/8 g'8 a'8 |") leaves = abjad.select(staff).leaves() abjad.slur(leaves) abjad.trill_spanner(leaves) abjad.beam(leaves) assert format(staff) == abjad.String.normalize(r""" \new Staff { { \time 2/8 c'8 ( \startTrillSpan [ d'8 } { \time 2/8 e'8 f'8 } { \time 2/8 g'8 a'8 ) \stopTrillSpan ] } } """), print(format(staff)) result = abjad.mutate(leaves[-3:]).copy() new = abjad.Staff(result) assert format(new) == abjad.String.normalize(r""" \new Staff { f'8 \time 2/8 g'8 a'8 ) \stopTrillSpan ] } """), print(format(new)) assert abjad.inspect(staff).wellformed() assert abjad.inspect(new).wellformed()
def test_Container_extend_08(): """ 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") abjad.beam(voice_1[:]) voice_2 = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice_2[:]) abjad.slur(voice_2[-2:]) assert format(voice_2) == abjad.String.normalize(r""" \new Voice { c'8 [ d'8 e'8 ( f'8 ) ] } """), print(format(voice_2)) voice_1.extend(voice_2[-2:]) assert format(voice_1) == abjad.String.normalize(r""" \new Voice { c'8 [ d'8 ] e'8 ( f'8 ) ] } """), print(format(voice_1)) assert abjad.inspect(voice_1).wellformed() assert format(voice_2) == abjad.String.normalize(r""" \new Voice { c'8 [ d'8 } """), print(format(voice_2)) assert abjad.inspect(voice_2).wellformed()
def test_mutate_replace_01(): """ Moves parentage from two old notes to five new notes. Equivalent to staff[1:3] = new_notes. """ staff = abjad.Staff("c'8 d'8 e'8 f'8") abjad.beam(staff[:2]) abjad.beam(staff[2:]) abjad.hairpin("< !", staff[:]) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'8 \< [ d'8 ] e'8 [ f'8 \! ] } """), print(abjad.lilypond(staff)) old_notes = staff[1:3] new_notes = abjad.Selection([ abjad.Note("c''16"), abjad.Note("c''16"), abjad.Note("c''16"), abjad.Note("c''16"), abjad.Note("c''16"), ]) abjad.mutate.replace(old_notes, new_notes) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'8 \< [ c''16 c''16 c''16 c''16 c''16 f'8 \! ] } """), print(abjad.lilypond(staff)) assert abjad.wf.wellformed(staff)
def test_Parentage_logical_voice_06(): """ 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" leaves = abjad.select(container).leaves() abjad.beam(leaves[:2]) abjad.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).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_Leaf__split_by_durations_11(): staff = abjad.Staff("c'8 c'8 c'8 c'8") abjad.beam(staff[:]) new_leaves = staff[0]._split_by_durations([abjad.Duration(1, 16)], tie_split_notes=False) assert len(staff) == 5 assert abjad.inspect(staff).wellformed()
def test_Container_extend_05(): """ Trying to extend container with noncomponent raises TypeError. """ voice = abjad.Voice("c'8 d'8") abjad.beam(voice[:]) assert pytest.raises(Exception, 'voice.extend(7)') assert pytest.raises(Exception, "voice.extend('foo')")
def test_Mutation_copy_01(): """ Deep copies components. Returns Python list of copied components. """ staff = abjad.Staff("abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 || 2/8 g'8 a'8 |") leaves = abjad.select(staff).leaves() abjad.slur(leaves) abjad.trill_spanner(leaves) abjad.beam(leaves) assert format(staff) == abjad.String.normalize(r""" \new Staff { { \time 2/8 c'8 ( \startTrillSpan [ d'8 } { \time 2/8 e'8 f'8 } { \time 2/8 g'8 a'8 ) \stopTrillSpan ] } } """), print(format(staff)) result = abjad.mutate(leaves[2:4]).copy() new = abjad.Staff(result) assert format(new) == abjad.String.normalize( r""" \new Staff { \time 2/8 e'8 f'8 } """, print(format(new)), ) assert abjad.inspect(staff).wellformed() assert abjad.inspect(new).wellformed()
def test_Container_pop_02(): """ Containers pop nested containers correctly. """ staff = abjad.Staff("{ c'8 d'8 } { e'8 f'8 }") leaves = abjad.select(staff).leaves() abjad.beam(leaves) assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'8 [ d'8 } { e'8 f'8 ] } } """ ), print(format(staff)) sequential = staff.pop() assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'8 [ d'8 } } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed() assert format(sequential) == abjad.String.normalize( r""" { e'8 f'8 ] } """ ), print(format(sequential)) assert abjad.inspect(sequential).wellformed()
def test_Skip___init___07(): """ Initialize skip from beamed note. """ staff = abjad.Staff(abjad.Note(0, (1, 8)) * 3) abjad.beam(staff[:]) skip = abjad.Skip(staff[0]) assert isinstance(staff[0], abjad.Note) assert isinstance(skip, abjad.Skip) assert staff[0]._parent is staff
def test_Leaf__split_by_durations_11(): staff = abjad.Staff("c'8 c'8 c'8 c'8") abjad.beam(staff[:]) new_leaves = staff[0]._split_by_durations( [abjad.Duration(1, 16)], tie_split_notes=False ) assert len(staff) == 5 assert abjad.inspect(staff).wellformed()
def _attach_beams(self, music): tuplets = abjad.iterate(music).components(abjad.Tuplet) for tuplet in tuplets: voice_numbers = [ abjad.inspect(_).indicator(int) for _ in tuplet] runs = baca.sequence(voice_numbers).group_by() counts = [len(_) for _ in runs] note_groups = baca.sequence(tuplet[:]).partition_by_counts(counts) for note_group in note_groups: note_group = abjad.select(note_group) abjad.beam(note_group)
def test_Mutation_replace_01(): """ Moves parentage from two old notes to five new notes. Equivalent to staff[1:3] = new_notes. """ staff = abjad.Staff("c'8 d'8 e'8 f'8") abjad.beam(staff[:2]) abjad.beam(staff[2:]) abjad.hairpin("< !", staff[:]) assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 \< [ d'8 ] e'8 [ f'8 \! ] } """ ), print(format(staff)) old_notes = staff[1:3] new_notes = 5 * abjad.Note("c''16") abjad.mutate(old_notes).replace(new_notes) assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 \< [ c''16 c''16 c''16 c''16 c''16 f'8 \! ] } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_Container_extend_05(): """ Trying to extend container with noncomponent raises TypeError. """ voice = abjad.Voice("c'8 d'8") abjad.beam(voice[:]) with pytest.raises(Exception): voice.extend(7) with pytest.raises(Exception): voice.extend("foo")
def test_Skip___init___04(): """ Initialize skip from beamed chord. """ staff = abjad.Staff(abjad.Chord([2, 3, 4], (1, 4)) * 3) abjad.beam(staff[:]) skip = abjad.Skip(staff[0]) assert isinstance(staff[0], abjad.Chord) assert isinstance(skip, abjad.Skip) assert staff[0]._parent is staff assert skip._parent is None
def test_Mutation_split_05(): """ Cyclically splits orphan measures. """ measures = [abjad.Container("c'8 d'8"), abjad.Container("e'8 f'8")] leaves = abjad.select(measures).leaves() abjad.beam(leaves[:2]) abjad.beam(leaves[-2:]) result = abjad.mutate(measures).split( [abjad.Duration(3, 32)], cyclic=True, tie_split_notes=False ) components = abjad.sequence(result).flatten(depth=-1) staff = abjad.Staff(components) assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'16. [ } { c'32 d'16 } { d'16 ] } { e'32 [ } { e'16. } { f'16. } { f'32 ] } } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed() assert len(result) == 6
def test_Container___setitem___11(): r"""Sets multiple leaves between spanned components. """ notes = [ abjad.Note("c'8"), abjad.Note("d'8"), abjad.Note("e'8"), abjad.Note("f'8"), abjad.Note("g'8"), abjad.Note("a'8"), ] beginning = notes[:2] middle = notes[2:4] end = notes[4:] staff = abjad.Staff(beginning + end) abjad.beam(staff[:]) assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 [ d'8 g'8 a'8 ] } """ ), print(format(staff)) staff[2:2] = middle assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 [ d'8 e'8 f'8 g'8 a'8 ] } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed()
def test_Mutation_swap_04(): """ Trying to move parentage, children to noncontainer raises exception. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) note = abjad.Note("c'4") with pytest.raises(Exception): abjad.mutate(voice[1:2]).swap(note)
def test_Container_extend_06(): """ Trying to extend container with noncontainer raises exception. """ voice = abjad.Voice("c'8 d'8") abjad.beam(voice[:]) with pytest.raises(AttributeError): voice.extend(abjad.Note(4, (1, 4))) with pytest.raises(AttributeError): voice.extend(abjad.Chord([2, 3, 5], (1, 4)))
def test_Mutation_swap_05(): """ Trying to move parentage, children from nonempty container to nonempty container raises exception. """ voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) tuplet = abjad.Tuplet((2, 3), "c'8 d'8 e'8") with pytest.raises(Exception): abjad.mutate(voice[1:2]).swap(tuplet)