def test_scoretools_Inspection_get_indicator_07(): note = abjad.Note("c'8") command = abjad.LilyPondLiteral(r'\stemUp') abjad.attach(command, note) command = abjad.LilyPondLiteral(r'\slurUp') abjad.attach(command, note) statement = 'inspect(note).get_indicator(abjad.LilyPondLiteral)' assert pytest.raises(Exception, statement)
def test_GraceContainer_06(): """ Grace containers can be appended. """ grace_container = abjad.GraceContainer("c'8 c'8") note = abjad.Note(1, (1, 4)) grace_container.append(note) assert len(grace_container) == 3 assert grace_container[-1] is note
def test_Staff_append_02(): """ Append one chord. """ staff = abjad.Staff(abjad.Note("c'4") * 4) staff.append(abjad.Chord([2, 3, 4], (1, 4))) assert abjad.inspect(staff).wellformed() assert len(staff) == 5 assert staff._get_contents_duration() == abjad.Duration(5, 4)
def test_GraceContainer_07(): """ Grace containers can be extended. """ grace_container = abjad.GraceContainer("c'8 c'8") ns = abjad.Note(1, (1, 4)) * 2 grace_container.extend(ns) assert len(grace_container) == 4 assert tuple(grace_container[-2:]) == tuple(ns)
def test_get_leaf_10(): """ Does not connect through contiguous unequally named voices. """ voice_1 = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(4)]) voice_1.name = "Your Voice" voice_2 = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(4, 8)]) voice_2.name = "My Voice" staff = abjad.Staff([voice_1, voice_2]) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { \context Voice = "Your Voice" { c'8 cs'8 d'8 ef'8 } \context Voice = "My Voice" { e'8 f'8 fs'8 g'8 } } """) assert abjad.get.leaf(voice_1[0], 1) is voice_1[1] assert abjad.get.leaf(voice_1[1], 1) is voice_1[2] assert abjad.get.leaf(voice_1[2], 1) is voice_1[3] assert abjad.get.leaf(voice_1[3], 1) is None voice_2.name = None assert abjad.get.leaf(voice_1[3], 1) is None assert abjad.get.leaf(voice_2[1], -1) is voice_2[0] assert abjad.get.leaf(voice_2[2], -1) is voice_2[1] assert abjad.get.leaf(voice_2[3], -1) is voice_2[2] assert abjad.get.leaf(voice_2[0], -1) is None
def test_scoretools_Inspection_get_indicator_11(): note = abjad.Note("c'8") comment = abjad.LilyPondComment('comment') abjad.attach(comment, note) comment = abjad.LilyPondComment('another comment') abjad.attach(comment, note) statement = 'inspect(note).get_indicator(abjad.LilyPondComment)' assert pytest.raises(Exception, statement)
def test_Mutation_fuse_01(): """ Works with list of leaves. """ notes = 8 * abjad.Note("c'4") fused = abjad.mutate(notes).fuse() assert len(fused) == 1 assert fused[0].written_duration == abjad.Duration(2)
def test_scoretools_GraceContainer_01(): notes = [ abjad.Note(0, (1, 16)), abjad.Note(2, (1, 16)), abjad.Note(4, (1, 16)) ] grace_container = abjad.GraceContainer(notes) assert format(grace_container) == abjad.String.normalize(r''' \grace { c'16 d'16 e'16 } ''') assert isinstance(grace_container, abjad.Container) assert len(grace_container) == 3
def test_Leaf__split_by_durations_04(): """ Returns selection of new leaves. """ note = abjad.Note("c'4") new_leaves = note._split_by_durations([abjad.Duration(1, 16)]) assert isinstance(new_leaves, abjad.Selection) assert all(isinstance(_, abjad.Note) for _ in new_leaves)
def test_scoretools_Note_grace_02(): r'''Attaches several grace notes. ''' note = abjad.Note("c'4") grace_notes = [abjad.Note(0, (1, 16)), abjad.Note(2, (1, 16)), abjad.Note(4, (1, 16))] grace_container = abjad.GraceContainer(grace_notes) abjad.attach(grace_container, note) assert format(note) == abjad.String.normalize( r''' \grace { c'16 d'16 e'16 } c'4 ''' )
def test_Inspection_leaf_10(): """ Does not connect through contiguous unequally named voices. """ voice_1 = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(4)]) voice_1.name = 'Your Voice' voice_2 = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(4, 8)]) voice_2.name = 'My Voice' staff = abjad.Staff([voice_1, voice_2]) assert format(staff) == abjad.String.normalize(r""" \new Staff { \context Voice = "Your Voice" { c'8 cs'8 d'8 ef'8 } \context Voice = "My Voice" { e'8 f'8 fs'8 g'8 } } """) assert abjad.inspect(voice_1[0]).leaf(1) is voice_1[1] assert abjad.inspect(voice_1[1]).leaf(1) is voice_1[2] assert abjad.inspect(voice_1[2]).leaf(1) is voice_1[3] assert abjad.inspect(voice_1[3]).leaf(1) is None voice_2.name = None assert abjad.inspect(voice_1[3]).leaf(1) is None assert abjad.inspect(voice_2[1]).leaf(-1) is voice_2[0] assert abjad.inspect(voice_2[2]).leaf(-1) is voice_2[1] assert abjad.inspect(voice_2[3]).leaf(-1) is voice_2[2] assert abjad.inspect(voice_2[0]).leaf(-1) is None
def _apply_trills(self, selections): container = abjad.Container() container.append(selections) for tie in abjad.iterate(container).logical_ties(pitched=True): if isinstance(tie[0], abjad.Chord): old_chord = tie[0] base_pitch = old_chord.written_pitches[0] trill_pitch = old_chord.written_pitches[-1] interval_ = abjad.NamedInterval().from_pitch_carriers( base_pitch, trill_pitch) new_leaf = abjad.Note(base_pitch, old_chord.written_duration) trill_start = abjad.LilyPondLiteral(r'\pitchedTrill', format_slot='before') trill_literal = abjad.LilyPondLiteral( f'\startTrillSpan {trill_pitch}', format_slot='after') trill_stop = abjad.LilyPondLiteral(r'\stopTrillSpan', format_slot='after') abjad.attach(trill_start, new_leaf) abjad.attach(trill_literal, new_leaf) last_leaf = tie[-1] next_leaf = abjad.inspect(last_leaf).leaf(1) if next_leaf != None: abjad.attach(trill_stop, next_leaf) indicators = abjad.inspect(old_chord).indicators() for indicator in indicators: abjad.attach(indicator, new_leaf) parent = abjad.inspect(old_chord).parentage().parent parent[parent.index(old_chord)] = new_leaf tail = abjad.select(tie).leaves()[1:] for leaf in tail: new_tail = abjad.Note(base_pitch, leaf.written_duration) parent = abjad.inspect(leaf).parentage().parent parent[parent.index(leaf)] = new_tail indicators = abjad.inspect(leaf).indicators() for indicator in indicators: abjad.attach(indicator, new_tail) return container[:]
def set_acciaccatura_pitch( nth_event: int, pitch: ji.JIPitch, novent_line: lily.NOventLine, ) -> None: novent_line[nth_event].acciaccatura.abjad = abjad.Note( lily.convert2abjad_pitch(pitch, globals_.RATIO2PITCHCLASS), abjad.Duration(1, 8), ) novent_line[nth_event].acciaccatura.mu_pitches = [pitch]
def test_QEventSequence_from_tempo_scaled_leaves_02(): staff = abjad.Staff([]) staff.append(abjad.Note(0, (1, 4))) staff.append(abjad.Rest((1, 4))) staff.append(abjad.Rest((1, 8))) staff.append(abjad.Note(1, (1, 8))) staff.append(abjad.Note(1, (1, 8))) staff.append(abjad.Note(2, (1, 8))) staff.append(abjad.Note(2, (1, 8))) staff.append(abjad.Note(3, (1, 8))) staff.append(abjad.Skip((1, 4))) staff.append(abjad.Rest((1, 4))) staff.append(abjad.Note(3, (1, 8))) staff.append(abjad.Chord([0, 1, 4], (1, 4))) abjad.tie(staff[3:5]) abjad.tie(staff[5:7]) tempo = abjad.MetronomeMark((1, 4), 58) abjad.attach(tempo, staff[0], context="Staff") tempo = abjad.MetronomeMark((1, 4), 77) abjad.attach(tempo, staff[9], context="Staff") leaves = abjad.select.leaves(staff) q_events = abjadext.nauert.QEventSequence.from_tempo_scaled_leaves(leaves) assert q_events == abjadext.nauert.QEventSequence( ( abjadext.nauert.PitchedQEvent( abjad.Offset(0, 1), (abjad.NamedPitch("c'"),) ), abjadext.nauert.SilentQEvent(abjad.Offset(30000, 29)), abjadext.nauert.PitchedQEvent( abjad.Offset(75000, 29), (abjad.NamedPitch("cs'"),) ), abjadext.nauert.PitchedQEvent( abjad.Offset(105000, 29), (abjad.NamedPitch("d'"),) ), abjadext.nauert.PitchedQEvent( abjad.Offset(135000, 29), (abjad.NamedPitch("ef'"),) ), abjadext.nauert.SilentQEvent(abjad.Offset(150000, 29)), abjadext.nauert.PitchedQEvent( abjad.Offset(15600000, 2233), (abjad.NamedPitch("ef'"),) ), abjadext.nauert.PitchedQEvent( abjad.Offset(16470000, 2233), ( abjad.NamedPitch("c'"), abjad.NamedPitch("cs'"), abjad.NamedPitch("e'"), ), ), abjadext.nauert.TerminalQEvent(abjad.Offset(18210000, 2233)), ) )
def test_PersistenceManager_as_pdf_01(): """ Persists PDF file when no PDF file exists. """ note = abjad.Note("c'4") with abjad.FilesystemState(remove=paths): result = abjad.persist(note).as_pdf(pdf_path) assert os.path.isfile(pdf_path) assert isinstance(result, tuple)
def test_get_leaf_14(): """ Tautological parentage asymmetries result in symmetric (balanced) logical voice parentage. """ container_1 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(4)]) container_2 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(4, 8)]) container_2 = abjad.Container([container_2]) container_2 = abjad.Container([container_2]) 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], 1) is container_1[1] assert abjad.get.leaf(container_1[1], 1) is container_1[2] assert abjad.get.leaf(container_1[2], 1) is container_1[3] assert abjad.get.leaf(container_1[3], 1) is container_2[0][0][0] assert abjad.get.leaf(container_2[0][0][1], -1) is container_2[0][0][0] assert abjad.get.leaf(container_2[0][0][2], -1) is container_2[0][0][1] assert abjad.get.leaf(container_2[0][0][3], -1) is container_2[0][0][2] assert abjad.get.leaf(container_2[0][0][0], -1) is container_1[3]
def test_scoretools_Container_index_01(): r'''Elements that compare equal return different indices in container. ''' container = abjad.Container(4 * abjad.Note("c'4")) assert container.index(container[0]) == 0 assert container.index(container[1]) == 1 assert container.index(container[2]) == 2 assert container.index(container[3]) == 3
def test_Inspection_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 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][0]).leaf(1) is container_1[0][0][1] assert abjad.inspect(container_1[0][0][1]).leaf(1) is container_1[0][0][2] assert abjad.inspect(container_1[0][0][2]).leaf(1) is container_1[0][0][3] assert abjad.inspect(container_1[0][0][3]).leaf(1) is container_2[0] assert abjad.inspect(container_2[0]).leaf(-1) is container_1[0][0][3] assert abjad.inspect(container_2[1]).leaf(-1) is container_2[0] assert abjad.inspect(container_2[2]).leaf(-1) is container_2[1] assert abjad.inspect(container_2[3]).leaf(-1) is container_2[2]
def test_PersistenceManager_as_ly_01(): """ Agent abjad.persists LilyPond file when no LilyPond file exists. """ note = abjad.Note("c'4") with abjad.FilesystemState(remove=[ly_path]): result = abjad.persist(note).as_ly(ly_path) assert os.path.isfile(ly_path) assert isinstance(result, tuple)
def test_Staff_append_01(): """ Append one note. """ staff = abjad.Staff("c'4 c'4 c'4 c'4") staff.append(abjad.Note("c'4")) assert abjad.wf.wellformed(staff) assert len(staff) == 5 assert staff._get_contents_duration() == abjad.Duration(5, 4)
def test_Leaf__split_by_durations_05(): """ Lone spanned leaf results in two spanned leaves. """ staff = abjad.Staff([abjad.Note("c'4")]) staff[0]._split_by_durations([abjad.Duration(1, 8)]) assert len(staff) == 2 assert abjad.inspect(staff).wellformed()
def test_scoretools_Inspection_get_indicator_04(): note = abjad.Note("c'8") articulation = abjad.Articulation('staccato') abjad.attach(articulation, note) articulation = abjad.Articulation('marcato') abjad.attach(articulation, note) statement = 'inspect(note).get_indicator(abjad.Articulation)' assert pytest.raises(Exception, statement)
def test_Mutation_fuse_03(): """ Works with containers. """ voice = abjad.Voice(8 * abjad.Note("c'4")) fused = abjad.mutate(voice[:]).fuse() assert len(fused) == 1 assert fused[0].written_duration == 2 assert voice[0] is fused[0]
def test_LilyPondParser__functions__language_01(): target = abjad.Container( [abjad.Note("cs'8"), abjad.Note("ds'8"), abjad.Note("ff'8")]) assert format(target) == abjad.String.normalize(r""" { cs'8 ds'8 ff'8 } """) string = r"\language nederlands { cis'8 dis'8 fes'8 }" parser = abjad.parser.LilyPondParser() result = parser(string) assert format(target) == format(result) and target is not result
def test_mutate__fuse_leaves_by_immediate_parent_03(): """ Fuse leaves in logical tie with same immediate parent. """ note = abjad.Note("c'4") logical_tie = abjad.get.logical_tie(note) result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie) assert len(result) == 1 assert abjad.wf.wellformed(note)
def test_LogicalTie__fuse_leaves_by_immediate_parent_03(): """ Fuse leaves in logical tie with same immediate parent. """ note = abjad.Note("c'4") logical_tie = abjad.inspect(note).logical_tie() result = logical_tie._fuse_leaves_by_immediate_parent() assert len(result) == 1 assert abjad.inspect(note).wellformed()
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 apply_rhythm(this_notes, spelled_rhythm, rhythm_strings, notes_with_lily_features): #print 'notes_with_lily_features {0}'.format(notes_with_lily_features) lily_features = map( lambda n: filter(lambda f: f[0] == 'lily', n.features), notes_with_lily_features)[0] if notes_with_lily_features else [] #print lily_features lily_features = map(lambda x: x[1], lily_features) #print lily_features lily_features = reduce(lambda x, y: x + y, lily_features) if lily_features else "" #print 'lily_features {0}'.format(lily_features) subnotes = [] for (num, base) in spelled_rhythm: for i in range(num): # F*****G (efficiency) this all happens for each num. can do it outside just once # empty => rest if this_notes == []: thisone = abj.Rest('r' + rhythm_strings(base) + '\mp') # one note elif len(this_notes) == 1: thisone = abj.Note( mid_2_lil(this_notes[0].pitch) + rhythm_strings(base) + lily_features) # chord else: thisone = abj.Chord( "<" + reduce(lambda x, y: x + " " + y, [mid_2_lil(n.pitch) for n in this_notes]) + ">" + rhythm_strings(base) + lily_features) # append to subnotes subnotes.append(thisone) # if more than one subnote then tie them all up # first count how many # then reach back into subnotes and tie themup # wait this shouldn't work... meaning it probs doesn't... how_many = sum([x for (x, y) in spelled_rhythm]) #print how_many if how_many > 1: #print "tieing" abj.attach(abj.Tie(), subnotes[how_many * -1::]) return subnotes
def __call__( self, q_events: typing.Sequence[QEvent] ) -> tuple[ tuple[abjad.NamedPitch, ...], typing.Optional[tuple], typing.Optional[abjad.BeforeGraceContainer], ]: """ Calls concatenating grace handler. """ grace_events, final_event = q_events[:-1], q_events[-1] attachments: tuple | None if grace_events and self._replace_rest_with_final_grace_note: index = self._find_last_pitched_q_event(q_events) grace_events, final_event = q_events[:index], q_events[index] if isinstance(final_event, PitchedQEvent): # TODO: we are only supporting preserving attachments for PitchedQEvent pitches = final_event.pitches attachments = final_event.attachments else: pitches = () attachments = None grace_events_list = list(grace_events) if self._discard_grace_rest: for q_event in grace_events_list: if isinstance(q_event, SilentQEvent): grace_events_list.remove(q_event) grace_events = tuple(grace_events_list) grace_container: abjad.BeforeGraceContainer | None if grace_events: grace_container = abjad.BeforeGraceContainer() for q_event in grace_events: leaf: abjad.Leaf if isinstance(q_event, PitchedQEvent): if len(q_event.pitches) == 1: leaf = abjad.Note(q_event.pitches[0], self.grace_duration) else: leaf = abjad.Chord(q_event.pitches, self.grace_duration) else: leaf = abjad.Rest(self.grace_duration) q_event_attachments = ( None if not hasattr(q_event, "attachments") else q_event.attachments ) # assert hasattr(q_event, "attachments") # q_event_attachments = q_event.attachments if q_event_attachments is not None: abjad.annotate(leaf, "q_event_attachments", q_event_attachments) grace_container.append(leaf) else: grace_container = None return tuple(pitches), attachments, grace_container
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]