Ejemplo n.º 1
0
    def permute(self, pitches):
        r'''Permutes `pitches` by twelve-tone row.

        ..  container:: example

            ::

                >>> notes = scoretools.make_notes([17, -10, -2, 11], [Duration(1, 4)])
                >>> row = pitchtools.TwelveToneRow([10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11])
                >>> row.permute(notes)
                [Note('bf4'), Note('d4'), Note("f''4"), Note("b'4")]

        Method works by reference. No objects are copied.

        Returns list.
        '''
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        result = []
        for pc in self:
            matching_pitches = []
            for pitch in pitches:
                if isinstance(pitch, pitchtools.NamedPitch):
                    if pitch.numbered_pitch_class == pc:
                        matching_pitches.append(pitch)
                elif isinstance(pitch, scoretools.Note):
                    if pitchtools.NumberedPitchClass(
                            pitch.written_pitch) == pc:
                        matching_pitches.append(pitch)
                else:
                    message = 'must be pitch or note: {!r}'
                    message = message.format(pitch)
                    raise TypeError(message)
            result.extend(matching_pitches)
        return result
def sort_named_pitch_carriers_in_expr(pitch_carriers):
    '''List named pitch carriers in `expr` sorted by
    numbered pitch-class:

    ::

        >>> notes = scoretools.make_notes([9, 11, 12, 14, 16], (1, 4))

    ::

        >>> pitchtools.sort_named_pitch_carriers_in_expr(notes)
        [Note("c''4"), Note("d''4"), Note("e''4"), Note("a'4"), Note("b'4")]

    The elements in `pitch_carriers` are not changed in any way.

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

    result = list(pitch_carriers[:])
    tmp = pitchtools.list_named_pitches_in_expr
    result.sort(key=lambda x: pitchtools.NumberedPitchClass(tmp(x)[0]).
                pitch_class_number)

    return result
Ejemplo n.º 3
0
    def duplicate_pitch_classes(self):
        r'''Gets duplicate pitch-classes in pitch set.

        ..  container:: example

            >>> set_ = abjad.PitchSet(
            ...     items=[-2, -1.5, 6, 7, -1.5, 7],
            ...     item_class=abjad.NumberedPitch,
            ...     )
            >>> set_.duplicate_pitch_classes
            PitchClassSet([])

            >>> set_ = abjad.PitchSet(
            ...     items=[-2, -1.5, 6, 7, 10.5, 7],
            ...     item_class=abjad.NumberedPitch,
            ...     )
            >>> set_.duplicate_pitch_classes
            PitchClassSet([10.5])

        Returns pitch-class set.
        '''
        from abjad.tools import pitchtools
        pitch_classes = []
        duplicate_pitch_classes = []
        for pitch in self:
            pitch_class = pitchtools.NumberedPitchClass(pitch)
            if pitch_class in pitch_classes:
                duplicate_pitch_classes.append(pitch_class)
            pitch_classes.append(pitch_class)
        return pitchtools.PitchClassSet(
            duplicate_pitch_classes,
            item_class=pitchtools.NumberedPitchClass,
        )
Ejemplo n.º 4
0
 def _initialize_by_number(self, expr):
     from abjad.tools import pitchtools
     pitch_class_number = float(expr) % 12
     numbered_pitch_class = pitchtools.NumberedPitchClass(
         pitch_class_number)
     pitch_class_name = numbered_pitch_class.pitch_class_name
     self._initialize_by_pitch_name(pitch_class_name)
 def _initialize_color_dictionary(self):
     from abjad.tools import pitchtools
     for pitch_iterable, color in zip(self.pitch_iterables, self.colors):
         for pitch in pitch_iterable:
             pc = pitchtools.NumberedPitchClass(pitch)
             if pc.pitch_class_number in list(self._color_dictionary.keys()):
                 print(pc, list(self._color_dictionary.keys()))
                 message = 'duplicated pitch-class in color map: {!r}.'
                 message = message.format(pc)
                 raise KeyError(message)
             self._color_dictionary[pc.pitch_class_number] = color
Ejemplo n.º 6
0
    def pitch_class(self):
        r'''Gets pitch-class of numbered pitch.

        ..  container:: example

            >>> abjad.NumberedPitch(13).pitch_class
            NumberedPitchClass(1)

        Returns numbered pitch-class.
        '''
        from abjad.tools import pitchtools
        return pitchtools.NumberedPitchClass(self)
Ejemplo n.º 7
0
    def numbered_pitch_class(self):
        r'''Numbered pitch-class corresponding to named pitch-class.

        ::

            >>> pitchtools.NamedPitchClass('cs').numbered_pitch_class
            NumberedPitchClass(1)

        Returns numbered pitch-class.
        '''
        from abjad.tools import pitchtools
        return pitchtools.NumberedPitchClass(self)
Ejemplo n.º 8
0
    def __getitem__(self, pc):
        r'''Gets color corresponding to `pc` in color map.

        ::

            >>> color_map[11]
            'green'

        Returns string.
        '''
        from abjad.tools import pitchtools
        pc = pitchtools.NumberedPitchClass(pc)
        color = self._color_dictionary[pc.pitch_class_number]
        return color
Ejemplo n.º 9
0
    def multiply(self, n):
        r'''Multiply pitch-class segment by `n`:

        ::

            >>> pitch_class_segment = pitchtools.PitchClassSegment(
            ...     items=[-2, -1.5, 6, 7, -1.5, 7],
            ...     )
            >>> pitch_class_segment.multiply(5)
            PitchClassSegment([2, 4.5, 6, 11, 4.5, 11])

        Returns new pitch-class segment.
        '''
        from abjad.tools import pitchtools
        items = (pitchtools.NumberedPitchClass(pc).multiply(n) for pc in self)
        return new(self, items=items)
Ejemplo n.º 10
0
    def duplicate_pitch_classes(self):
        r'''Duplicate pitch-classes in pitch set.

        Returns pitch-class set.
        '''
        from abjad.tools import pitchtools
        pitch_classes = []
        duplicate_pitch_classes = []
        for pitch in self:
            pitch_class = pitchtools.NumberedPitchClass(pitch)
            if pitch_class in pitch_classes:
                duplicate_pitch_classes.append(pitch_class)
            pitch_classes.append(pitch_class)
        return pitchtools.PitchClassSet(
            duplicate_pitch_classes,
            item_class=pitchtools.NumberedPitchClass,
        )
Ejemplo n.º 11
0
def get_numbered_pitch_class_from_pitch_carrier(pitch_carrier):
    '''Get numbered pitch-class from `pitch_carrier`:

    ::

        >>> note = Note("cs'4")
        >>> pitchtools.get_numbered_pitch_class_from_pitch_carrier(note)
        NumberedPitchClass(1)

    Raise missing pitch error on empty chords.

    Raise extra pitch error on many-note chords.

    Returns numbered pitch-class.
    '''
    from abjad.tools import pitchtools

    pitch = pitchtools.get_named_pitch_from_pitch_carrier(pitch_carrier)
    pitch_class = pitchtools.NumberedPitchClass(pitch)

    return pitch_class
Ejemplo n.º 12
0
def permute_named_pitch_carrier_list_by_twelve_tone_row(pitches, row):
    '''Permute named pitch carrier list by twelve-tone `row`:

    ::

        >>> notes = scoretools.make_notes([17, -10, -2, 11], [Duration(1, 4)])
        >>> row = pitchtools.TwelveToneRow([10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11])
        >>> pitchtools.permute_named_pitch_carrier_list_by_twelve_tone_row(notes, row)
        [Note('bf4'), Note('d4'), Note("f''4"), Note("b'4")]

    Function works by reference only. No objects are copied.

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

    if not isinstance(row, pitchtools.TwelveToneRow):
        message = 'must be twelve-tone row: {!r}.'
        message = message.format(row)
        raise TypeError(message)

    result = []

    for pc in row:
        matching_pitches = []
        for pitch in pitches:
            if isinstance(pitch, pitchtools.NamedPitch):
                if pitch.numbered_pitch_class == pc:
                    matching_pitches.append(pitch)
            elif isinstance(pitch, scoretools.Note):
                if pitchtools.NumberedPitchClass(pitch.written_pitch) == pc:
                    matching_pitches.append(pitch)
            else:
                message = 'must be pitch or note: {!r}'
                message = message.format(pitch)
                raise TypeError(message)
        result.extend(matching_pitches)

    return result
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
 def _from_pitch_class_octave(pitch_class, octave):
     from abjad.tools import pitchtools
     pitch_class = pitchtools.NumberedPitchClass(pitch_class)
     octave = pitchtools.Octave(octave)
     number = 12 * (octave.number - 4) + pitch_class.number
     return NumberedPitch(number)
Ejemplo n.º 15
0
    def __call__(self, pitch_classes):
        r'''Calls row on `pitch_classes`.

        ..  container:: example

            Example row:

            >>> numbers = [1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8, 0]
            >>> row = abjad.TwelveToneRow(numbers)
            >>> abjad.show(row) # doctest: +SKIP

        ..  container:: example

            Permutes pitch-classes:

            >>> row([abjad.NumberedPitchClass(2)])
            [NumberedPitchClass(9)]

            >>> row([abjad.NumberedPitchClass(3)])
            [NumberedPitchClass(3)]

            >>> row([abjad.NumberedPitchClass(4)])
            [NumberedPitchClass(6)]

        ..  container:: example

            Permutes pitch-class segment:

            >>> items = [-2, -1, 6, 7, -1, 7]
            >>> segment = abjad.PitchClassSegment(items=items)
            >>> abjad.show(segment) # doctest: +SKIP

            >>> segment_ = row(segment)
            >>> abjad.show(segment_) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = segment_.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    af'8
                    c'8
                    f'8
                    e'8
                    c'8
                    e'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

        ..  container:: example

            Permutes row:

            >>> numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
            >>> row_2 = abjad.TwelveToneRow(numbers)
            >>> abjad.show(row_2) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = row_2.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    c'8
                    cs'8
                    d'8
                    ef'8
                    e'8
                    f'8
                    fs'8
                    g'8
                    af'8
                    a'8
                    bf'8
                    b'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

            >>> row_3 = row(row_2)
            >>> abjad.show(row_3) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = row_3.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    cs'8
                    b'8
                    a'8
                    ef'8
                    fs'8
                    g'8
                    f'8
                    e'8
                    bf'8
                    d'8
                    af'8
                    c'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

        ..  container:: example

            Permutes row:

            >>> numbers = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
            >>> row_2 = abjad.TwelveToneRow(numbers)
            >>> abjad.show(row_2) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = row_2.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    b'8
                    bf'8
                    a'8
                    af'8
                    g'8
                    fs'8
                    f'8
                    e'8
                    ef'8
                    d'8
                    cs'8
                    c'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

            >>> row_3 = row(row_2)
            >>> abjad.show(row_3) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = row_3.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    c'8
                    af'8
                    d'8
                    bf'8
                    e'8
                    f'8
                    g'8
                    fs'8
                    ef'8
                    a'8
                    b'8
                    cs'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

        ..  container:: example

            Permutes row:

            >>> numbers = [10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11]
            >>> row_2 = abjad.TwelveToneRow(numbers)
            >>> abjad.show(row_2) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = row_2.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    bf'8
                    c'8
                    d'8
                    fs'8
                    af'8
                    g'8
                    f'8
                    ef'8
                    cs'8
                    a'8
                    e'8
                    b'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

            >>> row_3 = row(row_2)
            >>> abjad.show(row_3) # doctest: +SKIP

            ..  docs::

                >>> lilypond_file = row_3.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    af'8
                    cs'8
                    a'8
                    f'8
                    bf'8
                    e'8
                    g'8
                    ef'8
                    b'8
                    d'8
                    fs'8
                    c'8
                    \bar "|." %! SCORE1
                    \override Score.BarLine.transparent = ##f
                }

        Returns permuted pitch-classes in object of type `pitch_classes`.
        '''
        from abjad.tools import pitchtools
        new_pitch_classes = []
        for pitch_class in pitch_classes:
            pitch_class = pitchtools.NumberedPitchClass(pitch_class)
            i = pitch_class.number
            new_pitch_class = self[i]
            new_pitch_classes.append(new_pitch_class)
        result = type(pitch_classes)(new_pitch_classes)
        return result