def violin_pitches(): """ 1-175 """ aggregate = [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40] assert aggregate == [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40] cary = [[-2, -12, -10], [18, 8, 7, 17], [15, 25, 21, 4, 11]] order_1 = abjad.sequence.flatten(cary) order_1 = [_ % 12 for _ in order_1] assert order_1 == [10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11] order_2 = [abjad.sequence.rotate(_, n=1) for _ in cary] order_2 = abjad.sequence.rotate(order_2, n=-1) order_2 = abjad.sequence.flatten(order_2) order_2 = [_ % 12 for _ in order_2] assert order_2 == [5, 6, 8, 7, 11, 3, 1, 9, 4, 2, 10, 0] order_3 = [abjad.sequence.rotate(_, n=2) for _ in cary] order_3 = abjad.sequence.rotate(order_3, n=-2) order_3 = abjad.sequence.flatten(order_3) order_3 = [_ % 12 for _ in order_3] assert order_3 == [4, 11, 3, 1, 9, 0, 2, 10, 7, 5, 6, 8] aggregate_ = abjad.PitchSet(aggregate) violin_pitches = [] orders = (order_1, order_2, order_3) for order in orders: order = [abjad.NumberedPitchClass(_) for _ in order] pitches_ = baca.pcollections.register_pcs(aggregate_, order) violin_pitches.extend(pitches_) return violin_pitches
def create_named_pitch_set_in_pitch_range(self, pitch_range): r'''Creates named pitch-set in `pitch_range`. Returns pitch-set. ''' import abjad if not isinstance(pitch_range, abjad.PitchRange): pitch_range = abjad.PitchRange( float(abjad.NamedPitch(pitch_range[0])), float(abjad.NamedPitch(pitch_range[1]))) low = pitch_range.start_pitch.octave.number high = pitch_range.stop_pitch.octave.number pitches = [] octave = low while octave <= high: for x in self: pitch = abjad.NamedPitch((x.name, octave)) if (pitch_range.start_pitch <= pitch and pitch <= pitch_range.stop_pitch): pitches.append(pitch) octave += 1 return abjad.PitchSet( items=pitches, item_class=abjad.NamedPitch, )
def __init__(self, operator_string="&", pitches=None): import abjad assert operator_string in self._set_theoretic_operator_strings self._operator_string = operator_string # only intersection is currently implemented if not isinstance(pitches, collections.abc.Iterable): pitches = [pitches] pitches = abjad.PitchSet(items=pitches, item_class=abjad.NumberedPitch) self._pitches = pitches
def invert_down(segment, inversion): """ inverts a chord downwards assumes segment is within octave range returns new pitch segment Warning: no sanity check on transposition at the moment i.e. you can invert -433 times and still generate strings that represent pitches """ if inversion > 0: print("Inversion needs to be a negative int") interval = -12 new_segment = segment print("Initial segment: ", new_segment) for i in range(abs(inversion)): print("nwseg at top: ", new_segment) segment = new_segment highest_note = get_global_maxima( segment) #call global_minima to find lowest note print("top note: ", highest_note) set_ = abjad.PitchSet( items=[highest_note.name], item_class=abjad.NamedPitch, ) transposed_set = set_.transpose( interval) #transposed note is lowest note.tranpose("+P8") print("transposed note: ", transposed_set) transposed_pitch = None for i in transposed_set: transposed_pitch = abjad.NamedPitch(i) # initialize as named pitch print("items: ", i) print("transposed_pitch: ", transposed_pitch) new_pitches = [] segment_len = len(segment) section = range(0, segment_len - 1) # trim lowest note new_pitches.append(transposed_pitch) # append transposed for i in section: new_pitches.append(segment[i]) print(new_pitches) print("list of new pitches: ", new_pitches) new_segment = abjad.PitchSegment(new_pitches) # make new segment print("nwseg: ", new_segment) return new_segment
def has_duplicates(self): """ Is true when segment has duplicates. .. container:: example >>> segment = abjad.PitchSegment([-2, -1.5, 6, 7, -1.5, 7]) >>> segment.has_duplicates() True .. container:: example >>> segment = abjad.PitchSegment("c d e f g a b") >>> segment.has_duplicates() False Returns true or false. """ import abjad return len(abjad.PitchSet(self)) < len(self)
def invert_up(segment, inversion): """ inverts a chord upwards assumes segment is within octave range returns new pitch segment Warning: no sanity check on transposition at the moment i.e. you can invert 433 times and still generate strings that represent pitches """ interval = 12 new_segment = segment if inversion < 0: print("Inversion needs to be a positive int") for i in range(inversion): segment = new_segment lowest_note = get_global_minima( segment) #call global_minima to find lowest note set_ = abjad.PitchSet( items=[lowest_note.name], item_class=abjad.NamedPitch, ) transposed_set = set_.transpose( interval) #transposed note is lowest note.tranpose("+P8") transposed_pitch = None for i in transposed_set: transposed_pitch = abjad.NamedPitch(i) new_pitches = [] segment_len = len(segment) section = range(1, segment_len) # trim lowest note for i in section: new_pitches.append(segment[i]) new_pitches.append(transposed_pitch) # append transposed new_segment = abjad.PitchSegment(new_pitches) # make new segment return new_segment
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, ), )
def make_permutations(self, pitch_set): return list(permutations(pitch_set.items)) def __call__(self, duration, repetitions): self.duration = duration for cycle in range(repetitions): shuffle(self.permutation_sequence) self.add_permutation_sequence_to_staves(self.permutation_sequence) return abjad.Score(self.staves) def add_permutation_sequence_to_staves(self, permutation_sequence): for chord in permutation_sequence: for staff_number, pitch in enumerate(chord): note = abjad.Note(pitch, self.duration) self.staves[staff_number].append(note) if __name__ == "__main__": pset = abjad.PitchSet( ["g'", "a'", "b'"], item_class=abjad.NamedPitch, ) m = SkeletonMaker(pset) score = m(abjad.Duration(1,4), 10) abjad.show(score) abjad.play(score)