def get_sequence_elements_frequency_distribution(sequence):
    '''Get `sequence` elements frequency distribution:

    ::

        >>> sequence = [1, 3, 3, 3, 2, 1, 1, 2, 3, 3, 1, 2]

    ::

        >>> sequencetools.get_sequence_elements_frequency_distribution(sequence)
        [(1, 4), (2, 3), (3, 5)]

    Returns list of element / count pairs.
    '''
    from abjad.tools import sequencetools

    result = sorted(sequence)
    result = sequencetools.partition_sequence_by_value_of_elements(result)
    result = [(x[0], len(x)) for x in result]
    return result
コード例 #2
0
ファイル: Meter.py プロジェクト: adorsk/abjad
    def _make_gridded_test_rhythm(grid_length, rhythm_number, denominator=16):
        r'''Make test rhythm number `rhythm_number` that fits `grid_length`.

        Returns selection of one or more possibly tied notes.

        ..  container:: example

            **Example 1.** The eight test rhythms that fit a length-``4``
            grid:

            ::

                >>> from abjad.tools.metertools import Meter
                >>> for rhythm_number in range(8):
                ...     notes = Meter._make_gridded_test_rhythm(
                ...         4, rhythm_number, denominator=4)
                ...     measure = Measure((4, 4), notes)
                ...     print '{}\t{}'.format(rhythm_number, str(measure))
                ...
                0   |4/4 c'1|
                1   |4/4 c'2. c'4|
                2   |4/4 c'2 c'4 c'4|
                3   |4/4 c'2 c'2|
                4   |4/4 c'4 c'4 c'2|
                5   |4/4 c'4 c'4 c'4 c'4|
                6   |4/4 c'4 c'2 c'4|
                7   |4/4 c'4 c'2.|

        ..  container:: example

            **Example 2.** The sixteenth test rhythms for that a length-``5``
            grid:

            ::

                >>> for rhythm_number in range(16):
                ...     notes = Meter._make_gridded_test_rhythm(
                ...         5, rhythm_number, denominator=4)
                ...     measure = Measure((5, 4), notes)
                ...     print '{}\t{}'.format(rhythm_number, str(measure))
                ...
                0   |5/4 c'1 ~ c'4|
                1   |5/4 c'1 c'4|
                2   |5/4 c'2. c'4 c'4|
                3   |5/4 c'2. c'2|
                4   |5/4 c'2 c'4 c'2|
                5   |5/4 c'2 c'4 c'4 c'4|
                6   |5/4 c'2 c'2 c'4|
                7   |5/4 c'2 c'2.|
                8   |5/4 c'4 c'4 c'2.|
                9   |5/4 c'4 c'4 c'2 c'4|
                10  |5/4 c'4 c'4 c'4 c'4 c'4|
                11  |5/4 c'4 c'4 c'4 c'2|
                12  |5/4 c'4 c'2 c'2|
                13  |5/4 c'4 c'2 c'4 c'4|
                14  |5/4 c'4 c'2. c'4|
                15  |5/4 c'4 c'1|

        Use for testing meter establishment.
        '''
        from abjad.tools import scoretools
        # check input
        assert mathtools.is_positive_integer(grid_length)
        assert isinstance(rhythm_number, int)
        assert mathtools.is_positive_integer_power_of_two(denominator)
        # find count of all rhythms that fit grid length
        rhythm_count = 2 ** (grid_length - 1)
        # read rhythm number cyclically to allow large and
        # negative rhythm numbers
        rhythm_number = rhythm_number % rhythm_count
        # find binary representation of rhythm
        binary_representation = \
            mathtools.integer_to_binary_string(rhythm_number)
        binary_representation = binary_representation.zfill(grid_length)
        # partition binary representation of rhythm
        parts = sequencetools.partition_sequence_by_value_of_elements(
            binary_representation)
        # find durations
        durations = [
            durationtools.Duration(len(part), denominator)
            for part in parts
            ]
        # make notes
        notes = scoretools.make_notes([0], durations)
        # return notes
        return notes
コード例 #3
0
    def _make_gridded_test_rhythm(grid_length, rhythm_number, denominator=16):
        r'''Make test rhythm number `rhythm_number` that fits `grid_length`.

        Returns selection of one or more possibly tied notes.

        ..  container:: example

            **Example 1.** The eight test rhythms that fit a length-``4``
            grid:

            ::

                >>> from abjad.tools.metertools import Meter
                >>> for rhythm_number in range(8):
                ...     notes = Meter._make_gridded_test_rhythm(
                ...         4, rhythm_number, denominator=4)
                ...     measure = Measure((4, 4), notes)
                ...     print('{}\t{}'.format(rhythm_number, str(measure)))
                ...
                0	Measure((4, 4), "c'1")
                1	Measure((4, 4), "c'2. c'4")
                2	Measure((4, 4), "c'2 c'4 c'4")
                3	Measure((4, 4), "c'2 c'2")
                4	Measure((4, 4), "c'4 c'4 c'2")
                5	Measure((4, 4), "c'4 c'4 c'4 c'4")
                6	Measure((4, 4), "c'4 c'2 c'4")
                7	Measure((4, 4), "c'4 c'2.")

        ..  container:: example

            **Example 2.** The sixteenth test rhythms for that a length-``5``
            grid:

            ::

                >>> for rhythm_number in range(16):
                ...     notes = Meter._make_gridded_test_rhythm(
                ...         5, rhythm_number, denominator=4)
                ...     measure = Measure((5, 4), notes)
                ...     print('{}\t{}'.format(rhythm_number, str(measure)))
                ...
                0	Measure((5, 4), "c'1 ~ c'4")
                1	Measure((5, 4), "c'1 c'4")
                2	Measure((5, 4), "c'2. c'4 c'4")
                3	Measure((5, 4), "c'2. c'2")
                4	Measure((5, 4), "c'2 c'4 c'2")
                5	Measure((5, 4), "c'2 c'4 c'4 c'4")
                6	Measure((5, 4), "c'2 c'2 c'4")
                7	Measure((5, 4), "c'2 c'2.")
                8	Measure((5, 4), "c'4 c'4 c'2.")
                9	Measure((5, 4), "c'4 c'4 c'2 c'4")
                10	Measure((5, 4), "c'4 c'4 c'4 c'4 c'4")
                11	Measure((5, 4), "c'4 c'4 c'4 c'2")
                12	Measure((5, 4), "c'4 c'2 c'2")
                13	Measure((5, 4), "c'4 c'2 c'4 c'4")
                14	Measure((5, 4), "c'4 c'2. c'4")
                15	Measure((5, 4), "c'4 c'1")

        Use for testing meter establishment.
        '''
        from abjad.tools import scoretools
        # check input
        assert mathtools.is_positive_integer(grid_length)
        assert isinstance(rhythm_number, int)
        assert mathtools.is_positive_integer_power_of_two(denominator)
        # find count of all rhythms that fit grid length
        rhythm_count = 2**(grid_length - 1)
        # read rhythm number cyclically to allow large and
        # negative rhythm numbers
        rhythm_number = rhythm_number % rhythm_count
        # find binary representation of rhythm
        binary_representation = \
            mathtools.integer_to_binary_string(rhythm_number)
        binary_representation = binary_representation.zfill(grid_length)
        # partition binary representation of rhythm
        parts = sequencetools.partition_sequence_by_value_of_elements(
            binary_representation)
        # find durations
        durations = [
            durationtools.Duration(len(part), denominator) for part in parts
        ]
        # make notes
        notes = scoretools.make_notes([0], durations)
        # return notes
        return notes