def make_fused_tuplet_monads( *, measures: typings.SliceTyping = None, tuplet_ratio: typing.Tuple[int] = None, ) -> RhythmCommand: """ Makes fused tuplet monads. """ tuplet_ratios = [] if tuplet_ratio is None: tuplet_ratios.append((1, )) else: tuplet_ratios.append(tuplet_ratio) return RhythmCommand( rmakers.stack( rmakers.tuplet(tuplet_ratios), rmakers.beam(), rmakers.rewrite_rest_filled(), rmakers.trivialize(), rmakers.extract_trivial(), rmakers.force_repeat_tie(), preprocessor=lambda _: classes.Sequence( [classes.Sequence(_).sum()]), tag=_site(inspect.currentframe()), ), annotation_spanner_color="#darkcyan", frame=inspect.currentframe(), measures=measures, )
def make_single_attack(duration, *, measures: typings.SliceTyping = None) -> RhythmCommand: """ Makes single attacks with ``duration``. """ duration = abjad.Duration(duration) numerator, denominator = duration.pair return RhythmCommand( rmakers.stack( rmakers.incised( fill_with_rests=True, outer_divisions_only=True, prefix_talea=[numerator], prefix_counts=[1], talea_denominator=denominator, ), rmakers.beam(), rmakers.extract_trivial(), tag=_site(inspect.currentframe()), ), annotation_spanner_color="#darkcyan", frame=inspect.currentframe(), measures=measures, )
def glissando_rhythm(rotate=0): return baca.rhythm( rmakers.talea(abjad.sequence.rotate([5, 1, 2, 1], n=rotate), 8), rmakers.beam(), rmakers.extract_trivial(), rmakers.rewrite_meter(), tag=abjad.Tag("animales.glissando_rhythm()"), )
def make_music(self, durations, denominator, divisions, pitches): # make rhythm with one tuplet per division stack = rmakers.stack( rmakers.talea( durations, denominator, extra_counts=(0, 0, 0), ), rmakers.beam() ) selection = stack(divisions) # attach time signature to first leaf in each tuplet assert len(divisions) == len(selection) for division, tuplet in zip(divisions, selection): time_signature = abjad.TimeSignature(division) leaf = abjad.select(tuplet).leaf(0) abjad.attach(time_signature, leaf) # apply pitch material cyclic_tuple = abjad.CyclicTuple(pitches) iterator = abjad.iterate(selection).logical_ties(pitched=True) # make iterator out of selection using logical ties as virtual measures iterator = enumerate(iterator) # makes enum out of iterator for index, logical_tie in iterator: print("entered the loop make_music") pitch = cyclic_tuple[index] print(pitch) for old_leaf in logical_tie: print("here is the old leaf: ", old_leaf) if isinstance(pitch, int): print("in if pitch is still", pitch) old_leaf.written_pitch = pitch print(old_leaf) elif isinstance(pitch, list): print("entered elif") print("pitch is still", pitch) new_leaf = abjad.Chord(pitch, old_leaf.written_duration) print("this is the new leaf: ", new_leaf) indicators = abjad.inspect(old_leaf).indicators() if indicators != None: for indicator in indicators: abjad.attach(indicator, new_leaf) abjad.mutate(old_leaf).replace(new_leaf) elif isinstance(pitch, abjad.Chord): print("entered elif") print("pitch is still", pitch) new_leaf = abjad.Chord(pitch, old_leaf.written_duration) print("this is the new leaf: ", new_leaf) indicators = abjad.inspect(old_leaf).indicators() if indicators != None: for indicator in indicators: abjad.attach(indicator, new_leaf) abjad.mutate(old_leaf).replace(new_leaf) # remove trivial 1:1 tuplets self.staff.extend(selection) command = rmakers.extract_trivial() command(selection)
def clb_rhythm( section: str, member: int, counts: typing.Sequence[abjad.IntegerSequence], wrap: int, ): if section in ("First.Violin", "Second.Violin", "Viola"): assert member in range(1, 18 + 1), repr(member) elif section == "Cello": assert member in range(1, 14 + 1), repr(member) elif section == "Contrabass": assert member in range(1, 6 + 1), repr(member) else: assert ValueError(section) section_to_offset = { "First.Violin": 0, "Second.Violin": 18, "Viola": 36, "Cello": 54, "Contrabass": 68, } total_players = 74 index = section_to_offset[section] + member - 1 counts_ = baca.sequence.helianthate(counts, -1, -1) counts_ = abjad.sequence.flatten(counts_) counts_ = abjad.sequence.repeat_to_weight(counts_, total_players * wrap) shards = abjad.sequence.split(counts_, [wrap], cyclic=True, overhang=abjad.Exact) assert len(shards) == total_players assert abjad.sequence.weight(shards) == abjad.sequence.weight(counts_) counts_ = shards[index] extra_counts = None if index % 9 in [2, 3, 6, 7]: extra_counts = [-1] def preprocessor(divisions): result = baca.sequence.fuse(divisions) result = baca.sequence.quarters(result) return result return baca.rhythm( rmakers.talea(counts_, 16, extra_counts=extra_counts), rmakers.beam(), rmakers.rewrite_rest_filled(), rmakers.trivialize(), rmakers.force_diminution(), rmakers.extract_trivial(), rmakers.rewrite_meter(), preprocessor=preprocessor, tag=abjad.Tag("animales.clb_rhythm()"), )
def downbeat_attack(count=1, denominator=8): return baca.rhythm( rmakers.talea([count], denominator), rmakers.force_rest(baca.selectors.lts((1, None)), ), rmakers.beam(), rmakers.rewrite_rest_filled(), rmakers.extract_trivial(), rmakers.rewrite_meter(), tag=abjad.Tag("animales.downbeat_attack()"), )
def make_phrase(self, durations, denominator, divisions, pitches): # make rhythm with one tuplet per division stack = rmakers.stack( rmakers.talea( durations, denominator, extra_counts=(0, 0, 0), ), rmakers.beam() ) selection = stack(divisions) # attach time signature to first leaf in each tuplet assert len(divisions) == len(selection) previous_time_signature = None for division, tuplet in zip(divisions, selection): time_signature = abjad.TimeSignature(division) leaf = abjad.select(tuplet).leaf(0) if time_signature != previous_time_signature: abjad.attach(time_signature, leaf) previous_time_signature = time_signature # apply pitch material cyclic_tuple = abjad.CyclicTuple(pitches) iterator = abjad.iterate(selection).logical_ties(pitched=True) # make iterator out of selection using logical ties as virtual measures iterator = enumerate(iterator) # makes enum out of iterator for index, logical_tie in iterator: pitch = cyclic_tuple[index] for old_leaf in logical_tie: if isinstance(pitch, int): old_leaf.written_pitch = pitch elif isinstance(pitch, str): # warning: was formerly checking for list import rill.tools.FuzzyHarmony as FuzzyHarmony #import rill.tools.PhraseMaker as PhraseMaker new_leaf = abjad.Chord(pitch, old_leaf.written_duration) indicators = abjad.inspect(old_leaf).indicators() if indicators != None: for indicator in indicators: abjad.attach(indicator, new_leaf) abjad.mutate(old_leaf).replace(new_leaf) elif isinstance(pitch, abjad.Chord): new_leaf = abjad.Chord(pitch, old_leaf.written_duration) indicators = abjad.inspect(old_leaf).indicators() if indicators != None: for indicator in indicators: abjad.attach(indicator, new_leaf) abjad.mutate(old_leaf).replace(new_leaf) # remove trivial 1:1 tuplets self.container.extend(selection) command = rmakers.extract_trivial() command(selection)
def make_even_divisions(*, measures: typings.SliceTyping = None) -> RhythmCommand: """ Makes even divisions. """ return RhythmCommand( rmakers.stack( rmakers.even_division([8]), rmakers.beam(), rmakers.extract_trivial(), tag=_site(inspect.currentframe()), ), annotation_spanner_color="#darkcyan", frame=inspect.currentframe(), measures=measures, )
def make_tied_notes(*, measures: typings.SliceTyping = None) -> RhythmCommand: """ Makes tied notes; rewrites meter. """ return RhythmCommand( rmakers.stack( rmakers.note(), rmakers.beam(classes.select().plts()), rmakers.tie(classes.select().ptails()[:-1]), rmakers.rewrite_meter(), tag=_site(inspect.currentframe()), ), annotation_spanner_color="#darkcyan", frame=inspect.currentframe(), measures=measures, )
def make_music(self, durations, denominator, divisions, pitches): # make rhythm with one tuplet per division stack = rmakers.stack( rmakers.talea( durations, denominator, extra_counts=None, ), rmakers.beam(), ) selection = stack(divisions) # # attach time signature to first leaf in each tuplet # assert len(divisions) == len(selection) # for division, tuplet in zip(divisions, selection): # time_signature = abjad.TimeSignature(division) # leaf = abjad.select(tuplet).leaf(0) # abjad.attach(time_signature, leaf) # # apply pitches cyclic_tuple = abjad.CyclicTuple(pitches) iterator = abjad.iterate(selection).logical_ties(pitched=True) iterator = enumerate(iterator) for index, logical_tie in iterator: pitch = cyclic_tuple[index] for old_leaf in logical_tie: if isinstance(pitch, int): old_leaf.written_pitch = pitch elif isinstance(pitch, list): new_leaf = abjad.Chord(pitch, old_leaf.written_duration) indicators = abjad.inspect(old_leaf).indicators() if indicators != None: for indicator in indicators: abjad.attach(indicator, new_leaf) abjad.mutate(old_leaf).replace(new_leaf) # remove trivial 1:1 tuplets self.staff.extend(selection) command = rmakers.extract_trivial() command(selection)
def brass_manifest_rhythm(part): assert part in range(1, 12 + 1), repr(part) counts, delay, extra_counts = { 1: ([8, 8, -2], 9, [0, 0, 0, 1]), 2: ([8, 8, -2], 13, [0, 1, 0, 0]), 3: ([8, 8, -2], None, [0, 0, 1, 0]), 4: ([8, 8, -2], 4, [1, 0, 0, 0]), 5: ([7, 7, -2], 6, [0, 0, 0, 1]), 6: ([7, 7, -2], 10, [0, 1, 0, 0]), 7: ([7, 7, -2], None, [0, 0, 1, 0]), 8: ([7, 7, -2], 4, [1, 0, 0, 0]), 9: ([6, 6, 6, -2], 9, [0, 0, 0, 1]), 10: ([6, 6, 6, -2], 13, [0, 1, 0, 0]), 11: ([6, 6, 6, -2], None, [0, 0, 1, 0]), 12: ([6, 6, 6, -2], 4, [1, 0, 0, 0]), }[part] if delay is None: preamble = () else: preamble = [-delay] def preprocessor(divisions): result = baca.sequence.fuse(divisions) result = baca.sequence.quarters(divisions) return result return baca.rhythm( rmakers.talea(counts, 8, extra_counts=extra_counts, preamble=preamble), rmakers.beam(), rmakers.rewrite_rest_filled(), rmakers.trivialize(), rmakers.extract_trivial(), rmakers.rewrite_meter(), preprocessor=preprocessor, persist="brass_manifest_rhythm", tag=abjad.Tag("animales.brass_manifest_rhythm()"), )
def pennant_rhythm(extra_counts=None, silences=None): commands = [] if silences is not None: specifier = rmakers.force_rest(baca.selectors.tuplets(silences), ) commands.append(specifier) def preprocessor(divisions): result = baca.sequence.fuse(divisions) result = baca.sequence.quarters(divisions) return result return baca.rhythm( rmakers.talea([1], 16, extra_counts=extra_counts), *commands, rmakers.beam(), rmakers.rewrite_rest_filled(), rmakers.force_diminution(), rmakers.trivialize(), rmakers.extract_trivial(), rmakers.rewrite_meter(), preprocessor=preprocessor, tag=abjad.Tag("animales.pennant_rhythm()"), )
import abjad import abjadext.rmakers as rmakers import muda durations_general = [(4, 4)] * 32 rmaker_afluteA = rmakers.stack( rmakers.talea([4, -2, 1], 8), rmakers.extract_trivial(), # counts # denominator tag=abjad.Tag("Mat_A"), ) rmaker_afluteB = rmakers.stack( rmakers.talea([1], 8, extra_counts=[1]), rmakers.beam(), rmakers.extract_trivial(), # counts # denominator # rmakers.rewrite_meter(), tag=abjad.Tag("Mat_B"), ) rest_maker = rmakers.stack(rmakers.note(), rmakers.force_rest(abjad.select()), tag=abjad.Tag("Rests")) rmaker_bclarinetA = rmakers.stack( rmakers.talea([-4, 2], 8), # counts # denominator rmakers.beam(), rmakers.extract_trivial(), tag=abjad.Tag("Mat_A"), ) rmaker_bclarinetB = rmakers.stack(
def harp_exchange_rhythm(this_part, *commands, silence_first=False): part_to_pattern = dict([ (0, abjad.index([0, 30], period=36)), (1, abjad.index([0, 12, 16, 28, 32], period=48)), (2, abjad.index([0, 30], period=36)), (3, abjad.index([0, 12, 16, 28, 32], period=48)), ]) part_to_indices = {} for part in part_to_pattern: part_to_indices[part] = [] harp_indices = [] part = 0 pattern = part_to_pattern[part] index = 0 while True: if index % pattern.period in pattern.indices: part_to_indices[part].append(index) harp_indices.append((index, part)) degrees = [] for indices in part_to_indices.values(): talea = abjad.math.difference_series(indices) degree = baca.sequence.degree_of_rotational_symmetry(talea) degrees.append(degree) if all(1 < _ for _ in degrees): break part = (part + 1) % len(part_to_pattern) pattern = part_to_pattern[part] index += 1 if 999 < index: break part_to_preamble = {} part_to_counts = {} for part, indices in part_to_indices.items(): offset = indices[0] preamble = [] if offset != 0: preamble.append(offset) part_to_preamble[part] = preamble counts = abjad.math.difference_series(indices) period = baca.sequence.period_of_rotation(counts) counts = counts[:period] part_to_counts[part] = counts preamble = part_to_preamble[this_part] counts = [] for count in part_to_counts[this_part]: counts.append(2) rest = -(count - 2) counts.append(rest) silence_first_specifier = [] if silence_first is True: specifier = rmakers.force_rest(baca.selectors.lt(0)) silence_first_specifier.append(specifier) def preprocessor(divisions): result = baca.sequence.fuse(divisions) result = baca.sequence.quarters(result) return result return baca.rhythm( rmakers.talea(counts, 16, extra_counts=[2], preamble=preamble), *commands, rmakers.cache_state(), *silence_first_specifier, rmakers.beam(), rmakers.trivialize(), rmakers.extract_trivial(), rmakers.rewrite_meter(), rmakers.force_repeat_tie(), preprocessor=preprocessor, persist="harp_exchange_rhythm", tag=abjad.Tag("animales.harp_exchange_rhythm()"), )
def sforzando_exchange_rhythm(this_part): part_to_pattern = dict([ (0, abjad.index([0, 15], period=18)), (1, abjad.index([0, 6, 8, 14, 16], period=24)), (2, abjad.index([0, 15], period=18)), (3, abjad.index([0, 6, 8, 14, 16], period=24)), (4, abjad.index([0, 15], period=18)), (5, abjad.index([0, 6, 8, 14, 16], period=24)), (6, abjad.index([0, 15], period=18)), ]) part_to_indices = {} for part in part_to_pattern: part_to_indices[part] = [] sforzando_indices = [] part = 0 pattern = part_to_pattern[part] index = 0 while True: if index % pattern.period in pattern.indices: part_to_indices[part].append(index) sforzando_indices.append((index, part)) degrees = [] for indices in part_to_indices.values(): talea = abjad.math.difference_series(indices) degree = baca.sequence.degree_of_rotational_symmetry(talea) degrees.append(degree) if all(1 < _ for _ in degrees): break part = (part + 1) % len(part_to_pattern) pattern = part_to_pattern[part] index += 1 part_to_preamble = {} part_to_counts = {} for part, indices in part_to_indices.items(): offset = indices[0] preamble = [] if offset != 0: preamble.append(offset) part_to_preamble[part] = preamble counts = abjad.math.difference_series(indices) period = baca.sequence.period_of_rotation(counts) counts = counts[:period] part_to_counts[part] = counts preamble = part_to_preamble[this_part] counts = part_to_counts[this_part] def preprocessor(divisions): result = baca.sequence.fuse(divisions) result = baca.sequence.quarters(divisions) return result return baca.rhythm( rmakers.talea(counts, 16, extra_counts=[2], preamble=preamble), rmakers.beam(), rmakers.trivialize(), rmakers.extract_trivial(), rmakers.rewrite_meter(), rmakers.force_repeat_tie(), preprocessor=preprocessor, persist="sforzando_exchange_rhythm", tag=abjad.Tag("animales.sforzando_exchange_rhythm()"), )
def make_repeat_tied_notes( *specifiers: rmakers.Command, do_not_rewrite_meter: bool = None, measures: typings.SliceTyping = None, ) -> RhythmCommand: r""" Makes repeat-tied notes; rewrites meter. .. container:: example REGRESSION. All notes below are tagged NOT_YET_PITCHED_COLORING (and colored gold), even tied notes resulting from meter rewriting: >>> maker = baca.SegmentMaker( ... score_template=baca.SingleStaffScoreTemplate(), ... spacing=baca.minimum_duration((1, 12)), ... time_signatures=[(10, 8)], ... ) >>> maker( ... 'Music_Voice', ... baca.make_repeat_tied_notes(), ... ) >>> lilypond_file = maker.run(environment='docs') >>> abjad.show(lilypond_file) # doctest: +SKIP .. docs:: >>> string = abjad.lilypond(lilypond_file[abjad.Score]) >>> print(string) <BLANKLINE> \context Score = "Score" << <BLANKLINE> \context GlobalContext = "Global_Context" << <BLANKLINE> \context GlobalSkips = "Global_Skips" { <BLANKLINE> % [Global_Skips measure 1] \baca-new-spacing-section #1 #12 \time 10/8 \baca-time-signature-color #'blue s1 * 5/4 <BLANKLINE> % [Global_Skips measure 2] \baca-new-spacing-section #1 #4 \time 1/4 \baca-time-signature-transparent s1 * 1/4 \once \override Score.BarLine.transparent = ##t \once \override Score.SpanBar.transparent = ##t <BLANKLINE> } <BLANKLINE> >> <BLANKLINE> \context MusicContext = "Music_Context" << <BLANKLINE> \context Staff = "Music_Staff" { <BLANKLINE> \context Voice = "Music_Voice" { <BLANKLINE> % [Music_Voice measure 1] \baca-not-yet-pitched-coloring b'4. - \abjad-dashed-line-with-hook - \baca-text-spanner-left-text "make_repeat_tied_notes()" - \tweak bound-details.right.padding 2.75 - \tweak color #darkcyan - \tweak staff-padding 8 \bacaStartTextSpanRhythmAnnotation - \tweak stencil ##f ~ <BLANKLINE> \baca-not-yet-pitched-coloring b'4 \repeatTie - \tweak stencil ##f ~ <BLANKLINE> \baca-not-yet-pitched-coloring b'4. \repeatTie - \tweak stencil ##f ~ <BLANKLINE> \baca-not-yet-pitched-coloring b'4 \repeatTie <> \bacaStopTextSpanRhythmAnnotation <BLANKLINE> << <BLANKLINE> \context Voice = "Music_Voice" { <BLANKLINE> % [Music_Voice measure 2] \abjad-invisible-music-coloring %@% \abjad-invisible-music \baca-not-yet-pitched-coloring b'1 * 1/4 %@% ^ \baca-duration-multiplier-markup #"1" #"4" <BLANKLINE> } <BLANKLINE> \context Voice = "Rest_Voice" { <BLANKLINE> % [Rest_Voice measure 2] \once \override Score.TimeSignature.X-extent = ##f \once \override MultiMeasureRest.transparent = ##t \stopStaff \once \override Staff.StaffSymbol.transparent = ##t \startStaff R1 * 1/4 %@% ^ \baca-duration-multiplier-markup #"1" #"4" <BLANKLINE> } <BLANKLINE> >> <BLANKLINE> } <BLANKLINE> } <BLANKLINE> >> <BLANKLINE> >> """ specifier: rmakers.Command specifiers_ = list(specifiers) specifier = rmakers.beam(classes.select().plts()) specifiers_.append(specifier) specifier = rmakers.repeat_tie(classes.select().pheads()[1:]) specifiers_.append(specifier) if not do_not_rewrite_meter: command = rmakers.rewrite_meter() specifiers_.append(command) specifier = rmakers.force_repeat_tie() specifiers_.append(specifier) return RhythmCommand( rmakers.stack(rmakers.note(), *specifiers_, tag=_site(inspect.currentframe())), annotation_spanner_color="#darkcyan", frame=inspect.currentframe(), )