def test_prettify_rewrite_meter_01(): staff = abjad.Staff( r"\time 3/4 c'16 d'8 e'16 f'16 g'16 a'8 b'8 c''16 d''16") meter = abjad.Meter((3, 4)) abjad.mutate(staff[:]).rewrite_meter(meter) assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 3/4 c'16 d'16 ~ d'16 e'16 f'16 g'16 a'8 b'8 c''16 d''16 } """) auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 3/4 c'16 d'8 e'16 f'16 g'16 a'8 b'8 c''16 d''16 } """)
def test_Meter___init___03(): time_signature = abjad.TimeSignature((4, 4)) assert abjad.Meter(time_signature).rtm_format == \ '(4/4 (1/4 1/4 1/4 1/4))'
# durations_piano3 = durations_list[2] # durations_violin = durations_list[3] # durations_viola = durations_list[4] # durations_cello = durations_list[5] # time signatures for these timespan structures permitted_meters = [ # (7, 4), (5, 4), (4, 4), (3, 8), (11, 16), # (3, 16), ] permitted_meters = [abjad.Meter(_) for _ in permitted_meters] # argument = [_.duration for _ in timespans_aflute] # print(argument) # counter_path = f"""{pathlib.Path(__file__).parent}/segment_01_offset_counter.pdf""" # abjad.persist.as_pdf(offset_counter, pdf_file_path=counter_path, scale=0.70) # PDF # abjad.io.open_file(counter_path) # ts_lists = abjad.TimespanList([timespans_aflute, timespans_bclarinet]) # all_ts_list = abjad.TimespanList() # for tlist in ts_lists: # for span in tlist: # all_ts_list.append(span) # all_ts_list.sort()
def test_Meter___init___10(): hierarchy = abjad.Meter("(4/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4))))")
def test_prettify_rewrite_meter_15(): staff = abjad.Staff(r"c'4 d'2 r4" r"e'4. f'2 g'8" r"a'4. b'4. c''4" r"d''16 e''8. f''4. g''4 a''8") meter = abjad.Meter((4, 4)) for measure in abjad.select(staff[:]).group_by_measure(): abjad.Meter.rewrite_meter(measure, meter) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'4 d'2 r4 e'4. f'8 ~ f'4. g'8 a'4. b'4. c''4 d''16 e''8. f''4. g''8 ~ g''8 a''8 } """) abjad.mutate.prettify_rewrite_meter(staff[:], meter) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'4 d'2 r4 e'4. f'8 ~ f'4. g'8 a'4. b'8 ~ b'4 c''4 d''16 e''8. f''4 ~ f''8 g''4 a''8 } """) staff = abjad.Staff(r"c'4 d'2 r4" r"e'4. f'2 g'8" r"a'4. b'4. c''4" r"d''16 e''8. f''4. g''4 a''8") meter = abjad.Meter((4, 4)) for measure in abjad.select(staff[:]).group_by_measure(): abjad.Meter.rewrite_meter(measure, meter) abjad.mutate.prettify_rewrite_meter( staff[:], meter, split_quadruple_meter=False, ) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { c'4 d'2 r4 e'4. f'8 ~ f'4. g'8 a'4. b'4. c''4 d''16 e''8. f''4. g''4 a''8 } """)
def test_prettify_rewrite_meter_06(): staff = abjad.Staff(r"\time 5/8 c'16 d'8 e'8 f'8 g'8 a'16 ~ " r"a'16 b'8 c''8 d''8 e''8 f''16") meter = abjad.Meter((5, 8)) for measure in abjad.select(staff[:]).group_by_measure(): abjad.Meter.rewrite_meter(measure, meter) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { \time 5/8 c'16 d'16 ~ d'16 e'16 ~ e'16 f'16 ~ f'16 g'16 ~ g'16 a'16 ~ a'16 b'16 ~ b'16 c''16 ~ c''16 d''16 ~ d''16 e''16 ~ e''16 f''16 } """) auxjad.mutate.prettify_rewrite_meter(staff[:], meter) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { \time 5/8 c'16 d'8 e'8 f'16 ~ f'16 g'8 a'16 ~ a'16 b'8 c''8 d''16 ~ d''16 e''8 f''16 } """)
# (5, 8), # (2, 4), # (3, 8), # (1, 4), # (5, 16), # (1, 8), # ] # ) # # fitted_meters = abjad.Meter.fit_meters( # argument=offset_counter, # meters=permitted_meters, # # maximum_run_length=1, # ) fitted_meter_pairs = [ (4, 4), (5, 4), (4, 4), (4, 4), (4, 4), (3, 4), ] fitted_meters = [abjad.Meter(_) for _ in fitted_meter_pairs] time_signatures = [abjad.TimeSignature(_) for _ in fitted_meters] time_signatures.append(abjad.TimeSignature((3, 16))) # for ending skip bounds = abjad.math.cumulative_sums([_.duration for _ in time_signatures])
coincident_offsets.append(span1.start_offset) else: coincident_offsets.append(span2.start_offset) if span1.stop_offset > span2.stop_offset: coincident_offsets.append(abjad.Offset(span1.stop_offset)) # else: # print(span1.stop_offset) # print(span2.stop_offset) # coincident_offsets.append(abjad.Offset(span2.stop_offset)) coincident_offsets.sort() meters = [] for off1, off2 in zip(coincident_offsets, coincident_offsets[1:]): new_ts = abjad.AnnotatedTimespan(start_offset=off1, stop_offset=off2) final_list.append(new_ts) meters.append(abjad.Meter(new_ts.duration)) permitted_meters = [ # (7, 4), (5, 4), (4, 4), (3, 4), (3, 8), (11, 16), # (3, 16), ] # remove repeated coincident_offsets = list(dict.fromkeys(coincident_offsets)) # print(coincident_offsets)
def test_auto_rewrite_meter_04(): staff = abjad.Staff(r"\time 7/4 c'8 d'4 e'4 f'4 g'4 a'4 b'4 c''8 " r"\time 5/4 d''8 e''4 f''4 g''4 a''4 b''8") auxjad.mutate(staff).auto_rewrite_meter() assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 7/4 c'8 d'4 e'4 f'8 ~ f'8 g'4 a'8 ~ a'8 b'4 c''8 \time 5/4 d''8 e''4 f''4 g''8 ~ g''8 a''4 b''8 } """) staff = abjad.Staff(r"\time 7/4 c'8 d'4 e'4 f'4 g'4 a'4 b'4 c''8 " r"\time 5/4 d''8 e''4 f''4 g''4 a''4 b''8") meter_list = [ abjad.Meter((7, 4), increase_monotonic=True), abjad.Meter((5, 4), increase_monotonic=True), ] auxjad.mutate(staff).auto_rewrite_meter(meter_list=meter_list) assert format(staff) == abjad.String.normalize(r""" \new Staff { \time 7/4 c'8 d'4 e'8 ~ e'8 f'4 g'8 ~ g'8 a'4 b'4 c''8 \time 5/4 d''8 e''4 f''8 ~ f''8 g''4 a''4 b''8 } """)
def test_metertools_Meter___init___10(): hierarchy = abjad.Meter('(4/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4))))')
def test_metertools_Meter___init___08(): time_signature = abjad.TimeSignature((10, 4)) assert abjad.Meter(time_signature).rtm_format == \ '(10/4 ((5/4 ((3/4 (1/4 1/4 1/4)) (2/4 (1/4 1/4)))) (5/4 ((3/4 (1/4 1/4 1/4)) (2/4 (1/4 1/4))))))'
def test_metertools_Meter___init___07(): time_signature = abjad.TimeSignature((1, 4)) assert abjad.Meter(time_signature).rtm_format == \ '(1/4 (1/4))'
def test_example_of_usage_05(): random.seed(77124) container = abjad.Container([ auxjad.ArtificialHarmonic(r"<ds' gs'>4"), auxjad.ArtificialHarmonic(r"<b e'>8."), auxjad.ArtificialHarmonic(r"<g c'>16", is_parenthesized=True), abjad.Rest(r"r4"), abjad.Chord([2, 8, 9], (1, 8)), auxjad.ArtificialHarmonic(r"<d' a'>8", is_parenthesized=True), ]) abjad.mutate(container[:]).respell_accidentals() shuffler = auxjad.Shuffler(container) staff = abjad.Staff() notes = shuffler.shuffle_n(4) staff.append(notes) container = abjad.Container(shuffler.current_window) fader = auxjad.Fader(container, fader_type='out') notes = fader.output_all() staff.append(notes) abjad.mutate(staff[:]).prettify_rewrite_meter(abjad.Meter((4, 4))) abjad.mutate(staff[:]).remove_repeated_time_signatures() assert format(staff) == abjad.String.normalize( r""" \new Staff { \time 4/4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 <d' gs' a'>16 ~ <d' gs' a'>16 r8. r16 < b \tweak style #'harmonic e' >8. < ds' \tweak style #'harmonic gs' >4 r4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 <d' gs' a'>16 ~ <d' gs' a'>16 < b \tweak style #'harmonic e' >8. < ds' \tweak style #'harmonic gs' >4 < ds' \tweak style #'harmonic gs' >4 r4 < b \tweak style #'harmonic e' >8. <d' gs' a'>16 ~ <d' gs' a'>16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < ds' \tweak style #'harmonic gs' >4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 < b \tweak style #'harmonic e' >16 ~ < b \tweak style #'harmonic e' >8 <d' gs' a'>8 r4 < ds' \tweak style #'harmonic gs' >4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 < b \tweak style #'harmonic e' >16 ~ < b \tweak style #'harmonic e' >8 <d' gs' a'>8 r4 < ds' \tweak style #'harmonic gs' >4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 r16 r8 <d' gs' a'>8 r4 < ds' \tweak style #'harmonic gs' >4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 r16 r8 <d' gs'>8 r4 < ds' \tweak style #'harmonic gs' >4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 r16 r8 gs'8 r4 < ds' \tweak style #'harmonic gs' >4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 r16 r2 r4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 < \parenthesize \tweak ParenthesesItem.font-size #-4 d' \tweak style #'harmonic a' >8 r16 r2 r4 < \parenthesize \tweak ParenthesesItem.font-size #-4 g \tweak style #'harmonic c' >16 r8. r2 R1 } """)
rhythms = [(1, 4), (1, 8), (3, 8), (1, 2), (1, 8), (1, 8), (5, 8), (1, 8), (1, 8)] maker = abjad.LeafMaker() rhythms = [abjad.Duration(x) for x in rhythms] notes = maker(pitches, rhythms) staff1 = abjad.Staff(notes) pitches = [None] rhythms = [(1, 1), (1, 1), (1, 1)] maker = abjad.LeafMaker() rhythms = [abjad.Duration(x) for x in rhythms] notes = maker(pitches, rhythms) staff2 = abjad.Staff(notes) for leaf, signature in zip(staff2[:], time_signatures): abjad.attach(signature, leaf) leaf.multiplier = abjad.Multiplier(signature.pair) score = abjad.Score([staff2, staff1]) for staff in score: for i, shard in enumerate(abjad.mutate(staff[:]).split(time_signatures)): time_signature = time_signatures[i] abjad.mutate(shard).rewrite_meter(abjad.Meter(time_signature.pair), boundary_depth=1) abjad.show(score)
def test_Meter___init___04(): time_signature = abjad.TimeSignature((6, 8)) assert abjad.Meter(time_signature).rtm_format == \ '(6/8 ((3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8))))'
(5, 4), (5, 4), (3, 4), (5, 4), (3, 4), (3, 4), (3, 4), (3, 4), (5, 4), (5, 4), (5, 4), (5, 4), (5, 4), ) meters_01 = [abjad.Meter(_) for _ in pairs_01] signatures_01 = [abjad.TimeSignature(_) for _ in meters_01] signatures_01.append(abjad.TimeSignature((3, 16))) # for ending skip bounds_01 = abjad.math.cumulative_sums([_.duration for _ in signatures_01]) quarter_bounds_01 = abjad.math.cumulative_sums( [abjad.Duration((1, 4)) for _ in range(86)]) ## ## 02 ## pairs_02 = ((5, 4) for _ in range(20))
def test_Meter___init___09(): time_signature = abjad.TimeSignature((11, 4)) assert abjad.Meter(time_signature).rtm_format == \ '(11/4 ((3/4 (1/4 1/4 1/4)) (2/4 (1/4 1/4)) (2/4 (1/4 1/4)) (2/4 (1/4 1/4)) (2/4 (1/4 1/4))))'
def auto_rewrite_meter( container: abjad.Container, meter_list: Optional[list[Union[abjad.Meter, abjad.TimeSignature, ]]] = None, *, prettify_rewrite_meter: bool = True, extract_trivial_tuplets: bool = True, fuse_across_groups_of_beats: bool = True, fuse_quadruple_meter: bool = True, fuse_triple_meter: bool = True, boundary_depth: Optional[int] = None, maximum_dot_count: Optional[int] = None, rewrite_tuplets: bool = True, merge_partial_tuplets: bool = True, split_quadruple_meter: bool = True, ) -> None: r"""Mutates an input container (of type |abjad.Container| or child class) in place and has no return value; this function takes every measure of a container, detects its time signature, and apply both |abjad.Meter.rewrite_meter()| and |auxjad.mutate.prettify_rewrite_meter()| to it. Basic usage: For this example, the following container will be mutated: >>> staff = abjad.Staff( ... r"c'16 d'8 e'16 f'8 g'4 a'4 b'8 " ... r"c'16 d'4. e'16 f'8 g'4 a'16 b'16" ... ) >>> abjad.show(staff) .. docs:: \new Staff { c'16 d'8 e'16 f'8 g'4 a'4 b'8 c'16 d'4. e'16 f'8 g'4 a'16 b'16 } .. figure:: ../_images/auto_rewrite_meter-xyx2wh7ufer.png Abjad's |abjad.Meter.rewrite_meter()| mutates an |abjad.Selection| of a measure, improving its notation. >>> for measure in abjad.select(staff[:]).group_by_measure(): ... abjad.Meter.rewrite_meter(measure, abjad.Meter((4, 4))) >>> abjad.show(staff) .. docs:: \new Staff { c'16 d'16 ~ d'16 e'16 f'8 g'8 ~ g'8 a'8 ~ a'8 b'8 c'16 d'8. ~ d'8. e'16 f'8 g'8 ~ g'8 a'16 b'16 } .. figure:: ../_images/auto_rewrite_meter-7fn2uj2xupb.png This function mutates an |abjad.Container| (or child class), identifying the implied meters of each measure and applying both |abjad.Meter.rewrite_meter()| and |auxjad.mutate.prettify_rewrite_meter()| to it. See the documentation of the latter for a detailed explanation of what it does. Applying |auxjad.mutate.auto_rewrite_meter()| to the same initial container shown in the first figure above outputs: >>> staff = abjad.Staff( ... r"c'16 d'8 e'16 f'8 g'4 a'4 b'8 " ... r"c'16 d'4. e'16 f'8 g'4 a'16 b'16" ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { c'16 d'8 e'16 f'8 g'8 ~ g'8 a'4 b'8 c'16 d'8. ~ d'8. e'16 f'8 g'4 a'16 b'16 } .. figure:: ../_images/auto_rewrite_meter-ahdaggaiqbc.png .. note:: Auxjad automatically adds this function as an extension function to |abjad.mutate|. It can thus be used from either |auxjad.mutate|_ or |abjad.mutate| namespaces. Therefore, the two lines below are equivalent: >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.mutate.auto_rewrite_meter(staff) Time signature changes: It automatically handles time signature changes. >>> staff = abjad.Staff( ... r"c'16 d'8 e'16 f'8 g'4 a'4 b'8 " ... r"\time 6/8 b'4 c''4 r4 " ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { c'16 d'8 e'16 f'8 g'8 ~ g'8 a'4 b'8 \time 6/8 b'4 c''8 ~ c''8 r4 } .. figure:: ../_images/auto_rewrite_meter-08sckfp19vil.png ``prettify_rewrite_meter``: By default, this function invokes both |abjad.Meter.rewrite_meter()| and |auxjad.mutate.prettify_rewrite_meter()|. >>> staff = abjad.Staff( ... r"c'16 d'8 e'16 f'8 g'4 a'4 b'8 " ... r"c'16 d'8 e'16 f'8 g'4 a'4 b'8" ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { c'16 d'8 e'16 f'8 g'8 ~ g'8 a'4 b'8 c'16 d'8 e'16 f'8 g'8 ~ g'8 a'4 b'8 } .. figure:: ../_images/auto_rewrite_meter-vbytyszlkng.png Set ``prettify_rewrite_meter`` to ``False`` to not invoke |auxjad.mutate.prettify_rewrite_meter()|. >>> staff = abjad.Staff( ... r"c'16 d'8 e'16 f'8 g'4 a'4 b'8 " ... r"c'16 d'4. e'16 f'8 g'4 a'16 b'16" ... ) >>> auxjad.mutate.auto_rewrite_meter( ... staff, ... prettify_rewrite_meter=False, ... ) >>> abjad.show(staff) .. docs:: \new Staff { c'16 d'16 ~ d'16 e'16 f'8 g'8 ~ g'8 a'8 ~ a'8 b'8 c'16 d'8. ~ d'8. e'16 f'8 g'8 ~ g'8 a'16 b'16 } .. figure:: ../_images/auto_rewrite_meter-64wse58hvko.png ``meter_list``: When no ``meter_list`` is supplied, this function detects the time signature of each measure and uses those when rewritting it: >>> staff = abjad.Staff( ... r"\time 7/4 c'8 d'4 e'4 f'4 g'4 a'4 b'4 c''8 " ... r"\time 5/4 d''8 e''4 f''4 g''4 a''4 b''8" ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { \time 7/4 c'8 d'4 e'4 f'8 ~ f'8 g'4 a'8 ~ a'8 b'4 c''8 \time 5/4 d''8 e''4 f''4 g''8 ~ g''8 a''4 b''8 } .. figure:: ../_images/auto_rewrite_meter-l4xnpevp3z.png To use a custom list of meters (one for each measure), set ``meter_list`` to a :obj:`list` of |abjad.Meter|'s or |abjad.TimeSignature|'s. >>> staff = abjad.Staff( ... r"\time 7/4 c'8 d'4 e'4 f'4 g'4 a'4 b'4 c''8 " ... r"\time 5/4 d''8 e''4 f''4 g''4 a''4 b''8" ... ) >>> meter_list = [abjad.Meter((7, 4), increase_monotonic=True), ... abjad.Meter((5, 4), increase_monotonic=True), ... ] >>> auxjad.mutate.auto_rewrite_meter(staff, meter_list=meter_list) >>> abjad.show(staff) .. docs:: \new Staff { \time 7/4 c'8 d'4 e'8 ~ e'8 f'4 g'8 ~ g'8 a'4 b'4 c''8 \time 5/4 d''8 e''4 f''8 ~ f''8 g''4 a''4 b''8 } .. figure:: ../_images/auto_rewrite_meter-uqif4i8tqxk.png Number of measures: This function handles a container with any number of measures and any number of time signature changes: >>> staff = abjad.Staff( ... r"\time 3/4 c'8 d'4 e'4 f'8 " ... r"\time 5/8 g'4 a'4 r8 " ... r"\time 6/8 b'4 c''4 r4 " ... r"\time 4/4 d''8 e''4 f''8 g''16 a''4 r8." ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { \time 3/4 c'8 d'4 e'4 f'8 \time 5/8 g'4 a'8 ~ a'8 r8 \time 6/8 b'4 c''8 ~ c''8 r4 \time 4/4 d''8 e''4 f''8 g''16 a''8. ~ a''16 r8. } .. figure:: ../_images/auto_rewrite_meter-hkhtqnqita.png ``extract_trivial_tuplets``: By default, tuplets filled with rests or tied notes or chords are extracted: >>> staff = abjad.Staff( ... r"\times 2/3 {c'4 ~ c'8} \times 2/3 {d'8 r4} " ... r"\times 2/3 {r8 r8 r8} \times 2/3 {<e' g'>8 ~ <e' g'>4}" ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { c'4 \times 2/3 { d'8 r4 } r4 <e' g'>4 } .. figure:: ../_images/auto_rewrite_meter-nq6t6qwka7a.png Set ``extract_trivial_tuplets`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff( ... r"\times 2/3 {c'4 ~ c'8} \times 2/3 {d'8 r4} " ... r"\times 2/3 {r8 r8 r8} \times 2/3 {<e' g'>8 ~ <e' g'>4}" ... ) >>> auxjad.mutate.auto_rewrite_meter( ... staff, ... extract_trivial_tuplets=False, ... ) >>> abjad.show(staff) .. docs:: \new Staff { \times 2/3 { c'4. } \times 2/3 { d'8 r4 } \times 2/3 { r4. } \times 2/3 { <e' g'>4. } } .. figure:: ../_images/auto_rewrite_meter-ssnsui7o9cc.png ``merge_partial_tuplets``: By default, consecutive partial tuplets with the same ratio that sum up to an assignable duration will be merged together: >>> staff = abjad.Staff( ... r"\times 2/3 {c'2 d'1}" ... r"\times 2/3 {e'2} \times 2/3 {f'1}" ... ) >>> auxjad.mutate.auto_rewrite_meter(staff) >>> abjad.show(staff) .. docs:: \new Staff { \times 2/3 { c'2 d'1 } \times 2/3 { e'2 f'1 } } .. figure:: ../_images/auto_rewrite_meter-ty72t5wvc1.png Set ``merge_partial_tuplets`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff( ... r"\times 2/3 {c'2 d'1}" ... r"\times 2/3 {e'2} \times 2/3 {f'1}" ... ) >>> auxjad.mutate.auto_rewrite_meter( ... staff, ... merge_partial_tuplets=False, ... ) >>> abjad.show(staff) .. docs:: \new Staff { \times 2/3 { c'2 d'1 } \tweak edge-height #'(0.7 . 0) \times 2/3 { e'2 } \tweak edge-height #'(0.7 . 0) \times 2/3 { f'1 } } .. figure:: ../_images/auto_rewrite_meter-4rouf819bjb.png .. note:: This function also accepts the arguments ``boundary_depth``, ``maximum_dot_count``, and ``rewrite_tuplets``, which are passed on to |abjad.Meter.rewrite_meter()|, and ``fuse_across_groups_of_beats``, ``fuse_quadruple_meter``, ``fuse_triple_meter``, and ``split_quadruple_meter``, which are passed on to |auxjad.mutate.prettify_rewrite_meter()|. ``merge_partial_tuplets`` is used to invoke |auxjad.mutate.merge_partial_tuplets()| See the documentation of these functions for more details on these arguments. .. warning:: Setting ``boundary_depth`` to a value equal to or larger than ``1`` will automatically disable ``fuse_across_groups_of_beats``, ``fuse_quadruple_meter``, and ``fuse_triple_meter``, regardless of their values. This is because when any of those arguments is ``True``, |auxjad.mutate.prettify_rewrite_meter()| will fuse across beats, which goes against the purpose of using ``boundary_depth``. Compare the results below. In the first case, simply applying |auxjad.mutate.prettify_rewrite_meter()| with no arguments results in some logical ties being tied across beats. >>> staff = abjad.Staff(r"\time 4/4 c'4. d'4. e'4 f'8 g'4 a'4 b'4.") >>> meter = abjad.Meter((4, 4)) >>> for measure in abjad.select(staff[:]).group_by_measure(): ... abjad.mutate.rewrite_meter(measure, meter, boundary_depth=1) >>> for measure in abjad.select(staff[:]).group_by_measure(): ... auxjad.mutate.prettify_rewrite_meter(measure, meter) >>> abjad.show(staff) .. docs:: \new Staff { \time 4/4 c'4 ~ c'8 d'8 ~ d'4 e'4 f'8 g'4 a'8 ~ a'8 b'8 ~ b'4 } .. figure:: ../_images/auto_rewrite_meter-cf09ysj16fo.png By automatically setting all ``fuse_across_groups_of_beats``, ``fuse_quadruple_meter``, and ``fuse_triple_meter` to ``False`` when ``boundary_depth`` is equal to or larger than ``1``, this function will not fuse those leaves against the required boundary depth. >>> staff = abjad.Staff(r"\time 4/4 c'4. d'4. e'4 f'8 g'4 a'4 b'4.") >>> auxjad.mutate.auto_rewrite_meter(staff, boundary_depth=1) >>> abjad.show(staff) .. docs:: \new Staff { \time 4/4 c'4 ~ c'8 d'8 ~ d'4 e'4 f'8 g'8 ~ g'8 a'8 ~ a'8 b'8 ~ b'4 } .. figure:: ../_images/auto_rewrite_meter-mm9xvmaqwfj.png """ if not isinstance(container, abjad.Container): raise TypeError("first positional argument must be 'abjad.Container' " "or child class") if meter_list is not None: if not isinstance(meter_list, list): raise TypeError("'meter_list' must be a 'list' of 'abjad.Meter' " "or 'abjad.TimeSignature'") else: for meter in meter_list: if not isinstance(meter, (abjad.Meter, abjad.TimeSignature)): raise TypeError("elements of 'meter_list' must be " "'abjad.Meter' or 'abjad.TimeSignature'") if isinstance(meter, abjad.TimeSignature): meter = abjad.Meter(meter.pair) if not isinstance(prettify_rewrite_meter, bool): raise TypeError("'prettify_rewrite_meter' must be 'bool'") if not isinstance(fuse_across_groups_of_beats, bool): raise TypeError("'fuse_across_groups_of_beats' must be 'bool'") if not isinstance(fuse_quadruple_meter, bool): raise TypeError("'fuse_quadruple_meter' must be 'bool'") if not isinstance(fuse_triple_meter, bool): raise TypeError("'fuse_triple_meter' must be 'bool'") if boundary_depth is not None: if not isinstance(boundary_depth, int): raise TypeError("'boundary_depth' must be 'int'") if maximum_dot_count is not None: if not isinstance(maximum_dot_count, int): raise TypeError("'maximum_dot_count' must be 'int'") if not isinstance(rewrite_tuplets, bool): raise TypeError("'rewrite_tuplets' must be 'bool'") if not isinstance(merge_partial_tuplets, bool): raise TypeError("'merge_partial_tuplets' must be 'bool'") if not isinstance(split_quadruple_meter, bool): raise TypeError("'split_quadruple_meter' must be 'bool'") if merge_partial_tuplets: merge_partial_tuplets_function(container[:]) if extract_trivial_tuplets: extract_trivial_tuplets_function(container[:]) if meter_list is None: time_signatures = get.time_signature_list( container, do_not_use_none=True, ) meter_list = [abjad.Meter(ts.pair) for ts in time_signatures] measures = abjad.select(container[:]).group_by_measure() for meter, measure in zip(meter_list, measures): if isinstance(measure[0], abjad.MultimeasureRest): continue abjad.Meter.rewrite_meter( measure, meter, boundary_depth=boundary_depth, maximum_dot_count=maximum_dot_count, rewrite_tuplets=rewrite_tuplets, ) if prettify_rewrite_meter: measures = abjad.select(container[:]).group_by_measure() for meter, measure in zip(meter_list, measures): if boundary_depth is None or boundary_depth < 1: prettify_rewrite_meter_function( measure, meter, fuse_across_groups_of_beats=fuse_across_groups_of_beats, fuse_quadruple_meter=fuse_quadruple_meter, fuse_triple_meter=fuse_triple_meter, extract_trivial_tuplets=False, split_quadruple_meter=split_quadruple_meter, ) else: prettify_rewrite_meter_function( measure, meter, fuse_across_groups_of_beats=False, fuse_quadruple_meter=False, fuse_triple_meter=False, extract_trivial_tuplets=False, split_quadruple_meter=False, )
def prettify_rewrite_meter( selection: abjad.Selection, meter: Union[abjad.Meter, abjad.TimeSignature], *, fuse_across_groups_of_beats: bool = True, fuse_quadruple_meter: bool = True, fuse_triple_meter: bool = True, extract_trivial_tuplets: bool = True, split_quadruple_meter: bool = True, ) -> None: r"""Mutates an input |abjad.Selection| in place and has no return value; this function fuses pitched leaves according to the rules shown below, improving the default output of |abjad.mutate().rewrite_meter()|. Basic usage: Meters whose denominators are a crotchet or longer get tied notes within a beat after |abjad.mutate().rewrite_meter()| when they are at an offset ``denominator / 4``, so a rhythm such as ``denominator / 4`` ``denominator / 2`` ``denominator / 4`` becomes ``denominator / 4`` ``denominator / 4`` ``~`` ``denominator / 4`` ``denominator / 4``. This function looks for those specific cases and fuses them, generating an output which is often more readable. >>> staff = abjad.Staff( ... r"\time 3/4 c'16 d'8 e'16 f'16 g'16 a'8 b'8 c''16 d''16" ... ) >>> meter = abjad.Meter((3, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'16 d'16 ~ d'16 e'16 f'16 g'16 a'8 b'8 c''16 d''16 } .. figure:: ../_images/prettify_rewrite_meter-vlnd7l5fb7s.png >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'16 d'8 e'16 f'16 g'16 a'8 b'8 c''16 d''16 } .. figure:: ../_images/prettify_rewrite_meter-e7vfnese0ut.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[:]).prettify_rewrite_meter(meter) >>> abjad.mutate(staff[:]).prettify_rewrite_meter(meter) Other examples: The rhythm of the leaves just before and after the two leaves to be fused can be different than ``denominator / 4``, as the function searches for logical ties of specific length and offset, and its surroundings do not matter. >>> staff = abjad.Staff(r"\time 3/4 c'32 d'32 e'8 f'16 " ... r"\times 2/3 {g'32 a'32 b'32} c''8 " ... r"r16 r32. d''64 e''8 f''32 g''32" ... ) >>> meter = abjad.Meter((3, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'32 d'32 e'16 ~ e'16 f'16 \times 2/3 { g'32 a'32 b'32 } c''16 ~ c''16 r16 r32. d''64 e''16 ~ e''16 f''32 g''32 } .. figure:: ../_images/prettify_rewrite_meter-kw09gse2zxj.png >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'32 d'32 e'8 f'16 \times 2/3 { g'32 a'32 b'32 } c''8 r16 r32. d''64 e''8 f''32 g''32 } .. figure:: ../_images/prettify_rewrite_meter-u5gmtdippsa.png ``fuse_across_groups_of_beats``: By default, this function also fuses rhythms of type ``denominator / 2`` ``denominator / 2`` ``~`` ``denominator / 2`` ``denominator / 2``, becoming ``denominator / 2`` ``denominator`` ``denominator / 2``. This is only applied when the meter's structure has a depth of 2, which is the case for meters with numerators equal to or larger than ``5``. >>> staff = abjad.Staff(r"\time 6/4 c'8 d'4 e'4 f'4 g'4 a'4 b'8") >>> meter = abjad.Meter((6, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 6/4 c'8 d'8 ~ d'8 e'8 ~ e'8 f'8 ~ f'8 g'8 ~ g'8 a'8 ~ a'8 b'8 } .. figure:: ../_images/prettify_rewrite_meter-tqi4p0u8qog.png >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 6/4 c'8 d'4 e'4 f'8 ~ f'8 g'4 a'4 b'8 } .. figure:: ../_images/prettify_rewrite_meter-riif1glyqpo.png to disable this behaviour, set the optional keyword argument ``fuse_across_groups_of_beats`` to ``False``. >>> staff = abjad.Staff(r"\time 6/4 c'8 d'4 e'4 f'4 g'4 a'4 b'8") >>> meter = abjad.Meter((6, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter( ... meter, ... fuse_across_groups_of_beats=False, ... ) >>> abjad.f(staff) \new Staff { \time 6/4 c'8 d'8 ~ d'8 e'8 ~ e'8 f'8 ~ f'8 g'8 ~ g'8 a'8 ~ a'8 b'8 } .. figure:: ../_images/prettify_rewrite_meter-ki5xbiteij.png |abjad.Meter| with ``increase_monotonic=True``: The fused notes will respect the beat structures of such meters, even when ``increase_monotonic`` is set to the non-default value ``True``. Compare the outputs below. >>> staff = abjad.Staff(r"\time 7/4 c'8 d'4 e'4 f'4 g'4 a'4 b'4 c''8") >>> meter = abjad.Meter((7, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 7/4 c'8 d'4 e'4 f'8 ~ f'8 g'4 a'8 ~ a'8 b'4 c''8 } .. figure:: ../_images/prettify_rewrite_meter-bud0jhkvvl.png >>> staff = abjad.Staff(r"\time 7/4 c'8 d'4 e'4 f'4 g'4 a'4 b'4 c''8") >>> meter = abjad.Meter((7, 4), increase_monotonic=True) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 7/4 c'8 d'4 e'8 ~ e'8 f'4 g'8 ~ g'8 a'4 b'4 c''8 } .. figure:: ../_images/prettify_rewrite_meter-47y86pbwwv5.png Multiple measures at once: This function can take handle multiple measures at once, as long as they share the same meter. >>> staff = abjad.Staff(r"\time 5/8 c'16 d'8 e'8 f'8 g'8 a'16 ~ " ... r"a'16 b'8 c''8 d''8 e''8 f''16" ... ) >>> meter = abjad.Meter((5, 8)) >>> for measure in abjad.select(staff[:]).group_by_measure(): ... abjad.mutate(staff[:]).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 5/8 c'16 d'16 ~ d'16 e'16 ~ e'16 f'16 ~ f'16 g'16 ~ g'16 a'16 ~ a'16 b'16 ~ b'16 c''16 ~ c''16 d''16 ~ d''16 e''16 ~ e''16 f''16 } .. figure:: ../_images/prettify_rewrite_meter-8jdzmvf9yl.png >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 5/8 c'16 d'8 e'8 f'16 ~ f'16 g'8 a'16 ~ a'16 b'8 c''8 d''16 ~ d''16 e''8 f''16 } .. figure:: ../_images/prettify_rewrite_meter-pcn8x9hr6bb.png Multiple measures: Similarly to |abjad.mutate().rewrite_meter()|, this function accepts selections of multiple measures: >>> staff = abjad.Staff(r"\time 4/4 c'8 d'4 e'4 f'4 g'8 | " ... r"a'8 b'4 c''8 d''16 e''4 f''8.") >>> meter = abjad.Meter((4, 4)) >>> for measure in abjad.select(staff[:]).group_by_measure(): ... abjad.mutate(measure).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 4/4 c'8 d'8 ~ d'8 e'8 ~ e'8 f'8 ~ f'8 g'8 a'8 b'8 ~ b'8 c''8 d''16 e''8. ~ e''16 f''8. } .. figure:: ../_images/prettify_rewrite_meter-s8fg7a2k0tr.png >>> for measure in abjad.select(staff[:]).group_by_measure(): ... auxjad.mutate(measure).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 4/4 c'8 d'4 e'8 ~ e'8 f'4 g'8 a'8 b'4 c''8 d''16 e''8. ~ e''16 f''8. } .. figure:: ../_images/prettify_rewrite_meter-rgd7ok7fkq.png Multiple measures with different meters: If the measures have different meters, they can be passed on individually using :func:`zip()` as shown below. >>> staff = abjad.Staff(r"\time 3/4 c'8 d'4 e'4 f'16 g'16 | " ... r"\time 4/4 a'8 b'4 c''8 d''16 e''4 f''8.") >>> meters = [abjad.Meter((3, 4)), abjad.Meter((4, 4))] >>> for meter, measure in zip( ... meters, ... abjad.select(staff[:]).group_by_measure(), ... ): ... abjad.mutate(measure).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'8 d'8 ~ d'8 e'8 ~ e'8 f'16 g'16 \time 4/4 a'8 b'8 ~ b'8 c''8 d''16 e''8. ~ e''16 f''8. } .. figure:: ../_images/prettify_rewrite_meter-o2izz0m7s9k.png >>> for meter, measure in zip( ... meters, ... abjad.select(staff[:]).group_by_measure(), ... ): ... auxjad.mutate(measure).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'8 d'4 e'4 f'16 g'16 \time 4/4 a'8 b'4 c''8 d''16 e''8. ~ e''16 f''8. } .. figure:: ../_images/prettify_rewrite_meter-zh89kk66zon.png ``fuse_quadruple_meter``: This function also takes care of two special cases, namely quadruple and triple meters. By default, it will fuse leaves in quadruple meters across beats 1 and 2, and across beats 3 and 4 (as long as they fulfil the other requirements of duration and offset). >>> staff = abjad.Staff(r"\time 4/4 c'8 d'4 e'4 f'4 g'8") >>> meter = abjad.Meter((4, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 4/4 c'8 d'4 e'8 ~ e'8 f'4 g'8 } .. figure:: ../_images/prettify_rewrite_meter-nap4bbf7mxe.png Set ``fuse_quadruple_meter`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff(r"\time 4/4 c'8 d'4 e'4 f'4 g'8") >>> meter = abjad.Meter((4, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter( ... meter, ... fuse_quadruple_meter=False, ... ) >>> abjad.f(staff) \new Staff { \time 4/4 c'8 d'8 ~ d'8 e'8 ~ e'8 f'8 ~ f'8 g'8 } .. figure:: ../_images/prettify_rewrite_meter-juipg9nzna.png ``fuse_triple_meter``: In the case of triple meters, it will fuse leaves across any beat as long as the previously mentioned conditions of offset and duration are met. >>> staff = abjad.Staff(r"\time 3/4 c'8 d'4 e'4 f'8") >>> meter = abjad.Meter((3, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { \time 3/4 c'8 d'4 e'4 f'8 } .. figure:: ../_images/prettify_rewrite_meter-4wg3grpb94p.png Similarly to the example before, set ``fuse_triple_meter`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff(r"\time 3/4 c'8 d'4 e'4 f'8") >>> meter = abjad.Meter((3, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> auxjad.mutate(staff[:]).prettify_rewrite_meter( ... meter, ... fuse_triple_meter=False, ... ) >>> abjad.f(staff) \new Staff { \time 3/4 c'8 d'8 ~ d'8 e'8 ~ e'8 f'8 } .. figure:: ../_images/prettify_rewrite_meter-l16ostzscta.png ``extract_trivial_tuplets``: By default, this function extracts the contents of tuples that consist solely of rests, or solely of tied notes and chords. >>> staff = abjad.Staff( ... r"\times 2/3 {c'4 ~ c'8} \times 2/3 {d'8 r4} " ... r"\times 2/3 {r8 r8 r8} \times 2/3 {<e' g'>8 ~ <e' g'>4}" ... ) >>> meter = abjad.Meter((4, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> abjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { c'4 \times 2/3 { d'8 r4 } r4 <e' g'>4 } .. figure:: ../_images/prettify_rewrite_meter-a72jx4fc1xd.png Set ``extract_trivial_tuplets`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff( ... r"\times 2/3 {c'4 ~ c'8} \times 2/3 {d'8 r4} " ... r"\times 2/3 {r8 r8 r8} \times 2/3 {<e' g'>8 ~ <e' g'>4}" ... ) >>> meter = abjad.Meter((4, 4)) >>> abjad.mutate(staff[:]).rewrite_meter(meter) >>> abjad.mutate(staff[:]).prettify_rewrite_meter( ... meter, ... extract_trivial_tuplets=False, ... ) >>> abjad.f(staff) \new Staff { \times 2/3 { c'4. } \times 2/3 { d'8 r4 } \times 2/3 { r4. } \times 2/3 { <e' g'>4. } } .. figure:: ../_images/prettify_rewrite_meter-v9q0ka94qcd.png ``split_quadruple_meter`` When applying |abjad.mutate().rewrite_meter()| to a selection with quadruple meter and without using a deeper ``boundary_depth`` than the default, the resulting notation will often have leaves crossing the third beat of the measure, as shown below. >>> staff = abjad.Staff( ... r"c'4 d'2 r4" ... r"e'4. f'2 g'8" ... r"a'4. b'4. c''4" ... r"d''16 e''8. f''4. g''4 a''8" ... ) >>> meter = abjad.Meter((4, 4)) >>> for measure in abjad.select(staff[:]).group_by_measure(): ... abjad.mutate(measure).rewrite_meter(meter) >>> abjad.f(staff) \new Staff { c'4 d'2 r4 e'4. f'8 ~ f'4. g'8 a'4. b'4. c''4 d''16 e''8. f''4. g''8 ~ g''8 a''8 } .. figure:: ../_images/prettify_rewrite_meter-1wvhrjife1i.png This function tests those leaves against a series of rules, splitting them when the tests fails. In the case shown above, the first two bars are very easy to read rhythmically, but the third and fourth are less so. This is due to the dotted crotchet, which starts off a beat, crossing the third beat of the measure. This function will split these sort of leaves as shown below. >>> abjad.mutate(staff[:]).prettify_rewrite_meter(meter) >>> abjad.f(staff) \new Staff { c'4 d'2 r4 e'4. f'8 ~ f'4. g'8 a'4. b'8 ~ b'4 c''4 d''16 e''8. f''4 ~ f''8 g''4 a''8 } .. figure:: ../_images/prettify_rewrite_meter-56dy04wjzg.png Set ``split_quadruple_meter`` to ``False`` to disable this behaviour. >>> staff = abjad.Staff( ... r"c'4 d'2 r4" ... r"e'4. f'2 g'8" ... r"a'4. b'4. c''4" ... r"d''16 e''8. f''4. g''4 a''8" ... ) >>> meter = abjad.Meter((4, 4)) >>> for measure in abjad.select(staff[:]).group_by_measure(): ... abjad.mutate(measure).rewrite_meter(meter) >>> abjad.mutate(staff[:]).prettify_rewrite_meter( ... meter, ... split_quadruple_meter=False, ... ) >>> abjad.f(staff) \new Staff { c'4 d'2 r4 e'4. f'8 ~ f'4. g'8 a'4. b'4. c''4 d''16 e''8. f''4. g''4 a''8 } .. figure:: ../_images/prettify_rewrite_meter-ww1x0zsxlnd.png .. tip:: Use :func:`auxjad.auto_rewrite_meter()` to automatically apply |abjad.mutate().rewrite_meter()| and |auxjad.mutate().prettify_rewrite_meter()| to a container with multiple time signatures. .. 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("first argument must be 'abjad.Selection'") if not selection.leaves().are_contiguous_logical_voice(): raise ValueError("first argument must be contiguous logical voice") if not isinstance(meter, (abjad.Meter, abjad.TimeSignature)): raise TypeError("argument must be 'abjad.Meter' or " "'abjad.TimeSignature'") if not isinstance(fuse_across_groups_of_beats, bool): raise TypeError("'fuse_across_groups_of_beats' must be 'bool'") if not isinstance(fuse_quadruple_meter, bool): raise TypeError("'fuse_quadruple_meter' must be 'bool'") if not isinstance(fuse_triple_meter, bool): raise TypeError("'fuse_triple_meter' must be 'bool'") if not isinstance(extract_trivial_tuplets, bool): raise TypeError("'extract_trivial_tuplets' must be 'bool'") if not isinstance(split_quadruple_meter, bool): raise TypeError("'split_quadruple_meter' must be 'bool'") if isinstance(meter, abjad.TimeSignature): meter = abjad.Meter(meter.pair) logical_ties = selection.logical_ties(pitched=True) if len(logical_ties) == 0: return first_leaf = selection.leaf(0) initial_offset = abjad.inspect(first_leaf).timespan().start_offset base = 1 / meter.denominator def _merge_indicators_then_fuse(logical_tie): last_indicators = abjad.inspect(logical_tie[-1]).indicators() initial_indicators = abjad.inspect(logical_tie[0]).indicators() initial_indicators_types = tuple( type(indicator) for indicator in initial_indicators) abjad.mutate(logical_tie).fuse() for indicator in last_indicators: if isinstance(indicator, ( abjad.Dynamic, abjad.StopSlur, abjad.StopGroup, abjad.StopHairpin, abjad.StopTextSpan, abjad.StopTrillSpan, abjad.StopPianoPedal, abjad.StopPhrasingSlur, )): if not isinstance(indicator, initial_indicators_types): abjad.attach(indicator, logical_tie[0]) for logical_tie in logical_ties.filter_duration("==", base / 2): offset = abjad.inspect(logical_tie).timespan().start_offset offset -= initial_offset offset %= base if offset == base / 4: _merge_indicators_then_fuse(logical_tie) if fuse_across_groups_of_beats: for logical_tie in logical_ties.filter_duration("==", base): offset = abjad.inspect(logical_tie).timespan().start_offset offset -= initial_offset offset %= meter.duration offset_mod = offset % base if offset_mod == base / 2: if (not offset + base / 2 in meter.depthwise_offset_inventory[1]): _merge_indicators_then_fuse(logical_tie) if fuse_quadruple_meter and meter.numerator == 4: for logical_tie in logical_ties.filter_duration("==", base): offset = abjad.inspect(logical_tie).timespan().start_offset offset -= initial_offset offset %= meter.duration offset_mod = offset % base if offset_mod == base / 2: if not offset + base / 2 in ( abjad.Offset(0, 1), abjad.Offset(2 * base), abjad.Offset(4 * base), ): _merge_indicators_then_fuse(logical_tie) if fuse_triple_meter and meter.numerator == 3: for logical_tie in logical_ties.filter_duration("==", base): offset = abjad.inspect(logical_tie).timespan().start_offset offset -= initial_offset offset %= meter.duration offset_mod = offset % base if offset_mod == base / 2: if not offset + base / 2 in ( abjad.Offset(0, 1), abjad.Offset(3 * base), ): _merge_indicators_then_fuse(logical_tie) logical_ties = selection.logical_ties() # splitting not only pitched if split_quadruple_meter and meter.numerator == 4: half_point_offset = abjad.Offset(2 * base) for logical_tie in logical_ties: offset0 = abjad.inspect(logical_tie).timespan().start_offset offset0 -= initial_offset offset0 %= meter.duration if offset0 == abjad.Offset(0, 1): # do not split things like c'1, c'2.. r8, c'2. r4, etc. continue offset1 = abjad.inspect(logical_tie).timespan().stop_offset offset1 -= initial_offset offset1 %= meter.duration if offset1 == abjad.Offset(0, 1): offset1 = abjad.Offset(meter.duration) if (offset0 % abjad.Offset(base) == abjad.Offset(0, 1) and offset1 % abjad.Offset(base) == abjad.Offset(0, 1)): # do not split things like r4 c'2. continue if offset0 < half_point_offset < offset1: if (offset1 == abjad.Offset(meter.duration) and len(logical_tie) == 1): # do not split r8 c'2.., r16 c'2..., etc. break if any( abjad.inspect(leaf).duration() == abjad.Duration(2 * base) for leaf in logical_tie): # do not split r8 c'8~c'2 r4, r16 c'8.~c'2~c'8 r8, etc. break # do not split tuplets getter = abjad.select().logical_ties() result = selection.tuplets().map(getter).flatten() if logical_tie in result: break duration = abjad.Duration(half_point_offset - offset0) abjad.mutate(logical_tie).split([duration]) if extract_trivial_tuplets: extract_trivial_tuplets_function(selection)
dur.annotation = "note" print(dur.annotation) staff = abjad.Staff("c'1 d'1 c'1. d'1. c'1. d'1. ") abjad.hairpin("p < f", staff[:]) abjad.override(staff).dynamic_line_spanner.staff_padding = 3 durations = [(3, 4), (4, 4), (5, 4)] result = abjad.mutate.split( staff[:], durations, cyclic=True, ) abjad.f(result) meters = [abjad.Meter(_) for _ in durations] result2 = abjad.select(staff).leaves() result2 = result2.group_by # for measure, time_sig in zip(result2, meters): # print(measure) # abjad.Meter.rewrite_meter(measure, time_sig) # time_signatures = [] # for item in in_time_signatures: # time_signatures.append(abjad.Meter(item)) # abjad.mutate().split(music, in_time_signature, cyclic=True) # # selection # abjad.Meter.rewrite_meter(music[:], time_signatures) # selector = abjad.select(music).leaves()
abjad.attach(abjad.Clef("alto"), quartet_group[2][0][0]) abjad.attach(abjad.Clef("bass"), quartet_group[3][0][0]) score = abjad.Score([quartet_group, group, group_2]) abjad.attach(metronome_mark, group[0][0][0]) for voice in abjad.Selection(score).components(abjad.Voice): voice_dur = abjad.get.duration(voice) comparison_dur = abjad.get.duration(group[1][0]) if voice_dur < comparison_dur: new_dur = comparison_dur - voice_dur rest_leaves = maker([None], [new_dur]) for leaf in rest_leaves: voice.append(leaf) for voice in abjad.Selection(score).components(abjad.Voice): for i, shard in enumerate( abjad.mutate.split(voice[:], [abjad.Meter((4, 4))], cyclic=True)): abjad.Meter.rewrite_meter(shard, abjad.Meter((4, 4))) abjad.label.with_start_offsets(voice, clock_time=True) for handler, staff in zip(handlers, group): handler(staff) for handler, staff in zip(handlers_2, group_2): handler(staff) for handler, staff in zip(handlers_3, quartet_group): handler(staff) moment = "#(ly:make-moment 1 10)" abjad.setting(score).proportional_notation_duration = moment
import tsmakers print(os.path.dirname(__file__)) print(" ") file_name = os.path.basename(__file__) file_name = os.path.splitext(file_name)[0] illust_path = "../../muda_score/segments/illustrations" new_file = illust_path+"/"+str(file_name)+".ly" print(new_file) container = abjad.Container("c''4 d''8 e''16 e''32 e''4 e''4 e''4") meters = [(3, 4), (4, 4), (5, 4)] meters = [abjad.Meter(_) for _ in meters] argument = [(0, 4), (4, 4), (8, 4), (12, 4), (16, 4)] for meter in abjad.Meter.fit_meters(container, meters): print(meter.implied_time_signature) # for staff in score: # for container in staff: # leaf = abjad.get.leaf(container, 0) # time_signature = abjad.get.indicator(leaf, abjad.TimeSignature) # abjad.Meter.rewrite_meter(container[:], time_signature) #
def test_prettify_rewrite_meter_09(): staff = abjad.Staff(r"\times 2/3 {c'16 d'8 ~ } " r"\times 2/3 {d'32 e'8 f'32 ~ } " r"f'32 \times 2/3 {g'16 a'32} r32") abjad.attach(abjad.TimeSignature((3, 8)), staff[0][0]) meter = abjad.Meter((3, 8)) abjad.Meter.rewrite_meter(staff[:], meter) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { \times 2/3 { \time 3/8 c'16 d'8 ~ } \times 2/3 { d'32 e'32 ~ e'16. f'32 ~ } f'32 \times 2/3 { g'16 a'32 } r32 } """) auxjad.mutate.prettify_rewrite_meter(staff[:], meter) assert abjad.lilypond(staff) == abjad.String.normalize(r""" \new Staff { \times 2/3 { \time 3/8 c'16 d'8 ~ } \times 2/3 { d'32 e'32 ~ e'16. f'32 ~ } f'32 \times 2/3 { g'16 a'32 } r32 } """)
def test_WindowLooper_04(): container = abjad.Container(r"c'4 d'2 e'4 f'2 ~ f'8 g'4.") looper = auxjad.WindowLooper( container, window_size=(3, 4), step_size=(5, 8), max_steps=2, repetition_chance=0.25, forward_bias=0.2, head_position=(2, 8), omit_time_signatures=False, fill_with_rests=False, boundary_depth=0, maximum_dot_count=1, rewrite_tuplets=False, process_on_first_call=True, after_rest=(1, 8), after_rest_in_new_measure=True, use_multimeasure_rests=False, ) assert looper.window_size == abjad.Meter((3, 4)) assert looper.step_size == abjad.Duration((5, 8)) assert looper.max_steps == 2 assert looper.repetition_chance == 0.25 assert looper.forward_bias == 0.2 assert looper.head_position == abjad.Duration((1, 4)) assert not looper.omit_time_signatures assert not looper.fill_with_rests assert looper.boundary_depth == 0 assert looper.maximum_dot_count == 1 assert not looper.rewrite_tuplets assert looper.process_on_first_call assert looper.after_rest == abjad.Duration((1, 8)) assert looper.after_rest_in_new_measure assert not looper.use_multimeasure_rests looper.window_size = (5, 4) looper.step_size = (1, 4) looper.max_steps = 3 looper.repetition_chance = 0.1 looper.forward_bias = 0.8 looper.head_position = 0 looper.omit_time_signatures = True looper.fill_with_rests = True looper.boundary_depth = 1 looper.maximum_dot_count = 2 looper.rewrite_tuplets = True looper.process_on_first_call = False looper.after_rest = 0 looper.after_rest_in_new_measure = False looper.use_multimeasure_rests = True assert looper.window_size == abjad.Meter((5, 4)) assert looper.step_size == abjad.Duration((1, 4)) assert looper.max_steps == 3 assert looper.repetition_chance == 0.1 assert looper.forward_bias == 0.8 assert looper.head_position == abjad.Duration(0) assert looper.omit_time_signatures assert looper.fill_with_rests assert looper.boundary_depth == 1 assert looper.maximum_dot_count == 2 assert looper.rewrite_tuplets assert not looper.process_on_first_call assert looper.after_rest == abjad.Duration(0) assert not looper.after_rest_in_new_measure assert looper.use_multimeasure_rests
def test_Meter___init___05(): time_signature = abjad.TimeSignature((5, 8)) assert (abjad.Meter(time_signature).rtm_format == "(5/8 ((3/8 (1/8 1/8 1/8)) (2/8 (1/8 1/8))))")
import abjad meters = [ abjad.Meter(pair) for pair in [ (5, 4), (9, 8), (4, 4), (7, 8), (3, 4), (5, 8), (2, 4), (3, 8), (5, 16), (1, 4), (3, 16), (1, 8), ] ] for meter in meters: print(meter) inventories = [x for x in enumerate(meter.depthwise_offset_inventory)] if meter.denominator == 4: print(inventories[-1][0]) print(inventories[-1][1]) print("") else: print(inventories[-2][0]) print(inventories[-2][1]) print("")
def test_Meter___init___02(): time_signature = abjad.TimeSignature((3, 4)) assert abjad.Meter(time_signature).rtm_format == "(3/4 (1/4 1/4 1/4))"
divisions = evans.BacaSequence(divisions) divisions = evans.BacaSequence( evans.BacaSequence(_).quarters() for _ in divisions) divisions = evans.BacaSequence(divisions).flatten(depth=-1) return divisions commands = [ rmakers.trivialize(lambda _: abjad.Selection(_).tuplets()), rmakers.rewrite_rest_filled(lambda _: abjad.Selection(_).tuplets()), rmakers.rewrite_sustained(lambda _: abjad.Selection(_).tuplets()), rmakers.extract_trivial(), rmakers.RewriteMeterCommand( boundary_depth=-1, reference_meters=[ abjad.Meter((6, 8)), abjad.Meter((9, 8)), ], ), ] stack = rmakers.stack( rmaker, *commands, preprocessor=quarters, ) divisions = [(6, 8), (9, 8)] selections = stack(divisions)