def label_leaves_in_expr_with_numbered_interval_classes( expr, markup_direction=Up): r"""Label leaves in `expr` with numbered interval classes: :: >>> notes = scoretools.make_notes( ... [0, 25, 11, -4, -14, -13, 9, 10, 6, 5], ... [Duration(1, 8)], ... ) >>> staff = Staff(notes) >>> labeltools.label_leaves_in_expr_with_numbered_interval_classes( ... staff) .. doctest:: >>> print(format(staff)) \new Staff { c'8 ^ \markup { +1 } cs'''8 ^ \markup { -2 } b'8 ^ \markup { -3 } af8 ^ \markup { -10 } bf,8 ^ \markup { +1 } b,8 ^ \markup { +10 } a'8 ^ \markup { +1 } bf'8 ^ \markup { -4 } fs'8 ^ \markup { -1 } f'8 } :: >>> show(staff) # doctest: +SKIP Returns none. """ for note in iterate(expr).by_class(scoretools.Note): logical_voice_iterator = iterate(note).by_logical_voice_from_component( scoretools.Leaf, ) try: next(logical_voice_iterator) next_leaf = next(logical_voice_iterator) if isinstance(next_leaf, scoretools.Note): mdi = note.written_pitch - next_leaf.written_pitch mci = pitchtools.NumberedInterval(mdi) mcic = pitchtools.NumberedIntervalClass(mci) markup = markuptools.Markup(mcic, markup_direction) attach(markup, note) except StopIteration: pass
def __init__(self, number=0): from abjad.tools import pitchtools if isinstance(number, (int, float)): pass elif isinstance(number, pitchtools.Interval): number = number.semitones elif isinstance(number, pitchtools.IntervalClass): interval_class = pitchtools.NumberedIntervalClass(number) number = interval_class.number else: message = 'can not initialize {} from {!r}.' message = message.format(type(self).__name__, number) raise TypeError(message) number = mathtools.integer_equivalent_number_to_integer(number) self._number = number
def __init__(self, arg=None): from abjad.tools import pitchtools if isinstance(arg, (int, float, int)): number = arg elif isinstance(arg, pitchtools.Interval): number = arg.semitones elif isinstance(arg, pitchtools.IntervalClass): interval_class = pitchtools.NumberedIntervalClass(arg) number = interval_class.number elif arg is None: number = 0 else: message = 'can not initialize {}: {!r}.' message = message.format(type(self).__name__, arg) raise TypeError(message) self._number = number
def instantiate_pitch_and_interval_test_collection(): r'''Instantiate pitch and interval test collection: :: >>> for x in pitchtools.instantiate_pitch_and_interval_test_collection(): x ... NumberedInversionEquivalentIntervalClass(1) NamedInversionEquivalentIntervalClass('+M2') NumberedInterval(1) NumberedIntervalClass(1) NamedInterval('+M2') NamedIntervalClass('+M2') NamedPitch('c') NamedPitchClass('c') NumberedPitch(1) NumberedPitchClass(1) Use to test pitch and interval interface consistency. Returns list. ''' from abjad.tools import pitchtools result = [] result.append(pitchtools.NumberedInversionEquivalentIntervalClass(1)) result.append(pitchtools.NamedInversionEquivalentIntervalClass('M2')) result.append(pitchtools.NumberedInterval(1)) result.append(pitchtools.NumberedIntervalClass(1)) result.append(pitchtools.NamedInterval('M2')) result.append(pitchtools.NamedIntervalClass('M2')) result.append(pitchtools.NamedPitch('c')) result.append(pitchtools.NamedPitchClass('c')) result.append(pitchtools.NumberedPitch(1)) result.append(pitchtools.NumberedPitchClass(1)) return result