예제 #1
0
파일: RhythmMaker.py 프로젝트: ajyoon/abjad
 def _apply_division_masks(self, selections, rotation=None):
     from abjad.tools import rhythmmakertools
     if not self.division_masks:
         return selections
     new_selections = []
     duration_spelling_specifier = self._get_duration_spelling_specifier()
     decrease_durations_monotonically = \
         duration_spelling_specifier.decrease_durations_monotonically
     forbidden_written_duration = \
         duration_spelling_specifier.forbidden_written_duration
     tie_specifier = self._get_tie_specifier()
     length = len(selections)
     division_masks = self.division_masks
     for i, selection in enumerate(selections):
         matching_division_mask = division_masks.get_matching_pattern(
             i, 
             length, 
             rotation=rotation,
             )
         if not matching_division_mask:
             new_selections.append(selection)
             continue
         duration = selection.get_duration()
         if isinstance(
             matching_division_mask,
             rhythmmakertools.SustainMask,
             ):
             new_selection = scoretools.make_leaves(
                 [0],
                 [duration],
                 decrease_durations_monotonically=\
                     decrease_durations_monotonically,
                 forbidden_written_duration=forbidden_written_duration,
                 use_messiaen_style_ties=\
                     tie_specifier.use_messiaen_style_ties,
                 )
         else:
             use_multimeasure_rests = getattr(
                 matching_division_mask,
                 'use_multimeasure_rests',
                 False,
                 )
             new_selection = scoretools.make_leaves(
                 [None],
                 [duration],
                 decrease_durations_monotonically=\
                     decrease_durations_monotonically,
                 forbidden_written_duration=forbidden_written_duration,
                 use_multimeasure_rests=use_multimeasure_rests,
                 )
         for component in iterate(selection).by_class():
             detach(spannertools.Tie, component)
         new_selections.append(new_selection)
     return new_selections
예제 #2
0
 def _apply_division_masks(self, selections, rotation):
     from abjad.tools import rhythmmakertools
     if not self.division_masks:
         return selections
     new_selections = []
     duration_spelling_specifier = self._get_duration_spelling_specifier()
     decrease_durations_monotonically = \
         duration_spelling_specifier.decrease_durations_monotonically
     forbidden_written_duration = \
         duration_spelling_specifier.forbidden_written_duration
     tie_specifier = self._get_tie_specifier()
     length = len(selections)
     division_masks = self.division_masks
     for i, selection in enumerate(selections):
         matching_division_mask = division_masks.get_matching_pattern(
             i,
             length,
             rotation=rotation,
         )
         if not matching_division_mask:
             new_selections.append(selection)
             continue
         duration = selection.get_duration()
         if isinstance(
                 matching_division_mask,
                 rhythmmakertools.SustainMask,
         ):
             new_selection = scoretools.make_leaves(
                 [0],
                 [duration],
                 decrease_durations_monotonically=\
                     decrease_durations_monotonically,
                 forbidden_written_duration=forbidden_written_duration,
                 use_messiaen_style_ties=\
                     tie_specifier.use_messiaen_style_ties,
                 )
         else:
             use_multimeasure_rests = getattr(
                 matching_division_mask,
                 'use_multimeasure_rests',
                 False,
             )
             new_selection = scoretools.make_leaves(
                 [None],
                 [duration],
                 decrease_durations_monotonically=\
                     decrease_durations_monotonically,
                 forbidden_written_duration=forbidden_written_duration,
                 use_multimeasure_rests=use_multimeasure_rests,
                 )
         for component in iterate(selection).by_class():
             detach(spannertools.Tie, component)
         new_selections.append(new_selection)
     return new_selections
예제 #3
0
 def _make_music(self, duration_pairs, seeds):
     from abjad.tools import rhythmmakertools
     selections = []
     specifier = self.duration_spelling_specifier
     if specifier is None:
         specifier = rhythmmakertools.DurationSpellingSpecifier()
     for duration_pair in duration_pairs:
         selection = scoretools.make_leaves(
             pitches=0,
             durations=[duration_pair],
             decrease_durations_monotonically=\
                 specifier.decrease_durations_monotonically,
             forbidden_written_duration=\
                 specifier.forbidden_written_duration,
             )
         selections.append(selection)
     beam_specifier = self.beam_specifier
     if beam_specifier is None:
         beam_specifier = rhythmmakertools.BeamSpecifier()
     if beam_specifier.beam_divisions_together:
         for component in iterate(selections).by_class():
             detach(spannertools.Beam, component)
         beam = spannertools.MultipartBeam()
         leaves = iterate(selections).by_class(scoretools.Leaf)
         leaves = list(leaves)
         attach(beam, leaves) 
     elif beam_specifier.beam_each_division:
         for selection in selections:
             beam = spannertools.MultipartBeam()
             attach(beam, selection)
     return selections
예제 #4
0
 def _apply_output_masks(self, selections):
     from abjad.tools import rhythmmakertools
     if not self.output_masks:
         return selections
     new_selections = []
     if self.duration_spelling_specifier is None:
         duration_spelling_specifier = \
             rhythmmakertools.DurationSpellingSpecifier()
     decrease_durations_monotonically = \
         duration_spelling_specifier.decrease_durations_monotonically
     forbidden_written_duration = \
         duration_spelling_specifier.forbidden_written_duration
     length = len(selections)
     output_masks = self.output_masks
     for i, selection in enumerate(selections):
         if not any(_._matches_index(i, length) for _ in output_masks):
             new_selections.append(selection)
             continue
         duration = selection.get_duration()
         new_selection = scoretools.make_leaves(
             [None],
             [duration],
             decrease_durations_monotonically=\
                 decrease_durations_monotonically,
             forbidden_written_duration=forbidden_written_duration,
             )
         for component in iterate(selection).by_class():
             detach(spannertools.Tie, component)
         new_selections.append(new_selection)
     return new_selections
예제 #5
0
 def _make_music(self, divisions, seeds):
     from abjad.tools import rhythmmakertools
     selections = []
     duration_specifier = self.duration_spelling_specifier
     if duration_specifier is None:
         duration_specifier = rhythmmakertools.DurationSpellingSpecifier()
     tuplet_specifier = self.tuplet_spelling_specifier
     if tuplet_specifier is None:
         tuplet_specifier = rhythmmakertools.TupletSpellingSpecifier()
     for division in divisions:
         if (duration_specifier.spell_metrically == True or
             (duration_specifier.spell_metrically == 'unassignable' and
             not mathtools.is_assignable_integer(division.numerator))):
             meter = metertools.Meter(division)
             rhythm_tree_container = meter.root_node
             durations = [_.duration for _ in rhythm_tree_container]
         else:
             durations = [division]
         selection = scoretools.make_leaves(
             pitches=0,
             durations=durations,
             decrease_durations_monotonically=\
                 duration_specifier.decrease_durations_monotonically,
             forbidden_written_duration=\
                 duration_specifier.forbidden_written_duration,
             is_diminution=tuplet_specifier.is_diminution,
             )
         selections.append(selection)
     selections = self._apply_burnish_specifier(selections)
     self._apply_beam_specifier(selections)
     selections = self._apply_output_masks(selections)
     return selections
예제 #6
0
파일: RhythmMaker.py 프로젝트: rulio/abjad
 def _apply_output_masks(self, selections):
     from abjad.tools import rhythmmakertools
     if not self.output_masks:
         return selections
     new_selections = []
     duration_spelling_specifier = self.duration_spelling_specifier or \
         rhythmmakertools.DurationSpellingSpecifier()
     decrease_durations_monotonically = \
         duration_spelling_specifier.decrease_durations_monotonically
     forbidden_written_duration = \
         duration_spelling_specifier.forbidden_written_duration
     length = len(selections)
     output_masks = self.output_masks
     for i, selection in enumerate(selections):
         if not any(_._matches_index(i, length) for _ in output_masks):
             new_selections.append(selection)
             continue
         duration = selection.get_duration()
         new_selection = scoretools.make_leaves(
             [None],
             [duration],
             decrease_durations_monotonically=\
                 decrease_durations_monotonically,
             forbidden_written_duration=forbidden_written_duration,
             )
         for component in iterate(selection).by_class():
             detach(spannertools.Tie, component)
         new_selections.append(new_selection)
     return new_selections
예제 #7
0
    def to_measure(self, cell_duration_denominator=8):
        r'''Changes pitch array row to measures.
        
        Sets time signature numerators equal to pitch array row widths and time
        signature denominators equal to `cell_duration_denominator`.

        ..  container:: example

            **Example 1.** Changes row to measure:

            ::

                >>> array = pitchtools.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()
                >>> show(measure) # doctest: +SKIP

            ..  doctest::

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

        Returns measure.
        '''
        from abjad.tools import scoretools
        time_signature = indicatortools.TimeSignature(
            (self.width, cell_duration_denominator))
        measure = scoretools.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 = scoretools.make_leaves(measure_pitches, measure_durations)
        measure.extend(leaves)
        return measure
예제 #8
0
    def to_measure(self, cell_duration_denominator=8):
        r'''Changes pitch array row to measures.
        
        Sets time signature numerators equal to pitch array row widths and time
        signature denominators equal to `cell_duration_denominator`.

        ..  container:: example

            **Example 1.** Changes row to measure:

            ::

                >>> array = pitchtools.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()
                >>> show(measure) # doctest: +SKIP

            ..  doctest::

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

        Returns measure.
        '''
        from abjad.tools import scoretools
        time_signature = indicatortools.TimeSignature(
            (self.width, cell_duration_denominator))
        measure = scoretools.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 = scoretools.make_leaves(measure_pitches, measure_durations)
        measure.extend(leaves)
        return measure
예제 #9
0
def make_annotated_phrase(phrase, color=None):
    duration = inspect_(phrase).get_duration()
    annotated_phrase = scoretools.FixedDurationTuplet(duration)
    durations = [inspect_(_).get_duration() for _ in phrase]
    leaves = scoretools.make_leaves([0], durations)
    annotated_phrase.extend(leaves)
    if color:
        override(annotated_phrase).tuplet_bracket.color = color
    return annotated_phrase
예제 #10
0
 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 = scoretools.make_leaves([0], [power_of_two_division])
     tuplet = scoretools.Tuplet(tuplet_multiplier, leaves)
     return tuplet
예제 #11
0
 def _make_music(self, divisions, rotation):
     from abjad.tools import rhythmmakertools
     selections = []
     duration_specifier = self._get_duration_spelling_specifier()
     tie_specifier = self._get_tie_specifier()
     tuplet_specifier = self._get_tuplet_spelling_specifier()
     for division in divisions:
         if (duration_specifier.spell_metrically == True or
             (duration_specifier.spell_metrically == 'unassignable' and
             not mathtools.is_assignable_integer(division.numerator))):
             meter = metertools.Meter(division)
             rhythm_tree_container = meter.root_node
             durations = [_.duration for _ in rhythm_tree_container]
         elif isinstance(duration_specifier.spell_metrically,
             rhythmmakertools.PartitionTable):
             partition_table = duration_specifier.spell_metrically
             durations = partition_table.respell_division(division)
         else:
             durations = [division]
         selection = scoretools.make_leaves(
             pitches=0,
             durations=durations,
             decrease_durations_monotonically=\
                 duration_specifier.decrease_durations_monotonically,
             forbidden_written_duration=\
                 duration_specifier.forbidden_written_duration,
             is_diminution=tuplet_specifier.is_diminution,
             use_messiaen_style_ties=tie_specifier.use_messiaen_style_ties,
             )
         if (
             1 < len(selection) and
             not selection[0]._has_spanner(spannertools.Tie)
             ):
             tie = spannertools.Tie(
                 use_messiaen_style_ties=tie_specifier.use_messiaen_style_ties,
                 )
             attach(tie, selection[:])
         selections.append(selection)
     selections = self._apply_burnish_specifier(selections)
     beam_specifier = self._get_beam_specifier()
     beam_specifier._apply(selections)
     selections = self._apply_division_masks(selections, rotation)
     if duration_specifier.rewrite_meter:
         selections = duration_specifier._rewrite_meter_(
             selections,
             divisions,
             use_messiaen_style_ties=tie_specifier.use_messiaen_style_ties,
             )
     return selections
예제 #12
0
    def __call__(self, divisions, seeds=None):
        r'''Calls rest rhythm-maker on `divisions`.

        Returns list of selections.
        '''
        result = []
        for division in divisions:
            rests = scoretools.make_leaves(
                pitches=None, 
                durations=[division],
                decrease_durations_monotonically=\
                    self.decrease_durations_monotonically,
                forbidden_written_duration=self.forbidden_written_duration,
                )
            result.append(rests)
        return result
예제 #13
0
 def _make_music(self, duration_pairs, seeds):
     from abjad.tools import rhythmmakertools
     result = []
     specifier = self.duration_spelling_specifier
     if specifier is None:
         specifier = rhythmmakertools.DurationSpellingSpecifier()
     for duration_pair in duration_pairs:
         rests = scoretools.make_leaves(
             pitches=None,
             durations=[duration_pair],
             decrease_durations_monotonically=\
                 specifier.decrease_durations_monotonically,
             forbidden_written_duration=\
                 specifier.forbidden_written_duration,
             )
         result.append(rests)
     return result
예제 #14
0
 def _make_music(self, divisions, rotation):
     from abjad.tools import rhythmmakertools
     selections = []
     duration_specifier = self._get_duration_spelling_specifier()
     tie_specifier = self._get_tie_specifier()
     tuplet_specifier = self._get_tuplet_spelling_specifier()
     for division in divisions:
         if (duration_specifier.spell_metrically == True or
             (duration_specifier.spell_metrically == 'unassignable'
              and not mathtools.is_assignable_integer(division.numerator))):
             meter = metertools.Meter(division)
             rhythm_tree_container = meter.root_node
             durations = [_.duration for _ in rhythm_tree_container]
         elif isinstance(duration_specifier.spell_metrically,
                         rhythmmakertools.PartitionTable):
             partition_table = duration_specifier.spell_metrically
             durations = partition_table.respell_division(division)
         else:
             durations = [division]
         selection = scoretools.make_leaves(
             pitches=0,
             durations=durations,
             decrease_durations_monotonically=\
                 duration_specifier.decrease_durations_monotonically,
             forbidden_written_duration=\
                 duration_specifier.forbidden_written_duration,
             is_diminution=tuplet_specifier.is_diminution,
             use_messiaen_style_ties=tie_specifier.use_messiaen_style_ties,
             )
         if (1 < len(selection)
                 and not selection[0]._has_spanner(spannertools.Tie)):
             tie = spannertools.Tie(use_messiaen_style_ties=tie_specifier.
                                    use_messiaen_style_ties, )
             attach(tie, selection[:])
         selections.append(selection)
     selections = self._apply_burnish_specifier(selections)
     beam_specifier = self._get_beam_specifier()
     beam_specifier(selections)
     selections = self._apply_division_masks(selections, rotation)
     if duration_specifier.rewrite_meter:
         selections = duration_specifier._rewrite_meter_(
             selections,
             divisions,
             use_messiaen_style_ties=tie_specifier.use_messiaen_style_ties,
         )
     return selections
예제 #15
0
파일: Duration.py 프로젝트: DnMllr/abjad
    def to_score_markup(self):
        r'''Changes duration to score markup.

        ..  container:: example

            **Example 1.** Changes assignable duration to score markup:

            ::

                >>> markup = Duration(3, 16).to_score_markup()
                >>> show(markup) # doctest: +SKIP

            ..  doctest::

                >>> f(markup)
                \markup {
                    \score
                        {
                            \new Score \with {
                                \override SpacingSpanner #'spacing-increment = #0.5
                                proportionalNotationDuration = ##f
                            } <<
                                \new RhythmicStaff \with {
                                    \remove Time_signature_engraver
                                    \remove Staff_symbol_engraver
                                    \override Stem #'direction = #up
                                    \override Stem #'length = #5
                                    \override TupletBracket #'bracket-visibility = ##t
                                    \override TupletBracket #'direction = #up
                                    \override TupletBracket #'padding = #1.25
                                    \override TupletBracket #'shorten-pair = #'(-1 . -1.5)
                                    \override TupletNumber #'text = #tuplet-number::calc-fraction-text
                                    tupletFullLength = ##t
                                } {
                                    c'8.
                                }
                            >>
                            \layout {
                                indent = #0
                                ragged-right = ##t
                            }
                        }
                    }

        ..  container:: example

            **Example 2.** Changes nonassignable duration to score markup:

            ::

                >>> markup = Duration(5, 16).to_score_markup()
                >>> show(markup) # doctest: +SKIP

            ..  doctest::

                >>> f(markup)
                \markup {
                    \score
                        {
                            \new Score \with {
                                \override SpacingSpanner #'spacing-increment = #0.5
                                proportionalNotationDuration = ##f
                            } <<
                                \new RhythmicStaff \with {
                                    \remove Time_signature_engraver
                                    \remove Staff_symbol_engraver
                                    \override Stem #'direction = #up
                                    \override Stem #'length = #5
                                    \override TupletBracket #'bracket-visibility = ##t
                                    \override TupletBracket #'direction = #up
                                    \override TupletBracket #'padding = #1.25
                                    \override TupletBracket #'shorten-pair = #'(-1 . -1.5)
                                    \override TupletNumber #'text = #tuplet-number::calc-fraction-text
                                    tupletFullLength = ##t
                                } {
                                    c'4 ~
                                    c'16
                                }
                            >>
                            \layout {
                                indent = #0
                                ragged-right = ##t
                            }
                        }
                    }

        ..  container:: example

            **Example 3.** Override tuplet number text like this:

            ::

                >>> tuplet = Tuplet((5, 7), "c'16 c' c' c' c' c' c'")
                >>> attach(Beam(), tuplet[:])
                >>> staff = Staff([tuplet], context_name='RhythmicStaff')
                >>> duration = inspect_(tuplet).get_duration()
                >>> markup = duration.to_score_markup()
                >>> markup = markup.scale((0.75, 0.75))
                >>> override(tuplet).tuplet_number.text = markup
                >>> show(staff) # doctest: +SKIP

            ..  doctest::

                >>> f(staff)
                \new RhythmicStaff {
                    \override TupletNumber #'text = \markup {
                        \scale
                            #'(0.75 . 0.75)
                            \score
                                {
                                    \new Score \with {
                                        \override SpacingSpanner #'spacing-increment = #0.5
                                        proportionalNotationDuration = ##f
                                    } <<
                                        \new RhythmicStaff \with {
                                            \remove Time_signature_engraver
                                            \remove Staff_symbol_engraver
                                            \override Stem #'direction = #up
                                            \override Stem #'length = #5
                                            \override TupletBracket #'bracket-visibility = ##t
                                            \override TupletBracket #'direction = #up
                                            \override TupletBracket #'padding = #1.25
                                            \override TupletBracket #'shorten-pair = #'(-1 . -1.5)
                                            \override TupletNumber #'text = #tuplet-number::calc-fraction-text
                                            tupletFullLength = ##t
                                        } {
                                            c'4 ~
                                            c'16
                                        }
                                    >>
                                    \layout {
                                        indent = #0
                                        ragged-right = ##t
                                    }
                                }
                        }
                    \times 5/7 {
                        c'16 [
                        c'16
                        c'16
                        c'16
                        c'16
                        c'16
                        c'16 ]
                    }
                    \revert TupletNumber #'text
                }

        Returns markup.
        '''
        from abjad.tools import scoretools
        notes = scoretools.make_leaves([0], [self])
        markup = self._to_score_markup(notes)
        return markup
예제 #16
0
def make_leaves_from_talea(
    talea,
    talea_denominator,
    decrease_durations_monotonically=True,
    forbidden_written_duration=None,
    spell_metrically=None,
    use_messiaen_style_ties=False,
    ):
    r'''Makes leaves from `talea`.

    Interprets positive elements in `talea` as notes numerators.

    Interprets negative elements in `talea` as rests numerators.

    Sets the pitch of all notes to middle C.

    ..  container:: example

        **Example 1.** Makes leaves from talea:

        ::

            >>> leaves = scoretools.make_leaves_from_talea([3, -3, 5, -5], 16)
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 2.** Increases durations monotonically:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     decrease_durations_monotonically=False,
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 3.** Forbids written durations greater than or equal
        to a half note:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     forbidden_written_duration=Duration(1, 4),
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 4.** Spells unassignable durations metrically:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     spell_metrically='unassignable',
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print(format(staff))
            \new RhythmicStaff {
                \time 4/4
                c'8.
                r8.
                c'8. ~
                c'8
                r8.
                r8
            }

    ..  container:: example

        **Example 5.** Uses Messiaen-style ties:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [5, 9], 8,
            ...     spell_metrically='unassignable',
            ...     use_messiaen_style_ties=True,
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print(format(staff))
            \new RhythmicStaff {
                \time 4/4
                c'4.
                c'4 \repeatTie
                c'4.
                c'4. \repeatTie
                c'4. \repeatTie
            }

    Returns selection.
    '''
    from abjad.tools import metertools
    from abjad.tools import scoretools
    from abjad.tools import spannertools

    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]
        division = durationtools.Duration(
            abs(note_value),
            talea_denominator,
            )
        if (spell_metrically is True or
            (spell_metrically == 'unassignable' and
            not mathtools.is_assignable_integer(division.numerator))):
            meter = metertools.Meter(division)
            rhythm_tree_container = meter.root_node
            durations = [_.duration for _ in rhythm_tree_container]
        else:
            durations = [division]
        leaves = scoretools.make_leaves(
            pitches,
            durations,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            use_messiaen_style_ties=use_messiaen_style_ties,
            )
        if (
            1 < len(leaves) and
            not leaves[0]._has_spanner(spannertools.Tie) and
            not isinstance(leaves[0], scoretools.Rest)
            ):
            tie = spannertools.Tie(
                use_messiaen_style_ties=use_messiaen_style_ties,
                )
            attach(tie, leaves[:])
        result.extend(leaves)
    result = selectiontools.Selection(result)
    return result
예제 #17
0
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 = scoretools.make_leaves_from_talea([3, -3, 5, -5], 16)
            >>> staff = scoretools.RhythmicStaff(leaves)
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

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

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     decrease_durations_monotonically=False)
            >>> staff = scoretools.RhythmicStaff(leaves)
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print format(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 = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     forbidden_written_duration=Duration(1, 4))
            >>> staff = scoretools.RhythmicStaff(leaves)
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print format(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 scoretools

    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 = scoretools.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
예제 #18
0
    def to_score_markup(self):
        r'''Changes duration to score markup.

        ..  container:: example

            **Example 1.** Changes assignable duration to score markup:

            ::

                >>> markup = Duration(3, 16).to_score_markup()
                >>> show(markup) # doctest: +SKIP

            ..  doctest::

                >>> f(markup)
                \markup {
                    \score
                        {
                            \new Score \with {
                                \override SpacingSpanner.spacing-increment = #0.5
                                proportionalNotationDuration = ##f
                            } <<
                                \new RhythmicStaff \with {
                                    \remove Time_signature_engraver
                                    \remove Staff_symbol_engraver
                                    \override Stem.direction = #up
                                    \override Stem.length = #5
                                    \override TupletBracket.bracket-visibility = ##t
                                    \override TupletBracket.direction = #up
                                    \override TupletBracket.padding = #1.25
                                    \override TupletBracket.shorten-pair = #'(-1 . -1.5)
                                    \override TupletNumber.text = #tuplet-number::calc-fraction-text
                                    tupletFullLength = ##t
                                } {
                                    c'8.
                                }
                            >>
                            \layout {
                                indent = #0
                                ragged-right = ##t
                            }
                        }
                    }

        ..  container:: example

            **Example 2.** Changes nonassignable duration to score markup:

            ::

                >>> markup = Duration(5, 16).to_score_markup()
                >>> show(markup) # doctest: +SKIP

            ..  doctest::

                >>> f(markup)
                \markup {
                    \score
                        {
                            \new Score \with {
                                \override SpacingSpanner.spacing-increment = #0.5
                                proportionalNotationDuration = ##f
                            } <<
                                \new RhythmicStaff \with {
                                    \remove Time_signature_engraver
                                    \remove Staff_symbol_engraver
                                    \override Stem.direction = #up
                                    \override Stem.length = #5
                                    \override TupletBracket.bracket-visibility = ##t
                                    \override TupletBracket.direction = #up
                                    \override TupletBracket.padding = #1.25
                                    \override TupletBracket.shorten-pair = #'(-1 . -1.5)
                                    \override TupletNumber.text = #tuplet-number::calc-fraction-text
                                    tupletFullLength = ##t
                                } {
                                    c'4 ~
                                    c'16
                                }
                            >>
                            \layout {
                                indent = #0
                                ragged-right = ##t
                            }
                        }
                    }

        ..  container:: example

            **Example 3.** Override tuplet number text like this:

            ::

                >>> tuplet = Tuplet((5, 7), "c'16 c' c' c' c' c' c'")
                >>> attach(Beam(), tuplet[:])
                >>> staff = Staff([tuplet], context_name='RhythmicStaff')
                >>> duration = inspect_(tuplet).get_duration()
                >>> markup = duration.to_score_markup()
                >>> markup = markup.scale((0.75, 0.75))
                >>> override(tuplet).tuplet_number.text = markup
                >>> show(staff) # doctest: +SKIP

            ..  doctest::

                >>> f(staff)
                \new RhythmicStaff {
                    \override TupletNumber.text = \markup {
                        \scale
                            #'(0.75 . 0.75)
                            \score
                                {
                                    \new Score \with {
                                        \override SpacingSpanner.spacing-increment = #0.5
                                        proportionalNotationDuration = ##f
                                    } <<
                                        \new RhythmicStaff \with {
                                            \remove Time_signature_engraver
                                            \remove Staff_symbol_engraver
                                            \override Stem.direction = #up
                                            \override Stem.length = #5
                                            \override TupletBracket.bracket-visibility = ##t
                                            \override TupletBracket.direction = #up
                                            \override TupletBracket.padding = #1.25
                                            \override TupletBracket.shorten-pair = #'(-1 . -1.5)
                                            \override TupletNumber.text = #tuplet-number::calc-fraction-text
                                            tupletFullLength = ##t
                                        } {
                                            c'4 ~
                                            c'16
                                        }
                                    >>
                                    \layout {
                                        indent = #0
                                        ragged-right = ##t
                                    }
                                }
                        }
                    \times 5/7 {
                        c'16 [
                        c'16
                        c'16
                        c'16
                        c'16
                        c'16
                        c'16 ]
                    }
                    \revert TupletNumber.text
                }

        Returns markup.
        '''
        from abjad.tools import scoretools
        notes = scoretools.make_leaves([0], [self])
        markup = self._to_score_markup(notes)
        return markup
예제 #19
0
def make_leaves_from_talea(
    talea,
    talea_denominator,
    decrease_durations_monotonically=True,
    forbidden_written_duration=None,
    spell_metrically=None,
    use_messiaen_style_ties=False,
):
    r'''Makes leaves from `talea`.

    Interprets positive elements in `talea` as notes numerators.

    Interprets negative elements in `talea` as rests numerators.

    Sets the pitch of all notes to middle C.

    ..  container:: example

        **Example 1.** Makes leaves from talea:

        ::

            >>> leaves = scoretools.make_leaves_from_talea([3, -3, 5, -5], 16)
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 2.** Increases durations monotonically:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     decrease_durations_monotonically=False,
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 3.** Forbids written durations greater than or equal
        to a half note:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     forbidden_written_duration=Duration(1, 4),
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 4.** Spells unassignable durations metrically:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     spell_metrically='unassignable',
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print(format(staff))
            \new RhythmicStaff {
                \time 4/4
                c'8.
                r8.
                c'8. ~
                c'8
                r8.
                r8
            }

    ..  container:: example

        **Example 5.** Uses Messiaen-style ties:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [5, 9], 8,
            ...     spell_metrically='unassignable',
            ...     use_messiaen_style_ties=True,
            ...     )
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print(format(staff))
            \new RhythmicStaff {
                \time 4/4
                c'4.
                c'4 \repeatTie
                c'4.
                c'4. \repeatTie
                c'4. \repeatTie
            }

    Returns selection.
    '''
    from abjad.tools import metertools
    from abjad.tools import scoretools
    from abjad.tools import spannertools

    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]
        division = durationtools.Duration(
            abs(note_value),
            talea_denominator,
        )
        if (spell_metrically is True or
            (spell_metrically == 'unassignable'
             and not mathtools.is_assignable_integer(division.numerator))):
            meter = metertools.Meter(division)
            rhythm_tree_container = meter.root_node
            durations = [_.duration for _ in rhythm_tree_container]
        else:
            durations = [division]
        leaves = scoretools.make_leaves(
            pitches,
            durations,
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
            use_messiaen_style_ties=use_messiaen_style_ties,
        )
        if (1 < len(leaves) and not leaves[0]._has_spanner(spannertools.Tie)
                and not isinstance(leaves[0], scoretools.Rest)):
            tie = spannertools.Tie(
                use_messiaen_style_ties=use_messiaen_style_ties, )
            attach(tie, leaves[:])
        result.extend(leaves)
    result = selectiontools.Selection(result)
    return result
예제 #20
0
def make_leaves_from_talea(
    talea,
    talea_denominator,
    decrease_durations_monotonically=True,
    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 = scoretools.make_leaves_from_talea([3, -3, 5, -5], 16)
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    ..  container:: example

        **Example 2.** Increase durations monotonically:

        ::

            >>> leaves = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     decrease_durations_monotonically=False)
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

            >>> print(format(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 = scoretools.make_leaves_from_talea(
            ...     [3, -3, 5, -5], 16,
            ...     forbidden_written_duration=Duration(1, 4))
            >>> staff = Staff(leaves)
            >>> staff.context_name = 'RhythmicStaff'
            >>> time_signature = TimeSignature((4, 4))
            >>> attach(time_signature, staff)
            >>> show(staff) # doctest: +SKIP

        ..  doctest::

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

    Returns selection.
    '''
    from abjad.tools import scoretools

    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 = scoretools.make_leaves(
            pitches,
            [durationtools.Duration(abs(note_value), talea_denominator)],
            decrease_durations_monotonically=decrease_durations_monotonically,
            forbidden_written_duration=forbidden_written_duration,
        )
        result.extend(leaves)

    result = selectiontools.Selection(result)
    return result