Esempio n. 1
0
def moment_6():
    """
    >>> section, section_name = mraz.library.moment_6(), "section_6"
    >>> show_collections(section, section_name)
    section_6.stage_1.rh:
      PC<6, 9, 11>
      PC<0, 8, 11, 1>
      PC<10, 1, 3>
      PC<2, 4, 0, 3, 5>
      PC<8, 4, 7, 9>
    section_6.stage_1.lh:
      PC<7, 8, 10, 9>
      PC<11, 0, 2, 1>
      PC<2, 5, 7, 3, 4>
      PC<6, 5>

    """
    silver, names = silver_transform_7()
    silver = abjad.CyclicTuple(silver)
    segments = silver[42:45]
    segments = list(segments)
    assert len(segments) == 3, repr(len(segments))
    stages = abjad.sequence.partition_by_counts(segments, [1, 1, 1])
    stage_1_segments = stages[0]
    stage_1_segments = baca.sequence.accumulate(
        stage_1_segments,
        [lambda _: baca.pcollections.alpha(_), lambda _: _.transpose(n=2)],
    )
    stage_1_segments = abjad.sequence.flatten(stage_1_segments)
    stage_1_segments = abjad.sequence.join(stage_1_segments)
    stage_1_segments = baca.pcollections.read(stage_1_segments,
                                              [3, 5, 4, 3, 4, 5, 5, 3, 4],
                                              check=abjad.EXACT)
    assert len(abjad.sequence.join(stage_1_segments)[0]) == 36
    rh_indices = [0, 2, 3, 5, 8]
    rh_stage_1_segments = abjad.sequence.retain(stage_1_segments, rh_indices)
    rh_stage_1_segments = baca.pcollections.remove_duplicates(
        rh_stage_1_segments, level=1)
    rh_stage_1_segments = [
        abjad.PitchClassSegment(_) for _ in rh_stage_1_segments
    ]
    lh_stage_1_segments = abjad.sequence.remove(stage_1_segments, rh_indices)
    lh_stage_1_segments = baca.pcollections.remove_duplicates(
        lh_stage_1_segments, level=1)
    lh_stage_1_segments = [
        abjad.PitchClassSegment(_) for _ in lh_stage_1_segments
    ]
    assert len(rh_stage_1_segments) == 5
    assert len(lh_stage_1_segments) == 4
    rh_stage_1_segments = baca.Cursor(rh_stage_1_segments)
    lh_stage_1_segments = baca.Cursor(lh_stage_1_segments)
    return types.SimpleNamespace(
        stage_1=types.SimpleNamespace(
            rh=rh_stage_1_segments,
            lh=lh_stage_1_segments,
        ),
        stage_2=None,
        stage_3=None,
        stage_4=None,
    )
def test_pitchtools_PitchClassSegment__is_equivalent_under_transposition_01():

    pitch_class_segment_1 = abjad.PitchClassSegment(['c', 'e', 'b'])
    pitch_class_segment_2 = abjad.PitchClassSegment(['f', 'a', 'e'])
    pitch_class_segment_3 = abjad.PitchClassSegment(['f', 'a'])

    assert pitch_class_segment_1._is_equivalent_under_transposition(
        pitch_class_segment_1)
    assert pitch_class_segment_1._is_equivalent_under_transposition(
        pitch_class_segment_2)
    assert not pitch_class_segment_1._is_equivalent_under_transposition(
        pitch_class_segment_3)

    assert pitch_class_segment_2._is_equivalent_under_transposition(
        pitch_class_segment_1)
    assert pitch_class_segment_2._is_equivalent_under_transposition(
        pitch_class_segment_2)
    assert not pitch_class_segment_2._is_equivalent_under_transposition(
        pitch_class_segment_3)

    assert not pitch_class_segment_3._is_equivalent_under_transposition(
        pitch_class_segment_1)
    assert not pitch_class_segment_3._is_equivalent_under_transposition(
        pitch_class_segment_2)
    assert pitch_class_segment_3._is_equivalent_under_transposition(
        pitch_class_segment_3)
def test_PitchClassSegment__is_equivalent_under_transposition_01():

    pitch_class_segment_1 = abjad.PitchClassSegment(["c", "e", "b"])
    pitch_class_segment_2 = abjad.PitchClassSegment(["f", "a", "e"])
    pitch_class_segment_3 = abjad.PitchClassSegment(["f", "a"])

    assert pitch_class_segment_1._is_equivalent_under_transposition(
        pitch_class_segment_1
    )
    assert pitch_class_segment_1._is_equivalent_under_transposition(
        pitch_class_segment_2
    )
    assert not pitch_class_segment_1._is_equivalent_under_transposition(
        pitch_class_segment_3
    )

    assert pitch_class_segment_2._is_equivalent_under_transposition(
        pitch_class_segment_1
    )
    assert pitch_class_segment_2._is_equivalent_under_transposition(
        pitch_class_segment_2
    )
    assert not pitch_class_segment_2._is_equivalent_under_transposition(
        pitch_class_segment_3
    )

    assert not pitch_class_segment_3._is_equivalent_under_transposition(
        pitch_class_segment_1
    )
    assert not pitch_class_segment_3._is_equivalent_under_transposition(
        pitch_class_segment_2
    )
    assert pitch_class_segment_3._is_equivalent_under_transposition(
        pitch_class_segment_3
    )
Esempio n. 4
0
 def _get_most_compact_ordering(candidates):
     import abjad
     widths = []
     for candidate in candidates:
         if candidate[0] < candidate[-1]:
             width = abs(candidate[-1] - candidate[0])
         else:
             width = abs(candidate[-1] + 12 - candidate[0])
         widths.append(width)
     minimum_width = min(widths)
     candidates_ = []
     for candidate, width in zip(candidates, widths):
         if width == minimum_width:
             candidates_.append(candidate)
     candidates = candidates_
     assert 1 <= len(candidates)
     if len(candidates) == 1:
         segment = candidates[0]
         segment = abjad.PitchClassSegment(
             items=segment,
             item_class=abjad.NumberedPitchClass,
         )
         return segment
     for i in range(len(candidates[0]) - 1):
         widths = []
         for candidate in candidates:
             stop = i + 1
             if candidate[0] < candidate[stop]:
                 width = abs(candidate[stop] - candidate[0])
             else:
                 width = abs(candidate[stop] + 12 - candidate[0])
             widths.append(width)
         minimum_width = min(widths)
         candidates_ = []
         for candidate, width in zip(candidates, widths):
             if width == minimum_width:
                 candidates_.append(candidate)
         candidates = candidates_
         if len(candidates) == 1:
             segment = candidates[0]
             segment = abjad.PitchClassSegment(
                 items=segment,
                 item_class=abjad.NumberedPitchClass,
             )
             return segment
     candidates.sort(key=lambda x: x[0])
     segment = candidates[0]
     segment = abjad.PitchClassSegment(
         items=segment,
         item_class=abjad.NumberedPitchClass,
     )
     return segment
Esempio n. 5
0
def silver_start():
    """
    >>> segments, names = mraz.library.silver_start()
    >>> for segment in segments: print(segment)
    PC<4, 6, 10>
    PC<9, 7, 8, 11, 9, 1>
    PC<0, 2, 3, 5>

    """
    J = abjad.PitchClassSegment([4, 6, 10])
    K = abjad.PitchClassSegment([9, 7, 8, 11, 9, 1])
    L = abjad.PitchClassSegment([0, 2, 3, 5])
    segments = [J, K, L]
    names = ["J", "K", "L"]
    return segments, names
Esempio n. 6
0
def moment_2():
    """
    >>> section, section_name = mraz.library.moment_2(), "section_2"
    >>> show_collections(section, section_name)
    section_2.stage_2.rh:
      [<6, 12, 16, 17, 20>, <10, 15, 23, 31, 33>, <2, 13, 20, 22, 27, 29>, <9, 11, 19, 30, 36>, <4, 5, 8, 10, 15>, <11, 19, 21>]
      [<2, 13, 20, 22, 27>, <5, 9, 11, 19, 30, 36>, <4, 5, 8, 10, 15, 23>, <7, 11, 21, 26, 37>, <8, 10, 15, 17, 21>]
      [<11, 19, 30, 36>, <4, 5, 8, 10>, <3, 11, 19, 21>, <2, 13, 20, 22, 27>, <5, 9, 11, 19>]
      [<6, 12, 16, 17>, <8, 10, 15>, <11, 19, 21>, <2, 13, 20, 22, 27>]
      [<5, 9, 11, 19, 30>, <0, 4, 5, 8>, <10, 15, 23, 31>, <11, 21, 26>]

    """
    silver, names = silver_transform_7()
    silver = abjad.CyclicTuple(silver)
    segments = list(silver[14:20])
    assert len(segments) == 6, repr(len(segments))
    stages = abjad.sequence.partition_by_counts(segments, [2, 4])
    segments = stages[1]
    counts = 2 * [5, 6, 6, 5, 5, 4] + 2 * [4, 5, 5, 4, 4, 3]
    segments = abjad.sequence.join(segments)
    segments = baca.pcollections.read(segments, counts)
    segments = baca.pcollections.remove_duplicates(segments, level=1)
    segments = abjad.sequence.partition_by_counts(segments, [6, 5, 5, 4, 4])
    segments = [[abjad.PitchClassSegment(_) for _ in list_]
                for list_ in segments]
    segments = [[baca.pcollections.arpeggiate_up(_) for _ in list_]
                for list_ in segments]
    segments = baca.Cursor(segments, singletons=True)
    return types.SimpleNamespace(
        stage_1=None,
        stage_2=types.SimpleNamespace(rh=segments, ),
    )
Esempio n. 7
0
    def order_by(self, segment):
        """
        Orders pitch-class set by pitch-class `segment`.

        ..  container:: example

            >>> set_ = abjad.PitchClassSet(['c', 'e', 'b'])
            >>> segment = abjad.PitchClassSegment(['e', 'a', 'f'])
            >>> set_.order_by(segment)
            PitchClassSegment("b e c")

        Returns pitch-class segment.
        """
        import abjad
        if not len(self) == len(segment):
            message = 'set and segment must be on equal length.'
            raise ValueError(message)
        enumerator = Enumerator(self)
        for pitch_classes in enumerator.yield_permutations():
            candidate = abjad.PitchClassSegment(pitch_classes)
            if candidate._is_equivalent_under_transposition(segment):
                return candidate
        message = '{!s} can not order by {!s}.'
        message = message.format(self, segment)
        raise ValueError(message)
Esempio n. 8
0
    def to_pitch_classes(self):
        r"""
        Changes to pitch-classes.

        ..  container:: example

            To numbered pitch-class segment:

            >>> segment = abjad.PitchSegment([-2, -1.5, 6, 7, -1.5, 7])

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

            ..  docs::

                >>> lilypond_file = segment.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.StaffGroup])
                \new PianoStaff
                <<
                    \context Staff = "Treble_Staff"
                    {
                        \clef "treble"
                        r1 * 1/8
                        r1 * 1/8
                        fs'1 * 1/8
                        g'1 * 1/8
                        r1 * 1/8
                        g'1 * 1/8
                    }
                    \context Staff = "Bass_Staff"
                    {
                        \clef "bass"
                        bf1 * 1/8
                        bqf1 * 1/8
                        r1 * 1/8
                        r1 * 1/8
                        bqf1 * 1/8
                        r1 * 1/8
                    }
                >>

            >>> segment = segment.to_pitch_classes()

            >>> str(segment)
            'PC<10, 10.5, 6, 7, 10.5, 7>'

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

            ..  docs::

                >>> lilypond_file = segment.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    bf'8
                    bqf'8
                    fs'8
                    g'8
                    bqf'8
                    g'8
                    \bar "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

        ..  container:: example

            To named pitch-class segment:

            >>> segment = abjad.PitchSegment("bf, aqs fs' g' bqf g'")

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

            ..  docs::

                >>> lilypond_file = segment.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.StaffGroup])
                \new PianoStaff
                <<
                    \context Staff = "Treble_Staff"
                    {
                        \clef "treble"
                        r1 * 1/8
                        r1 * 1/8
                        fs'1 * 1/8
                        g'1 * 1/8
                        r1 * 1/8
                        g'1 * 1/8
                    }
                    \context Staff = "Bass_Staff"
                    {
                        \clef "bass"
                        bf,1 * 1/8
                        aqs1 * 1/8
                        r1 * 1/8
                        r1 * 1/8
                        bqf1 * 1/8
                        r1 * 1/8
                    }
                >>

            >>> segment = segment.to_pitch_classes()

            >>> str(segment)
            'PC<bf aqs fs g bqf g>'

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

            ..  docs::

                >>> lilypond_file = segment.__illustrate__()
                >>> abjad.f(lilypond_file[abjad.Voice])
                \new Voice
                {
                    bf'8
                    aqs'8
                    fs'8
                    g'8
                    bqf'8
                    g'8
                    \bar "|." %! SCORE_1
                    \override Score.BarLine.transparent = ##f
                }

        Returns new segment.
        """
        import abjad

        class_ = abjad.Pitch
        item_class = class_._to_pitch_class_item_class(self.item_class)
        return abjad.PitchClassSegment(items=self.items, item_class=item_class)
Esempio n. 9
0
def moment_8():
    """
    >>> section, section_name = mraz.library.moment_8(), "section_8"
    >>> show_collections(section, section_name)
    section_8.stage_3.rh:
      PC<7, 6>
      PC<7, 9, 1>
      PC<11, 8, 9>
      PC<1, 9, 8>
      PC<10, 2, 0, 11>
      PC<2, 10>
      PC<11, 1, 5>
      PC<3, 0, 1, 3>
      PC<0, 2>
      PC<6, 4, 3>
      PC<2, 3, 5>
      PC<9, 7>
      PC<11, 9, 5, 4>
      PC<6, 10, 8>
    section_8.stage_3.lh:
      PC<8, 0, 10>
      PC<11, 3>
      PC<10, 0, 4>
      PC<7, 5, 1>
      PC<2, 4, 8, 6>
      PC<4, 5, 7>

    """
    silver, names = silver_transform_7()
    silver = abjad.CyclicTuple(silver)
    segments = silver[59:65]
    segments = list(segments)
    assert len(segments) == 6, repr(len(segments))
    stages = abjad.sequence.partition_by_counts(segments, [1, 1, 1, 3])
    stage_3_segments = baca.pcollections.remove_duplicates(stages[2])
    stage_3_segments = [abjad.PitchClassSegment(_) for _ in stage_3_segments]
    stage_3_segments = baca.sequence.accumulate(
        stage_3_segments,
        [lambda _: baca.pcollections.alpha(_), lambda _: _.transpose(n=2)],
    )
    stage_3_segments = abjad.sequence.join(stage_3_segments)
    stage_3_segments = abjad.sequence.flatten(stage_3_segments)
    stage_3_segments = baca.pcollections.read(stage_3_segments,
                                              5 * [2, 3, 4, 3],
                                              check=abjad.EXACT)
    assert len(stage_3_segments) == 20
    assert len(abjad.sequence.join(stage_3_segments)[0]) == 60
    assert not baca.pcollections.has_repeats(stage_3_segments, level=-1)
    v5_indices = [0, 2, 3, 5, 6, 8, 9]
    v5_stage_3_segments = abjad.sequence.retain(stage_3_segments,
                                                v5_indices,
                                                period=10)
    v5_stage_3_segments = baca.pcollections.remove_repeats(v5_stage_3_segments,
                                                           level=-1)
    v5_stage_3_segments = [
        abjad.PitchClassSegment(_) for _ in v5_stage_3_segments
    ]
    assert not baca.pcollections.has_repeats(v5_stage_3_segments, level=-1)
    v6_stage_3_segments = abjad.sequence.remove(stage_3_segments,
                                                v5_indices,
                                                period=10)
    v6_stage_3_segments = baca.pcollections.remove_repeats(v6_stage_3_segments,
                                                           level=-1)
    v6_stage_3_segments = [
        abjad.PitchClassSegment(_) for _ in v6_stage_3_segments
    ]
    assert not baca.pcollections.has_repeats(v6_stage_3_segments, level=-1)
    assert len(v5_stage_3_segments) == 14, len(v5_stage_3_segments)
    assert len(v6_stage_3_segments) == 6, len(v6_stage_3_segments)
    v5_stage_3_segments = baca.Cursor(v5_stage_3_segments)
    v6_stage_3_segments = baca.Cursor(v6_stage_3_segments)
    return types.SimpleNamespace(
        stage_1=None,
        stage_2=None,
        stage_3=types.SimpleNamespace(
            rh=v5_stage_3_segments,
            lh=v6_stage_3_segments,
        ),
        stage_4=None,
    )
Esempio n. 10
0
def moment_5():
    """
    >>> section, section_name = mraz.library.moment_5(), "section_5"
    >>> show_collections(section, section_name)
    section_5.stage_1.rh:
      PC<0, 2, 3, 5>
    section_5.stage_1.lh:
      PC<9, 1, 11, 8, 7>
    section_5.stage_2.rh:
      PC<2, 3, 5, 0>
      PC<9, 10, 0, 7, 4, 5, 3>
      PC<5, 6, 8, 3>
      PC<0, 1, 3, 10, 7, 8, 6>
      PC<4, 7, 9, 2>
      PC<1, 0, 2, 11, 6, 9, 7>
      PC<7, 10, 0, 5>
      PC<4, 3, 5, 2, 9, 0, 10>
      PC<6, 11, 1, 4>
      PC<5, 2, 4, 3, 8, 1, 11>
      PC<9, 2, 4, 7>
      PC<8, 5, 7, 6, 11, 4, 2>
      PC<8, 3, 5, 6>
      PC<9, 4, 6, 7, 10, 5, 3>
      PC<11, 6, 8, 9>
      PC<0, 7, 9, 10, 1, 8, 6>
      PC<10, 7, 9, 8>
      PC<1, 6, 8, 11, 0, 9, 7>
      PC<1, 10, 0, 11>
      PC<4, 9, 11, 2, 3, 0, 10>
      PC<0, 11, 1, 10>
      PC<5, 8, 10, 3, 2, 1, 11>
      PC<3, 2, 4, 1>
      PC<8, 11, 1, 6, 5, 4, 2>
    section_5.stage_2.lh:
      PC<11, 3, 1>
      PC<8, 4, 10, 1>
      PC<11, 7>
      PC<11, 3, 1, 8>
      PC<4, 10>
      PC<1, 11, 7>
      PC<11, 3>
      PC<1, 8, 4>
      PC<10, 1, 11, 7>

    """
    silver, names = silver_transform_7()
    silver = abjad.CyclicTuple(silver)
    segments = silver[36:42]
    assert len(segments) == 6, repr(len(segments))
    stages = abjad.sequence.partition_by_counts(segments, [2, 4])
    stage_1_segments = stages[0]
    stage_2_segments = stages[1]
    stage_1_segments = baca.pcollections.remove_duplicate_pitch_classes(
        stage_1_segments, level=1)
    rh, lh = abjad.sequence.partition_by_counts(stage_1_segments, [1, 1])
    rh = [abjad.PitchClassSegment(_) for _ in rh]
    lh = [abjad.PitchClassSegment(_) for _ in lh]
    rh = baca.Cursor(rh, singletons=True)
    lh = baca.Cursor(lh, singletons=True)
    stage_1_rh = rh
    stage_1_lh = lh
    stage_2_segments = baca.pcollections.remove_duplicate_pitch_classes(
        stage_2_segments, level=1)
    rh, lh = abjad.sequence.partition_by_counts(stage_2_segments, [2, 2])
    rh = [abjad.PitchClassSegment(_) for _ in rh]
    rh = baca.sequence.accumulate(
        rh, [lambda _: _.transpose(n=3), lambda _: baca.pcollections.alpha(_)])
    rh = abjad.sequence.flatten(rh)
    rh = baca.Cursor(rh, singletons=True)
    lh = abjad.sequence.repeat(lh, n=3)
    lh = abjad.sequence.flatten(lh)
    lh = [abjad.PitchClassSegment(_) for _ in lh]
    lh = baca.pcollections.read(lh, [3, 4, 2, 4, 2, 3, 2, 3, 4],
                                check=abjad.EXACT)
    lh = [abjad.PitchClassSegment(_) for _ in lh]
    lh = baca.Cursor(lh, singletons=True)
    stage_2_rh = rh
    stage_2_lh = lh
    return types.SimpleNamespace(
        stage_1=types.SimpleNamespace(
            rh=stage_1_rh,
            lh=stage_1_lh,
        ),
        stage_2=types.SimpleNamespace(
            rh=stage_2_rh,
            lh=stage_2_lh,
        ),
    )
Esempio n. 11
0
def moment_4():
    """
    >>> section, section_name = mraz.library.moment_4(), "section_4"
    >>> show_collections(section, section_name)
    section_4.stage_1.rh:
      PC<3, 1, 0, 10>
      PC<3, 1, 0, 10>
      PC<3, 1, 0, 10>
    section_4.stage_1.lh:
      PC<8, 2, 4>
      PC<8, 2, 4>
      PC<8, 2, 4>
    section_4.stage_2.lh:
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      {7, 11, 17, 18, 21}
      PC<6, 9, 7, 11, 7, 5, 2, 4, 8>
    section_4.stage_4.rh:
      PC<2, 8, 3, 9, 2, 5, 11, 4>
      PC<10, 5, 6, 0, 7, 1, 6, 9>
      PC<3, 8, 2, 9, 10, 4, 11, 5, 10, 1, 7, 0, 6, 1>
    section_4.stage_4.lh:
      {0, 10}
      {2, 5}
      {0, 4, 8}
      {10}
      {2, 5}
      {4, 8}
      {0, 5, 10}
      {2, 4, 8}
    section_4.stage_5.rh:
      PC<3>
      PC<5>
      PC<10>
      PC<3>
      PC<5>
      PC<10>
    section_4.stage_5.lh:
      PC<11, 6, 7, 9, 1>
      PC<10, 1, 8, 9, 11>
      PC<3, 0, 10, 11, 1>
      PC<5, 2, 0, 1>
      PC<3, 7, 4, 2>
      PC<3, 5, 9, 6, 4>
      PC<5, 7, 11, 8>
      PC<6, 7, 9, 1, 10>
      PC<1, 8, 9, 11, 3, 0>
      PC<3, 10, 11, 1, 5>
      PC<2, 5, 0, 1, 3>
      PC<7, 4, 2, 3, 5>
      PC<9, 6, 4, 5>
      PC<7, 11, 8, 6>
      PC<7, 9, 1, 10, 8>
    section_4.stage_6.rh:
      {17, 27, 36, 40, 42, 46}
      {-3, 7, 8, 11, 13, 17, 27, 36}
      {4, 6, 10, 21, 31, 32, 35, 37}

    """
    silver, names = silver_transform_7()
    silver = abjad.CyclicTuple(silver)
    segments = silver[23:36]
    segments = list(segments)
    assert len(segments) == 13, repr(len(segments))
    stages = abjad.sequence.partition_by_counts(segments, [2, 2, 2, 2, 2, 3])
    stage_1_segments = stages[0]
    stage_2_segments = stages[1]
    stage_4_segments = stages[3]
    stage_5_segments = stages[4]
    stage_6_segments = stages[5]
    stage_1_rh_segments = stage_1_segments[:1]
    stage_1_rh_segments = abjad.sequence.repeat(stage_1_rh_segments, n=3)
    stage_1_rh_segments = abjad.sequence.flatten(stage_1_rh_segments)
    stage_1_rh_segments = baca.Cursor(stage_1_rh_segments)
    stage_1_lh_segments = stage_1_segments[1:]
    stage_1_lh_segments = abjad.sequence.repeat(stage_1_lh_segments, n=3)
    stage_1_lh_segments = abjad.sequence.flatten(stage_1_lh_segments)
    stage_1_lh_segments = baca.Cursor(stage_1_lh_segments)
    chord = abjad.PitchSet(stage_2_segments[0])
    chord = baca.pcollections.space_up(chord, bass=7, soprano=9)
    chords = 10 * [chord]
    last = abjad.sequence.join(stages[1])[0]
    chords.append(last)
    stage_2_segments = baca.Cursor(chords, cyclic=False, singletons=True)
    assert len(stage_4_segments) == 2
    rh, lh = abjad.sequence.partition_by_counts(stage_4_segments, [1, 1])
    lh = baca.pcollections.remove_duplicates(lh, level=-1)
    lh = baca.pcollections.read(lh, [2, 2, 3, 1, 2, 2, 3, 3],
                                check=abjad.EXACT)
    lh = [abjad.PitchClassSegment(_) for _ in lh]
    lh = [abjad.PitchSet(_) for _ in lh]
    lh = baca.Cursor(lh, cyclic=True, singletons=True)
    rh = baca.sequence.accumulate(
        rh, [lambda _: baca.pcollections.alpha(_), lambda _: _.transpose(n=2)])
    if isinstance(rh, list):
        rh = abjad.sequence.flatten(rh)
    rh = abjad.sequence.join(rh)
    rh = baca.pcollections.remove_repeats(rh)
    rh = baca.pcollections.read(rh, [8, 8, 14], check=abjad.EXACT)
    rh = [abjad.PitchClassSegment(_) for _ in rh]
    rh = baca.Cursor(rh)
    stage_4_rh_segments = rh
    stage_4_lh_segments = lh
    stage_5_segments = baca.pcollections.remove_duplicate_pitch_classes(
        stage_5_segments, level=1)
    rh, lh = abjad.sequence.partition_by_counts(stage_5_segments, [1, 1])
    rh = baca.pcollections.read(rh, 6 * [1], check=abjad.EXACT)
    rh = [abjad.PitchClassSegment(_) for _ in rh]
    rh = baca.Cursor(rh, singletons=True)
    lh = [abjad.PitchClassSegment(_) for _ in lh]
    lh = baca.sequence.accumulate(lh, [lambda _: _.transpose(n=2)])
    if isinstance(lh, list):
        lh = abjad.sequence.flatten(lh)
    lh = abjad.sequence.join(lh)
    lh = baca.pcollections.read(lh, 5 * [5, 5, 6])
    lh = baca.pcollections.remove_duplicates(lh, level=1)
    lh = [abjad.PitchClassSegment(_) for _ in lh]
    lh = baca.Cursor(lh, singletons=True)
    stage_5_rh_segments = rh
    stage_5_lh_segments = lh
    stage_6_segments = [abjad.PitchClassSegment(_) for _ in stage_6_segments]
    stage_6_segments = abjad.sequence.repeat(stage_6_segments, n=2)
    stage_6_segments = abjad.sequence.flatten(stage_6_segments)
    stage_6_segments = abjad.sequence.partition_by_counts(stage_6_segments,
                                                          [2],
                                                          cyclic=True)
    stage_6_segments = [abjad.sequence.join(_)[0] for _ in stage_6_segments]
    stage_6_segments = baca.pcollections.remove_duplicates(stage_6_segments,
                                                           level=1)
    stage_6_segments = [
        baca.pcollections.arpeggiate_up(_) for _ in stage_6_segments
    ]
    stage_6_segments = [
        baca.pcollections.soprano_to_octave(_, n=7) for _ in stage_6_segments
    ]
    stage_6_segments = [abjad.PitchSet(_) for _ in stage_6_segments]
    stage_6_segments = baca.Cursor(stage_6_segments, singletons=True)
    return types.SimpleNamespace(
        stage_1=types.SimpleNamespace(
            rh=stage_1_rh_segments,
            lh=stage_1_lh_segments,
        ),
        stage_2=types.SimpleNamespace(
            rh=None,
            lh=stage_2_segments,
        ),
        stage_3=None,
        stage_4=types.SimpleNamespace(
            rh=stage_4_rh_segments,
            lh=stage_4_lh_segments,
        ),
        stage_5=types.SimpleNamespace(
            rh=stage_5_rh_segments,
            lh=stage_5_lh_segments,
        ),
        stage_6=types.SimpleNamespace(
            rh=stage_6_segments,
            lh=None,
        ),
    )
Esempio n. 12
0
    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)
        start = i
        stop = i + count
        group = list_[start:stop]
        if len(group) == count:
            combination_list.append(group)
    return combination_list


for n in range(2, 13):
    score = abjad.Score([])
    for combination_group in adjacent_combinations(
            list_=[0, 5, 7, 1, 4, 11, 3, 2, 10, 8, 9, 6], count=n):
        staff_group1 = abjad.StaffGroup([])
        for rotation in range(len(combination_group)):
            staff_group2 = abjad.StaffGroup([])
            p = abjad.PitchClassSegment(combination_group).rotate(
                n=0 - rotation, stravinsky=False)
            i = p.invert()
            p_values = [item.number for item in p.items]
            i_values = [item.number for item in i.items]
            p_list = [p.transpose(_) for _ in i_values]
            p_staff = abjad.Staff()
            i_list = [i.transpose(_) for _ in p_values]
            i_staff = abjad.Staff()
            r_list = [_.retrograde() for _ in p_list]
            r_staff = abjad.Staff()
            ri_list = [_.retrograde() for _ in i_list]
            ri_staff = abjad.Staff()
            for _ in p_list:
                numbers = [n.number for n in _]
                list_ = []
                for note in numbers: