def invert(self, axis=None): """ Inverts numbered pitch-class. .. container:: example >>> for n in range(12): ... pitch_class = abjad.NumberedPitchClass(n) ... print(repr(pitch_class), repr(pitch_class.invert())) ... NumberedPitchClass(0) NumberedPitchClass(0) NumberedPitchClass(1) NumberedPitchClass(11) NumberedPitchClass(2) NumberedPitchClass(10) NumberedPitchClass(3) NumberedPitchClass(9) NumberedPitchClass(4) NumberedPitchClass(8) NumberedPitchClass(5) NumberedPitchClass(7) NumberedPitchClass(6) NumberedPitchClass(6) NumberedPitchClass(7) NumberedPitchClass(5) NumberedPitchClass(8) NumberedPitchClass(4) NumberedPitchClass(9) NumberedPitchClass(3) NumberedPitchClass(10) NumberedPitchClass(2) NumberedPitchClass(11) NumberedPitchClass(1) Interprets axis of inversion equal to pitch-class 0. Returns new numbered pitch-class. """ import abjad axis = axis or abjad.NumberedPitch('c') axis = abjad.NumberedPitch(axis) this = abjad.NumberedPitch(self) interval = this - axis result = axis.transpose(interval) result = type(self)(result) return result
def test_init(input_, expected_semitones): if isinstance(expected_semitones, type) and issubclass( expected_semitones, Exception): with pytest.raises(expected_semitones): abjad.NumberedPitch(input_) return instance = abjad.NumberedPitch(input_) assert float(instance) == expected_semitones
def custom_ties(music): tuplets = abjad.select(music).tuplets() for tuplet in tuplets: leaves = abjad.select(tuplet).leaves() for leaf in leaves: if not isinstance(leaf, abjad.Rest): pitch = [leaf.written_pitch] abjad.mutate(leaf).replace( abjad.Chord(pitch, leaf.written_duration)) leaves2 = abjad.select(tuplet).leaves() # print(leaves2) for leaf1, leaf2 in zip(leaves2, leaves2[1:]): if isinstance(leaf1, abjad.Chord): pitch1 = leaf1.written_pitches pitch2 = leaf2.written_pitches interval = abjad.NumberedPitch( pitch2[0]) - abjad.NumberedPitch(pitch1[0]) interval = abs(interval.number) if interval <= 10 and interval != 0: leaf2.written_pitches = [pitch1[0], pitch2[0]] # TIES selection = abjad.select(music).leaves().logical_ties() # verify next leave to apply ties correctly for leave, next_leave in zip(selection, selection[1:]): if isinstance(leave[-1], abjad.Note) and isinstance( next_leave[0], abjad.Chord): # verify if there are same pitches in both leaves for item in next_leave[0].written_pitches: if item == leave[-1].written_pitch: # print("note-chord tie:" + str(leave[-1])) abjad.attach(abjad.Tie(), leave[-1]) if isinstance(leave[-1], abjad.Note) and isinstance( next_leave[0], abjad.Note): if leave[-1].written_pitch == next_leave[0].written_pitch: # print("note-note tie:" + str(leave[-1])) abjad.attach(abjad.Tie(), leave[-1]) # if leave is chord if isinstance(leave[-1], abjad.Chord) and isinstance( next_leave[0], abjad.Chord): # verify if there are same pitches in both leaves if set(leave[-1].written_pitches) & set( next_leave[0].written_pitches): # print("chord-chord tie:" + str(leave[-1])) abjad.attach(abjad.Tie(), leave[-1]) if isinstance(leave[-1], abjad.Chord) and isinstance( next_leave[0], abjad.Note): for item in leave[-1].written_pitches: # print("chord-note tie:" + str(leave[-1])) if item == next_leave[0].written_pitch: abjad.attach(abjad.Tie(), leave[-1]) tuplets = abjad.select(music).tuplets() for tuplet in tuplets: if tuplet.multiplier == 1: abjad.mutate(tuplet).extract() return music
def _get_intervals_in_subrun(subrun_source): subrun_source = list(subrun_source) result = [0] for first, second in abjad.Sequence(subrun_source).nwise(): first_pitch = abjad.NamedPitch(first) second_pitch = abjad.NamedPitch(second) interval = (abjad.NumberedPitch(second_pitch).number - abjad.NumberedPitch(first_pitch).number) result.append(interval + result[-1]) result.pop(0) return result
def tune_to_ratio( note_head, ratio, quarter_tones=False, ): """ Tunes pitch to ratio. """ ratio = quicktions.Fraction(ratio) log_ratio = quicktions.Fraction(math.log10(ratio)) log_2 = quicktions.Fraction(1200 / math.log10(2)) ji_cents = quicktions.Fraction(log_ratio * log_2) semitones = ji_cents / 100 parts = math.modf(semitones) pitch = abjad.NumberedPitch(note_head.written_pitch) + parts[1] remainder = round(parts[0] * 100) if 50 < abs(remainder): if 0 < remainder: pitch += 1 remainder = -100 + remainder else: pitch -= 1 remainder = 100 + remainder if quarter_tones: if 25 < abs(remainder): if 0 < remainder: pitch += 0.5 remainder = -50 + remainder else: pitch -= 0.5 remainder = 50 + remainder note_head.written_pitch = pitch
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 _calculate_pitch_and_deviation( self, pitch, ratio, ): ratio = quicktions.Fraction(ratio) log_ratio = quicktions.Fraction(math.log10(ratio)) log_2 = quicktions.Fraction(1200 / math.log10(2)) ji_cents = quicktions.Fraction(log_ratio * log_2) semitones = ji_cents / 100 parts = math.modf(semitones) pitch = abjad.NumberedPitch(pitch) + parts[1] remainder = round(parts[0] * 100) if 50 < abs(remainder): if 0 < remainder: pitch += 1 remainder = -100 + remainder else: pitch -= 1 remainder = 100 + remainder if self.with_quarter_tones: if 25 < abs(remainder): if 0 < remainder: pitch += 0.5 remainder = -50 + remainder else: pitch -= 0.5 remainder = 50 + remainder return pitch, remainder
def return_cent_markup( note_head, ratio, quarter_tones=False, ): ratio = quicktions.Fraction(ratio) log_ratio = quicktions.Fraction(math.log10(ratio)) log_2 = quicktions.Fraction(1200 / math.log10(2)) ji_cents = quicktions.Fraction(log_ratio * log_2) semitones = ji_cents / 100 parts = math.modf(semitones) pitch = abjad.NumberedPitch(note_head.written_pitch) + parts[1] remainder = round(parts[0] * 100) if 50 < abs(remainder): if 0 < remainder: pitch += 1 remainder = -100 + remainder else: pitch -= 1 remainder = 100 + remainder if quarter_tones: if 25 < abs(remainder): if 0 < remainder: pitch += 0.5 remainder = -50 + remainder else: pitch -= 0.5 remainder = 50 + remainder if remainder < 0: cent_string = f"{remainder}" else: cent_string = f"+{remainder}" mark = abjad.Markup(rf"\markup \center-align {cent_string}", direction=abjad.Up) return mark
def numbered_pitch_list(self): """Gets pitches from segment as numbered pitches""" pitch_list = self.pitch_list num_pitch_list = [] for pitch in pitch_list: num_pitch = abjad.NumberedPitch(pitch) num_pitch_list.append(int(str(num_pitch))) return num_pitch_list
def _make_new_notes(anchor_pitch, anchor_written_duration, subrun_intervals): new_notes = [] for subrun_interval in subrun_intervals: new_pc = abjad.NumberedPitch(anchor_pitch).number new_pc += subrun_interval new_pc %= 12 new_note = abjad.Note(new_pc, anchor_written_duration) new_notes.append(new_note) return new_notes
def combination_tones(pitches=[0, 5, 7], depth=1): """ .. container:: example >>> print( ... evans.combination_tones( ... pitches=[ ... 8.25, ... 18.75, ... 23.5, ... ], ... depth=1, ... ) ... ) [-2.0, 6.0, 8.0, 14.5, 19.0, 23.5, 26.0, 29.5, 33.5] .. container:: example >>> print( ... evans.combination_tones( ... pitches=[ ... 7.75, ... 19, ... 25.25, ... 28.5 ... ], ... depth=1, ... ) ... ) [-1.0, 4.0, 6.0, 8.0, 13.5, 17.0, 19.0, 22.0, 25.0, 26.0, 28.5, 30.5, 33.0, 34.0, 36.5, 39.0] """ pitches = [abjad.NumberedPitch(_).hertz for _ in pitches] new_pitches = [] for iter in range(depth): for i, num in enumerate(pitches): new_pitches.append(num) for num_ in pitches[i + 1:]: new_pitches.append(num + num_) if num > num_: new_pitches.append(num - num_) elif num < num_: new_pitches.append(num_ - num) else: continue pitches = new_pitches new_pitches = [] pitches = [float(abjad.NumberedPitch.from_hertz(x)) for x in pitches] reduce = [] for y in pitches: if y not in reduce: reduce.append(y) reduce.sort() pitches = reduce return pitches
def pennant_pitches(start_pitch, intervals=(0, ), *, direction=abjad.Up): start_pitch_ = abjad.NumberedPitch(start_pitch) start_pitch = start_pitch_.number intervals_ = [ 0, 1, 0, -1, -2, 0, -1, 0, 1, 3, 2, 1, 0, 2, 3, 4, 3, 5, 6, 4, 5 ] if direction == abjad.Down: intervals_ = [-_ for _ in intervals_] pitch_numbers = [_ + start_pitch for _ in intervals_] return baca.loop(pitch_numbers, intervals)
def from_pitch_carriers(class_, pitch_carrier_1, pitch_carrier_2): '''Makes named interval calculated from `pitch_carrier_1` to `pitch_carrier_2`. .. container:: example >>> abjad.NamedInterval.from_pitch_carriers( ... abjad.NamedPitch(-2), ... abjad.NamedPitch(12), ... ) NamedInterval('+M9') .. todo:: Improve this behavior. >>> abjad.NamedInterval.from_pitch_carriers( ... abjad.NamedPitch("cs'"), ... abjad.NamedPitch("cf'"), ... ) NamedInterval('-M2') Returns named interval. ''' import abjad pitch_1 = abjad.NamedPitch.from_pitch_carrier(pitch_carrier_1) pitch_2 = abjad.NamedPitch.from_pitch_carrier(pitch_carrier_2) degree_1 = pitch_1._get_diatonic_pitch_number() degree_2 = pitch_2._get_diatonic_pitch_number() named_interval_number = abs(degree_1 - degree_2) + 1 number = abs( abjad.NumberedPitch(pitch_1).number - abjad.NumberedPitch(pitch_2).number ) numbered_interval = abjad.NumberedInterval(number) absolute_named_interval = numbered_interval.to_named_interval( named_interval_number ) if pitch_2 < pitch_1: named_interval = -absolute_named_interval else: named_interval = absolute_named_interval return class_(named_interval)
def _parse_range_string(self, range_string): import abjad assert isinstance(range_string, str), repr(range_string) range_string = range_string.replace("-inf", "-1000") range_string = range_string.replace("+inf", "1000") match = constants._range_string_regex.match(range_string) if match is None: message = "can not instantiate pitch range: {!r}" message = message.format(range_string) raise ValueError(message) group_dict = match.groupdict() start_punctuation = group_dict["open_bracket"] start_pitch_string = group_dict["start_pitch"] stop_pitch_string = group_dict["stop_pitch"] stop_punctuation = group_dict["close_bracket"] start_inclusivity_string = constants._start_punctuation_to_inclusivity_string[ start_punctuation] stop_inclusivity_string = constants._stop_punctuation_to_inclusivity_string[ stop_punctuation] if start_pitch_string == "-1000": start_pitch = None else: try: start_pitch = abjad.NamedPitch(start_pitch_string) except (TypeError, ValueError): start_pitch = abjad.NumberedPitch(int(start_pitch_string)) if stop_pitch_string == "1000": stop_pitch = None else: try: stop_pitch = abjad.NamedPitch(stop_pitch_string) except (TypeError, ValueError): stop_pitch = abjad.NumberedPitch(int(stop_pitch_string)) start_pair = (start_pitch, start_inclusivity_string) stop_pair = (stop_pitch, stop_inclusivity_string) return start_pair, stop_pair
def _parse_range_string(self, range_string): import abjad assert isinstance(range_string, str), repr(range_string) range_string = range_string.replace('-inf', '-1000') range_string = range_string.replace('+inf', '1000') match = self._range_string_regex.match(range_string) if match is None: message = 'can not instantiate pitch range: {!r}' message = message.format(range_string) raise ValueError(message) group_dict = match.groupdict() start_punctuation = group_dict['open_bracket'] start_pitch_string = group_dict['start_pitch'] stop_pitch_string = group_dict['stop_pitch'] stop_punctuation = group_dict['close_bracket'] start_inclusivity_string = \ self._start_punctuation_to_inclusivity_string[start_punctuation] stop_inclusivity_string = \ self._stop_punctuation_to_inclusivity_string[stop_punctuation] if start_pitch_string == '-1000': start_pitch = None else: try: start_pitch = abjad.NamedPitch(start_pitch_string) except (TypeError, ValueError): start_pitch = abjad.NumberedPitch(int(start_pitch_string)) if stop_pitch_string == '1000': stop_pitch = None else: try: stop_pitch = abjad.NamedPitch(stop_pitch_string) except (TypeError, ValueError): stop_pitch = abjad.NumberedPitch(int(stop_pitch_string)) start_pair = (start_pitch, start_inclusivity_string) stop_pair = (stop_pitch, stop_inclusivity_string) return start_pair, stop_pair
def test_LeafDynMaker_08(): pitches = [ 0, "d'", 'E4', abjad.NumberedPitch(5), abjad.NamedPitch("g'"), abjad.NamedPitch('A4'), ] durations = [ (1, 32), '2/32', abjad.Duration('3/32'), abjad.Duration(0.125), abjad.Duration(5, 32), abjad.Duration(6 / 32), ] dynamics = [ 'p', abjad.Dynamic('f'), ] articulations = [ '>', abjad.Articulation('-'), abjad.Staccato(), ] leaf_dyn_maker = auxjad.LeafDynMaker() notes = leaf_dyn_maker(pitches, durations, dynamics, articulations) staff = abjad.Staff(notes) assert format(staff) == abjad.String.normalize(r""" \new Staff { c'32 \p - \accent d'16 \f - \tenuto e'16. \staccato f'8 g'8 ~ g'32 a'8. } """)
def __init__(self, n_divisions=48, octaves=3): float_and_oct = tuple(( n // n_divisions, (n % n_divisions) / n_divisions * 12, 2**(n // n_divisions), ) for n in range(n_divisions * octaves)) float_and_oct += tuple(( n // n_divisions, (n % n_divisions) / n_divisions * 12, 2**(n // n_divisions), ) for n in range(-18, 0)) self.available_pitches = tuple( sorted( tuple((edo.EDO2_12Pitch(fl, oc), abjad.NumberedPitch(fl - 15 + (12 * n))) for n, fl, oc in float_and_oct), key=operator.itemgetter(0), )) self.cents_of_available_pitches = tuple( p[0].cents for p in self.available_pitches)
def convert2abjad_pitches(self, pitches) -> list: res = [] for pitch in pitches: chord = [] for p in pitch: if p != mel.EmptyPitch(): res_string = None for s in self.strings: if p == s.pitch: res_string = s.number break if res_string is not None: pitch_number = Monochord.convert_string_number2pitch_number( res_string) abjad_pitch = abjad.NumberedPitch(pitch_number) chord.append(abjad_pitch) else: raise ValueError( "Pitch: {0} could not be found in Monochord-Tuning!" .format(p)) res.append(chord) return res
def _segment_target_by_tag( self, target: abjad.Voice) -> typing.List[abjad.Selection]: selection: abjad.Selection = abjad.select(target).logical_ties() all_tags: typing.List[int] = [ tag for tag in self._sequence.tags if tag is not None ] unique_tags: typing.List[int] = list(set(all_tags)) pitch_tags: typing.List[abjad.NumberedPitch] = [ abjad.NumberedPitch(tag) for tag in unique_tags ] results: typing.List[typing.Union[abjad.Selection, abjad.Expression]] = [ selection.filter_pitches( "&", pitch.get_name(locale="us")) for pitch in pitch_tags ] for result in results: if not isinstance(result, abjad.Selection): raise TypeError return [ result for result in results if isinstance(result, abjad.Selection) ]
def get_normal_order(self): r'''Gets normal order. .. container:: example Gets normal order of empty pitch-class set: >>> pc_set = abjad.PitchClassSet() >>> pc_set.get_normal_order() PitchClassSegment([]) .. container:: example Gets normal order: >>> pc_set = abjad.PitchClassSet([0, 1, 10, 11]) >>> pc_set.get_normal_order() PitchClassSegment([10, 11, 0, 1]) .. container:: example Gets normal order: >>> pc_set = abjad.PitchClassSet([2, 8, 9]) >>> pc_set.get_normal_order() PitchClassSegment([8, 9, 2]) .. container:: example Gets normal order of pitch-class set with degree of symmetry equal to 2: >>> pc_set = abjad.PitchClassSet([1, 2, 7, 8]) >>> pc_set.get_normal_order() PitchClassSegment([1, 2, 7, 8]) .. container:: example Gets normal order of pitch-class set with degree of symmetry equal to 4: >>> pc_set = abjad.PitchClassSet([0, 3, 6, 9]) >>> pc_set.get_normal_order() PitchClassSegment([0, 3, 6, 9]) Returns pitch-class segment. ''' import abjad if not len(self): return abjad.PitchClassSegment( items=None, item_class=abjad.NumberedPitchClass, ) pitch_classes = list(self) pitch_classes.sort() candidates = [] for i in range(self.cardinality): candidate = [abjad.NumberedPitch(_) for _ in pitch_classes] candidate = abjad.sequence(candidate).rotate(n=-i) candidates.append(candidate) return self._get_most_compact_ordering(candidates)
def test_staff_splitter_04(): staff = abjad.Staff(r"c'4 d'4 e'4 <d' f' a'>4") staves = auxjad.staff_splitter(staff, threshold="e'") score = abjad.Score(staves) assert abjad.lilypond(score) == abjad.String.normalize( r""" \new Score << \new Staff { \clef "treble" r2 e'4 <f' a'>4 } \new Staff { \clef "bass" c'4 d'4 r4 d'4 } >> """ ) staves = auxjad.staff_splitter(staff, threshold='E4') score = abjad.Score(staves) assert abjad.lilypond(score) == abjad.String.normalize( r""" \new Score << \new Staff { \clef "treble" r2 e'4 <f' a'>4 } \new Staff { \clef "bass" c'4 d'4 r4 d'4 } >> """ ) staves = auxjad.staff_splitter(staff, threshold=abjad.NamedPitch("e'")) score = abjad.Score(staves) assert abjad.lilypond(score) == abjad.String.normalize( r""" \new Score << \new Staff { \clef "treble" r2 e'4 <f' a'>4 } \new Staff { \clef "bass" c'4 d'4 r4 d'4 } >> """ ) staves = auxjad.staff_splitter(staff, threshold=abjad.NumberedPitch(4)) score = abjad.Score(staves) assert abjad.lilypond(score) == abjad.String.normalize( r""" \new Score << \new Staff { \clef "treble" r2 e'4 <f' a'>4 } \new Staff { \clef "bass" c'4 d'4 r4 d'4 } >> """ ) staves = auxjad.staff_splitter(staff, threshold=4) score = abjad.Score(staves) assert abjad.lilypond(score) == abjad.String.normalize( r""" \new Score << \new Staff { \clef "treble" r2 e'4 <f' a'>4 } \new Staff { \clef "bass" c'4 d'4 r4 d'4 } >> """ )
import abjad instrument_one = abjad.Violin() instrument_one_range = instrument_one.pitch_range instrument_one_range_lowest = abjad.NumberedPitch( instrument_one_range.start_pitch) instrument_one_range_highest = abjad.NumberedPitch( instrument_one_range.stop_pitch) instrument_two = abjad.Violin() instrument_two_range = instrument_two.pitch_range instrument_two_range_lowest = abjad.NumberedPitch( instrument_two_range.start_pitch) instrument_two_range_highest = abjad.NumberedPitch( instrument_two_range.stop_pitch) instrument_three = abjad.Viola() instrument_three_range = instrument_three.pitch_range instrument_three_range_lowest = abjad.NumberedPitch( instrument_three_range.start_pitch) instrument_three_range_highest = abjad.NumberedPitch( instrument_three_range.stop_pitch) instrument_four = abjad.Cello() instrument_four_range = instrument_four.pitch_range instrument_four_range_lowest = abjad.NumberedPitch( instrument_four_range.start_pitch) instrument_four_range_highest = abjad.NumberedPitch( instrument_four_range.stop_pitch) instruments = [
def return_cent_deviation_markup( ratio=1, fundamental="a'", chris=False ): # chris values are temp. pitch = None ratio = quicktions.Fraction(ratio) tonic_cent_difference = abjad.NamedPitch(fundamental).number * 100 log_ratio = quicktions.Fraction(math.log10(ratio)) log_2 = quicktions.Fraction(1200 / math.log10(2)) ji_cents = quicktions.Fraction(log_ratio * log_2) et_cents = ( make_ji_bundle(fundamental, ratio).pitch.number * 100 ) - tonic_cent_difference cent_difference = ji_cents - et_cents final_cents = round(float(cent_difference)) if chris is True: final_cents = round(float(cent_difference), 2) if chris is True: p_string = f"{fundamental}4" demo_note = abjad.Note(p_string) demo_head = demo_note.note_head tune_to_ratio(demo_head, quicktions.Fraction(ratio) * quicktions.Fraction(9, 8)) pitch = abjad.NumberedPitch(demo_head.written_pitch) if 50 < abs(final_cents): if chris is False: p_string = f"{fundamental}4" demo_note = abjad.Note(p_string) demo_head = demo_note.note_head tune_to_ratio(demo_head, ratio) pitch = abjad.NumberedPitch(demo_head.written_pitch) semitones = final_cents / 100 parts = math.modf(semitones) pitch += parts[1] remainder = round(parts[0] * 100) if 50 < abs(remainder): if 0 < remainder: pitch += 1 remainder = -100 + remainder else: pitch -= 1 remainder = 100 + remainder final_cents = remainder if final_cents < 0: cent_string = f"{final_cents}" if chris is True: if not cent_string[0].isalpha(): pitch_string = str(abjad.NamedPitchClass(pitch)) pos, acc = pitch_string[0], pitch_string[1:] pos = pos.capitalize() acc = acc.replace("s", "♯") acc = acc.replace("f", "♭") cent_string = pos + acc + cent_string cent_string = cent_string.replace("A♭", "G♯") if chris is False: if pitch is not None: pitch_string = str(abjad.NamedPitchClass(pitch)) pos, acc = pitch_string[0], pitch_string[1:] pos = pos.capitalize() acc = acc.replace("s", "♯") acc = acc.replace("f", "♭") cent_string = pos + acc + cent_string else: cent_string = f"+{final_cents}" if chris is True: if not cent_string[0].isalpha(): pitch_string = str(abjad.NamedPitchClass(pitch)) pos, acc = pitch_string[0], pitch_string[1:] pos = pos.capitalize() acc = acc.replace("s", "♯") acc = acc.replace("f", "♭") cent_string = pos + acc + cent_string cent_string = cent_string.replace("A♭", "G♯") if chris is False: if pitch is not None: pitch_string = str(abjad.NamedPitchClass(pitch)) pos, acc = pitch_string[0], pitch_string[1:] pos = pos.capitalize() acc = acc.replace("s", "♯") acc = acc.replace("f", "♭") cent_string = pos + acc + cent_string mark = abjad.Markup( fr"\markup \center-align {{ {cent_string} }}", direction=abjad.Up, literal=True, ) return mark
def make_ji_bundle(pitch, ratio): r""" Makes JI bundle. .. container:: example >>> bundle = microtones.make_ji_bundle(abjad.NamedPitch("c'"), "3/2") >>> bundle.pitch NamedPitch("g'") >>> print(abjad.storage(bundle.vector)) microtones.JIVector( diatonic_accidental='natural', syntonic_commas_down=0, syntonic_commas_up=0, septimal_commas_down=0, septimal_commas_up=0, undecimal_quarter_tones_down=0, undecimal_quarter_tones_up=0, tridecimal_third_tones_down=0, tridecimal_third_tones_up=0, seventeen_limit_schismas_down=0, seventeen_limit_schismas_up=0, nineteen_limit_schismas_down=0, nineteen_limit_schismas_up=0, twenty_three_limit_commas_down=0, twenty_three_limit_commas_up=0, ) """ if isinstance(pitch, str): pitch = abjad.NamedPitch(pitch) elif isinstance(pitch, int): pitch = abjad.NumberedPitch(pitch) ratio = quicktions.Fraction(ratio) numerator_factors = _prime_factors(ratio.numerator) denominator_factors = _prime_factors(ratio.denominator) accidental_vector = JIVector(diatonic_accidental=pitch.accidental.name) for prime in numerator_factors: assert prime <= 23 for string in _numerator_factor_to_intervals[prime]: pitch = abjad.NamedInterval(string).transpose(pitch) if prime in _numerator_factor_to_nudge: string = _numerator_factor_to_nudge[prime] value = getattr(accidental_vector, string) setattr(accidental_vector, string, value + 1) for prime in denominator_factors: assert prime <= 23 for string in _numerator_factor_to_intervals[prime]: string = string.replace("+", "-") pitch = abjad.NamedInterval(string).transpose(pitch) if prime in _numerator_factor_to_nudge: string = _numerator_factor_to_nudge[prime] if string.endswith("_up"): string = string.replace("_up", "_down") else: string = string.replace("_down", "_up") value = getattr(accidental_vector, string) setattr(accidental_vector, string, value + 1) accidental_vector.diatonic_accidental = pitch.accidental.name return JIBundle(pitch, accidental_vector)
def from_pitch_carriers(class_, pitch_carrier_1, pitch_carrier_2): """ Makes named interval calculated from `pitch_carrier_1` to `pitch_carrier_2`. .. container:: example >>> abjad.NamedInterval.from_pitch_carriers( ... abjad.NamedPitch(-2), ... abjad.NamedPitch(12), ... ) NamedInterval('+M9') >>> abjad.NamedInterval.from_pitch_carriers( ... abjad.NamedPitch("css'"), ... abjad.NamedPitch("cff'"), ... ) NamedInterval('-AAAA1') >>> abjad.NamedInterval.from_pitch_carriers("c'", "cs'''") NamedInterval('+A15') >>> abjad.NamedInterval.from_pitch_carriers('c', 'cqs') NamedInterval('+P+1') >>> abjad.NamedInterval.from_pitch_carriers("cf'", 'bs') NamedInterval('-dd2') >>> abjad.NamedInterval.from_pitch_carriers("cff'", 'aqs') NamedInterval('-ddd+3') >>> abjad.NamedInterval.from_pitch_carriers("cff'", 'atqs') NamedInterval('-dddd+3') Returns named interval. """ import abjad pitch_1 = abjad.NamedPitch(pitch_carrier_1) pitch_2 = abjad.NamedPitch(pitch_carrier_2) degree_1 = pitch_1._get_diatonic_pitch_number() degree_2 = pitch_2._get_diatonic_pitch_number() named_sign = mathtools.sign(degree_1 - degree_2) named_i_number = abs(degree_1 - degree_2) + 1 numbered_sign = mathtools.sign( float(abjad.NumberedPitch(pitch_1)) - float(abjad.NumberedPitch(pitch_2))) numbered_i_number = abs( float(abjad.NumberedPitch(pitch_1)) - float(abjad.NumberedPitch(pitch_2))) named_ic_number = named_i_number numbered_ic_number = numbered_i_number while named_ic_number > 8 and numbered_ic_number > 12: named_ic_number -= 7 numbered_ic_number -= 12 # Multiply-diminished intervals can have opposite signs if named_sign and (named_sign == -numbered_sign): numbered_ic_number *= -1 quartertone = "" if numbered_ic_number % 1: quartertone = "+" numbered_ic_number -= 0.5 mapping = { value: key for key, value in constants. _diatonic_number_and_quality_to_semitones[named_ic_number].items() } quality = "" while numbered_ic_number > max(mapping): numbered_ic_number -= 1 quality += "A" while numbered_ic_number < min(mapping): numbered_ic_number += 1 quality += "d" quality += mapping[numbered_ic_number] quality += quartertone direction = 1 if pitch_2 < pitch_1: direction = -1 return class_((quality, named_i_number * direction))
("dss,,", -32), ("fake", ValueError), (("bf", 2), -14), (("c", 4), 0), (("cs", 4), 1), (("dss", 1), -32), (("gff", 5), 17), (abjad.NamedPitch("bs'"), 12), (abjad.NamedPitch("c"), -12), (abjad.NamedPitch("cf,"), -25), (abjad.NamedPitch(), 0), (abjad.NamedPitchClass("cs'"), 1), (abjad.NamedPitchClass("c"), 0), (abjad.NamedPitchClass("cf,"), -1), # TODO: Is this correct? (None, 0), (abjad.NumberedPitch("bs'"), 12), (abjad.NumberedPitch("c"), -12), (abjad.NumberedPitch("cf,"), -25), (abjad.NumberedPitch(), 0), (abjad.NumberedPitchClass("bs'"), 0), (abjad.NumberedPitchClass("c"), 0), (abjad.NumberedPitchClass("cf,"), 11), ]) @pytest.mark.parametrize("input_, expected_semitones", values) def test_init(input_, expected_semitones): if isinstance(expected_semitones, type) and issubclass( expected_semitones, Exception): with pytest.raises(expected_semitones): abjad.NamedPitch(input_)
import abjad import evans instrument_one = abjad.Violin() instrument_one_range = instrument_one.pitch_range instrument_one_range_lowest = abjad.NumberedPitch( instrument_one_range.start_pitch) instrument_one_range_highest = abjad.NumberedPitch( instrument_one_range.stop_pitch) instrument_two = abjad.Violin() instrument_two_range = instrument_two.pitch_range instrument_two_range_lowest = abjad.NumberedPitch( instrument_two_range.start_pitch) instrument_two_range_highest = abjad.NumberedPitch( instrument_two_range.stop_pitch) instrument_three = abjad.Violin() instrument_three_range = instrument_three.pitch_range instrument_three_range_lowest = abjad.NumberedPitch( instrument_three_range.start_pitch) instrument_three_range_highest = abjad.NumberedPitch( instrument_three_range.stop_pitch) instrument_four = abjad.Violin() instrument_four_range = instrument_four.pitch_range instrument_four_range_lowest = abjad.NumberedPitch( instrument_four_range.start_pitch) instrument_four_range_highest = abjad.NumberedPitch( instrument_four_range.stop_pitch)
def interpolate(self, stop_pitch, fraction): """ Interpolates between numbered pitch and `stop_pitch` by `fraction`. .. container:: example Interpolates from C4 to C5: >>> start_pitch = abjad.NumberedPitch(0) >>> stop_pitch = abjad.NumberedPitch(12) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(0)) NumberedPitch(0) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(1, 4)) NumberedPitch(3) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(1, 2)) NumberedPitch(6) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(3, 4)) NumberedPitch(9) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(1)) NumberedPitch(12) .. container:: example Interpolates from C5 to C4: >>> start_pitch = abjad.NumberedPitch(12) >>> stop_pitch = abjad.NumberedPitch(0) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(0)) NumberedPitch(12) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(1, 4)) NumberedPitch(9) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(1, 2)) NumberedPitch(6) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(3, 4)) NumberedPitch(3) >>> start_pitch.interpolate(stop_pitch, abjad.Fraction(1)) NumberedPitch(0) Returns new numbered pitch. """ import abjad assert 0 <= fraction <= 1, repr(fraction) stop_pitch = type(self)(stop_pitch) distance = stop_pitch - self distance = abs(distance.semitones) distance = fraction * distance distance = int(distance) if stop_pitch < self: distance *= -1 pitch_number = self.number pitch_number = pitch_number + distance pitch = abjad.NumberedPitch(pitch_number) if self <= stop_pitch: triple = (self, pitch, stop_pitch) assert self <= pitch <= stop_pitch, triple else: triple = (self, pitch, stop_pitch) assert self >= pitch >= stop_pitch, triple return pitch
state2 = stack2.state selection3 = stack([time_signatures[2]], previous_state=state1) selection4 = stack2(time_signatures[3:], previous_state=state2) selection = selection1 + selection2 + selection3 + selection4 staff = abjad.Staff(selection, name="staffname") abjad.attach(abjad.Clef("bass"), abjad.select(staff).leaf(0)) pitches = [] ties = abjad.select(staff).logical_ties(pitched=True) for eye in range(len(ties)): multiplied_val = eye * 0.25 sin_val = math.sin(eye) added_val = multiplied_val + sin_val if 3 < added_val: added_val -= 4.5 pitch = abjad.NumberedPitch(added_val) pitch -= 12 pitches.append(pitch) zipped = zip(pitches, abjad.select(staff).logical_ties(pitched=True)) for pitch, tie in zipped: for leaf in abjad.select(tie).leaves(): leaf.written_pitch = pitch score = abjad.Score([ts_staff, staff]) file = abjad.LilyPondFile.new( score, includes=[r"\Users\Matthew\mason\mason\lilypond\stylesheet.ily"]) abjad.persist(file).as_pdf( r"\Users\Matthew\mason\mason\playground\july_second.pdf")
r""" \with-color #black""", r""" \line { \hspace #0.75 Spring Valley, Oh. }""", r""" \with-color #black""", r""" \line { \hspace #0.75 April 2020 }""", r""" }""", r"""}""", ], format_slot="absolute_after", ) invisible_command = abjad.LilyPondLiteral( r"\once \override Staff.TimeSignature.color = #white", format_slot="after") measure_0_tuplet = abjad.Staff([abjad.Tuplet((6, 5), "b'8 af'8 g'8 f'8 ef'8")]) for note in abjad.select(measure_0_tuplet).leaves(): note.written_pitch = abjad.NumberedPitch(note.written_pitch) + 9 abjad.beam(measure_0_tuplet[:]) abjad.attach(abjad.Dynamic("pp"), abjad.select(measure_0_tuplet).leaf(0)) mm_1 = abjad.MetronomeMark((1, 8), 108) mm_2 = abjad.MetronomeMark((1, 4), 108) maker = evans.SegmentMaker( instruments=magnolia.instruments, names=[abjad.Markup.center_column(["Alto", "Saxophone"])], # names=['"Alto Saxophone"'], commands=[ magnolia.rhythm_commands, evans.call( "score",