def test_LilyPondParser__spanners__Slur_07(): """ With direction. """ maker = abjad.NoteMaker() target = abjad.Container(maker([0] * 4, [(1, 4)])) start_slur = abjad.StartSlur(direction=abjad.Down) abjad.slur(target[:3], start_slur=start_slur) start_slur = abjad.StartSlur(direction=abjad.Up) abjad.slur(target[2:], start_slur=start_slur) assert format(target) == abjad.String.normalize(r""" { c'4 _ ( c'4 c'4 ) ^ ( c'4 ) } """) parser = abjad.parser.LilyPondParser() result = parser(format(target)) assert format(target) == format(result) and target is not result
def post_process_voice_two(voice_two, score): # REGISTER TRANSPOSITION abjad.mutate(voice_two).transpose(-12) # literals abjad.attach(abjad.LilyPondLiteral(r" \voiceOne"), voice_two[0]) abjad.attach(abjad.LilyPondLiteral(r" \voiceTwo"), voice_two[4]) abjad.attach(abjad.LilyPondLiteral(r" \voiceOne"), voice_two[6]) abjad.attach(abjad.LilyPondLiteral(r" \voiceTwo"), voice_two[7]) abjad.attach(abjad.LilyPondLiteral(r" \voiceOne"), voice_two[8]) # metronome mark I # abjad.attach( # abjad.MetronomeMark((1, 8), (100), ), voice_two[0]) # # numbered leaves selection = abjad.select(voice_two).leaves() for i, leaf in enumerate(selection): # abjad.attach(abjad.Markup(i), leaf) pass # slurs start_slur = abjad.StartSlur() start_slur_up = abjad.StartSlur(direction=abjad.Up) start_slur_down = abjad.StartSlur(direction=abjad.Down) stop_slur = abjad.StopSlur() # attach slurs start_stop_slur = [(3, 4), (8, 9), (10, 11), (12, 14)] for tuples in start_stop_slur: abjad.attach(start_slur, voice_two[tuples[0]]) abjad.attach(stop_slur, voice_two[tuples[1]]) # shapes come first abjad.attach( abjad.LilyPondLiteral(r""" \shape #'((1 . 0) (0 . 0) (-3 . 0) (-3 . 0)) Slur """), voice_two[7]) abjad.attach(start_slur_up, voice_two[7]) abjad.attach(stop_slur, voice_two[8]) # delete del voice_two[-1] # accelerando mark accel_text_span = abjad.LilyPondLiteral( r'\once \override TextSpanner.bound-details.left.text = "accelerando"' + " " + r"\once \override TextSpanner.style = #'dashed-line") start_accel = abjad.LilyPondLiteral(r"\startTextSpan") abjad.attach(accel_text_span, voice_two[0]) abjad.attach(start_accel, voice_two[0]) stop_accel_text_span = abjad.StopTextSpan(command=r"\stopTextSpan") abjad.attach(stop_accel_text_span, voice_two[-1]) return voice_two
def post_process_voice_three(voice_three): # literals abjad.attach(abjad.LilyPondLiteral(r" \voiceTwo"), voice_three[0]) abjad.attach(abjad.LilyPondLiteral(r" \voiceOne"), voice_three[6]) abjad.attach(abjad.LilyPondLiteral(r" \voiceTwo"), voice_three[8]) abjad.attach(abjad.LilyPondLiteral(r" \voiceOne"), voice_three[9]) abjad.attach(abjad.LilyPondLiteral(r" \voiceTwo"), voice_three[10]) abjad.attach(abjad.LilyPondLiteral(r" \tieUp"), voice_three[5]) abjad.attach(abjad.LilyPondLiteral(r" \tieNeutral"), voice_three[7]) abjad.attach(abjad.LilyPondLiteral(r" \tieUp"), voice_three[8]) # numbered leaves selection = abjad.select(voice_three).leaves() for i, leaf in enumerate(selection): # abjad.attach(abjad.Markup(i), leaf) pass del voice_three[-2:] # respells abjad.Accidental.respell_with_flats(voice_three[1]) abjad.Accidental.respell_with_sharps(voice_three[8:10]) voice_three[11].written_pitch = "e''" abjad.Accidental.respell_with_flats(voice_three[12]) # slurs start_slur = abjad.StartSlur() start_slur_down = abjad.StartSlur(direction=abjad.Down) stop_slur = abjad.StopSlur() #shapes come first # abjad.attach(abjad.LilyPondLiteral( # r""" # \shape #'((0 . 0) (1 . 0) (3 . 0) (7 . 0)) Slur # """), voice_four[20]) # attach slurs start_stop_slur = [(0, 1), (2, 3), (10, 11), (12, 13), (14, 15)] for tuples in start_stop_slur: abjad.attach(start_slur, voice_three[tuples[0]]) abjad.attach(stop_slur, voice_three[tuples[1]]) voice_three[-1].written_duration = abjad.Duration(1, 4) voice_three.extend("r8") return voice_three
def _notate_music( self, dummy_container: abjad.Container, start: int, ) -> None: r'Handles the notation aspects of the looping window.' start_head = abjad.select(dummy_container).logical_tie(0)[0] start_tail = abjad.select(dummy_container).logical_tie(0)[-1] if (abjad.inspect(start_head).indicator(abjad.StartSlur) is None and abjad.inspect(start_tail).indicator(abjad.StopSlur) is None): for leaf in self._contents_logical_ties[start - 1::-1].leaves(): if abjad.inspect(leaf).indicator(abjad.StartSlur) is not None: abjad.attach(abjad.StartSlur(), start_head) break elif abjad.inspect(leaf).indicator(abjad.StopSlur) is not None: break if abjad.inspect(start_head).indicator(abjad.Dynamic) is None: for leaf in self._contents_logical_ties[start - 1::-1].leaves(): dynamic = abjad.inspect(leaf).indicator(abjad.Dynamic) if dynamic is not None: abjad.attach(dynamic, start_head) break mutate(dummy_container[:]).reposition_dynamics() mutate(dummy_container[:]).reposition_slurs() # rewriting meter if not self._disable_rewrite_meter: mutate(dummy_container).auto_rewrite_meter( boundary_depth=self._boundary_depth, maximum_dot_count=self._maximum_dot_count, rewrite_tuplets=self._rewrite_tuplets, prettify_rewrite_meter=self._prettify_rewrite_meter, extract_trivial_tuplets=self._extract_trivial_tuplets, fuse_across_groups_of_beats=self._fuse_across_groups_of_beats, fuse_quadruple_meter=self._fuse_quadruple_meter, fuse_triple_meter=self._fuse_triple_meter, ) self._current_window = dummy_container[:] dummy_container[:] = []
def slur( *tweaks: abjad.TweakInterface, map: abjad.Expression = None, selector: abjad.Expression = classes.select().tleaves(), start_slur: abjad.StartSlur = None, stop_slur: abjad.StopSlur = None, ) -> SpannerIndicatorCommand: r""" Attaches slur. .. container:: example Attaches slur to trimmed leaves: >>> stack = baca.stack( ... baca.figure( ... [1, 1, 5, -1], ... 16, ... affix=baca.rests_around([2], [4]), ... restart_talea=True, ... treatments=[-1], ... ), ... rmakers.beam(), ... baca.slur(), ... baca.slur_down(), ... baca.tuplet_bracket_staff_padding(2), ... ) >>> selection = stack([[0, 2, 10], [18, 16, 15, 20, 19], [9]]) >>> lilypond_file = abjad.LilyPondFile.rhythm(selection) >>> rmakers.attach_markup_struts(lilypond_file) >>> abjad.show(lilypond_file) # doctest: +SKIP .. docs:: >>> string = abjad.lilypond(lilypond_file[abjad.Score]) >>> print(string) \new Score << \new GlobalContext { \time 11/8 s1 * 11/8 } \new Staff { \tweak text #tuplet-number::calc-fraction-text \times 9/10 { \override Slur.direction = #down \override TupletBracket.staff-padding = 2 r8 - \tweak staff-padding 11 - \tweak transparent ##t ^ \markup I c'16 [ ( d'16 ] bf'4 ~ bf'16 r16 } \tweak text #tuplet-number::calc-fraction-text \times 9/10 { fs''16 [ e''16 ] ef''4 ~ ef''16 r16 af''16 [ g''16 ] } \times 4/5 { a'16 ) r4 \revert Slur.direction \revert TupletBracket.staff-padding } } >> """ start_slur = start_slur or abjad.StartSlur() stop_slur = stop_slur or abjad.StopSlur() return SpannerIndicatorCommand( map=map, selector=selector, start_indicator=start_slur, stop_indicator=stop_slur, tags=[_site(inspect.currentframe())], tweaks=tweaks, )
def post_process_voice_four(voice_four, score): print("post processing voice four") # delete and change durations voice_four[-2].written_duration = (1, 4) del voice_four[-1] voice_four[-1].written_duration = (3, 8) # abjad.mutate(voice_four[17]).transpose(-12) # numbered leaves selection = abjad.select(voice_four).leaves() for i, leaf in enumerate(selection): # abjad.attach(abjad.Markup(i), leaf) pass # change staff rh_staff = score['Piano_Staff'][0] lh_staff = score['Piano_Staff'][1] voice_four = score['LH_Voice_Four'] staff_change1 = abjad.StaffChange(lh_staff) staff_change2 = abjad.StaffChange(rh_staff) abjad.attach(staff_change2, voice_four[-5]) abjad.attach(staff_change1, voice_four[-2]) voice_four[-3].written_pitch = "f''''" voice_four[-4].written_pitch = "g''" voice_four[14].written_pitch = "c'''" abjad.attach(abjad.Fermata(), voice_four[-1]) clef3 = abjad.Clef("treble^8") clef3_range = abjad.pitch.PitchRange("[C6, +inf]") clef2 = abjad.Clef("treble") clef2_range = abjad.pitch.PitchRange("[D4, +inf]") clef1 = abjad.Clef("bass") clef1_range = abjad.pitch.PitchRange("[C1, C#4]") selection = abjad.select(voice_four).leaves() for i, leaf in enumerate(selection): # test3 = leaf in clef3_range test2 = leaf in clef2_range test1 = leaf in clef1_range test_note = not isinstance(leaf, abjad.Rest) # if test_note is True and test3 is True: # abjad.attach(clef3, voice_four[i]) if test_note is True and test2 is True: abjad.attach(clef2, voice_four[i]) if test_note is True and test1 is True: abjad.attach(clef1, voice_four[i]) abjad.Accidental.respell_with_sharps(voice_four[8:9]) abjad.Accidental.respell_with_sharps(voice_four[19:22]) # REGISTER TRANSPOSITION abjad.mutate(voice_four).transpose(-12) #[:-7] # slurs start_slur = abjad.StartSlur() start_slur_down = abjad.StartSlur(direction=abjad.Down) stop_slur = abjad.StopSlur() abjad.attach(start_slur, voice_four[6]) abjad.attach(stop_slur, voice_four[8]) abjad.attach(start_slur, voice_four[12]) abjad.attach(stop_slur, voice_four[15]) abjad.attach(start_slur_down, voice_four[18]) abjad.attach(stop_slur, voice_four[21]) abjad.attach(start_slur_down, voice_four[-4]) abjad.attach(stop_slur, voice_four[-3]) # metronome mark IV abjad.attach( abjad.MetronomeMark(None, None, "meno mosso"), voice_four[-4]) return voice_four
def _notate_music( self, dummy_container: abjad.Container, start: int, end: int, ) -> None: r'Handles the notation aspects of the looping window.' window_size = self._window_size # passing on indicators from the head of an initial splitted leaf for index in range(start - 1, -1, -1): if abjad.inspect(dummy_container[index]).indicator(abjad.Tie): inspect_contents = abjad.inspect(dummy_container[index - 1]) if index == 0 or not inspect_contents.indicator(abjad.Tie): inspect_contents = abjad.inspect(dummy_container[index]) for indicator in inspect_contents.indicators(): inspector = abjad.inspect(dummy_container[start]) if (not isinstance(indicator, (abjad.TimeSignature, abjad.Tie)) and inspector.indicator(type(indicator)) is None): abjad.attach(indicator, dummy_container[start]) # removing ties generated by the split mutation abjad.detach(abjad.Tie(), dummy_container[start - 1]) abjad.detach(abjad.Tie(), dummy_container[end - 1]) # handling initial dynamics and slurs start_head = abjad.select(dummy_container[start:]).logical_tie(0)[0] start_tail = abjad.select(dummy_container[start:]).logical_tie(0)[-1] if (abjad.inspect(start_head).indicator(abjad.StartSlur) is None and abjad.inspect(start_tail).indicator(abjad.StopSlur) is None): for leaf in dummy_container[start - 1::-1].leaves(): if abjad.inspect(leaf).indicator(abjad.StartSlur) is not None: abjad.attach(abjad.StartSlur(), start_head) break elif abjad.inspect(leaf).indicator(abjad.StopSlur) is not None: break if (abjad.inspect(start_head).indicator(abjad.Dynamic) is None and not isinstance(start_head, ( abjad.Rest, abjad.MultimeasureRest, ))): for leaf in dummy_container[start - 1::-1].leaves(): dynamic = abjad.inspect(leaf).indicator(abjad.Dynamic) if dynamic is not None: abjad.attach(dynamic, start_head) break # appending rests if necessary contents_dur = abjad.inspect(dummy_container[start:end]).duration() if contents_dur < window_size.duration: missing_dur = window_size.duration - contents_dur rests = abjad.LeafMaker()(None, missing_dur) dummy_container.extend(rests) end += len(rests) # transforming abjad.Selection -> abjad.Container for rewrite_meter dummy_container = abjad.Container( abjad.mutate(dummy_container[start:end]).copy()) # rewriting meter if not self._disable_rewrite_meter: mutate(dummy_container).auto_rewrite_meter( meter_list=[abjad.TimeSignature(window_size)], boundary_depth=self._boundary_depth, maximum_dot_count=self._maximum_dot_count, rewrite_tuplets=self._rewrite_tuplets, prettify_rewrite_meter=self._prettify_rewrite_meter, extract_trivial_tuplets=self._extract_trivial_tuplets, fuse_across_groups_of_beats=self._fuse_across_groups_of_beats, fuse_quadruple_meter=self._fuse_quadruple_meter, fuse_triple_meter=self._fuse_triple_meter, ) abjad.attach( abjad.TimeSignature(window_size), abjad.select(dummy_container).leaf(0), ) mutate(dummy_container[:]).reposition_dynamics() mutate(dummy_container[:]).reposition_slurs() self._current_window = dummy_container[:] dummy_container[:] = []
def post_process_voice_two(voice_two, score): # REGISTER TRANSPOSITION abjad.mutate(voice_two).transpose(-12) # registers abjad.attach(abjad.LilyPondLiteral(r"\override TextScript.outside-staff-priority = #'1100"), voice_two[0]) register_one = abjad.Markup( r"""\scale #'(0.5 . 0.5) \column{ \line{ \draw-circle #1.1 #0.3 ##t \draw-circle #1.1 #0.3 ##f } \line{ \draw-circle #1.1 #0.3 ##t \draw-circle #1.1 #0.3 ##t } \line{ \draw-circle #1.1 #0.3 ##f \draw-circle #1.1 #0.3 ##t } \line{ \draw-circle #1.1 #0.3 ##f \draw-circle #1.1 #0.3 ##f } }""", direction=abjad.Up) abjad.attach(register_one, voice_two[0]) # metronome mark I abjad.attach( abjad.MetronomeMark((1, 8), (64, 72), "Lento"), voice_two[0]) # rehearsal mark markI = abjad.RehearsalMark(number=4) abjad.attach(markI, voice_two[0]) scheme = abjad.Scheme("format-mark-box-alphabet") abjad.setting(score).markFormatter = scheme # numbered leaves selection = abjad.select(voice_two).leaves() for i, leaf in enumerate(selection): # abjad.attach(abjad.Markup(i), leaf) pass # slurs start_slur = abjad.StartSlur() start_slur_down = abjad.StartSlur(direction=abjad.Down) stop_slur = abjad.StopSlur() abjad.attach(start_slur, voice_two[6]) abjad.attach(stop_slur, voice_two[8]) abjad.attach(abjad.LilyPondLiteral( r""" \shape #'((0 . 0) (0 . 0) (-1.5 . -3) (0 . -8)) Slur """), voice_two[16]) abjad.attach(start_slur, voice_two[16]) abjad.attach(stop_slur, voice_two[17]) abjad.attach(start_slur, voice_two[23]) abjad.attach(stop_slur, voice_two[25]) abjad.attach(start_slur, voice_two[26]) abjad.attach(stop_slur, voice_two[27]) abjad.attach(start_slur, voice_two[34]) abjad.attach(stop_slur, voice_two[37]) abjad.attach(start_slur, voice_two[39]) abjad.attach(stop_slur, voice_two[40]) abjad.attach(start_slur, voice_two[43]) abjad.attach(stop_slur, voice_two[45]) abjad.attach(abjad.Clef("treble"), voice_two[0]) # accelerando mark accel_text_span = abjad.LilyPondLiteral( r'\once \override TextSpanner.bound-details.left.text = "accelerando poco a poco"' + " " + r"\once \override TextSpanner.style = #'dashed-line" ) start_accel = abjad.LilyPondLiteral(r"\startTextSpan") abjad.attach(accel_text_span, voice_two[-20]) abjad.attach(start_accel, voice_two[-20]) stop_accel_text_span = abjad.StopTextSpan(command=r"\stopTextSpan") abjad.attach(stop_accel_text_span, voice_two[-1]) # voice_two.append(abjad.Container( # r"""cs'''2 # ( # g''8 # ) # r8 # r8 # fs'''4 # ~ # ( # fs'''4 # g'''8 # ) # """ # )) voice_two[-1].written_pitch = "af''" abjad.attach(abjad.Tie(), voice_two[-1]) return voice_two
def post_process_voice_four(voice_four, score): print("post processing voice four") voice_four[0] = "s2." voice_four[1] = "s4" voice_four[2] = "s8" voice_four[3] = "s4" voice_four[4] = "s8" voice_four[5] = "s4." # numbered leaves selection = abjad.select(voice_four).leaves() for i, leaf in enumerate(selection): # abjad.attach(abjad.Markup(i), leaf) pass # add tenuto tenuto_notes = [11, 17, 29, 32, 52] for i, leaf in enumerate(selection): if i in tenuto_notes: abjad.attach(abjad.Articulation("tenuto"), voice_four[i]) # respells abjad.Accidental.respell_with_sharps(selection[27]) abjad.Accidental.respell_with_sharps(selection[37]) abjad.Accidental.respell_with_sharps(selection[52]) # literals abjad.attach(abjad.LilyPondLiteral(r" \voiceOne"), voice_four[22]) voice_four[22] = "s4." voice_four[24] = "d4" voice_four[25] = "d4." abjad.attach(abjad.LilyPondLiteral(r"\rest"), voice_four[25]) abjad.attach(abjad.LilyPondLiteral(r"\rest"), voice_four[26]) # slurs start_slur = abjad.StartSlur() start_slur_down = abjad.StartSlur(direction=abjad.Down) stop_slur = abjad.StopSlur() # shapes come first abjad.attach(abjad.LilyPondLiteral( r""" \shape #'((0 . 0) (1 . 0) (3 . 0) (7 . 0)) Slur """), voice_four[20]) # attach slurs start_slur_notes = [13, 35, 39, 49, 54] start_slur_down_notes = [5, 20, 27, 31, 43] stop_slur_notes = [8, 14, 22, 28, 32, 37, 40, 47, 50, 55] for i, leaf in enumerate(selection): if i in start_slur_notes: abjad.attach(start_slur, voice_four[i]) if i in start_slur_down_notes: abjad.attach(start_slur_down, voice_four[i]) if i in stop_slur_notes: abjad.attach(stop_slur, voice_four[i]) del voice_four[-3:] abjad.attach(abjad.Clef("bass"), voice_four[0]) voice_four[-1] = "r8" return voice_four
def slur_all(notes): abjad.attach(abjad.StartSlur(), notes[0]) abjad.attach(abjad.StopSlur(), notes[-1]) return notes
def _slur_runs(selections): for run in abjad.Selection(selections).runs(): if 1 < len(run): abjad.attach(abjad.StartSlur(), run[0]) abjad.attach(abjad.StopSlur(), run[-1])
), evans.attach( "Voice 3", abjad.Dynamic("f"), baca.selectors.leaf(0, pitched=True), ), evans.attach( "Voice 4", abjad.Dynamic("f"), baca.selectors.leaf(0, pitched=True), ), evans.attach( "Voice 2", abjad.StopSlur(), baca.selectors.leaf(-19, pitched=True) ), evans.attach( "Voice 2", abjad.StartSlur(), baca.selectors.leaf(-18, pitched=True) ), evans.attach( "Voice 3", abjad.StopSlur(), baca.selectors.leaf(-4, pitched=True) ), evans.attach( "Voice 3", abjad.StartSlur(), baca.selectors.leaf(-3, pitched=True) ), evans.attach( "Voice 4", abjad.StopSlur(), baca.selectors.leaf(-8, pitched=True) ), evans.attach( "Voice 4", abjad.StartSlur(), baca.selectors.leaf(-7, pitched=True) ), evans.attach( "Global Context",
evans.call( "Voice 2", _slur_runs, baca.selectors.leaves(), ), # evans.call( # "Voice 3", # _slur_runs, # baca.selectors.leaves(), # ), evans.call( "Voice 4", _slur_runs, baca.selectors.leaves(), ), evans.detach("Voice 1", abjad.StartSlur(), baca.selectors.leaf(10)), evans.attach("Voice 1", abjad.StartSlur(), baca.selectors.leaf(11)), evans.detach("Voice 2", abjad.StartSlur(), baca.selectors.leaf(1)), evans.attach("Voice 2", abjad.StartSlur(), baca.selectors.leaf(3)), evans.attach("Voice 3", abjad.StartSlur(), baca.selectors.leaf(0, pitched=True)), evans.attach("Voice 3", abjad.StopSlur(), baca.selectors.leaf(3, pitched=True)), evans.attach("Voice 3", abjad.StartSlur(), baca.selectors.leaf(4, pitched=True)), evans.attach("Voice 3", abjad.StopSlur(), baca.selectors.leaf(6, pitched=True)), evans.attach("Voice 3", abjad.StartSlur(), baca.selectors.leaf(7, pitched=True)), evans.attach("Voice 3", abjad.StopSlur(), baca.selectors.leaf(18, pitched=True)),
def write_indicators( self, material_name=None, dynamics=None, articulations=None, slur_up=None, slur_down=None, change_staffs_names=None, pitched=True, ): """Write indicators to leaves.""" if material_name is not None: selection1 = abjad.Selection(self.container).components( abjad.Container) for container in selection1: if container.name is not None and ( (isinstance(material_name, list) or material_name in container.name)): selection2 = abjad.Selection(container).leaves( pitched=pitched) if dynamics: for key in dynamics: if dynamics[key] == "all": for i, leaf in enumerate(selection2[0::2]): a = i b = i + 1 abjad.hairpin(key, selection2[a:b]) else: for i in dynamics[key]: if isinstance(i, tuple): a, b = i b = b + 1 abjad.hairpin(key, selection2[a:b]) else: abjad.hairpin(key, selection2[i]) # attach slurs if slur_up: for n in slur_up: a, b = n b = b abjad.attach(abjad.StartSlur(), selection2[a]) abjad.attach(abjad.StopSlur(), selection2[b]) if slur_down: for n in slur_down: a, b = n abjad.attach(abjad.StartSlur(direction=abjad.Down), selection2[a]) abjad.attach(abjad.StopSlur(), selection2[b]) if articulations: for key in articulations: for i in articulations[key]: abjad.attach(abjad.Articulation(key), selection2[i]) else: selection = abjad.Selection(self.container).leaves(pitched=pitched) if dynamics: for key in dynamics: for i in dynamics[key]: if isinstance(i, tuple): a, b = i b = b + 1 abjad.hairpin(key, selection[a:b]) else: abjad.hairpin(key, selection[i]) # attach slurs if slur_up: for n in slur_up: a, b = n b = b abjad.attach(abjad.StartSlur(), selection[a]) abjad.attach(abjad.StopSlur(), selection[b]) if slur_down: for n in slur_down: a, b = n abjad.attach(abjad.StartSlur(direction=abjad.Down), selection[a]) abjad.attach(abjad.StopSlur(), selection[b]) if articulations: for key in articulations: for i in articulations[key]: abjad.attach(abjad.Articulation(key), selection[i])
def post_process_voice_four(voice_four, score): print("post processing voice four") rh_staff = score['Piano_Staff'][0] lh_staff = score['Piano_Staff'][1] voice_four = score['LH_Voice_Four'] staff_change1 = abjad.StaffChange(lh_staff) staff_change2 = abjad.StaffChange(rh_staff) abjad.attach(staff_change2, voice_four[5]) abjad.attach(staff_change1, voice_four[-5]) abjad.attach(staff_change2, voice_four[-2]) abjad.attach(staff_change1, voice_four[-1]) # REGISTER TRANSPOSITION selection_reg = abjad.select(voice_four).leaves() register_range = abjad.pitch.PitchRange("[C4, +inf]") for leaf in selection_reg: test_resgister = leaf in register_range if test_resgister is True: abjad.mutate(leaf).transpose(-12) clef3 = abjad.Clef("treble^8") clef3_range = abjad.pitch.PitchRange("[A#6, +inf]") clef2 = abjad.Clef("treble") clef2_range = abjad.pitch.PitchRange("[D4, G6]") clef1 = abjad.Clef("bass") clef1_range = abjad.pitch.PitchRange("[C1, C#4]") selection = abjad.select(voice_four).leaves() for i, leaf in enumerate(selection): test3 = leaf in clef3_range test2 = leaf in clef2_range test1 = leaf in clef1_range test_note = not isinstance(leaf, abjad.Rest) if test_note is True and test3 is True: abjad.attach(clef3, voice_four[i]) if test_note is True and test2 is True: abjad.attach(clef2, voice_four[i]) if test_note is True and test1 is True: abjad.attach(clef1, voice_four[i]) # slurs start_slur = abjad.StartSlur() start_slur_down = abjad.StartSlur(direction=abjad.Down) stop_slur = abjad.StopSlur() abjad.attach(start_slur, voice_four[6]) abjad.attach(stop_slur, voice_four[9]) abjad.attach(start_slur, voice_four[12]) abjad.attach(stop_slur, voice_four[16]) abjad.attach(start_slur, voice_four[18]) abjad.attach(stop_slur, voice_four[21]) abjad.attach(start_slur, voice_four[23]) abjad.attach(stop_slur, voice_four[27]) abjad.attach(start_slur, voice_four[-4]) abjad.attach(stop_slur, voice_four[-2]) # metronome mark VII quasi_statico = abjad.MetronomeMark(None, None, "Quasi Statico") abjad.attach(quasi_statico, voice_four[-4]) # accelerando mark accel_text_span = abjad.LilyPondLiteral( r'\once \override TextSpanner.bound-details.left.text = "accelerando"' + " " + r"\once \override TextSpanner.style = #'dashed-line") start_accel = abjad.LilyPondLiteral(r"\startTextSpan") abjad.attach(accel_text_span, voice_four[13]) abjad.attach(start_accel, voice_four[13]) stop_accel_text_span = abjad.StopTextSpan(command=r"\stopTextSpan") abjad.attach(stop_accel_text_span, voice_four[16]) return voice_four
def reposition_slurs( selection: abjad.Selection, *, allow_slurs_under_rests: bool = False, close_unterminated_final_slur: bool = True, ) -> None: r"""Mutates an input |abjad.Selection| in place and has no return value; this function repositions all slurs that starts or ends on rests. Basic usage: This function will shift slurs that ends on rests to the previous pitched leaf. >>> staff = abjad.Staff(r"c'1( d'2 r2) r1 e'1") >>> abjad.f(staff) \new Staff { c'1 ( d'2 r2 ) r1 e'1 } .. figure:: ../_images/reposition_slurs-uxji4xx6ftk.png >>> staff = abjad.Staff(r"c'1( d'2 r2) r1 e'1") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) r2 r1 e'1 } .. figure:: ../_images/reposition_slurs-7nnp5cttm4y.png .. note:: Auxjad automatically adds this function as an extension method to |abjad.mutate()|. It can thus be used from either :func:`auxjad.mutate()` or |abjad.mutate()|. Therefore, the two lines below are equivalent: >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.mutate(staff[:]).reposition_slurs() Rests: Slurs starting on rests are shifted to the next pitched leaf. >>> staff = abjad.Staff(r"c'1 r2( d'2 e'1)") >>> abjad.f(staff) \new Staff { c'1 r2 ( d'2 e'1 ) } .. figure:: ../_images/reposition_slurs-2j7hgqd7bt1.png >>> staff = abjad.Staff(r"c'1 r2( d'2 e'1)") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 r2 d'2 ( e'1 ) } .. figure:: ../_images/reposition_slurs-i957u1wt30m.png Multiple rests: This function also works when multiple rests are present. >>> staff = abjad.Staff(r"c'1( d'2 r2 r1) e'1") >>> abjad.f(staff) \new Staff { c'1 ( d'2 r2 r1 ) e'1 } .. figure:: ../_images/reposition_slurs-v76u42x7idk.png >>> staff = abjad.Staff(r"c'1( d'2 r2 r1) e'1") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) r2 r1 e'1 } .. figure:: ../_images/reposition_slurs-burs1t0daid.png ``allow_slurs_under_rests``: By default, a slur crossing a rest is broken into two. >>> staff = abjad.Staff(r"c'1( d'2 r2 e'1 f'1)") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) r2 e'1 ( f'1 ) } .. figure:: ../_images/reposition_slurs-8wb7orpt285.png Set the optional keyword argument ``allow_slurs_under_rests`` to ``True`` to allow slurs under rests. >>> staff = abjad.Staff(r"c'1( d'2 r2 e'1 f'1)") >>> auxjad.mutate(staff[:]).reposition_slurs( ... allow_slurs_under_rests=True, ... ) >>> abjad.f(staff) \new Staff { c'1 ( d'2 r2 e'1 f'1 ) } .. figure:: ../_images/reposition_slurs-ftb59kz6u8j.png ``close_unterminated_final_slur``: By default, unterminated slurs at the end of the selection are closed when possible or removed when not. >>> staff = abjad.Staff(r"c'1( d'2 r2 e'2 f'2) g'1( a'1") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) r2 e'2 ( f'2 ) g'1 ( a'1 ) } .. figure:: ../_images/reposition_slurs-70dli8e0kqr.png Set the optional keyword argument ``close_unterminated_final_slur`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff(r"c'1( d'2 r2 e'2 f'2) g'1( a'1") >>> auxjad.mutate(staff[:]).reposition_slurs( ... close_unterminated_final_slur=False, ... ) >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) r2 e'2 ( f'2 ) g'1 ( a'1 } .. figure:: ../_images/reposition_slurs-1usa2dezl45.png When there are no pitched leaves left after an unterminated open slur, it is removed. >>> staff = abjad.Staff(r"c'1( d'2 r2 e'2 f'2) g'1( r1") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) r2 e'2 ( f'2 ) g'1 r1 } .. figure:: ../_images/reposition_slurs-a0uakfcltuf.png .. note:: Duplicate slur starts or stops are removed. Note that the score output will not change, as LilyPond also ignores duplicate slurs, but the output of |abjad.f()| will be cleaner. >>> staff = abjad.Staff(r"c'1( d'2) e'2) f'2( g'2( a'1)") >>> auxjad.mutate(staff[:]).reposition_slurs() >>> abjad.f(staff) \new Staff { c'1 ( d'2 ) e'2 f'2 ( g'2 a'1 ) } .. figure:: ../_images/reposition_slurs-0ugn322x3tr.png .. warning:: The input selection must be a contiguous logical voice. When dealing with a container with multiple subcontainers (e.g. a score containing multiple staves), the best approach is to cycle through these subcontainers, applying this function to them individually. """ if not isinstance(selection, abjad.Selection): raise TypeError("argument must be 'abjad.Container' or child class") if not selection.leaves().are_contiguous_logical_voice(): raise ValueError("argument must be contiguous logical voice") if not isinstance(allow_slurs_under_rests, bool): raise TypeError("'allow_slurs_under_rests' must be 'bool'") if not isinstance(close_unterminated_final_slur, bool): raise TypeError("'close_unterminated_final_slur' must be 'bool'") leaves = selection.leaves() # checking for final unfinished slurs if close_unterminated_final_slur: for leaf in leaves[::-1]: inspector = abjad.inspect(leaf) if inspector.indicator(abjad.StartSlur) is not None: if leaf is leaves[-1]: abjad.detach(abjad.StartSlur(), leaf) elif (abjad.inspect(leaves[-1]).indicator(abjad.StopSlur) is None): abjad.attach(abjad.StopSlur(), leaves[-1]) if inspector.indicator(abjad.StopSlur) is not None: break # checking for duplicate open or close slurs start_slur_count = 0 stop_slur_count = 0 for leaf in leaves: inspector = abjad.inspect(leaf) if inspector.indicator(abjad.StartSlur) is not None: start_slur_count += 1 stop_slur_count = 0 if start_slur_count > 1: abjad.detach(abjad.StartSlur(), leaf) elif inspector.indicator(abjad.StopSlur) is not None: stop_slur_count += 1 start_slur_count = 0 if stop_slur_count > 1: abjad.detach(abjad.StopSlur(), leaf) # shifting slurs from rests to notes shifted_startslur = None for leaf in leaves: inspector = abjad.inspect(leaf) if isinstance(leaf, (abjad.Rest, abjad.MultimeasureRest)): if inspector.indicator(abjad.StartSlur) is not None: shifted_startslur = inspector.indicator(abjad.StartSlur) abjad.detach(abjad.StartSlur, leaf) else: if inspector.indicator(abjad.StartSlur) is None: if shifted_startslur is not None: abjad.attach(shifted_startslur, leaf) shifted_startslur = None shifted_stopslur = None for leaf in leaves[::-1]: inspector = abjad.inspect(leaf) if isinstance(leaf, (abjad.Rest, abjad.MultimeasureRest)): if inspector.indicator(abjad.StopSlur) is not None: shifted_stopslur = inspector.indicator(abjad.StopSlur) abjad.detach(abjad.StopSlur, leaf) else: if inspector.indicator(abjad.StopSlur) is None: if shifted_stopslur is not None: abjad.attach(shifted_stopslur, leaf) shifted_stopslur = None # splitting slurs under rests if not allow_slurs_under_rests: active_slur = False for index, leaf in enumerate(leaves): inspector = abjad.inspect(leaf) if inspector.indicator(abjad.StartSlur) is not None: active_slur = True elif inspector.indicator(abjad.StopSlur) is not None: if not active_slur: abjad.detach(abjad.StopSlur, leaf) active_slur = False if (isinstance(leaf, (abjad.Rest, abjad.MultimeasureRest)) and active_slur): previous_leaf = abjad.select(leaf).with_previous_leaf()[0] if (abjad.inspect(previous_leaf).indicator(abjad.StopSlur) is None): abjad.attach(abjad.StopSlur(), previous_leaf) for next_leaf in leaves[index + 1:]: if not isinstance(next_leaf, (abjad.Rest, abjad.MultimeasureRest)): if (abjad.inspect(next_leaf).indicator(abjad.StartSlur) is None): abjad.attach(abjad.StartSlur(), next_leaf) break for leaf in leaves: inspector = abjad.inspect(leaf) if (inspector.indicator(abjad.StartSlur) is not None and inspector.indicator(abjad.StopSlur) is not None): abjad.detach(abjad.StartSlur, leaf) abjad.detach(abjad.StopSlur, leaf) # removing slurs spanning a single logical tie for logical_tie in selection.logical_ties(): inspector_head = abjad.inspect(logical_tie[0]) inspector_tail = abjad.inspect(logical_tie[-1]) if (inspector_head.indicator(abjad.StartSlur) is not None and inspector_tail.indicator(abjad.StopSlur) is not None): abjad.detach(abjad.StartSlur, logical_tie[0]) abjad.detach(abjad.StopSlur, logical_tie[-1])