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
def all_are_assignable_integers(expr): '''True when `expr` is a sequence and all elements in `expr` are notehead-assignable integers: :: >>> sequencetools.all_are_assignable_integers([1, 2, 3, 4, 6, 7, 8, 12, 14, 15, 16]) True True when `expr` is an empty sequence: :: >>> sequencetools.all_are_assignable_integers([]) True False otherwise: :: >>> sequencetools.all_are_assignable_integers('foo') False Returns boolean. ''' try: return all(mathtools.is_assignable_integer(x) for x in expr) except TypeError: return False
def is_assignable(self): r'''Is true when duration is assignable. Otherwise false: :: >>> for numerator in range(0, 16 + 1): ... duration = Duration(numerator, 16) ... sixteenths = duration.with_denominator(16) ... print('{!s}\t{}'.format(sixteenths, duration.is_assignable)) ... 0/16 False 1/16 True 2/16 True 3/16 True 4/16 True 5/16 False 6/16 True 7/16 True 8/16 True 9/16 False 10/16 False 11/16 False 12/16 True 13/16 False 14/16 True 15/16 True 16/16 True Returns true or false. ''' if 0 < self < 16: if mathtools.is_nonnegative_integer_power_of_two(self.denominator): if mathtools.is_assignable_integer(self.numerator): return True return False
def test_mathtools_is_assignable_integer_02(): assert not mathtools.is_assignable_integer(9) assert not mathtools.is_assignable_integer(10) assert not mathtools.is_assignable_integer(11) assert mathtools.is_assignable_integer(12) assert not mathtools.is_assignable_integer(13) assert mathtools.is_assignable_integer(14) assert mathtools.is_assignable_integer(15) assert mathtools.is_assignable_integer(16)
def test_mathtools_is_assignable_integer_01(): r'''Is true when integer n can be written without recourse to ties. Otherwise false. ''' assert not mathtools.is_assignable_integer(0) assert mathtools.is_assignable_integer(1) assert mathtools.is_assignable_integer(2) assert mathtools.is_assignable_integer(3) assert mathtools.is_assignable_integer(4) assert not mathtools.is_assignable_integer(5) assert mathtools.is_assignable_integer(6) assert mathtools.is_assignable_integer(7) assert mathtools.is_assignable_integer(8)
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
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
def is_assignable(self): r'''Is true when duration is assignable. Otherwise false. .. container:: example **Example.** Is true when duration is assignable: :: >>> for numerator in range(0, 16 + 1): ... duration = Duration(numerator, 16) ... sixteenths = duration.with_denominator(16) ... print('{!s}\t{}'.format(sixteenths, duration.is_assignable)) ... 0/16 False 1/16 True 2/16 True 3/16 True 4/16 True 5/16 False 6/16 True 7/16 True 8/16 True 9/16 False 10/16 False 11/16 False 12/16 True 13/16 False 14/16 True 15/16 True 16/16 True Returns true or false. ''' if 0 < self < 16: if mathtools.is_nonnegative_integer_power_of_two( self.denominator): if mathtools.is_assignable_integer(self.numerator): return True return False
def is_assignable(self): r'''True when assignable. Otherwise false: :: >>> for numerator in range(0, 16 + 1): ... duration = Duration(numerator, 16) ... print '{}\t{}'.format(duration.with_denominator(16), ... duration.is_assignable) ... 0/16 False 1/16 True 2/16 True 3/16 True 4/16 True 5/16 False 6/16 True 7/16 True 8/16 True 9/16 False 10/16 False 11/16 False 12/16 True 13/16 False 14/16 True 15/16 True 16/16 True Returns boolean. ''' if 0 < self < 16: if mathtools.is_nonnegative_integer_power_of_two( self.denominator): if mathtools.is_assignable_integer(self.numerator): return True return False
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
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