def test_get_leaf_15(): """ Tautological parentage asymmetries result in symmetric (balanced) lgoical voice parentage. """ container_1 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(4)]) container_1 = abjad.Container([container_1]) container_1 = abjad.Container([container_1]) container_2 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(4, 8)]) voice = abjad.Voice([container_1, container_2]) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { { { { c'8 cs'8 d'8 ef'8 } } } { e'8 f'8 fs'8 g'8 } } """) assert abjad.get.leaf(container_1[0][0][0], 1) is container_1[0][0][1] assert abjad.get.leaf(container_1[0][0][1], 1) is container_1[0][0][2] assert abjad.get.leaf(container_1[0][0][2], 1) is container_1[0][0][3] assert abjad.get.leaf(container_1[0][0][3], 1) is container_2[0] assert abjad.get.leaf(container_2[0], -1) is container_1[0][0][3] assert abjad.get.leaf(container_2[1], -1) is container_2[0] assert abjad.get.leaf(container_2[2], -1) is container_2[1] assert abjad.get.leaf(container_2[3], -1) is container_2[2]
def test_Container___delitem___03(): """ Deletes slice in middle of container. """ voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]") del voice[1:3] assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ f'8 ] } """) assert abjad.inspect(voice).wellformed()
def from_selections(class_, selections, time_signatures=None): """ Makes a selection of measures from ``selections``. Returns selections. """ import abjad assert len(selections) if not time_signatures: time_signatures = [_.duration() for _ in selections] assert len(selections) == len(time_signatures) durations = [abjad.inspect(_).duration() for _ in selections] assert durations == [abjad.Duration(_) for _ in time_signatures] maker = abjad.MeasureMaker() measures = maker(time_signatures) temporary_voice = abjad.Voice(measures) abjad.mutate(temporary_voice).replace_measure_contents(selections) temporary_voice[:] = [] return measures
def test_Mutation_fuse_10(): tuplet_1 = abjad.Tuplet((2, 3), "c'8") tuplet_2 = abjad.Tuplet((2, 3), "c'4") voice = abjad.Voice([tuplet_1, tuplet_2, abjad.Note("c'4")]) leaves = abjad.select(voice).leaves() abjad.slur(leaves) assert format(voice) == abjad.String.normalize(r""" \new Voice { \tweak edge-height #'(0.7 . 0) \times 2/3 { c'8 ( } \tweak edge-height #'(0.7 . 0) \times 2/3 { c'4 } c'4 ) } """), print(format(voice)) tuplets = voice[:2] abjad.mutate(tuplets).fuse() assert format(voice) == abjad.String.normalize(r""" \new Voice { \times 2/3 { c'8 ( c'4 } c'4 ) } """), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Leaf__set_duration_02(): """ Change tied leaf to tied value. Duplicate ties are not created. """ voice = abjad.Voice("c'8 c'8 c'8 c'8") abjad.tie(voice[:2]) abjad.beam(voice[:2]) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 ~ [ c'8 ] c'8 c'8 } """), print(format(voice)) voice[1]._set_duration(abjad.Duration(5, 32)) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ ~ c'8 ] ~ c'32 ] c'8 c'8 } """), print(format(voice)) assert abjad.inspect(voice).wellformed()
def test_Mutation_extract_01(): """ Extracts note. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.glissando(voice[:]) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando d'8 \glissando e'8 \glissando f'8 ] } """), print(format(voice)) note = voice[1] abjad.mutate(note).extract() assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando e'8 \glissando f'8 ] } """), print(format(voice)) assert abjad.inspect(note).wellformed() assert abjad.inspect(voice).wellformed()
def test_mutate_extract_02(): """ Extracts multiple notes. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.glissando(voice[:]) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando %! abjad.glissando(7) d'8 \glissando %! abjad.glissando(7) e'8 \glissando %! abjad.glissando(7) f'8 ] } """), print(abjad.lilypond(voice)) notes = voice[:2] for note in notes: abjad.mutate.extract(note) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { e'8 \glissando %! abjad.glissando(7) f'8 ] } """), print(abjad.lilypond(voice)) for note in notes: assert abjad.wf.wellformed(note) assert abjad.wf.wellformed(voice)
def test_Mutation_extract_02(): """ Extracts multiple notes. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.glissando(voice[:]) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando %! abjad.glissando(7) d'8 \glissando %! abjad.glissando(7) e'8 \glissando %! abjad.glissando(7) f'8 ] } """), print(format(voice)) notes = voice[:2] for note in notes: abjad.mutate(note).extract() assert format(voice) == abjad.String.normalize(r""" \new Voice { e'8 \glissando %! abjad.glissando(7) f'8 ] } """), print(format(voice)) for note in notes: assert abjad.inspect(note).wellformed() assert abjad.inspect(voice).wellformed()
def test_scoretools_Selection_are_contiguous_logical_voice_01(): r'''Components that start at the same moment are bad. Even if components are all part of the same logical voice. ''' voice = abjad.Voice(r''' { c'8 d'8 } \new Voice { e'8 f'8 } { g'8 a'8 } ''') r''' \new Voice { { c'8 d'8 } \new Voice { e'8 f'8 } { g'8 a'8 } } ''' selection = abjad.select([voice, voice[0]]) assert not selection.are_contiguous_logical_voice() selection = voice[0:1] + voice[0][:] assert not selection.are_contiguous_logical_voice() selection = voice[-1:] + voice[-1][:] assert not selection.are_contiguous_logical_voice()
def test_Container___setitem___02(): """ Replaces in-score leaf with out-of-score container. """ voice = abjad.Voice("c'8 [ d'8 ] e'8 f'8") leaves = abjad.select(voice).leaves() assert format(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ d'8 ] e'8 f'8 } """ ) voice[1] = abjad.Container("c'16 c'16 c'16") assert format(voice) == abjad.String.normalize( r""" \new Voice { c'8 [ { c'16 c'16 c'16 } e'8 f'8 } """ ) assert abjad.inspect(voice).wellformed()
def test_Inspection_leaf_13(): """ Does connect through symmetrical nested containers in a voice. """ container_1 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(4)]) container_1 = abjad.Container([container_1]) container_2 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(4, 8)]) container_2 = abjad.Container([container_2]) voice = abjad.Voice([container_1, container_2]) assert format(voice) == abjad.String.normalize(r""" \new Voice { { { c'8 cs'8 d'8 ef'8 } } { { e'8 f'8 fs'8 g'8 } } } """) assert abjad.inspect(container_1[0][0]).leaf(1) is container_1[0][1] assert abjad.inspect(container_1[0][1]).leaf(1) is container_1[0][2] assert abjad.inspect(container_1[0][2]).leaf(1) is container_1[0][3] assert abjad.inspect(container_1[0][3]).leaf(1) is container_2[0][0] assert abjad.inspect(container_2[0][1]).leaf(-1) is container_2[0][0] assert abjad.inspect(container_2[0][2]).leaf(-1) is container_2[0][1] assert abjad.inspect(container_2[0][3]).leaf(-1) is container_2[0][2] assert abjad.inspect(container_2[0][0]).leaf(-1) is container_1[0][3]
def test_Leaf__split_by_durations_05(): """ Assignable duration produces two notes. """ voice = abjad.Voice(r"c'8 \times 2/3 { d'8 e'8 f'8 }") leaves = abjad.select(voice).leaves() abjad.beam(leaves) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \times 2/3 { d'8 e'8 f'8 ] } } """), print(format(staff)) new_leaves = leaves[1]._split_by_durations([abjad.Duration(1, 24)], tie_split_notes=False) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \times 2/3 { d'16 d'16 e'8 f'8 ] } } """), print(format(staff)) assert abjad.inspect(voice).wellformed()
def test_mutate__set_leaf_duration_04(): """ Change leaf to tied duration without power-of-two denominator. abjad.Tuplet inserted over new tied notes. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:2]) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ d'8 ] e'8 f'8 } """), print(abjad.lilypond(voice)) abjad.mutate._set_leaf_duration(voice[1], abjad.Duration(5, 48)) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \tweak edge-height #'(0.7 . 0) \times 2/3 { d'8 ~ d'32 ] } e'8 f'8 } """), print(abjad.lilypond(voice)) assert abjad.wf.wellformed(voice)
def _notate( self, attach_tempos=True, attack_point_optimizer=None, grace_handler=None, ): import abjad voice = abjad.Voice() # generate the first beat = self.items[0] components = beat.q_grid(beat.beatspan) if attach_tempos: attachment_target = components[0] leaves = select(attachment_target).leaves() if isinstance(attachment_target, abjad.Container): attachment_target = leaves[0] tempo = copy.copy(beat.tempo) attach(tempo, attachment_target) voice.extend(components) # generate the rest pairwise, comparing tempi for beat_one, beat_two in abjad.sequence(self.items).nwise(): components = beat_two.q_grid(beat_two.beatspan) if (beat_two.tempo != beat_one.tempo) and attach_tempos: attachment_target = components[0] leaves = select(attachment_target).leaves() if isinstance(attachment_target, abjad.Container): attachment_target = leaves[0] tempo = copy.copy(beat_two.tempo) attach(tempo, attachment_target) voice.extend(components) # apply logical ties, pitches, grace containers self._notate_leaves( grace_handler=grace_handler, voice=voice, ) # partition logical ties in voice attack_point_optimizer(voice) return voice
def test_Container___setitem___03(): """ Replaces in-score container with out-of-score leaf. """ voice = abjad.Voice("{ c'8 [ d'8 } { e'8 f'8 ] }") assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ d'8 } { e'8 f'8 ] } } """ ) voice[1] = abjad.Note("c''8") assert format(voice) == abjad.String.normalize( r""" \new Voice { { c'8 [ d'8 } c''8 } """ ) assert abjad.inspect(voice).wellformed()
def test_mutate_extract_01(): """ Extracts note. """ voice = abjad.Voice("c'8 d'8 e'8 f'8") abjad.beam(voice[:]) abjad.glissando(voice[:]) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando d'8 \glissando e'8 \glissando f'8 ] } """), print(abjad.lilypond(voice)) note = voice[1] abjad.mutate.extract(note) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ \glissando e'8 \glissando f'8 ] } """), print(abjad.lilypond(voice)) assert abjad.wf.wellformed(note) assert abjad.wf.wellformed(voice)
def test_Container___setitem___19(): r"""Extremely large coequal indices indicate last slice in staff.""" voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]") voice[1000:1000] = [abjad.Rest("r8")] assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ d'8 e'8 f'8 ] r8 } """), print(abjad.lilypond(voice)) assert abjad.wf.wellformed(voice)
def test_scoretools_Container_extend_03(): r'''Extending container with empty list leaves container unchanged. ''' voice = abjad.Voice("c'8 d'8") beam = abjad.Beam() abjad.attach(beam, voice[:]) voice.extend([]) assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ d'8 ] } ''') assert abjad.inspect(voice).is_well_formed()
def test_Container___delitem___02(): """ Deletes in-score leaf. """ voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]") del (voice[1]) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ e'8 f'8 ] } """) assert abjad.inspect(voice).wellformed()
def test_Container_extend_03(): """ Extending container with empty list leaves container unchanged. """ voice = abjad.Voice("c'8 d'8") abjad.beam(voice[:]) voice.extend([]) assert format(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ d'8 ] } """), print(format(voice)) assert abjad.inspect(voice).wellformed()
def make_hairpin_score_01(self): """ Make 200-note voice with crescendo spanner on every 4 notes. 2.12 (r9726) initialization: 248,502 function calls 2.12 (r9728) initialization: 248,502 function calls 2.12 (r9726) LilyPond format: 138,313 function calls 2.12 (r9728) LilyPond format: 134,563 function calls """ import abjad voice = abjad.Voice(200 * abjad.Note("c'16")) for part in abjad.sequence(voice[:]).partition_by_counts( [4], cyclic=True, ): crescendo = abjad.Hairpin('<') abjad.attach(crescendo, part) return voice
def test_scoretools_Selection__get_dominant_spanners_08(): r'''Only trill dominates first two notes. abjad.Note that trill abjad.attaches to notes. abjad.Note that beam and glissando abjad.attach to containers. ''' 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[:4]) glissando = abjad.Glissando() abjad.attach(glissando, leaves[-4:]) trill = abjad.TrillSpanner() abjad.attach(trill, leaves) receipt = leaves[:2]._get_dominant_spanners() assert len(receipt) == 2 assert (beam, 0) in receipt assert (trill, 0) in receipt
def __call__(self): """ Calls score template. Returns LilyPond file. """ # make bell voice and staff bell_voice = abjad.Voice(name='Bell Voice') bell_staff = abjad.Staff([bell_voice], name='Bell Staff') # make first violin voice and staff first_violin_voice = abjad.Voice(name='First Violin Voice') first_violin_staff = abjad.Staff( [first_violin_voice], name='First Violin Staff', ) # make second violin voice and staff second_violin_voice = abjad.Voice(name='Second Violin Voice') second_violin_staff = abjad.Staff( [second_violin_voice], name='Second Violin Staff', ) # make viola voice and staff viola_voice = abjad.Voice(name='Viola Voice') viola_staff = abjad.Staff([viola_voice], name='Viola Staff') # make cello voice and staff cello_voice = abjad.Voice(name='Cello Voice') cello_staff = abjad.Staff([cello_voice], name='Cello Staff') # make bass voice and staff bass_voice = abjad.Voice(name='Bass Voice') bass_staff = abjad.Staff([bass_voice], name='Bass Staff') # make strings staff group strings_staff_group = abjad.StaffGroup( [ first_violin_staff, second_violin_staff, viola_staff, cello_staff, bass_staff, ], name='Strings Staff Group', ) # make score score = abjad.Score([ bell_staff, strings_staff_group, ], name='Pärt Cantus Score') # return Pärt Cantus score return score
def test_Container___delitem___02(): """ Deletes in-score leaf. """ voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]") del voice[1] assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ e'8 f'8 ] } """) assert abjad.wf.wellformed(voice)
def test_scoretools_Mutation_scale_06(): r'''Doubles measures. ''' voice = abjad.Voice() voice.append(abjad.Measure((2, 8), "c'8 d'8")) voice.append(abjad.Measure((2, 8), "e'8 f'8")) assert format(voice) == abjad.String.normalize(r''' \new Voice { { % measure \time 2/8 c'8 d'8 } % measure { % measure e'8 f'8 } % measure } ''') abjad.mutate(voice).scale(abjad.Multiplier(2)) assert format(voice) == abjad.String.normalize(r''' \new Voice { { % measure \time 2/4 c'4 d'4 } % measure { % measure e'4 f'4 } % measure } ''') assert abjad.inspect(voice).is_well_formed()
def test_scoretools_Container___setitem___01(): r'''Replaces in-score leaf with out-of-score leaf. ''' voice = abjad.Voice("c'8 [ d'8 ] e'8 f'8") leaves = abjad.select(voice).leaves() abjad.attach(abjad.Glissando(), leaves) assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ \glissando d'8 ] \glissando e'8 \glissando f'8 } ''') voice[1] = abjad.Note("c''8") assert format(voice) == abjad.String.normalize(r''' \new Voice { c'8 [ \glissando c''8 ] \glissando e'8 \glissando f'8 } ''') assert abjad.inspect(voice).is_well_formed()
def test_scoretools_Inspection_get_duration_02(): voice = abjad.Voice([ abjad.Measure((2, 12), "c'8 d'8", implicit_scaling=True), abjad.Measure((2, 8), "c'8 d'8") ]) leaves = abjad.select(voice).leaves() beam = abjad.Beam() abjad.attach(beam, leaves) crescendo = abjad.Hairpin('<') abjad.attach(crescendo, voice[0][:]) diminuendo = abjad.Hairpin('>') abjad.attach(diminuendo, voice[1][:]) assert format(voice) == abjad.String.normalize(r''' \new Voice { { % measure \time 2/12 \scaleDurations #'(2 . 3) { c'8 [ \< d'8 \! } } % measure { % measure \time 2/8 c'8 \> d'8 ] \! } % measure } ''') assert abjad.inspect(beam).get_duration() == abjad.Duration(5, 12) assert abjad.inspect(crescendo).get_duration() == abjad.Duration(2, 12) assert abjad.inspect(diminuendo).get_duration() == abjad.Duration(2, 8)
def test_scoretools_Leaf__set_duration_01(): r'''Change leaf to tied duration. ''' voice = abjad.Voice("c'8 d'8 e'8 f'8") beam = abjad.Beam() abjad.attach(beam, voice[:2]) assert format(voice) == abjad.String.normalize( r''' \new Voice { c'8 [ d'8 ] e'8 f'8 } ''' ) voice[1]._set_duration(abjad.Duration(5, 32)) assert format(voice) == abjad.String.normalize( r''' \new Voice { c'8 [ d'8 ~ d'32 ] e'8 f'8 } ''' ) assert abjad.inspect(voice).is_well_formed()
def test_mutate__set_leaf_duration_02(): """ Change tied leaf to tied value. Duplicate ties are not created. """ voice = abjad.Voice("c'8 c'8 c'8 c'8") abjad.tie(voice[:2]) abjad.beam(voice[:2]) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 ~ [ c'8 ] c'8 c'8 } """), print(abjad.lilypond(voice)) abjad.mutate._set_leaf_duration(voice[1], abjad.Duration(5, 32)) assert abjad.lilypond(voice) == abjad.String.normalize(r""" \new Voice { c'8 [ ~ c'8 ~ c'32 ] c'8 c'8 } """), print(abjad.lilypond(voice)) assert abjad.wf.wellformed(voice)
def test_scoretools_Selection_are_contiguous_same_parent_02(): r'''Is true for unincorporated components when orphans allowed. Is false for unincorporated components when orphans not allowed. ''' voice = abjad.Voice(r''' { c'8 d'8 } { e'8 f'8 } ''') assert format(voice) == abjad.String.normalize(r''' \new Voice { { c'8 d'8 } { e'8 f'8 } } ''') assert abjad.select(voice).are_contiguous_same_parent() assert not abjad.select(voice).are_contiguous_same_parent( allow_orphans=False) assert voice[:].are_contiguous_same_parent() assert voice[0][:].are_contiguous_same_parent() assert voice[1][:].are_contiguous_same_parent() leaves = abjad.select(voice).leaves() assert not leaves.are_contiguous_same_parent()