def test_mutate__fuse_leaves_by_immediate_parent_01(): """ Fuse leaves in logical tie with same immediate parent. """ staff = abjad.Staff([abjad.Container("c'8 c'8"), abjad.Container("c'8 c'8")]) leaves = abjad.select(staff).leaves() abjad.tie(leaves) logical_tie = abjad.get.logical_tie(leaves[1]) result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie) assert abjad.lilypond(staff) == abjad.String.normalize( r""" \new Staff { { c'4 ~ } { c'4 } } """ ), print(abjad.lilypond(staff)) assert len(result) == 2 assert abjad.wf.wellformed(staff)
def test_LilyPondParser__spanners__Tie_01(): target = abjad.Container([abjad.Note(0, 1), abjad.Note(0, 1)]) abjad.tie(target[:]) parser = abjad.parser.LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_LogicalTie__fuse_leaves_by_immediate_parent_01(): """ Fuse leaves in logical tie with same immediate parent. """ staff = abjad.Staff(2 * abjad.Container("c'8 c'8")) leaves = abjad.select(staff).leaves() abjad.tie(leaves) logical_tie = abjad.inspect(leaves[1]).logical_tie() result = logical_tie._fuse_leaves_by_immediate_parent() assert format(staff) == abjad.String.normalize(r""" \new Staff { { c'4 ~ } { c'4 } } """), print(format(staff)) assert len(result) == 2 assert abjad.inspect(staff).wellformed()
def edit_viola_voice(score, durated_reservoir): """ Edits viola voice. """ voice = score["Viola Voice"] descents = durated_reservoir["Viola"] for leaf in descents[-1]: articulation = abjad.Articulation("accent") abjad.attach(articulation, leaf) articulation = abjad.Articulation("tenuto") abjad.attach(articulation, leaf) last_descent = abjad.Selection(descents[-1]) copied_descent = abjad.mutate(last_descent).copy() for leaf in copied_descent: if leaf.written_duration == abjad.Duration(4, 4): leaf.written_duration = abjad.Duration(8, 4) else: leaf.written_duration = abjad.Duration(4, 4) voice.extend(copied_descent) bridge = abjad.Note("e1") articulation = abjad.Articulation("tenuto") abjad.attach(articulation, bridge) articulation = abjad.Articulation("accent") abjad.attach(articulation, bridge) voice.append(bridge) final_sustain_rhythm = [(6, 4)] * 21 + [(1, 2)] maker = abjad.NoteMaker() final_sustain_notes = maker(["e"], final_sustain_rhythm) articulation = abjad.Articulation("accent") abjad.attach(articulation, final_sustain_notes[0]) articulation = abjad.Articulation("tenuto") abjad.attach(articulation, final_sustain_notes[0]) voice.extend(final_sustain_notes) abjad.tie(final_sustain_notes) voice.extend("r4 r2.")
def recurse(node, tuplet_duration): basic_prolated_duration = ( tuplet_duration / node._get_contents_duration() ) basic_written_duration = ( basic_prolated_duration.equal_or_greater_power_of_two ) tuplet = abjad.Tuplet(1, []) for child in node.children: if isinstance(child, type(self)): tuplet.extend( recurse( child, child.preprolated_duration * basic_written_duration, ) ) else: leaves = child(basic_written_duration) tuplet.extend(leaves) if 1 < len(leaves): abjad.tie(leaves) assert tuplet.multiplier == 1, repr(tuplet.multiplier) contents_duration = abjad.inspect(tuplet).duration() target_duration = tuplet_duration multiplier = target_duration / contents_duration tuplet.multiplier = multiplier if tuplet.multiplier == 1: return tuplet[:] return [tuplet]
def test_LogicalTie__fuse_leaves_by_immediate_parent_02(): """ Fuse leaves in logical tie with same immediate parent. """ staff = abjad.Staff("c'8 c'8 c'8 c'8") abjad.tie(staff[:]) assert format(staff) == abjad.String.normalize(r""" \new Staff { c'8 ~ c'8 ~ c'8 ~ c'8 } """), print(format(staff)) logical_tie = abjad.inspect(staff[1]).logical_tie() result = logical_tie._fuse_leaves_by_immediate_parent() assert format(staff) == abjad.String.normalize(r""" \new Staff { c'2 } """), print(format(staff)) assert abjad.inspect(staff).wellformed() assert len(result) == 1
def edit_second_violin_voice(score, durated_reservoir): """ Edits second violin voice. """ voice = score['Second Violin Voice'] descents = durated_reservoir['Second Violin'] last_descent = abjad.Selection(descents[-1]) copied_descent = abjad.mutate(last_descent).copy() copied_descent = list(copied_descent) copied_descent[-1].written_duration = abjad.Duration(1, 1) copied_descent.append(abjad.Note('a2')) for leaf in copied_descent: articulation = abjad.Articulation('accent') abjad.attach(articulation, leaf) articulation = abjad.Articulation('tenuto') abjad.attach(articulation, leaf) voice.extend(copied_descent) final_sustain = [] for _ in range(32): final_sustain.append(abjad.Note('a1.')) final_sustain.append(abjad.Note('a2')) final_sustain = abjad.Selection(final_sustain) articulation = abjad.Articulation('accent') abjad.attach(articulation, final_sustain[0]) articulation = abjad.Articulation('tenuto') abjad.attach(articulation, final_sustain[0]) voice.extend(final_sustain) abjad.tie(final_sustain) voice.extend('r4 r2.')
def recurse(node, tuplet_duration): basic_prolated_duration = \ tuplet_duration / node._get_contents_duration() basic_written_duration = \ basic_prolated_duration.equal_or_greater_power_of_two tuplet = abjad.Tuplet(1, []) for child in node.children: if isinstance(child, type(self)): tuplet.extend( recurse( child, child.preprolated_duration * basic_written_duration)) else: leaves = child(basic_written_duration) tuplet.extend(leaves) if 1 < len(leaves): abjad.tie(leaves) assert tuplet.multiplier == 1, repr(tuplet.multiplier) contents_duration = abjad.inspect(tuplet).duration() target_duration = tuplet_duration multiplier = target_duration / contents_duration tuplet.multiplier = multiplier if tuplet.multiplier == 1: return tuplet[:] return [tuplet]
def test_mutate__fuse_leaves_by_immediate_parent_02(): """ Fuse leaves in logical tie with same immediate parent. """ staff = abjad.Staff("c'8 c'8 c'8 c'8") abjad.tie(staff[:]) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'8 ~ c'8 ~ c'8 ~ c'8 } """), print(abjad.lilypond(staff)) logical_tie = abjad.get.logical_tie(staff[1]) result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'2 } """), print(abjad.lilypond(staff)) assert abjad.wf.wellformed(staff) assert len(result) == 1
def edit_viola_voice(score, durated_reservoir): """ Edits viola voice. """ voice = score['Viola Voice'] descents = durated_reservoir['Viola'] for leaf in descents[-1]: articulation = abjad.Articulation('accent') abjad.attach(articulation, leaf) articulation = abjad.Articulation('tenuto') abjad.attach(articulation, leaf) last_descent = abjad.Selection(descents[-1]) copied_descent = abjad.mutate(last_descent).copy() for leaf in copied_descent: if leaf.written_duration == abjad.Duration(4, 4): leaf.written_duration = abjad.Duration(8, 4) else: leaf.written_duration = abjad.Duration(4, 4) voice.extend(copied_descent) bridge = abjad.Note('e1') articulation = abjad.Articulation('tenuto') abjad.attach(articulation, bridge) articulation = abjad.Articulation('accent') abjad.attach(articulation, bridge) voice.append(bridge) final_sustain_rhythm = [(6, 4)] * 21 + [(1, 2)] maker = abjad.NoteMaker() final_sustain_notes = maker(['e'], final_sustain_rhythm) articulation = abjad.Articulation('accent') abjad.attach(articulation, final_sustain_notes[0]) articulation = abjad.Articulation('tenuto') abjad.attach(articulation, final_sustain_notes[0]) voice.extend(final_sustain_notes) abjad.tie(final_sustain_notes) voice.extend('r4 r2.')
def edit_second_violin_voice(score, durated_reservoir): """ Edits second violin voice. """ voice = score["Second Violin Voice"] descents = durated_reservoir["Second Violin"] last_descent = abjad.Selection(descents[-1]) copied_descent = abjad.mutate(last_descent).copy() copied_descent = list(copied_descent) copied_descent[-1].written_duration = abjad.Duration(1, 1) copied_descent.append(abjad.Note("a2")) for leaf in copied_descent: articulation = abjad.Articulation("accent") abjad.attach(articulation, leaf) articulation = abjad.Articulation("tenuto") abjad.attach(articulation, leaf) voice.extend(copied_descent) final_sustain = [] for _ in range(32): final_sustain.append(abjad.Note("a1.")) final_sustain.append(abjad.Note("a2")) final_sustain = abjad.Selection(final_sustain) articulation = abjad.Articulation("accent") abjad.attach(articulation, final_sustain[0]) articulation = abjad.Articulation("tenuto") abjad.attach(articulation, final_sustain[0]) voice.extend(final_sustain) abjad.tie(final_sustain) voice.extend("r4 r2.")
def test_LogicalTie__fuse_leaves_by_immediate_parent_01(): """ Fuse leaves in logical tie with same immediate parent. """ staff = abjad.Staff(2 * abjad.Container("c'8 c'8")) leaves = abjad.select(staff).leaves() abjad.tie(leaves) logical_tie = abjad.inspect(leaves[1]).logical_tie() result = logical_tie._fuse_leaves_by_immediate_parent() assert format(staff) == abjad.String.normalize( r""" \new Staff { { c'4 ~ } { c'4 } } """ ), print(format(staff)) assert len(result) == 2 assert abjad.inspect(staff).wellformed()
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_LilyPondParser__spanners__Tie_05(): """ With direction. """ target = abjad.Container([abjad.Note(0, 1), abjad.Note(0, 1)]) abjad.tie(target[:], direction=abjad.Down) parser = abjad.parser.LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def test_QEventSequence_from_tempo_scaled_leaves_01(): 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), 55) leaves = abjad.select.leaves(staff) q_events = abjadext.nauert.QEventSequence.from_tempo_scaled_leaves(leaves, tempo) assert q_events == abjadext.nauert.QEventSequence( ( abjadext.nauert.PitchedQEvent( abjad.Offset(0, 1), (abjad.NamedPitch("c'"),) ), abjadext.nauert.SilentQEvent(abjad.Offset(12000, 11)), abjadext.nauert.PitchedQEvent( abjad.Offset(30000, 11), (abjad.NamedPitch("cs'"),) ), abjadext.nauert.PitchedQEvent( abjad.Offset(42000, 11), (abjad.NamedPitch("d'"),) ), abjadext.nauert.PitchedQEvent( abjad.Offset(54000, 11), (abjad.NamedPitch("ef'"),) ), abjadext.nauert.SilentQEvent(abjad.Offset(60000, 11)), abjadext.nauert.PitchedQEvent( abjad.Offset(84000, 11), (abjad.NamedPitch("ef'"),) ), abjadext.nauert.PitchedQEvent( abjad.Offset(90000, 11), ( abjad.NamedPitch("c'"), abjad.NamedPitch("cs'"), abjad.NamedPitch("e'"), ), ), abjadext.nauert.TerminalQEvent(abjad.Offset(102000, 11)), ) )
def test_LilyPondParser__spanners__Tie_04(): """ With direction. """ target = abjad.Container([abjad.Note(0, 1), abjad.Note(0, 1)]) abjad.tie(target[:], direction=abjad.Up) parser = abjad.parser.LilyPondParser() result = parser(abjad.lilypond(target)) assert abjad.lilypond(target) == abjad.lilypond( result) and target is not result
def _notate_leaves(self, grace_handler: GraceHandler, voice: abjad.Voice | None = None) -> list[tuple | None]: all_q_event_attachments: list[tuple | None] = [] for leaf in abjad.iterate.leaves(voice): if leaf._has_indicator(dict): annotation = leaf._get_indicator(dict) q_events = annotation["q_events"] pitches, attachments, grace_container = grace_handler(q_events) new_leaf: abjad.Leaf if not pitches: new_leaf = abjad.Rest(leaf) elif 1 < len(pitches): new_leaf = abjad.Chord(leaf) new_leaf.written_pitches = pitches else: new_leaf = abjad.Note(leaf) new_leaf.written_pitch = pitches[0] if attachments is not None: all_q_event_attachments.append(attachments) if grace_container: abjad.attach(grace_container, new_leaf) abjad.mutate.replace(leaf, new_leaf) if not isinstance(new_leaf, abjad.Rest): abjad.annotate(new_leaf, "tie_to_next", True) elif abjad.get.indicator(new_leaf, abjad.Tie): abjad.detach(abjad.Tie, new_leaf) else: previous_leaf = abjad._iterlib._get_leaf(leaf, -1) if isinstance(previous_leaf, abjad.Rest): new_leaf = type(previous_leaf)(leaf.written_duration) elif isinstance(previous_leaf, abjad.Note): new_leaf = type(previous_leaf)(previous_leaf.written_pitch, leaf.written_duration) else: new_leaf = type(previous_leaf)( previous_leaf.written_pitches, leaf.written_duration) abjad.mutate.replace(leaf, new_leaf) if abjad.get.annotation(previous_leaf, "tie_to_next") is True: leaves = [previous_leaf, new_leaf] abjad.tie(leaves) abjad.annotate(new_leaf, "tie_to_next", True) if leaf._has_indicator(abjad.MetronomeMark): tempo = leaf._get_indicator(abjad.MetronomeMark) abjad.detach(abjad.MetronomeMark, leaf) abjad.detach(abjad.MetronomeMark, new_leaf) abjad.attach(tempo, new_leaf) if leaf._has_indicator(abjad.TimeSignature): time_signature = leaf._get_indicator(abjad.TimeSignature) abjad.detach(abjad.TimeSignature, leaf) abjad.detach(abjad.TimeSignature, new_leaf) abjad.attach(time_signature, new_leaf) return all_q_event_attachments
def edit_first_violin_voice(score, durated_reservoir): """ Edits first violin voice. """ voice = score["First Violin Voice"] descents = durated_reservoir["First Violin"] last_descent = abjad.Selection(descents[-1]) copied_descent = abjad.mutate(last_descent).copy() voice.extend(copied_descent) final_sustain_rhythm = [(6, 4)] * 43 + [(1, 2)] maker = abjad.NoteMaker() final_sustain_notes = maker(["c'"], final_sustain_rhythm) voice.extend(final_sustain_notes) abjad.tie(final_sustain_notes) voice.extend("r4 r2.")
def edit_first_violin_voice(score, durated_reservoir): """ Edits first violin voice. """ voice = score['First Violin Voice'] descents = durated_reservoir['First Violin'] last_descent = abjad.Selection(descents[-1]) copied_descent = abjad.mutate(last_descent).copy() voice.extend(copied_descent) final_sustain_rhythm = [(6, 4)] * 43 + [(1, 2)] maker = abjad.NoteMaker() final_sustain_notes = maker(["c'"], final_sustain_rhythm) voice.extend(final_sustain_notes) abjad.tie(final_sustain_notes) voice.extend('r4 r2.')
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 _notate_leaves(self, grace_handler=None, voice=None): for leaf in abjad.iterate(voice).leaves(): if leaf._has_indicator(dict): annotation = leaf._get_indicator(dict) q_events = annotation["q_events"] pitches, grace_container = grace_handler(q_events) if not pitches: new_leaf = abjad.Rest(leaf) elif 1 < len(pitches): new_leaf = abjad.Chord(leaf) new_leaf.written_pitches = pitches else: new_leaf = abjad.Note(leaf) new_leaf.written_pitch = pitches[0] if grace_container: abjad.attach(grace_container, new_leaf) abjad.mutate.replace(leaf, new_leaf) if not isinstance(new_leaf, abjad.Rest): abjad.annotate(new_leaf, "tie_to_next", True) else: previous_leaf = abjad._iterate._get_leaf(leaf, -1) if isinstance(previous_leaf, abjad.Rest): new_leaf = type(previous_leaf)(leaf.written_duration) elif isinstance(previous_leaf, abjad.Note): new_leaf = type(previous_leaf)(previous_leaf.written_pitch, leaf.written_duration) else: new_leaf = type(previous_leaf)(previous_leaf.written_pitch, leaf.written_duration) abjad.mutate.replace(leaf, new_leaf) if abjad.get.annotation(previous_leaf, "tie_to_next") is True: leaves = abjad.select([previous_leaf, new_leaf]) abjad.tie(leaves) abjad.annotate(new_leaf, "tie_to_next", True) if leaf._has_indicator(abjad.MetronomeMark): tempo = leaf._get_indicator(abjad.MetronomeMark) abjad.detach(abjad.MetronomeMark, leaf) abjad.detach(abjad.MetronomeMark, new_leaf) abjad.attach(tempo, new_leaf) if leaf._has_indicator(abjad.TimeSignature): time_signature = leaf._get_indicator(abjad.TimeSignature) abjad.detach(abjad.TimeSignature, leaf) abjad.detach(abjad.TimeSignature, new_leaf) abjad.attach(time_signature, new_leaf)
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_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_LogicalTie__fuse_leaves_by_immediate_parent_02(): """ Fuse leaves in logical tie with same immediate parent. """ staff = abjad.Staff("c'8 c'8 c'8 c'8") abjad.tie(staff[:]) assert format(staff) == abjad.String.normalize( r""" \new Staff { c'8 ~ c'8 ~ c'8 ~ c'8 } """ ), print(format(staff)) logical_tie = abjad.inspect(staff[1]).logical_tie() result = logical_tie._fuse_leaves_by_immediate_parent() assert format(staff) == abjad.String.normalize( r""" \new Staff { c'2 } """ ), print(format(staff)) assert abjad.inspect(staff).wellformed() assert len(result) == 1
def make_bartok_score(): """ make the Bartok example score. """ # make score skeleton score = abjad.Score() piano_staff = abjad.StaffGroup(lilypond_type="PianoStaff") upper_staff = abjad.Staff([]) lower_staff = abjad.Staff([]) piano_staff.append(upper_staff) piano_staff.append(lower_staff) score.append(piano_staff) # make upper measures upper_measures = [] upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) lower_measures = copy.deepcopy(upper_measures) upper_staff.extend(upper_measures) lower_staff.extend(lower_measures) # add leaves to upper measures upper_measures[0].extend("a'8 g'8 f'8 e'8") abjad.attach(abjad.TimeSignature((2, 4)), upper_measures[0][0]) upper_measures[1].extend("d'4 g'8 f'8 e'8 d'8") abjad.attach(abjad.TimeSignature((3, 4)), upper_measures[1][0]) upper_measures[2].extend("c'8 d'16 e'16 f'8 e'8") abjad.attach(abjad.TimeSignature((2, 4)), upper_measures[2][0]) upper_measures[3].append("d'2") upper_measures[4].append("d'2") # add leaves to lower measures lower_measures[0].extend("b4 d'8 c'8") lower_measures[1].extend("b8 a8 af4 c'8 bf8") lower_measures[2].extend("a8 g8 fs8 g16 a16") # make parallel music for measure 4 upper_voice = abjad.Voice("b2", name="upper voice") command = abjad.LilyPondLiteral(r"\voiceOne") abjad.attach(command, upper_voice) lower_voice = abjad.Voice("b4 a4", name="lower voice") command = abjad.LilyPondLiteral(r"\voiceTwo") abjad.attach(command, lower_voice) lower_measures[3].extend([upper_voice, lower_voice]) lower_measures[3].is_simultaneous = True # make parallel music for measure 5 upper_voice = abjad.Voice("b2", name="upper voice") command = abjad.LilyPondLiteral(r"\voiceOne") abjad.attach(command, upper_voice) lower_voice = abjad.Voice("g2", name="lower voice") command = abjad.LilyPondLiteral(r"\voiceTwo") abjad.attach(command, lower_voice) lower_measures[4].extend([upper_voice, lower_voice]) lower_measures[4].is_simultaneous = True # add bass clef clef = abjad.Clef("bass") leaf = abjad.inspect(lower_staff).leaf(0) abjad.attach(clef, leaf) # add dynamics dynamic = abjad.Dynamic("pp") abjad.attach(dynamic, upper_measures[0][0]) dynamic = abjad.Dynamic("mp") abjad.attach(dynamic, upper_measures[1][1]) dynamic = abjad.Dynamic("pp") abjad.attach(dynamic, lower_measures[0][1]) dynamic = abjad.Dynamic("mp") abjad.attach(dynamic, lower_measures[1][3]) # add final bar line score.add_final_bar_line() # select leaves for attaching spanners to upper_leaves = abjad.select(upper_staff).leaves() lower_leaves = abjad.select(lower_staff).leaves() # attach beams abjad.beam(upper_leaves[:4]) abjad.beam(lower_leaves[1:5]) abjad.beam(lower_leaves[6:10]) # attach slurs abjad.slur(upper_leaves[:5]) abjad.slur(upper_leaves[5:]) abjad.slur(lower_leaves[1:6]) # attach hairpins abjad.hairpin("<", upper_leaves[-7:-2]) abjad.hairpin(">", upper_leaves[-2:]) # attach a ritardando with markup start_text_span = abjad.StartTextSpan(left_text=abjad.Markup("ritard.")) abjad.text_spanner(upper_leaves[-7:], start_text_span=start_text_span) # tie notes abjad.tie(upper_leaves[-2:]) # tie more notes note_1 = lower_staff[-2]["upper voice"][0] note_2 = lower_staff[-1]["upper voice"][0] notes = abjad.select([note_1, note_2]) abjad.tie(notes) # return the score return score
def make_bartok_score(): """ Makes Bartók score. """ # makes empty score score = abjad.Score() piano_staff = abjad.StaffGroup(lilypond_type="PianoStaff") upper_staff = abjad.Staff(name="Upper_Staff") upper_staff_voice = abjad.Voice(name="Upper_Staff_Voice") upper_staff.append(upper_staff_voice) lower_staff = abjad.Staff(name="Lower_Staff") lower_staff_voice_2 = abjad.Voice(name="Lower_Staff_Voice_II") lower_staff.append(lower_staff_voice_2) piano_staff.append(upper_staff) piano_staff.append(lower_staff) score.append(piano_staff) # populates upper measures upper_staff_voice.append(r"{ \time 2/4 a'8 g'8 f'8 e'8 }") upper_staff_voice.append(r"{ \time 3/4 d'4 g'8 f'8 e'8 d'8 }") upper_staff_voice.append(r"{ \time 2/4 c'8 d'16 e'16 f'8 e'8 }") upper_staff_voice.append("{ d'2 }") upper_staff_voice.append("{ d'2 }") # populates lower measures lower_staff_voice_2.append("{ b4 d'8 c'8 }") lower_staff_voice_2.append("{ b8 a8 af4 c'8 bf8 }") lower_staff_voice_2.append("{ a8 g8 fs8 g16 a16 }") # makes simultaneous music for measure 4 container = abjad.Container( [ abjad.Voice(name="Lower_Staff_Voice_I"), abjad.Voice(name="Lower_Staff_Voice_II"), ], simultaneous=True, ) literal = abjad.LilyPondLiteral(r"\voiceOne") abjad.attach(literal, container["Lower_Staff_Voice_I"]) container["Lower_Staff_Voice_I"].append("b2") literal = abjad.LilyPondLiteral(r"\voiceTwo") abjad.attach(literal, container["Lower_Staff_Voice_II"]) container["Lower_Staff_Voice_II"].extend("b4 a4") lower_staff.append(container) # measure 5 container = abjad.Container( [ abjad.Voice(name="Lower_Staff_Voice_I"), abjad.Voice(name="Lower_Staff_Voice_II"), ], simultaneous=True, ) literal = abjad.LilyPondLiteral(r"\voiceOne") abjad.attach(literal, container["Lower_Staff_Voice_I"]) container["Lower_Staff_Voice_I"].append("b2") literal = abjad.LilyPondLiteral(r"\voiceTwo") abjad.attach(literal, container["Lower_Staff_Voice_II"]) container["Lower_Staff_Voice_II"].append("g2") lower_staff.append(container) # get leaves upper_staff_leaves = abjad.select(upper_staff).leaves() lower_staff_voice_1_leaves = [] for leaf in abjad.select(lower_staff).leaves(): voice = abjad.inspect(leaf).parentage().get(abjad.Voice) if voice.name == "Lower_Staff_Voice_I": lower_staff_voice_1_leaves.append(leaf) lower_staff_voice_2_leaves = [] for leaf in abjad.select(lower_staff).leaves(): voice = abjad.inspect(leaf).parentage().get(abjad.Voice) if voice.name == "Lower_Staff_Voice_II": lower_staff_voice_2_leaves.append(leaf) # adds bass clef and final bar line clef = abjad.Clef("bass") leaf = lower_staff_voice_2_leaves[0] abjad.attach(clef, leaf) score.add_final_bar_line() # adds dynamics abjad.attach(abjad.Dynamic("pp"), upper_staff_leaves[0]) abjad.attach(abjad.Dynamic("mp"), upper_staff_leaves[5]) abjad.attach(abjad.Dynamic("pp"), lower_staff_voice_2_leaves[1]) abjad.attach(abjad.Dynamic("mp"), lower_staff_voice_2_leaves[6]) abjad.override(upper_staff).dynamic_line_spanner.staff_padding = 2 abjad.override(lower_staff).dynamic_line_spanner.staff_padding = 3 # attaches beams abjad.beam(upper_staff_leaves[:4]) abjad.beam(lower_staff_voice_2_leaves[1:5]) abjad.beam(lower_staff_voice_2_leaves[6:10]) # attaches slurs abjad.slur(upper_staff_leaves[:5]) abjad.slur(upper_staff_leaves[5:]) abjad.slur(lower_staff_voice_2_leaves[1:6]) abjad.slur(lower_staff_voice_2_leaves[-10:]) leaf = lower_staff_voice_2_leaves[-10] abjad.override(leaf).slur.direction = abjad.Down # attaches hairpins abjad.hairpin("< !", upper_staff_leaves[-7:-2]) abjad.hairpin("> !", upper_staff_leaves[-2:]) leaf = upper_staff_leaves[-2] abjad.override(leaf).hairpin.to_barline = False # attaches text spanner with ritardando markup markup = abjad.Markup("ritard.") start_text_span = abjad.StartTextSpan(left_text=markup) abjad.text_spanner(upper_staff_leaves[-7:], start_text_span=start_text_span) abjad.override(upper_staff_leaves[-7]).text_spanner.staff_padding = 2 # ties notes abjad.tie(upper_staff_leaves[-2:]) abjad.tie(lower_staff_voice_1_leaves) # returns score return score
def make_bartok_score(): """ make the Bartok example score. """ # make score skeleton score = abjad.Score() piano_staff = abjad.StaffGroup(lilypond_type='PianoStaff') upper_staff = abjad.Staff([]) lower_staff = abjad.Staff([]) piano_staff.append(upper_staff) piano_staff.append(lower_staff) score.append(piano_staff) # make upper measures upper_measures = [] upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) upper_measures.append(abjad.Container()) lower_measures = copy.deepcopy(upper_measures) upper_staff.extend(upper_measures) lower_staff.extend(lower_measures) # add leaves to upper measures upper_measures[0].extend("a'8 g'8 f'8 e'8") abjad.attach(abjad.TimeSignature((2, 4)), upper_measures[0][0]) upper_measures[1].extend("d'4 g'8 f'8 e'8 d'8") abjad.attach(abjad.TimeSignature((3, 4)), upper_measures[1][0]) upper_measures[2].extend("c'8 d'16 e'16 f'8 e'8") abjad.attach(abjad.TimeSignature((2, 4)), upper_measures[2][0]) upper_measures[3].append("d'2") upper_measures[4].append("d'2") # add leaves to lower measures lower_measures[0].extend("b4 d'8 c'8") lower_measures[1].extend("b8 a8 af4 c'8 bf8") lower_measures[2].extend("a8 g8 fs8 g16 a16") # make parallel music for measure 4 upper_voice = abjad.Voice("b2", name='upper voice') command = abjad.LilyPondLiteral(r'\voiceOne') abjad.attach(command, upper_voice) lower_voice = abjad.Voice("b4 a4", name='lower voice') command = abjad.LilyPondLiteral(r'\voiceTwo') abjad.attach(command, lower_voice) lower_measures[3].extend([upper_voice, lower_voice]) lower_measures[3].is_simultaneous = True # make parallel music for measure 5 upper_voice = abjad.Voice("b2", name='upper voice') command = abjad.LilyPondLiteral(r'\voiceOne') abjad.attach(command, upper_voice) lower_voice = abjad.Voice("g2", name='lower voice') command = abjad.LilyPondLiteral(r'\voiceTwo') abjad.attach(command, lower_voice) lower_measures[4].extend([upper_voice, lower_voice]) lower_measures[4].is_simultaneous = True # add bass clef clef = abjad.Clef('bass') leaf = abjad.inspect(lower_staff).leaf(0) abjad.attach(clef, leaf) # add dynamics dynamic = abjad.Dynamic('pp') abjad.attach(dynamic, upper_measures[0][0]) dynamic = abjad.Dynamic('mp') abjad.attach(dynamic, upper_measures[1][1]) dynamic = abjad.Dynamic('pp') abjad.attach(dynamic, lower_measures[0][1]) dynamic = abjad.Dynamic('mp') abjad.attach(dynamic, lower_measures[1][3]) # add final bar line score.add_final_bar_line() # select leaves for attaching spanners to upper_leaves = abjad.select(upper_staff).leaves() lower_leaves = abjad.select(lower_staff).leaves() # attach beams abjad.beam(upper_leaves[:4]) abjad.beam(lower_leaves[1:5]) abjad.beam(lower_leaves[6:10]) # attach slurs abjad.slur(upper_leaves[:5]) abjad.slur(upper_leaves[5:]) abjad.slur(lower_leaves[1:6]) # attach hairpins abjad.hairpin('<', upper_leaves[-7:-2]) abjad.hairpin('>', upper_leaves[-2:]) # attach a ritardando with markup start_text_span = abjad.StartTextSpan(left_text=abjad.Markup('ritard.')) abjad.text_spanner(upper_leaves[-7:], start_text_span=start_text_span) # tie notes abjad.tie(upper_leaves[-2:]) # tie more notes note_1 = lower_staff[-2]['upper voice'][0] note_2 = lower_staff[-1]['upper voice'][0] notes = abjad.select([note_1, note_2]) abjad.tie(notes) # return the score return score