Пример #1
0
def test_init(input_, expected_semitones):
    if isinstance(expected_semitones, type) and issubclass(
            expected_semitones, Exception):
        with pytest.raises(expected_semitones):
            abjad.NumberedPitchClass(input_)
        return
    instance = abjad.NumberedPitchClass(input_)
    assert float(instance) == expected_semitones
Пример #2
0
    def _from_number(self, number):
        import abjad

        self._number = self._to_nearest_quarter_tone(number)
        octave_number, pc_number = divmod(self._number, 12)
        self._octave = abjad.Octave(octave_number + 4)
        self._pitch_class = abjad.NumberedPitchClass(pc_number)
Пример #3
0
def violin_pitches():
    """
    1-175
    """
    aggregate = [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40]
    assert aggregate == [10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40]
    cary = [[-2, -12, -10], [18, 8, 7, 17], [15, 25, 21, 4, 11]]
    order_1 = abjad.sequence.flatten(cary)
    order_1 = [_ % 12 for _ in order_1]
    assert order_1 == [10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11]
    order_2 = [abjad.sequence.rotate(_, n=1) for _ in cary]
    order_2 = abjad.sequence.rotate(order_2, n=-1)
    order_2 = abjad.sequence.flatten(order_2)
    order_2 = [_ % 12 for _ in order_2]
    assert order_2 == [5, 6, 8, 7, 11, 3, 1, 9, 4, 2, 10, 0]
    order_3 = [abjad.sequence.rotate(_, n=2) for _ in cary]
    order_3 = abjad.sequence.rotate(order_3, n=-2)
    order_3 = abjad.sequence.flatten(order_3)
    order_3 = [_ % 12 for _ in order_3]
    assert order_3 == [4, 11, 3, 1, 9, 0, 2, 10, 7, 5, 6, 8]
    aggregate_ = abjad.PitchSet(aggregate)
    violin_pitches = []
    orders = (order_1, order_2, order_3)
    for order in orders:
        order = [abjad.NumberedPitchClass(_) for _ in order]
        pitches_ = baca.pcollections.register_pcs(aggregate_, order)
        violin_pitches.extend(pitches_)
    return violin_pitches
Пример #4
0
    def duplicate_pitch_classes(self):
        """
        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.
        """
        import abjad

        pitch_classes = []
        duplicate_pitch_classes = []
        for pitch in self:
            pitch_class = abjad.NumberedPitchClass(pitch)
            if pitch_class in pitch_classes:
                duplicate_pitch_classes.append(pitch_class)
            pitch_classes.append(pitch_class)
        return abjad.PitchClassSet(duplicate_pitch_classes,
                                   item_class=abjad.NumberedPitchClass)
Пример #5
0
    def _from_pitch_or_pitch_class(self, pitch_or_pitch_class):
        import abjad

        self._number = self._to_nearest_quarter_tone(
            float(pitch_or_pitch_class))
        octave_number, pc_number = divmod(self._number, 12)
        self._octave = abjad.Octave(octave_number + 4)
        self._pitch_class = abjad.NumberedPitchClass(
            pc_number, arrow=pitch_or_pitch_class.arrow)
Пример #6
0
 def _from_number(self, number):
     import abjad
     number = self._to_nearest_quarter_tone(number)
     div, mod = divmod(number, 12)
     pitch_class = abjad.NumberedPitchClass(mod)
     self._from_named_parts(
         dpc_number=pitch_class._get_diatonic_pc_number(),
         alteration=pitch_class._get_alteration(),
         octave=div + 4,
         )
Пример #7
0
 def _from_named_parts(self, dpc_number, alteration, octave):
     import abjad
     pc_number = constants._diatonic_pc_number_to_pitch_class_number[
         dpc_number]
     pc_number += alteration
     pc_number += (octave - 4) * 12
     self._number = mathtools.integer_equivalent_number_to_integer(
         pc_number)
     octave_number, pc_number = divmod(self._number, 12)
     self._pitch_class = abjad.NumberedPitchClass(pc_number)
     self._octave = abjad.Octave(octave_number + 4)
Пример #8
0
 def _from_number(self, number):
     import abjad
     numbered_pitch_class = abjad.NumberedPitchClass(number)
     self._from_pitch_or_pitch_class(numbered_pitch_class)
Пример #9
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_)
        return
    instance = abjad.NamedPitch(input_)
    assert float(instance) == expected_semitones
Пример #10
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 "|." %! SCORE_1
                    \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 "|." %! SCORE_1
                    \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 "|." %! SCORE_1
                    \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 "|." %! SCORE_1
                    \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 "|." %! SCORE_1
                    \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 "|." %! SCORE_1
                    \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 "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

        Returns permuted pitch-classes in object of type `pitch_classes`.
        """
        import abjad

        new_pitch_classes = []
        for pitch_class in pitch_classes:
            pitch_class = abjad.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
Пример #11
0
 def _initialize_by_number(self, argument):
     import abjad
     pitch_class_number = float(argument) % 12
     numbered_pitch_class = abjad.NumberedPitchClass(pitch_class_number)
     pitch_class_name = numbered_pitch_class.name
     self._initialize_by_pitch_name(pitch_class_name)