def _make_monad(self, division):
     numerator, talea_denominator = division
     power_of_two_denominator = \
         mathtools.greatest_power_of_two_less_equal(talea_denominator)
     duration = fractions.Fraction(abs(numerator), talea_denominator)
     power_of_two_duration = \
         fractions.Fraction(abs(numerator), power_of_two_denominator)
     power_of_two_division = (numerator, power_of_two_denominator)
     tuplet_multiplier = duration / power_of_two_duration
     leaves = leaftools.make_leaves([0], [power_of_two_division])
     tuplet = tuplettools.Tuplet(tuplet_multiplier, leaves)
     return tuplet
Example #2
0
    def to_measure(self, cell_duration_denominator=8):
        r'''Change pitch array row to measure with time signature
        numerator equal to pitch array row width and
        time signature denominator equal to `cell_duration_denominator`:

        ::

            >>> array = pitcharraytools.PitchArray([
            ...     [1, (2, 1), ([-2, -1.5], 2)],
            ...     [(7, 2), (6, 1), 1]])

        ::

            >>> print array
            [  ] [d'] [bf bqf    ]
            [g'     ] [fs'   ] [ ]

        ::

            >>> measure = array.rows[0].to_measure()

        ..  doctest::

            >>> f(measure)
            {
                \time 4/8
                r8
                d'8
                <bf bqf>4
            }

        Returns measure.
        '''
        time_signature = contexttools.TimeSignatureMark(
            (self.width, cell_duration_denominator))
        measure = measuretools.Measure(time_signature, [])
        basic_cell_duration = \
            durationtools.Duration(1, cell_duration_denominator)
        measure_pitches, measure_durations = [], []
        for cell in self.cells:
            cell_pitches = cell.pitches
            if not cell_pitches:
                measure_pitches.append(None)
            elif len(cell_pitches) == 1:
                measure_pitches.append(cell_pitches[0])
            else:
                measure_pitches.append(cell_pitches)
            measure_duration = cell.width * basic_cell_duration
            measure_durations.append(measure_duration)
        leaves = leaftools.make_leaves(measure_pitches, measure_durations)
        measure.extend(leaves)
        return measure
def durate_pitch_contour_reservoir(pitch_contour_reservoir):

    instrument_names = [
        'First Violin',
        'Second Violin',
        'Viola',
        'Cello',
        'Bass',
        ]

    durated_reservoir = {}

    for i, instrument_name in enumerate(instrument_names):
        long_duration = Duration(1, 2) * pow(2, i)
        short_duration = long_duration / 2
        rest_duration = long_duration * Multiplier(3, 2)

        div = rest_duration // Duration(3, 2)
        mod = rest_duration % Duration(3, 2)

        initial_rest = resttools.MultimeasureRest((3, 2)) * div
        if mod:
            initial_rest += resttools.make_rests(mod)

        durated_contours = [tuple(initial_rest)]

        pitch_contours = pitch_contour_reservoir[instrument_name]
        durations = [long_duration, short_duration]
        counter = 0
        for pitch_contour in pitch_contours:
            contour = []
            for pitch in pitch_contour:
                contour.extend(leaftools.make_leaves([pitch], [durations[counter]]))
                counter = (counter + 1) % 2
            durated_contours.append(tuple(contour))

        durated_reservoir[instrument_name] = tuple(durated_contours)

    return durated_reservoir
def make_leaves_from_talea(
    talea, 
    talea_denominator,
    decrease_durations_monotonically=True, 
    tie_rests=False,
    forbidden_written_duration=None,
    ):
    r'''Make leaves from `talea`.

    Interpret positive elements in `talea` as notes numerators.

    Interpret negative elements in `talea` as rests numerators.

    Set the pitch of all notes to middle C.

    ..  container:: example
    
        **Example 1.** Make leaves from talea:

        ::

            >>> leaves = leaftools.make_leaves_from_talea([3, -3, 5, -5], 16)
            >>> staff = stafftools.RhythmicStaff(leaves)
            >>> time_signature = contexttools.TimeSignatureMark((4, 4))
            >>> attach(time_signature, staff)
            TimeSignatureMark((4, 4))(RhythmicStaff{6})
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new RhythmicStaff {
                \time 4/4
                c'8.
                r8.
                c'4 ~
                c'16
                r4
                r16
            }

    ..  container:: example
    
        **Example 2.** Increase durations monotonically:

        ::

            >>> leaves = leaftools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     decrease_durations_monotonically=False)
            >>> staff = stafftools.RhythmicStaff(leaves)
            >>> time_signature = contexttools.TimeSignatureMark((4, 4))
            >>> attach(time_signature, staff)
            TimeSignatureMark((4, 4))(RhythmicStaff{6})
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new RhythmicStaff {
                \time 4/4
                c'8.
                r8.
                c'16 ~
                c'4
                r16
                r4
            }

    ..  container:: example
    
        **Example 3.** Forbid written durations greater than or equal 
        to a half note:

        ::

            >>> leaves = leaftools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     forbidden_written_duration=Duration(1, 4))
            >>> staff = stafftools.RhythmicStaff(leaves)
            >>> time_signature = contexttools.TimeSignatureMark((4, 4))
            >>> attach(time_signature, staff)
            TimeSignatureMark((4, 4))(RhythmicStaff{8})
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> f(staff)
            \new RhythmicStaff {
                \time 4/4
                c'8.
                r8.
                c'8 ~
                c'8 ~
                c'16
                r8
                r8
                r16
            }

    Returns list of leaves.
    '''
    from abjad.tools import leaftools

    assert all(x != 0 for x in talea), repr(talea)

    result = []
    for note_value in talea:
        if 0 < note_value:
            pitches = [0]
        else:
            pitches = [None]
        leaves = leaftools.make_leaves(
            pitches, 
            [durationtools.Duration(abs(note_value), talea_denominator)],
            decrease_durations_monotonically=decrease_durations_monotonically,
            tie_rests=tie_rests, 
            forbidden_written_duration=forbidden_written_duration,
            )
        result.extend(leaves)

    result = selectiontools.Selection(result)
    return result