def test_ArtificialHarmonic_13(): harm = auxjad.ArtificialHarmonic(r"<g c'>4") assert harm.written_pitches == abjad.PitchSegment(r"g c'") harm.written_pitches = r"a d'" assert harm.written_pitches == abjad.PitchSegment(r"a d'") with pytest.raises(ValueError): harm.written_pitches = r"a d' e'"
def test_PitchRandomiser_02(): container = abjad.Container(r"c'4 d'4 e'4 f'4") randomiser = auxjad.PitchRandomiser( container, pitches=r"a b cs' ds' e'", weights=[1.0, 2.0, 1.0, 1.5, 1.3], omit_time_signatures=True, process_on_first_call=True, use_tenney_selector=True, ) assert randomiser.pitches == abjad.PitchSegment(r"a b cs' ds' e'") assert randomiser.weights == [1.0, 2.0, 1.0, 1.5, 1.3] assert randomiser.omit_time_signatures assert randomiser.process_on_first_call assert randomiser.use_tenney_selector randomiser.pitches = abjad.PitchSegment(r"c' d' e' f'") randomiser.weights = [1, 2, 5, 8] randomiser.omit_time_signatures = False randomiser.process_on_first_call = False randomiser.use_tenney_selector = False assert randomiser.pitches == abjad.PitchSegment(r"c' d' e' f'") assert randomiser.weights == [1, 2, 5, 8] assert not randomiser.omit_time_signatures assert not randomiser.process_on_first_call assert not randomiser.use_tenney_selector
def test_ArtificialHarmonic_06(): harm = auxjad.ArtificialHarmonic(r"<g c'>4") assert harm.written_pitches == abjad.PitchSegment(r"g c'") assert harm.written_duration == 1 / 4 assert harm.style == "#'harmonic" assert not harm.is_parenthesized harm.written_pitches = [-5, 2] harm.written_duration = abjad.Duration(1, 8) harm.style = "#'harmonic-mixed" harm.is_parenthesized = True assert harm.written_pitches == abjad.PitchSegment(r"g d'") assert harm.written_duration == 1 / 8 assert harm.style == "#'harmonic-mixed" assert harm.is_parenthesized
def __init__(self, pitch_segment=None, ratio=None): if pitch_segment is not None: pitch_segment = abjad.PitchSegment(pitch_segment) self._pitch_segment = pitch_segment if ratio is not None: ratio = abjad.Ratio(ratio) self._ratio = ratio
def voice_scale_degrees_in_open_position(self, scale_degrees): r'''Voices `scale_degrees` in open position. .. container:: example >>> scale = abjad.tonalanalysistools.Scale(('c', 'major')) >>> scale_degrees = [1, 3, 'b5', 7, '#9'] >>> segment = scale.voice_scale_degrees_in_open_position( ... scale_degrees) >>> segment PitchSegment("c' e' gf' b' ds''") Return pitch segment. ''' import abjad from abjad.tools import tonalanalysistools scale_degrees = [ tonalanalysistools.ScaleDegree(x) for x in scale_degrees ] pitch_classes = [ self.scale_degree_to_named_pitch_class(x) for x in scale_degrees ] pitches = [abjad.NamedPitch(pitch_classes[0])] for pitch_class in pitch_classes[1:]: pitch = abjad.NamedPitch(pitch_class) while pitch < pitches[-1]: pitch += 12 pitches.append(pitch) pitches = abjad.PitchSegment(pitches) return pitches
def __init__(self, pitch_segment=None, sequence=None): self._pitch_segment = pitch_segment or abjad.PitchSegment() self._sequence = sequence or tuple() self._reorder_segment() self._make_ascent() self._set_arp_pitches() self._set_arp_strings()
def test_virtual_fundamental_10(): pitches = abjad.PitchSegment(r"c'' cs'' d'' ef'' e'' fs''") with pytest.raises(ValueError): auxjad.get.virtual_fundamental( pitches, min_fundamental=abjad.NamedPitch(r"c'"), )
def test_virtual_fundamental_09(): pitches = abjad.PitchSegment(r"c'' cs'' d'' ef'' e'' fs''") fundamental = auxjad.get.virtual_fundamental( pitches, min_fundamental=abjad.NumberedPitch(-48), ) assert fundamental == abjad.NamedPitch(r"d,,")
def _reorder_segment(self): """Sets a reordered segment according to sequence""" pitches = [] for i in range(len(self._sequence)): seq_val = self._sequence[i] pitches.append(self._pitch_segment[seq_val]) self._reordered_segment = abjad.PitchSegment(pitches) print("Reordered pitches: ", self._reordered_segment)
def add_pitches(self, score): pitches = abjad.PitchSegment("g b d' f'") logical_ties = abjad.select(score).logical_ties(pitched=True) for i, logical_tie in enumerate(logical_ties): index = i % len(pitches) pitch = pitches[index] for note in logical_tie: note.written_pitch = pitch return score
def written_pitches( self, written_pitches, ) -> None: written_pitches_ = abjad.PitchSegment(written_pitches) if len(written_pitches_) != 2: raise ValueError("'ArtificialHarmonic' requires exactly two " "pitches") for index, pitch in enumerate(written_pitches_): self._note_heads[index].written_pitch = pitch
def test_PitchRandomiser_10(): container = abjad.Container(r"c'8 d'8 e'8 f'8 g'8 a'8 b'8 c'8") pitches = r"fs' gs' a' b'" randomiser = auxjad.PitchRandomiser(container, pitches, weights=[100.0, 1.0, 1.0, 1.0], ) randomiser.pitches = r"c'' d'' e'' f''" assert randomiser.pitches == abjad.PitchSegment(r"c'' d'' e'' f''") assert randomiser.weights == [100.0, 1.0, 1.0, 1.0]
def find_pitches(self, abjad_pitch: abjad.NamedPitch) -> None: from mutools import lily basic_pitch = abjad.NamedPitch( lily.round_scale_index_to_12th_tone( float(abjad_pitch) - self.ground_interval)) harmonic_pitch = abjad.NamedPitch( lily.round_scale_index_to_12th_tone( float(basic_pitch) + self.harmonic_interval)) return abjad.PitchSegment([basic_pitch, harmonic_pitch])
def __call__(self, argument): """ Calls retrograde on `argument`. .. container:: example Gets retrograde pitch classes: >>> retrograde = abjad.Retrograde() >>> segment = abjad.PitchClassSegment([0, 1, 4, 7]) >>> retrograde(segment) PitchClassSegment([7, 4, 1, 0]) .. container:: example Does not retrograde single pitches or pitch-classes: >>> retrogresion = abjad.Retrograde() >>> pitch_class = abjad.NumberedPitchClass(6) >>> retrograde(pitch_class) NumberedPitchClass(6) .. container:: example Periodic retrograde: .. todo:: Deprecated. >>> retrograde = abjad.Retrograde(period=3) >>> segment = abjad.PitchSegment("c' d' e' f' g' a' b' c''") >>> retrograde(segment) PitchSegment("e' d' c' a' g' f' c'' b'") Returns new object with type equal to that of `argument`. """ import abjad if isinstance(argument, (abjad.Pitch, abjad.PitchClass)): return argument if not isinstance(argument, ( abjad.PitchSegment, abjad.PitchClassSegment, )): argument = abjad.PitchSegment(argument) if not self.period: return type(argument)(reversed(argument)) result = abjad.new(argument, items=()) for shard in abjad.sequence(argument).partition_by_counts( [self.period], cyclic=True, overhang=True, ): shard = type(argument)(shard) shard = type(argument)(reversed(shard)) result = result + shard return result
def test_new_02(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment('c d e f'), ratio=abjad.Ratio([1, 2, 3])) assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) new_aggregate = abjad.new( old_aggregate, ratio=(4, 5), ) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) assert format(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((4, 5)), ) """)
def test_new_01(): old_aggregate = Aggregate( pitch_segment=abjad.PitchSegment("c d e f"), ratio=abjad.Ratio([1, 2, 3]), ) assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) new_aggregate = abjad.new(old_aggregate) assert new_aggregate is not old_aggregate assert new_aggregate == old_aggregate assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) assert abjad.storage(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """)
def _get_artifical_harmonic_pitches(pitch: ji.JIPitch) -> tuple: ground_pitch = lily.convert2abjad_pitch(pitch, globals_.RATIO2PITCHCLASS) ( harmonic_pitch_class, harmonic_octave_difference, ) = globals_.RATIO2ARTIFICAL_HARMONIC_PITCHCLASS_AND_ARTIFICIAL_HARMONIC_OCTAVE[ pitch.register(0)] harmonic_pitch_octave = ground_pitch.octave.number + harmonic_octave_difference harmonic_pitch = abjad.NamedPitch(name=harmonic_pitch_class, octave=harmonic_pitch_octave) return abjad.PitchSegment(sorted([ground_pitch, harmonic_pitch]))
def test_new_03(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment('c d e f'), ) assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) new_aggregate = abjad.new( old_aggregate, pitch_segment='af bf df', ratio=(5, 4), ) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) assert format(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('af'), abjad.NamedPitch('bf'), abjad.NamedPitch('df'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((5, 4)), ) """)
def test_new_05(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment("c d e f")) assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) new_aggregate = abjad.new(old_aggregate, ratio=[4, 5], pitch_segment__rotate=2) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) assert abjad.storage(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('e'), abjad.NamedPitch('f'), abjad.NamedPitch('c'), abjad.NamedPitch('d'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((4, 5)), ) """)
def guitar_bitones_test(): print( "Running guitar bitones test using ``muda.Material.guitar_bitones()`` method." ) timespans = muda.alternating_timespans([[1, 1], [1, 1], [1, 1]], 4, ["matA", "matB"]) durations = timespans.annotated_durations(subdivision=(2, 4)) makers = { "matA": rmakers.stack(rmakers.note()), "matB": rmakers.stack(rmakers.note()) } mat = muda.Material("A") mat.alternating_materials(durations, makers) pitches = { "matA": abjad.PitchSegment("fs'"), "matB": abjad.PitchSegment("ds'"), } pitched_leaves = lambda _: abjad.select.leaves(_) mat.write_pitches_by_name(pitches) mat.attach(abjad.StringNumber([2]), pitched_leaves, "matA") mat.attach(abjad.StringNumber([3]), pitched_leaves, "matB") mat.guitar_bitones(pitched_leaves, "matA", hammering=True) mat.print()
def material_test(): print( "Running material test using ``muda.Material()`` class and its methods." ) timespans = muda.alternating_timespans([[1, 1], [1, 1], [1, 1]], 2, ["matA", "matB"]) durations = timespans.annotated_durations(subdivision=(2, 4)) makers = { "matA": rmakers.stack(rmakers.talea([-1, 2, -1], 16), rmakers.extract_trivial()), "matB": rmakers.stack(rmakers.talea([1, 1, 1, 1], 16), rmakers.extract_trivial()), } mat = muda.Material("A") mat.alternating_materials(durations, makers) pitches = { "matA": abjad.PitchSegment("fs'"), "matB": abjad.PitchSegment("ds'"), } mat.write_pitches_by_name(pitches) mat.material_name_markups(["matA", "matB"])
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 pitches( self, pitches: Union[list[Union[int, float, str, abjad.Pitch]], tuple[Union[int, float, str, abjad.Pitch]], str, abjad.PitchSegment, ], ) -> None: if not isinstance(pitches, (list, tuple, str, abjad.PitchSegment)): raise TypeError("'pitches' must be 'list', 'tuple', 'str', or " "'abjad.PitchSegment'") if isinstance(pitches, (list, tuple, str)): self._pitches = abjad.PitchSegment(pitches) else: self._pitches = pitches pitch_list = [pitch for pitch in self._pitches] self._tenney_selector = TenneySelector(pitch_list) if self._weights is not None: if len(pitch_list) != len(self._weights): self.weights = None
def written_pitches(self): """ Written pitches in chord. .. container:: example Get written pitches: >>> chord = abjad.Chord("<g' c'' e''>4") >>> abjad.show(chord) # doctest: +SKIP >>> chord.written_pitches PitchSegment("g' c'' e''") .. container:: example Set written pitches with pitch names: >>> chord = abjad.Chord("<e' g' c''>4") >>> abjad.show(chord) # doctest: +SKIP >>> chord.written_pitches = "f' b' d''" >>> abjad.show(chord) # doctest: +SKIP .. docs:: >>> abjad.f(chord) <f' b' d''>4 >>> chord.written_pitches PitchSegment("f' b' d''") Set written pitches with any iterable. Returns tuple. """ import abjad return abjad.PitchSegment( items=(note_head.written_pitch for note_head in self.note_heads), item_class=abjad.NamedPitch, )
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
import abjad import abjadext.rmakers staff = abjad.Staff( segment = ( abjad.PitchSegment( [ "e'", "ef'", "c'" "cs'" ] ) ) rhs = [(1, 4), (3, 8), (2, 4), (1, 8)] rhythms = [abjad.Duration(x) for x in rhs] zip(pitches, abjad.select(rhythms).logical_ties(pitched=True): for leaf in tie: leaf.written_pitch = pitch) ) abjad.f(staff)
def __call__(self, argument): """ Calls rotation on `argument`. .. container:: example Rotates pitch classes: >>> rotation = abjad.Rotation(n=1) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7]) >>> rotation(pitch_classes) PitchClassSegment([7, 0, 1, 4]) .. container:: example Rotates pitch classes with Stravinsky-style back-transposition to zero: >>> rotation = abjad.Rotation(n=1, stravinsky=True) >>> pitch_classes = abjad.PitchClassSegment([0, 1, 4, 7]) >>> rotation(pitch_classes) PitchClassSegment([0, 5, 6, 9]) .. container:: example Does not rotate single pitches or pitch-classes: >>> rotation = abjad.Rotation(n=1) >>> pitch_class = abjad.NumberedPitchClass(6) >>> rotation(pitch_class) NumberedPitchClass(6) .. container:: example Periodic rotation: .. todo:: Deprecated. >>> rotation = abjad.Rotation(n=1, period=3) >>> pitches = abjad.PitchSegment("c' d' e' f' g' a' b' c''") >>> rotation(pitches) PitchSegment("e' c' d' a' f' g' c'' b'") .. container:: example Stravinsky-style periodic rotation: .. todo:: Deprecated. >>> rotation = abjad.Rotation( ... n=1, ... period=3, ... stravinsky=True, ... ) >>> pitches = abjad.PitchSegment("c' d' e' f' g' a' b' c''") >>> rotation(pitches) PitchSegment("c' af bf f' df' ef' b' as'") Returns new object with type equal to that of `argument`. """ import abjad if isinstance(argument, (abjad.Pitch, abjad.PitchClass)): return argument if not isinstance(argument, ( abjad.PitchSegment, abjad.PitchClassSegment, )): argument = abjad.PitchSegment(argument) if not self.period: return argument.rotate(self.n, stravinsky=self.stravinsky) result = abjad.new(argument, items=()) for shard in abjad.sequence(argument).partition_by_counts( [self.period], cyclic=True, overhang=True, ): shard = type(argument)(shard) shard = shard.rotate(self.n, stravinsky=self.stravinsky) result = result + shard return result
import abjad chord_01 = abjad.PitchSegment("af'' g'' fs'' " + "f'' d'' cs'' " + "b'' af'' g'' " + "e'' c'' g'' " + "fs'' cs'' gs''") chord_02 = abjad.PitchSegment("af'' g'' fs'' " + "f'' d'' cs'' " + "b'' af'' g'' " + "e'' c'' g'' " + "fs'' cs'' gs''") pitch_list_01 = [ chord_01, chord_02, chord_01, chord_02, chord_01, chord_02, chord_01 ]
def test_virtual_fundamental_11(): pitches = abjad.PitchSegment(r"c'' g''") fundamental = abjad.get.virtual_fundamental(pitches) assert fundamental == abjad.NamedPitch(r"c'")
def test_virtual_fundamental_04(): pitches = abjad.PitchSegment(r"c'' d'' ef'' fs''") fundamental = auxjad.get.virtual_fundamental(pitches) assert fundamental == abjad.NamedPitch(r"bf,,")