def __init__(self, items=None, *, intervals=None): if items is not None: assert isinstance(items, collections.abc.Iterable), repr(items) items = [abjad.NamedPitch(_) for _ in items] items = abjad.CyclicTuple(items) abjad.CyclicTuple.__init__(self, items=items) if intervals is not None: assert isinstance(items, collections.abc.Iterable), repr(items) intervals = abjad.CyclicTuple(intervals) self._intervals = intervals
def _make_cyclic_tuple_generator(iterable): import abjad cyclic_tuple = abjad.CyclicTuple(iterable) i = 0 while True: yield cyclic_tuple[i] i += 1
def moment_2(): """ >>> section, section_name = mraz.library.moment_2(), "section_2" >>> show_collections(section, section_name) section_2.stage_2.rh: [<6, 12, 16, 17, 20>, <10, 15, 23, 31, 33>, <2, 13, 20, 22, 27, 29>, <9, 11, 19, 30, 36>, <4, 5, 8, 10, 15>, <11, 19, 21>] [<2, 13, 20, 22, 27>, <5, 9, 11, 19, 30, 36>, <4, 5, 8, 10, 15, 23>, <7, 11, 21, 26, 37>, <8, 10, 15, 17, 21>] [<11, 19, 30, 36>, <4, 5, 8, 10>, <3, 11, 19, 21>, <2, 13, 20, 22, 27>, <5, 9, 11, 19>] [<6, 12, 16, 17>, <8, 10, 15>, <11, 19, 21>, <2, 13, 20, 22, 27>] [<5, 9, 11, 19, 30>, <0, 4, 5, 8>, <10, 15, 23, 31>, <11, 21, 26>] """ silver, names = silver_transform_7() silver = abjad.CyclicTuple(silver) segments = list(silver[14:20]) assert len(segments) == 6, repr(len(segments)) stages = abjad.sequence.partition_by_counts(segments, [2, 4]) segments = stages[1] counts = 2 * [5, 6, 6, 5, 5, 4] + 2 * [4, 5, 5, 4, 4, 3] segments = abjad.sequence.join(segments) segments = baca.pcollections.read(segments, counts) segments = baca.pcollections.remove_duplicates(segments, level=1) segments = abjad.sequence.partition_by_counts(segments, [6, 5, 5, 4, 4]) segments = [[abjad.PitchClassSegment(_) for _ in list_] for list_ in segments] segments = [[baca.pcollections.arpeggiate_up(_) for _ in list_] for list_ in segments] segments = baca.Cursor(segments, singletons=True) return types.SimpleNamespace( stage_1=None, stage_2=types.SimpleNamespace(rh=segments, ), )
def moment_6(): """ >>> section, section_name = mraz.library.moment_6(), "section_6" >>> show_collections(section, section_name) section_6.stage_1.rh: PC<6, 9, 11> PC<0, 8, 11, 1> PC<10, 1, 3> PC<2, 4, 0, 3, 5> PC<8, 4, 7, 9> section_6.stage_1.lh: PC<7, 8, 10, 9> PC<11, 0, 2, 1> PC<2, 5, 7, 3, 4> PC<6, 5> """ silver, names = silver_transform_7() silver = abjad.CyclicTuple(silver) segments = silver[42:45] segments = list(segments) assert len(segments) == 3, repr(len(segments)) stages = abjad.sequence.partition_by_counts(segments, [1, 1, 1]) stage_1_segments = stages[0] stage_1_segments = baca.sequence.accumulate( stage_1_segments, [lambda _: baca.pcollections.alpha(_), lambda _: _.transpose(n=2)], ) stage_1_segments = abjad.sequence.flatten(stage_1_segments) stage_1_segments = abjad.sequence.join(stage_1_segments) stage_1_segments = baca.pcollections.read(stage_1_segments, [3, 5, 4, 3, 4, 5, 5, 3, 4], check=abjad.EXACT) assert len(abjad.sequence.join(stage_1_segments)[0]) == 36 rh_indices = [0, 2, 3, 5, 8] rh_stage_1_segments = abjad.sequence.retain(stage_1_segments, rh_indices) rh_stage_1_segments = baca.pcollections.remove_duplicates( rh_stage_1_segments, level=1) rh_stage_1_segments = [ abjad.PitchClassSegment(_) for _ in rh_stage_1_segments ] lh_stage_1_segments = abjad.sequence.remove(stage_1_segments, rh_indices) lh_stage_1_segments = baca.pcollections.remove_duplicates( lh_stage_1_segments, level=1) lh_stage_1_segments = [ abjad.PitchClassSegment(_) for _ in lh_stage_1_segments ] assert len(rh_stage_1_segments) == 5 assert len(lh_stage_1_segments) == 4 rh_stage_1_segments = baca.Cursor(rh_stage_1_segments) lh_stage_1_segments = baca.Cursor(lh_stage_1_segments) return types.SimpleNamespace( stage_1=types.SimpleNamespace( rh=rh_stage_1_segments, lh=lh_stage_1_segments, ), stage_2=None, stage_3=None, stage_4=None, )
def _make_progression(self): """ Makes cyclic tuple of abjad.Chords""" chords = [] for chord_name in self._chord_names: chords.append(self.dictionary.get(chord_name)) self._chords = chords cyclic_tuple = abjad.CyclicTuple(self._chords) # make pitch material self._progression = cyclic_tuple # generate chord progression
def _make_time_signatures(): pairs = [[(4, 4), (4, 4), (4, 4)], [(3, 4), (3, 4)], [(4, 4), (4, 4), (2, 4)]] pairs = baca.sequence.helianthate(pairs, -1, -1) pairs = abjad.sequence.flatten(pairs) pairs = [abjad.TimeSignature(_) for _ in pairs] time_signatures = abjad.CyclicTuple(pairs) return time_signatures
def _burnish_each_division(class_, input_, divisions): import abjad left_classes = input_['left_classes'] middle_classes = input_['middle_classes'] right_classes = input_['right_classes'] left_counts = input_['left_counts'] left_counts = left_counts or abjad.CyclicTuple([0]) right_counts = input_['right_counts'] right_counts = right_counts or abjad.CyclicTuple([0]) lefts_index, rights_index = 0, 0 burnished_divisions = [] for division_index, division in enumerate(divisions): left_count = left_counts[division_index] left = left_classes[lefts_index:lefts_index + left_count] lefts_index += left_count right_count = right_counts[division_index] right = right_classes[rights_index:rights_index + right_count] rights_index += right_count available_left_count = len(division) left_count = min([left_count, available_left_count]) available_right_count = len(division) - left_count right_count = min([right_count, available_right_count]) middle_count = len(division) - left_count - right_count left = left[:left_count] if middle_classes: middle = middle_count * [middle_classes[division_index]] else: middle = middle_count * [0] right = right[:right_count] result = abjad.sequence(division).partition_by_counts( [left_count, middle_count, right_count], cyclic=False, overhang=False, ) left_part, middle_part, right_part = result left_part = class_._burnish_division_part(left_part, left) middle_part = class_._burnish_division_part(middle_part, middle) right_part = class_._burnish_division_part(right_part, right) burnished_division = left_part + middle_part + right_part burnished_divisions.append(burnished_division) unburnished_weights = [abjad.mathtools.weight(x) for x in divisions] burnished_weights = [ abjad.mathtools.weight(x) for x in burnished_divisions ] assert burnished_weights == unburnished_weights return burnished_divisions
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 add_pitches(music, pitches): # THIS IS HOW WE ADD PITCHES pitches = abjad.CyclicTuple(pitches) logical_ties = abjad.iterate(music).logical_ties(pitched=True) for i, logical_tie in enumerate(logical_ties): pitch = pitches[i] for note in logical_tie: note.written_pitch = pitch return music
def _burnish_outer_divisions(self, selections): import abjad left_classes = self.burnish_specifier.left_classes left_counts = self.burnish_specifier.left_counts right_classes = self.burnish_specifier.right_classes right_counts = self.burnish_specifier.right_counts if left_counts: assert len(left_counts) == 1, repr(left_counts) left_count = left_counts[0] else: left_count = 0 if right_counts: assert len(right_counts) == 1, repr(right_counts) right_count = right_counts[0] else: right_count = 0 if left_count + right_count <= len(selections): middle_count = len(selections) - (left_count + right_count) elif left_count <= len(selections): right_count = len(selections) - left_count middle_count = 0 else: left_count = len(selections) right_count = 0 middle_count = 0 assert left_count + middle_count + right_count == len(selections) new_selections = [] left_classes = abjad.CyclicTuple(left_classes) for i, selection in enumerate(selections[:left_count]): target_class = left_classes[i] new_selection = self._cast_selection(selection, target_class) new_selections.append(new_selection) if right_count: for selection in selections[left_count:-right_count]: new_selections.append(selection) right_classes = abjad.CyclicTuple(right_classes) for i, selection in enumerate(selections[-right_count:]): target_class = right_classes[i] new_selection = self._cast_selection(selection, target_class) new_selections.append(new_selection) else: for selection in selections[left_count:]: new_selections.append(selection) return new_selections
def _add_pitches(self, music, pitches): """ Add ``pitches`` to music. """ pitches = abjad.CyclicTuple(pitches) logical_ties = abjad.iterate(music).logical_ties(pitched=True) for i, logical_tie in enumerate(logical_ties): pitch = pitches[i] for note in logical_tie: note.written_pitch = pitch return music
def __getitem__(self, i) -> abjad.Pitch: if isinstance(i, slice): raise NotImplementedError iteration = i // len(self) if self.intervals is None: transposition = 0 else: transposition = sum(self.intervals[:iteration]) pitch_ = abjad.CyclicTuple(list(self))[i] pitch = type(pitch_)(pitch_.number + transposition) return pitch
def weave(self, staff, index=0, **kwargs): my_line = calliope.Line() for repeat in range(self.repeats): my_phrase = ImaginaryPhrase() for i, p in enumerate(self.pattern): my_accent = abjad.CyclicTuple(self.pattern_accent)[i] my_fill_in = abjad.CyclicTuple(self.pattern_fill_in)[i] my_pulse_type = abjad.CyclicTuple(self.pattern_pulse_type)[i] my_accent = abjad.CyclicTuple(self.pattern_accent)[i] if my_pulse_type == "all": my_rhythm = (self.pulse_duration, ) * p elif my_pulse_type == "first": if my_fill_in: my_rhythm = (p * self.pulse_duration, ) else: my_rhythm = (self.pulse_duration, self.pulse_duration - p * self.pulse_duration) else: # other if my_fill_in: q, r = divmod(p, 2) my_rhythm = [ self.pulse_duration * 2 for pq in range(q) ] if r: my_rhythm.append(self.pulse_duration) else: my_rhythm = [[ self.pulse_duration, 0 - self.pulse_duration ][pj % 2] for pj in range(p)] my_cell = ImaginaryCell(rhythm=my_rhythm) if my_accent: my_cell.note_events[0].tag(">") my_phrase.append(my_cell) my_line.append(my_phrase) return my_line
def __call__( self, durations=None, layer=None, division_masks=None, division_mask_seed=None, padding=None, seed=None, start_offset=None, timespan_specifier=None, voice_name=None, ): seed = seed or 0 rotation_indices = self.rotation_indices or (0, ) rotation_indices = abjad.CyclicTuple(rotation_indices) primary_durations = abjad.Sequence(durations) start_offset = start_offset or 0 if self.discard_inner_offsets: secondary_durations = [sum(primary_durations)] else: # secondary_durations = rotate( # primary_durations, # rotation_indices[seed], # ) secondary_durations = primary_durations.rotate( rotation_indices[seed]) primary_timespans = self.primary_music_specifier( durations=primary_durations, layer=layer, division_masks=division_masks, division_mask_seed=division_mask_seed, padding=padding, seed=seed, start_offset=start_offset, timespan_specifier=timespan_specifier, voice_name=self.primary_voice_name, ) secondary_timespans = self.secondary_music_specifier( durations=secondary_durations, layer=layer, division_masks=division_masks, division_mask_seed=division_mask_seed, padding=padding, seed=seed, start_offset=start_offset, timespan_specifier=timespan_specifier, voice_name=self.secondary_voice_name, ) timespans = primary_timespans[:] + secondary_timespans[:] timespans = abjad.TimespanList(timespans) timespans.sort() return timespans
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 weave(self, staff, index=0, **kwargs): pattern = abjad.CyclicTuple( (self.event_duration, ) * (self.dove_event_count + self.tail_event_count) + (0 - self.event_duration, ) * ((self.dove_event_count) * (self.dove_count - 1) - self.tail_event_count)) # abjac.CyclicTuple is unhappy about negative slice starts, so # reset offset if negative: if self.offset < 0: self.offset = self.offset % len(pattern) start_index = index * (self.dove_count - 1) * self.dove_event_count + self.offset my_rhythm = list( pattern[start_index:start_index + int(self.dovetail_duration / self.event_duration)]) # DO TO: THIS IS CONFUSING... document or rethink initial_tail_index = (start_index - self.dove_event_count) % len(pattern) if not self.tail_bookends[ 0] and initial_tail_index < self.tail_event_count: for i in range(self.tail_event_count - initial_tail_index): my_rhythm[i] = 0 - self.event_duration final_tail_index = start_index % len(pattern) if not self.tail_bookends[ 1] and final_tail_index <= self.tail_event_count: for i in range(final_tail_index): my_rhythm[0 - i - 1] = 0 - self.event_duration my_line = ImaginaryLine() cell_rhythm = [] last_rest = None for r in my_rhythm: my_is_rest = r < 0 if last_rest is not None and my_is_rest != last_rest: my_line.append(ImaginaryCell(rhythm=cell_rhythm)) cell_rhythm = [] cell_rhythm.append(r) last_rest = my_is_rest if cell_rhythm: my_line.append(ImaginaryCell(rhythm=cell_rhythm)) return my_line
def _populate_pitches(self, voice, pitch_range): import abjad assert isinstance(pitch_range, abjad.PitchRange) pitch_numbers = [ _ for _ in self._test_pitch_numbers if _ in pitch_range ] pitch_numbers = abjad.sequence(pitch_numbers).remove_repeats() pitch_numbers = abjad.CyclicTuple(pitch_numbers) logical_ties = abjad.iterate(voice).logical_ties(pitched=True) for i, logical_tie in enumerate(logical_ties): pitch_number = pitch_numbers[i] for note in logical_tie: note.written_pitch = pitch_number
def _make_timespans( self, layer=None, music_specifiers=None, target_timespan=None, timespan_list=None, ): new_timespans = abjad.TimespanList() if not self.voice_names and not self.labels: return new_timespans rotation_indices = self.rotation_indices or (0,) rotation_indices = abjad.CyclicTuple(rotation_indices) context_counter = collections.Counter() preexisting_timespans = self._collect_preexisting_timespans( target_timespan=target_timespan, timespan_list=timespan_list, ) partitioned_timespans = self._partition_preexisting_timespans( preexisting_timespans) for group_index, group in enumerate(partitioned_timespans): rotation_index = rotation_indices[group_index] offsets = set() offsets.add(group.start_offset) offsets.add(group.stop_offset) for timespan in group: if self.include_inner_starts: offsets.add(timespan.start_offset) if self.include_inner_stops: offsets.add(timespan.stop_offset) offsets = tuple(sorted(offsets)) durations = abjad.Sequence(mathtools.difference_series(offsets)) durations = durations.rotate(rotation_index) start_offset = offsets[0] for context_name, music_specifier in music_specifiers.items(): context_seed = context_counter[context_name] timespans = music_specifier( durations=durations, layer=layer, division_masks=self.division_masks, padding=self.padding, seed=context_seed, start_offset=start_offset, timespan_specifier=self.timespan_specifier, voice_name=context_name, ) context_counter[context_name] += 1 new_timespans.extend(timespans) return new_timespans
def _prepare_input(self): import abjad input_ = {} names = ( 'left_classes', 'left_counts', 'middle_classes', 'right_classes', 'right_counts', ) for name in names: value = getattr(self, name) value = value or () value = abjad.CyclicTuple(value) input_[name] = value return input_
def _ready_counts(self, counts, translation): total_duration = self.total_duration normalized_duration = total_duration.with_denominator(self.denominator) total_numerator = normalized_duration.numerator - translation counts = abjad.CyclicTuple(counts) repeated_counts = [] increment = 0 previous_sum = 0 while previous_sum < total_numerator: new_sum = sum(abs(_) for _ in repeated_counts) count = counts[increment] if new_sum + count <= total_numerator: repeated_counts.append(count) increment += 1 continue break return repeated_counts
def make_music(self, time_signature_pairs): music = self.make_basic_rhythm(time_signature_pairs, ) shards = abjad.mutate(music[:]).split(time_signature_pairs) beam_specifier = rmakers.BeamSpecifier( beam_divisions_together=self.beams, beam_each_division=self.beams, beam_rests=self.beams, ) time_signature_pairs = abjad.CyclicTuple(time_signature_pairs) for i, shard in enumerate(shards): leaves = abjad.select(shard).leaves() if not all(isinstance(_, abjad.Rest) for _ in leaves): beam_specifier([shard]) container = abjad.Container(time_signature_pairs[i]) abjad.mutate(shard).wrap(container) # music = self.add_attachments(music) return music
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 _scale_counts(self, divisions, talea_denominator, counts): import abjad talea_denominator = talea_denominator or 1 dummy_division = (1, talea_denominator) divisions.append(dummy_division) divisions = abjad.Duration.durations_to_nonreduced_fractions(divisions) dummy_division = divisions.pop() lcd = dummy_division.denominator multiplier = lcd / talea_denominator assert abjad.mathtools.is_integer_equivalent(multiplier) multiplier = int(multiplier) counts_ = {} for name, vector in counts.items(): vector = [multiplier * _ for _ in vector] vector = abjad.CyclicTuple(vector) counts_[name] = vector counts = counts_ return { 'divisions': divisions, 'lcd': lcd, 'counts': counts, }
def __init__(self, rtm, tie_across_divisions=False): self.rtm = abjad.CyclicTuple(rtm) self.tie_across_divisions = tie_across_divisions self._state = -1
def __init__(self, sequence=(1, 2, 3), index=None): self._sequence = abjad.CyclicTuple(sequence) if index is not None: index = int(index) self._index = index
def moment_8(): """ >>> section, section_name = mraz.library.moment_8(), "section_8" >>> show_collections(section, section_name) section_8.stage_3.rh: PC<7, 6> PC<7, 9, 1> PC<11, 8, 9> PC<1, 9, 8> PC<10, 2, 0, 11> PC<2, 10> PC<11, 1, 5> PC<3, 0, 1, 3> PC<0, 2> PC<6, 4, 3> PC<2, 3, 5> PC<9, 7> PC<11, 9, 5, 4> PC<6, 10, 8> section_8.stage_3.lh: PC<8, 0, 10> PC<11, 3> PC<10, 0, 4> PC<7, 5, 1> PC<2, 4, 8, 6> PC<4, 5, 7> """ silver, names = silver_transform_7() silver = abjad.CyclicTuple(silver) segments = silver[59:65] segments = list(segments) assert len(segments) == 6, repr(len(segments)) stages = abjad.sequence.partition_by_counts(segments, [1, 1, 1, 3]) stage_3_segments = baca.pcollections.remove_duplicates(stages[2]) stage_3_segments = [abjad.PitchClassSegment(_) for _ in stage_3_segments] stage_3_segments = baca.sequence.accumulate( stage_3_segments, [lambda _: baca.pcollections.alpha(_), lambda _: _.transpose(n=2)], ) stage_3_segments = abjad.sequence.join(stage_3_segments) stage_3_segments = abjad.sequence.flatten(stage_3_segments) stage_3_segments = baca.pcollections.read(stage_3_segments, 5 * [2, 3, 4, 3], check=abjad.EXACT) assert len(stage_3_segments) == 20 assert len(abjad.sequence.join(stage_3_segments)[0]) == 60 assert not baca.pcollections.has_repeats(stage_3_segments, level=-1) v5_indices = [0, 2, 3, 5, 6, 8, 9] v5_stage_3_segments = abjad.sequence.retain(stage_3_segments, v5_indices, period=10) v5_stage_3_segments = baca.pcollections.remove_repeats(v5_stage_3_segments, level=-1) v5_stage_3_segments = [ abjad.PitchClassSegment(_) for _ in v5_stage_3_segments ] assert not baca.pcollections.has_repeats(v5_stage_3_segments, level=-1) v6_stage_3_segments = abjad.sequence.remove(stage_3_segments, v5_indices, period=10) v6_stage_3_segments = baca.pcollections.remove_repeats(v6_stage_3_segments, level=-1) v6_stage_3_segments = [ abjad.PitchClassSegment(_) for _ in v6_stage_3_segments ] assert not baca.pcollections.has_repeats(v6_stage_3_segments, level=-1) assert len(v5_stage_3_segments) == 14, len(v5_stage_3_segments) assert len(v6_stage_3_segments) == 6, len(v6_stage_3_segments) v5_stage_3_segments = baca.Cursor(v5_stage_3_segments) v6_stage_3_segments = baca.Cursor(v6_stage_3_segments) return types.SimpleNamespace( stage_1=None, stage_2=None, stage_3=types.SimpleNamespace( rh=v5_stage_3_segments, lh=v6_stage_3_segments, ), stage_4=None, )
def moment_7(): """ >>> section, section_name = mraz.library.moment_7(), "section_7" >>> show_collections(section, section_name) section_7.stage_1.rh: [PC<4, 1, 0, 2, 6, 2>, PC<5, 7, 8, 10>, PC<11, 3, 9>] [PC<0, 2, 3, 5>] [PC<6, 10, 4>, PC<6, 7, 9, 4>] [PC<1, 5, 11>, PC<1, 2, 4, 11>, PC<5, 3, 9>] [PC<8, 9, 11, 6>] [PC<0, 10, 4>, PC<1, 10, 9, 11, 3, 11>, PC<7, 5, 11>] [PC<8, 5, 4, 6, 10, 6>] [PC<9, 11, 0, 2>, PC<3, 0, 11, 1, 5, 1>] [PC<4, 6, 7, 9>, PC<10, 2, 8>, PC<11, 1, 2, 4>] [PC<5, 9, 3>] [PC<5, 6, 8, 3>, PC<0, 4, 10>, PC<0, 1, 3, 10>] [PC<4, 2, 8>] section_7.stage_1.lh: [PC<6, 0, 4, 5, 8, 10, 3>, PC<11, 7, 11>] [PC<6, 2, 6>, PC<4, 9, 8, 3, 5, 10, 0>, PC<11, 4, 3, 10, 0, 5, 7>] [PC<11, 1, 9>] [PC<6, 8, 4>, PC<0, 11, 9, 10, 2, 4, 9>, PC<7, 6, 4, 5, 9, 11, 4>] [PC<10, 4, 8, 9, 0, 2, 7>] """ silver, names = silver_transform_7() silver = abjad.CyclicTuple(silver) segments = silver[45:59] segments = list(segments) assert len(segments) == 14, repr(len(segments)) rh_segments, lh_segments, stage_2_segments = abjad.sequence.partition_by_counts( segments, [5, 5, 4]) rh_segments = abjad.CyclicTuple(rh_segments) lh_segments = abjad.CyclicTuple(lh_segments) all_rh_segments = [] for i in range(8): start = i stop = i + 3 rh_segments_ = rh_segments[start:stop] index = i * 7 rh_segments_ = [_.transpose(n=index) for _ in rh_segments_] all_rh_segments.extend(rh_segments_) rh_segment_lists = abjad.sequence.partition_by_counts(all_rh_segments, [3, 1, 2, 3, 1], cyclic=True, overhang=True) assert len(rh_segment_lists) == 12 rh_segment_lists = baca.Cursor(rh_segment_lists, singletons=True) all_lh_segments = [] for i in range(5): start = i stop = i + 2 lh_segments_ = lh_segments[start:stop] index = i * 7 lh_segments_ = [_.transpose(n=index) for _ in lh_segments_] all_lh_segments.extend(lh_segments_) lh_segment_lists = abjad.sequence.partition_by_counts(all_lh_segments, [2, 3, 1, 3, 1], cyclic=True, overhang=True) assert len(lh_segment_lists) == 5 lh_segment_lists = baca.Cursor(lh_segment_lists, singletons=True) return types.SimpleNamespace( stage_1=types.SimpleNamespace( rh=rh_segment_lists, lh=lh_segment_lists, ), stage_2=None, )
def __call__(self, argument): r'''Calls rotation on `argument`. .. container:: example Duplicates once without period: >>> operator_ = abjad.Duplication(counts=1) >>> numbers = [1, 2, 3, 4] >>> operator_(numbers) [1, 2, 3, 4, 1, 2, 3, 4] .. container:: example Duplicates twice without period: >>> operator_ = abjad.Duplication(counts=2) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7]) >>> operator_(pitch_classes) PitchClassSegment([0, 1, 4, 7, 0, 1, 4, 7, 0, 1, 4, 7]) .. container:: example Duplicates periodically: >>> operator_ = abjad.Duplication(counts=1, period=3) >>> pitches = abjad.PitchSegment("c' d' e' f' g' a' b' c''") >>> for pitch in operator_(pitches): ... pitch ... NamedPitch("c'") NamedPitch("d'") NamedPitch("e'") NamedPitch("c'") NamedPitch("d'") NamedPitch("e'") NamedPitch("f'") NamedPitch("g'") NamedPitch("a'") NamedPitch("f'") NamedPitch("g'") NamedPitch("a'") NamedPitch("b'") NamedPitch("c''") NamedPitch("b'") NamedPitch("c''") .. container:: example Duplicate indices: >>> operator_ = abjad.Duplication( ... counts=1, ... indices=(0, -1), ... ) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7]) >>> operator_(pitch_classes) PitchClassSegment([0, 0, 1, 4, 7, 7]) .. container:: example Duplicate indices periodically: >>> operator_ = abjad.Duplication( ... counts=1, ... indices=(0,), ... period=2, ... ) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7, 9]) >>> operator_(pitch_classes) PitchClassSegment([0, 0, 1, 4, 4, 7, 9, 9]) .. container:: example Duplicate indices periodically with different counts: >>> operator_ = abjad.Duplication( ... counts=(1, 2), ... indices=(0,), ... period=2, ... ) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7, 9]) >>> operator_(pitch_classes) PitchClassSegment([0, 0, 1, 4, 4, 4, 7, 9, 9]) .. container:: example Cyclic counts: >>> operator_ = abjad.Duplication(counts=(0, 1, 2, 3)) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7, 9]) >>> operator_(pitch_classes) PitchClassSegment([0, 1, 1, 4, 4, 4, 7, 7, 7, 7, 9]) Returns new object with type equal to that of `argument`. ''' import abjad if not isinstance(argument, collections.Sequence): argument = (argument, ) counts = self.counts if isinstance(counts, int): counts = counts + 1 else: counts = [_ + 1 for _ in counts] if not self.period and not self.indices: if isinstance(counts, int): return type(argument)(argument * counts) else: counts = abjad.CyclicTuple(counts) result = [] for i, x in enumerate(argument): count = counts[i] result.extend([x] * count) if isinstance(argument, abjad.TypedCollection): result = abjad.new(argument, items=result) else: result = type(argument)(result) return result if isinstance(counts, int): counts = [counts] counts = abjad.CyclicTuple(counts) if not self.indices: if isinstance(argument, abjad.TypedCollection): result = abjad.new(argument, items=()) else: result = type(argument)() iterator = abjad.sequence(argument).partition_by_counts( [self.period], cyclic=True, overhang=True, ) for i, shard in enumerate(iterator): shard = type(argument)(shard) * counts[i] result = result + shard return result pattern = abjad.Pattern( indices=self.indices, period=self.period, ) result = [] length = len(argument) j = 0 for i, x in enumerate(argument): if pattern.matches_index(i, length): count = counts[j] result.extend([x] * count) j += 1 else: result.append(x) if isinstance(argument, abjad.TypedCollection): result = abjad.new(argument, items=result) else: result = type(argument)(result) return result
def moment_5(): """ >>> section, section_name = mraz.library.moment_5(), "section_5" >>> show_collections(section, section_name) section_5.stage_1.rh: PC<0, 2, 3, 5> section_5.stage_1.lh: PC<9, 1, 11, 8, 7> section_5.stage_2.rh: PC<2, 3, 5, 0> PC<9, 10, 0, 7, 4, 5, 3> PC<5, 6, 8, 3> PC<0, 1, 3, 10, 7, 8, 6> PC<4, 7, 9, 2> PC<1, 0, 2, 11, 6, 9, 7> PC<7, 10, 0, 5> PC<4, 3, 5, 2, 9, 0, 10> PC<6, 11, 1, 4> PC<5, 2, 4, 3, 8, 1, 11> PC<9, 2, 4, 7> PC<8, 5, 7, 6, 11, 4, 2> PC<8, 3, 5, 6> PC<9, 4, 6, 7, 10, 5, 3> PC<11, 6, 8, 9> PC<0, 7, 9, 10, 1, 8, 6> PC<10, 7, 9, 8> PC<1, 6, 8, 11, 0, 9, 7> PC<1, 10, 0, 11> PC<4, 9, 11, 2, 3, 0, 10> PC<0, 11, 1, 10> PC<5, 8, 10, 3, 2, 1, 11> PC<3, 2, 4, 1> PC<8, 11, 1, 6, 5, 4, 2> section_5.stage_2.lh: PC<11, 3, 1> PC<8, 4, 10, 1> PC<11, 7> PC<11, 3, 1, 8> PC<4, 10> PC<1, 11, 7> PC<11, 3> PC<1, 8, 4> PC<10, 1, 11, 7> """ silver, names = silver_transform_7() silver = abjad.CyclicTuple(silver) segments = silver[36:42] assert len(segments) == 6, repr(len(segments)) stages = abjad.sequence.partition_by_counts(segments, [2, 4]) stage_1_segments = stages[0] stage_2_segments = stages[1] stage_1_segments = baca.pcollections.remove_duplicate_pitch_classes( stage_1_segments, level=1) rh, lh = abjad.sequence.partition_by_counts(stage_1_segments, [1, 1]) rh = [abjad.PitchClassSegment(_) for _ in rh] lh = [abjad.PitchClassSegment(_) for _ in lh] rh = baca.Cursor(rh, singletons=True) lh = baca.Cursor(lh, singletons=True) stage_1_rh = rh stage_1_lh = lh stage_2_segments = baca.pcollections.remove_duplicate_pitch_classes( stage_2_segments, level=1) rh, lh = abjad.sequence.partition_by_counts(stage_2_segments, [2, 2]) rh = [abjad.PitchClassSegment(_) for _ in rh] rh = baca.sequence.accumulate( rh, [lambda _: _.transpose(n=3), lambda _: baca.pcollections.alpha(_)]) rh = abjad.sequence.flatten(rh) rh = baca.Cursor(rh, singletons=True) lh = abjad.sequence.repeat(lh, n=3) lh = abjad.sequence.flatten(lh) lh = [abjad.PitchClassSegment(_) for _ in lh] lh = baca.pcollections.read(lh, [3, 4, 2, 4, 2, 3, 2, 3, 4], check=abjad.EXACT) lh = [abjad.PitchClassSegment(_) for _ in lh] lh = baca.Cursor(lh, singletons=True) stage_2_rh = rh stage_2_lh = lh return types.SimpleNamespace( stage_1=types.SimpleNamespace( rh=stage_1_rh, lh=stage_1_lh, ), stage_2=types.SimpleNamespace( rh=stage_2_rh, lh=stage_2_lh, ), )
def moment_4(): """ >>> section, section_name = mraz.library.moment_4(), "section_4" >>> show_collections(section, section_name) section_4.stage_1.rh: PC<3, 1, 0, 10> PC<3, 1, 0, 10> PC<3, 1, 0, 10> section_4.stage_1.lh: PC<8, 2, 4> PC<8, 2, 4> PC<8, 2, 4> section_4.stage_2.lh: {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} {7, 11, 17, 18, 21} PC<6, 9, 7, 11, 7, 5, 2, 4, 8> section_4.stage_4.rh: PC<2, 8, 3, 9, 2, 5, 11, 4> PC<10, 5, 6, 0, 7, 1, 6, 9> PC<3, 8, 2, 9, 10, 4, 11, 5, 10, 1, 7, 0, 6, 1> section_4.stage_4.lh: {0, 10} {2, 5} {0, 4, 8} {10} {2, 5} {4, 8} {0, 5, 10} {2, 4, 8} section_4.stage_5.rh: PC<3> PC<5> PC<10> PC<3> PC<5> PC<10> section_4.stage_5.lh: PC<11, 6, 7, 9, 1> PC<10, 1, 8, 9, 11> PC<3, 0, 10, 11, 1> PC<5, 2, 0, 1> PC<3, 7, 4, 2> PC<3, 5, 9, 6, 4> PC<5, 7, 11, 8> PC<6, 7, 9, 1, 10> PC<1, 8, 9, 11, 3, 0> PC<3, 10, 11, 1, 5> PC<2, 5, 0, 1, 3> PC<7, 4, 2, 3, 5> PC<9, 6, 4, 5> PC<7, 11, 8, 6> PC<7, 9, 1, 10, 8> section_4.stage_6.rh: {17, 27, 36, 40, 42, 46} {-3, 7, 8, 11, 13, 17, 27, 36} {4, 6, 10, 21, 31, 32, 35, 37} """ silver, names = silver_transform_7() silver = abjad.CyclicTuple(silver) segments = silver[23:36] segments = list(segments) assert len(segments) == 13, repr(len(segments)) stages = abjad.sequence.partition_by_counts(segments, [2, 2, 2, 2, 2, 3]) stage_1_segments = stages[0] stage_2_segments = stages[1] stage_4_segments = stages[3] stage_5_segments = stages[4] stage_6_segments = stages[5] stage_1_rh_segments = stage_1_segments[:1] stage_1_rh_segments = abjad.sequence.repeat(stage_1_rh_segments, n=3) stage_1_rh_segments = abjad.sequence.flatten(stage_1_rh_segments) stage_1_rh_segments = baca.Cursor(stage_1_rh_segments) stage_1_lh_segments = stage_1_segments[1:] stage_1_lh_segments = abjad.sequence.repeat(stage_1_lh_segments, n=3) stage_1_lh_segments = abjad.sequence.flatten(stage_1_lh_segments) stage_1_lh_segments = baca.Cursor(stage_1_lh_segments) chord = abjad.PitchSet(stage_2_segments[0]) chord = baca.pcollections.space_up(chord, bass=7, soprano=9) chords = 10 * [chord] last = abjad.sequence.join(stages[1])[0] chords.append(last) stage_2_segments = baca.Cursor(chords, cyclic=False, singletons=True) assert len(stage_4_segments) == 2 rh, lh = abjad.sequence.partition_by_counts(stage_4_segments, [1, 1]) lh = baca.pcollections.remove_duplicates(lh, level=-1) lh = baca.pcollections.read(lh, [2, 2, 3, 1, 2, 2, 3, 3], check=abjad.EXACT) lh = [abjad.PitchClassSegment(_) for _ in lh] lh = [abjad.PitchSet(_) for _ in lh] lh = baca.Cursor(lh, cyclic=True, singletons=True) rh = baca.sequence.accumulate( rh, [lambda _: baca.pcollections.alpha(_), lambda _: _.transpose(n=2)]) if isinstance(rh, list): rh = abjad.sequence.flatten(rh) rh = abjad.sequence.join(rh) rh = baca.pcollections.remove_repeats(rh) rh = baca.pcollections.read(rh, [8, 8, 14], check=abjad.EXACT) rh = [abjad.PitchClassSegment(_) for _ in rh] rh = baca.Cursor(rh) stage_4_rh_segments = rh stage_4_lh_segments = lh stage_5_segments = baca.pcollections.remove_duplicate_pitch_classes( stage_5_segments, level=1) rh, lh = abjad.sequence.partition_by_counts(stage_5_segments, [1, 1]) rh = baca.pcollections.read(rh, 6 * [1], check=abjad.EXACT) rh = [abjad.PitchClassSegment(_) for _ in rh] rh = baca.Cursor(rh, singletons=True) lh = [abjad.PitchClassSegment(_) for _ in lh] lh = baca.sequence.accumulate(lh, [lambda _: _.transpose(n=2)]) if isinstance(lh, list): lh = abjad.sequence.flatten(lh) lh = abjad.sequence.join(lh) lh = baca.pcollections.read(lh, 5 * [5, 5, 6]) lh = baca.pcollections.remove_duplicates(lh, level=1) lh = [abjad.PitchClassSegment(_) for _ in lh] lh = baca.Cursor(lh, singletons=True) stage_5_rh_segments = rh stage_5_lh_segments = lh stage_6_segments = [abjad.PitchClassSegment(_) for _ in stage_6_segments] stage_6_segments = abjad.sequence.repeat(stage_6_segments, n=2) stage_6_segments = abjad.sequence.flatten(stage_6_segments) stage_6_segments = abjad.sequence.partition_by_counts(stage_6_segments, [2], cyclic=True) stage_6_segments = [abjad.sequence.join(_)[0] for _ in stage_6_segments] stage_6_segments = baca.pcollections.remove_duplicates(stage_6_segments, level=1) stage_6_segments = [ baca.pcollections.arpeggiate_up(_) for _ in stage_6_segments ] stage_6_segments = [ baca.pcollections.soprano_to_octave(_, n=7) for _ in stage_6_segments ] stage_6_segments = [abjad.PitchSet(_) for _ in stage_6_segments] stage_6_segments = baca.Cursor(stage_6_segments, singletons=True) return types.SimpleNamespace( stage_1=types.SimpleNamespace( rh=stage_1_rh_segments, lh=stage_1_lh_segments, ), stage_2=types.SimpleNamespace( rh=None, lh=stage_2_segments, ), stage_3=None, stage_4=types.SimpleNamespace( rh=stage_4_rh_segments, lh=stage_4_lh_segments, ), stage_5=types.SimpleNamespace( rh=stage_5_rh_segments, lh=stage_5_lh_segments, ), stage_6=types.SimpleNamespace( rh=stage_6_segments, lh=None, ), )