How to use the abjad.tools.pitchtools function in abjad

To help you get started, we’ve selected a few abjad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Abjad / abjad / trunk / abjad / tools / labeltools / label_leaves_in_expr_with_named_interval_classes.py View on Github external
>>> show(staff) # doctest: +SKIP

    Returns none.
    """

    for note in iterationtools.iterate_notes_in_expr(expr):
        logical_voice_iterator = \
            iterationtools.iterate_logical_voice_from_component(
            note, scoretools.Leaf)
        try:
            logical_voice_iterator.next()
            next_leaf = logical_voice_iterator.next()
            if isinstance(next_leaf, scoretools.Note):
                mdi = pitchtools.NamedInterval.from_pitch_carriers(
                    note, next_leaf)
                mdic = pitchtools.NamedIntervalClass(mdi)
                markup = markuptools.Markup(mdic, markup_direction)
                attach(markup, note)
        except StopIteration:
            pass
github Abjad / abjad / trunk / abjad / tools / pitchtools / _transpose_pitch_carrier_by_melodic_chromatic_interval.py View on Github external
if isinstance(pitch_carrier, pitchtools.Pitch):
        return type(pitch_carrier)(pitch_carrier.chromatic_pitch_number + mci.semitones)
    elif isinstance(pitch_carrier, numbers.Number):
        pitch_carrier = pitchtools.NumberedChromaticPitch(pitch_carrier)
        result = _transpose_pitch_carrier_by_melodic_chromatic_interval(pitch_carrier, mci)
        return result.chromatic_pitch_number
    elif isinstance(pitch_carrier, notetools.Note):
        new_note = componenttools.copy_components_and_remove_spanners([pitch_carrier])[0]
        new_pitch = pitchtools.NamedChromaticPitch(
            abs(pitch_carrier.written_pitch.numbered_chromatic_pitch) + mci.number)
        new_note.written_pitch = new_pitch
        return new_note
    elif isinstance(pitch_carrier, chordtools.Chord):
        new_chord = componenttools.copy_components_and_remove_spanners([pitch_carrier])[0]
        for new_nh, old_nh in zip(new_chord.note_heads, pitch_carrier.note_heads):
            new_pitch = pitchtools.NamedChromaticPitch(
                abs(old_nh.written_pitch.numbered_chromatic_pitch) + mci.number)
            new_nh.written_pitch = new_pitch
        return new_chord
    else:
        return pitch_carrier
github Abjad / abjad / trunk / abjad / tools / pitchtools / NamedDiatonicPitchClass / NamedDiatonicPitchClass.py View on Github external
def __init__(self, arg):
        from abjad.tools import pitchtools
        if hasattr(arg, '_diatonic_pitch_class_name'):
            diatonic_pitch_class_name = arg._diatonic_pitch_class_name
        elif hasattr(arg, '_diatonic_pitch_class_number'):
            tmp = pitchtools.diatonic_pitch_class_number_to_diatonic_pitch_class_name
            diaotnic_pitch_class_name = tmp(arg._diatonic_pitch_class_number)
        elif pitchtools.is_chromatic_pitch_name(arg):
            tmp = pitchtools.chromatic_pitch_name_to_diatonic_pitch_class_name
            diatonic_pitch_class_name = tmp(arg)
        elif pitchtools.is_diatonic_pitch_number(arg):
            tmp = pitchtools.diatonic_pitch_number_to_diatonic_pitch_class_name
            diatonic_pitch_class_name = tmp(arg)
        else:
            raise TypeError(
                'can not initialize named diatonic pitch-class from %r.' % 
                arg)
        object.__setattr__(
            self, '_diatonic_pitch_class_name', diatonic_pitch_class_name)
        object.__setattr__(
            self, '_comparison_attribute', diatonic_pitch_class_name)
        object.__setattr__(
            self, '_format_string', repr(diatonic_pitch_class_name))
github Abjad / abjad / trunk / abjad / tools / labeltools / label_vertical_moments_in_expr_with_interval_class_vectors.py View on Github external
1000020
                        }
            }
        >>

    ::

        >>> show(score) # doctest: +SKIP

    Returns none.
    '''

    for vertical_moment in \
        iterationtools.iterate_vertical_moments_in_expr(expr):
        leaves = vertical_moment.leaves
        pitches = pitchtools.PitchSegment.from_selection(leaves)
        if not pitches:
            continue
        interval_class_vector = \
            pitchtools.numbered_inversion_equivalent_interval_class_dictionary(
            pitches)
        formatted = _format_interval_class_vector(interval_class_vector)
        markup = markuptools.Markup(formatted, markup_direction)
        attach(markup, vertical_moment.start_leaves[-1])
github Abjad / abjad / trunk / abjad / tools / pitchtools / PitchSet.py View on Github external
def _sort_self(self):
        from abjad.tools import pitchtools
        return sorted(pitchtools.PitchSegment(tuple(self)))
github Abjad / abjad / trunk / abjad / tools / instrumenttools / MezzoSopranoVoice.py View on Github external
def __init__(self, **kwargs):
        Instrument.__init__(self, **kwargs)
        self._default_instrument_name = 'mezzo-soprano voice'
        self._default_performer_names.extend([
            'vocalist',
            'mezzo-soprano',
            ])
        self._default_short_instrument_name = 'mezzo-soprano'
        self._is_primary_instrument = True
        self.sounding_pitch_of_written_middle_c = \
            pitchtools.NamedPitch("c'")
        self._starting_clefs = [marktools.ClefMark('treble')]
        self._copy_default_starting_clefs_to_default_allowable_clefs()
        self._default_pitch_range = pitchtools.PitchRange(('A3', 'C6'))
github Abjad / abjad / trunk / abjad / tools / pitchtools / NamedPitchClass.py View on Github external
def _init_by_pitch_name(self, expr):
        from abjad.tools import pitchtools
        match = pitchtools.Pitch._pitch_name_regex.match(expr.lower())
        if match is None:
            raise ValueError
        groups = match.groups()
        diatonic_pitch_class_name = groups[0]
        alphabetic_accidental_abbreviation = groups[1]
        self._alteration_in_semitones = \
            pitchtools.Accidental._alphabetic_accidental_abbreviation_to_semitones[
                alphabetic_accidental_abbreviation]
        self._diatonic_pitch_class_number = \
            self._diatonic_pitch_class_name_to_diatonic_pitch_class_number[
                diatonic_pitch_class_name]
github Abjad / abjad / trunk / abjad / tools / pitchtools / pitch_number_to_pitch_name.py View on Github external
def pitch_number_to_pitch_name(
    pitch_number, accidental_spelling='mixed'):
    '''Change `pitch_number` to chromatic pitch name:

    ::

        >>> pitchtools.pitch_number_to_pitch_name(13)
        "cs''"

    Return string.
    '''
    from abjad.tools import pitchtools

    if not pitchtools.Pitch.is_pitch_number(pitch_number):
        raise ValueError('\n\tNot chromatic pitch number: '
            '{!r}'.format(pitch_number))

    if not isinstance(accidental_spelling, str):
        raise TypeError

    if not accidental_spelling in ('mixed', 'flats', 'sharps'):
        raise ValueError

    pitch_class_number = pitch_number % 12

    if accidental_spelling == 'mixed':
        pitch_class_name = pitchtools.pitch_class_number_to_pitch_class_name(
            pitch_class_number)
    elif accidental_spelling == 'sharps':
        pitch_class_name = \
github Abjad / abjad / trunk / abjad / tools / pitchtools / list_ordered_named_pitch_pairs_from_expr_1_to_expr_2.py View on Github external
>>> for pair in pitchtools.list_ordered_named_pitch_pairs_from_expr_1_to_expr_2(
        ...     chord_1, chord_2):
        ...     pair
        (NamedPitch("c'"), NamedPitch("ef'"))
        (NamedPitch("c'"), NamedPitch("e'"))
        (NamedPitch("cs'"), NamedPitch("ef'"))
        (NamedPitch("cs'"), NamedPitch("e'"))
        (NamedPitch("d'"), NamedPitch("ef'"))
        (NamedPitch("d'"), NamedPitch("e'"))

    Returns generator.
    '''
    from abjad.tools import pitchtools

    pitches_1 = sorted(pitchtools.list_named_pitches_in_expr(expr_1))
    pitches_2 = sorted(pitchtools.list_named_pitches_in_expr(expr_2))
    for pair in sequencetools.yield_all_pairs_between_sequences(pitches_1, pitches_2):
        yield pair
github Abjad / abjad / abjad / tools / pitchtools / list_numbered_interval_numbers_pairwise.py View on Github external
When ``wrap = False`` do not return
    ``pitch_carriers[-1] - pitch_carriers[0]`` as last in series.

    When ``wrap = True`` do return ``pitch_carriers[-1] - pitch_carriers[0]``
    as last in series.

    Returns list.
    '''
    from abjad.tools import pitchtools

    result = []

    if len(pitch_carriers) == 0:
        return result
    elif len(pitch_carriers) == 1:
        if pitchtools.Pitch.is_pitch_carrier(pitch_carriers[0]):
            return result
        else:
            message = 'must be pitch, not, note-head or chord.'
            raise TypeError(message)

    pairs = sequencetools.iterate_sequence_nwise(pitch_carriers, wrapped=wrap)
    pairs = list(pairs)

    for first_carrier, second_carrier in pairs:
        first_pitch = pitchtools.NamedPitch.from_pitch_carrier(first_carrier)
        second_pitch = pitchtools.NamedPitch.from_pitch_carrier(second_carrier)
        signed_interval = \
            pitchtools.NumberedPitch(second_pitch).pitch_number - \
            pitchtools.NumberedPitch(first_pitch).pitch_number
        result.append(signed_interval)