def apply_scratch(selections): start_dynamic = abjad.Dynamic("sfp") stop_dynamic = abjad.Dynamic("ff") scratch_text = abjad.Markup( r"""\override #'(style . "box") \override #'(box-padding . 0.5) \italic \box \whiteout \small "scratch" """, literal=True, ) start_scratch_span = abjad.StartTextSpan( left_text=scratch_text, style="solid-line-with-hook", ) abjad.tweak(start_scratch_span).padding = 2 abjad.tweak(start_scratch_span).staff_padding = 3 stop_scratch_span = abjad.StopTextSpan() scratch_dynamic = abjad.Dynamic("f") ties = abjad.select(selections).logical_ties(pitched=True) for i, tie in enumerate(ties): if len(tie) < 2: abjad.attach(start_dynamic, tie[0]) else: if i % 2 == 0: abjad.attach(start_dynamic, tie[0]) abjad.attach(abjad.StartHairpin("<"), tie[0]) abjad.attach(stop_dynamic, tie[-1]) else: next_leaf = abjad.get.leaf(tie[-1], 1) abjad.attach(start_scratch_span, tie[0]) abjad.attach(scratch_dynamic, tie[0]) abjad.attach(stop_scratch_span, next_leaf)
def _apply_position_and_span(staff, poses): positions = cyc(poses) for run in abjad.select(staff).runs(): span = abjad.StartTextSpan( left_text=abjad.Markup(next(positions)).upright(), right_text=abjad.Markup(next(positions)).upright(), style="dashed-line-with-arrow", ) abjad.attach(span, run[0]) abjad.attach(abjad.StopTextSpan(), run[-1]) abjad.override(staff).text_spanner.staff_padding = 0
def apply_spanner(selections): for run in abjad.Selection(selections).runs(): start = abjad.StartTextSpan( left_text=abjad.Markup(r"\upright noise"), right_text=abjad.Markup(r"\markup \upright XSB"), style="dashed-line-with-arrow", ) abjad.tweak(start).staff_padding = 2 stop = abjad.StopTextSpan() abjad.attach(start, abjad.Selection(run).leaf(0)) abjad.attach(stop, abjad.get.leaf(abjad.Selection(run).leaf(-1), 1))
def attach_material(selections): ties = abjad.Selection(selections).logical_ties() first_leaf = abjad.Selection(ties).leaf(0) center_leaf = abjad.Selection(ties[len(ties) // 2]).leaf(0) last_leaf = abjad.Selection(ties).leaf(-1) cyc_dynamics = evans.CyclicList(["p", "f"], forget=False) cyc_hairpins = evans.CyclicList(["<", ">"], forget=False) for tie in ties: dynamic = abjad.Dynamic(cyc_dynamics(r=1)[0]) abjad.attach(dynamic, tie[0]) for tie in ties[:-1]: hairpin = abjad.StartHairpin(cyc_hairpins(r=1)[0]) abjad.attach(hairpin, tie[0]) start = abjad.StartTextSpan( left_text=abjad.Markup(r"\upright norm."), style="dashed-line-with-arrow", ) middle = abjad.StartTextSpan( left_text=abjad.Markup(r"\upright msp."), right_text=abjad.Markup(r"\markup \upright st."), style="dashed-line-with-arrow", ) middle_stop = abjad.StopTextSpan() final_stop = abjad.StopTextSpan() abjad.tweak(start).staff_padding = 2 abjad.tweak(middle).staff_padding = 2 abjad.attach(start, first_leaf) abjad.attach(middle_stop, center_leaf) abjad.attach(middle, center_leaf) abjad.attach(final_stop, last_leaf) for leaf in abjad.Selection(selections).leaves(): literal_1 = abjad.LilyPondLiteral( r"\once \override Staff.Tie.transparent = ##t", format_slot="before", ) abjad.attach(literal_1, leaf) literal_2 = abjad.LilyPondLiteral( r"\once \override Dots.staff-position = #1.75", format_slot="before", ) abjad.attach(literal_2, leaf)
def _handle_markup(self): voice = self._score[f"{self.instrument_name}_Music_Voice"] leaves = abjad.select(voice).leaves() if not leaves: return music_durations = [abjad.inspect(_).duration() for _ in leaves] maker = rmakers.multiplied_duration(abjad.Skip) selections = maker(music_durations) skips = mccartney.select(selections).skips() markup_voice = self._score[f"{self.instrument_name}_Markup_Voice"] markup_voice.extend(skips) expressions = self.markup for i, expression in enumerate(expressions): index = expression[0] markup = expression[1] skip = skips[index] if len(expression) == 3 and isinstance(expression[2], tuple): abjad.attach(markup, skip) extra_offset = expression[2] x, y = extra_offset string = fr"\once \override TextScript.extra-offset" string += f" = #'({x} . {y})" command = abjad.LilyPondLiteral(string) abjad.attach(command, skip) continue if 0 < i: stop_text_span = abjad.StopTextSpan() abjad.attach(stop_text_span, skip) if isinstance(markup, list): markup = markup[0] style = "dashed-line-with-arrow" else: style = "invisible-line" start_text_span = abjad.StartTextSpan( left_text=markup, style=style ) abjad.attach(start_text_span, skip) if len(expression) == 3: staff_padding = expression[2] string = ( fr"\override TextScript.staff-padding = {staff_padding}" ) command = abjad.LilyPondLiteral(string) abjad.attach(command, skip) value = staff_padding + 0.75 string = fr"\override TextSpanner.staff-padding = {value}" command = abjad.LilyPondLiteral(string) abjad.attach(command, skip) stop_text_span = abjad.StopTextSpan() abjad.attach(stop_text_span, skips[-1])
def main() -> versemaker.Verse: vm = versemaker.VerseMaker( 59, 1, tempo_factor=0.32, octave_of_first_pitch=-1, harmonic_tolerance=0.8, ro_temperature=0.712, ro_density=0.68, harmonic_pitches_tonality_flux_maximum_octave_difference_from_melody_pitch=( 1, 0, ), harmonic_pitches_complex_interval_helper_maximum_octave_difference_from_melody_pitch=( 1, 0, ), area_density_maker=infit.Gaussian(0.5, 0.05), area_density_reference_size=F(1, 2), area_min_split_size=F(3, 16), ) vm.remove_area(0, 1) vm.attach( violin=strings.SimpleStringMaker( globals_.VIOLIN, pizz_maker=infit.ActivityLevel(5, start_at=0), tremolo_maker=infit.ActivityLevel(0), acciaccatura_maker=infit.ActivityLevel(6), force_acciaccatura_to_glissando_maker=infit.ActivityLevel(0), acciaccatura_glissando_size_maker=infit.Cycle((0, 1, 0, 0, 1)), harmonic_pitches_activity=0.6, harmonic_pitches_density=0.72, shall_add_optional_pitches=True, optional_pitches_maximum_octave_difference_from_melody_pitch=(1, 0), optional_pitches_min_size=F(3, 32), optional_pitches_avg_size=F(2, 16), optional_pitches_density=0.7, after_glissando_size=F(1, 8), ), viola=strings.SimpleStringMaker( globals_.VIOLA, tremolo_maker=infit.ActivityLevel(0), pizz_maker=infit.ActivityLevel(5, start_at=0), acciaccatura_maker=infit.ActivityLevel(6, start_at=2), force_acciaccatura_to_glissando_maker=infit.ActivityLevel(0), acciaccatura_glissando_size_maker=infit.Cycle((0, 1, 0, 1, 2, 0, 1)), harmonic_pitches_activity=0.65, harmonic_pitches_density=0.72, shall_add_optional_pitches=True, optional_pitches_maximum_octave_difference_from_melody_pitch=(1, 0), optional_pitches_min_size=F(3, 32), optional_pitches_avg_size=F(1, 8), optional_pitches_density=0.7, ), cello=strings.SimpleStringMaker( globals_.CELLO, tremolo_maker=infit.ActivityLevel(0), pizz_maker=infit.ActivityLevel(8), acciaccatura_maker=infit.ActivityLevel(8), force_acciaccatura_to_glissando_maker=infit.ActivityLevel(0), acciaccatura_glissando_size_maker=infit.Cycle((0, 1, 0, 1, 1)), shall_add_optional_pitches=True, harmonic_pitches_activity=0.69, harmonic_pitches_density=0.72, optional_pitches_min_size=F(1, 8), optional_pitches_avg_size=F(2, 16), optional_pitches_density=0.9, ), keyboard=keyboard.KeyboardMaker( lh_min_metricity_to_add_harmony=0.4, lh_min_metricity_to_add_accent=1.2, lh_max_metricity_for_arpeggio=0.35, lh_min_metricity_to_add_restricted_harmony=0, lh_prohibit_repetitions=False, lh_add_repetitions_avoiding_notes=False, rh_likelihood_making_harmony=1, harmonies_max_difference=1200, harmonies_min_difference=250, colotomic_structure=(0, 1, 1, 1), ), ) _adapt_violin(vm.violin.musdat[1], vm) _adapt_viola(vm.viola.musdat[1], vm) _adapt_cello(vm.cello.musdat[1], vm) _adapt_keyboard(vm.keyboard.musdat[2], vm.keyboard.musdat[1], vm) vm.add_bar(5, abjad.TimeSignature((2, 4))) vm.add_bar(11, abjad.TimeSignature((2, 4))) vm.add_bar(13, abjad.TimeSignature((1, 4))) vm.force_remove_area(len(vm.violin.bars) - 1, len(vm.violin.bars)) # second round of postprocessing _adapt_violin2(vm.violin.musdat[1], vm) _adapt_viola2(vm.viola.musdat[1], vm) _adapt_cello2(vm.cello.musdat[1], vm) _adapt_left2(vm.keyboard.musdat[2], vm) _adapt_right2(vm.keyboard.musdat[1], vm) for instr in ("violin", "viola", "cello", "keyboard"): if instr == "keyboard": nth_line = (2, 1) else: nth_line = (1,) novent_line = getattr(vm, instr).musdat[nth_line[0]] novent_line[0].dynamic = attachments.Dynamic("pp") for string in (vm.violin.musdat[1], vm.viola.musdat[1], vm.cello.musdat[1]): tw.detach_hauptstimme(string) verse = vm() for instr in ("violin", "viola", "cello", "keyboard"): if instr == "keyboard": indices = ((1, 0), (1, 1)) else: indices = ((1,),) for idx in indices: staff = getattr(verse, instr).abjad for subidx in idx: staff = staff[subidx] # [bar_idx][event_idx] # adapting accidental notation of keyboard if instr == "keyboard" and idx[1] == 0: abjad.Accidental.respell_with_sharps(staff[1]) abjad.Accidental.respell_with_sharps(staff[2]) abjad.Accidental.respell_with_sharps(staff[3]) # abjad.Accidental.respell_with_sharps(staff[4]) abjad.Accidental.respell_with_sharps(staff[7]) abjad.Accidental.respell_with_flats(staff[8]) abjad.Accidental.respell_with_sharps(staff[15][2:]) abjad.attach(abjad.Tie(), staff[19][1]) abjad.attach(abjad.Tie(), staff[19][2]) elif instr == "keyboard" and idx[1] == 1: # abjad.Accidental.respell_with_sharps(staff[11]) abjad.Accidental.respell_with_sharps(staff[1]) abjad.Accidental.respell_with_sharps(staff[2]) abjad.Accidental.respell_with_sharps(staff[3]) # abjad.Accidental.respell_with_sharps(staff[4]) # abjad.attach(abjad.Ottava(-1), staff[9][0]) # tw.put_gong_to_separate_vox(9, 0, staff) elif instr == "violin": abjad.detach(abjad.Markup, staff[2][2]) abjad.attach( tw.scpm("arco sul tasto"), staff[2][2], ) abjad.attach( tw.scpm("molto sul tasto"), staff[3][2], ) abjad.attach(abjad.StartHairpin(">"), staff[3][2]) abjad.attach(abjad.Dynamic("ppp"), staff[4][0]) abjad.attach(abjad.Dynamic("pp"), staff[4][1]) abjad.detach(abjad.Markup, staff[5][1]) abjad.attach( tw.scpm("arco ordinario"), staff[5][1], ) elif instr == "viola": abjad.attach( abjad.StartTextSpan(left_text=abjad.Markup("rit.")), staff[-1][0] ) abjad.attach(abjad.StopTextSpan(), staff[-1][-1]) abjad.attach(abjad.StartHairpin(">"), staff[-1][0]) abjad.attach(abjad.Dynamic("ppp"), staff[-1][-1]) return verse
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
import baca import evans import quicktions from adumbration.materials.pitch import clef_handlers from adumbration.materials.score_structure.instruments import instruments as insts from adumbration.materials.score_structure.score_structure import score from adumbration.materials.score_structure.segment_15.time_signatures import ( time_signatures, ) from adumbration.materials.timespans.segment_15.convert_timespans import rhythm_commands bar_literal = abjad.LilyPondLiteral(r'\bar ".|:"', format_slot="before") xsb_noise_poco_a_poco = abjad.StartTextSpan( left_text=abjad.Markup(r"""\upright "XSB (noise poco a poco)" """), style="dashed-line-with-arrow", ) abjad.tweak(xsb_noise_poco_a_poco).padding = 9 xsb_noise_poco_a_poco_final_noise = abjad.StartTextSpan( left_text=abjad.Markup(r"\upright noise"), style="invisible-line", ) abjad.tweak(xsb_noise_poco_a_poco_final_noise).padding = 9 noise_poco_a_poco = abjad.StartTextSpan( left_text=abjad.Markup(r"""\upright "noise poco a poco" """), style="dashed-line-with-arrow", ) abjad.tweak(noise_poco_a_poco).padding = 6