diff --git a/abjad/__init__.py b/abjad/__init__.py index 960fd34f5f0..e483a73da1d 100644 --- a/abjad/__init__.py +++ b/abjad/__init__.py @@ -88,17 +88,19 @@ from abjad.tools.timespantools import Timespan # rhythm-maker functions (but not classes) -from abjad.tools.rhythmmakertools import silence -from abjad.tools.rhythmmakertools import silence_all -from abjad.tools.rhythmmakertools import silence_every -from abjad.tools.rhythmmakertools import silence_except -from abjad.tools.rhythmmakertools import silence_first -from abjad.tools.rhythmmakertools import silence_last -from abjad.tools.rhythmmakertools import sustain -from abjad.tools.rhythmmakertools import sustain_all -from abjad.tools.rhythmmakertools import sustain_every -from abjad.tools.rhythmmakertools import sustain_first -from abjad.tools.rhythmmakertools import sustain_last +from abjad.tools.rhythmmakertools import SilenceMask +from abjad.tools.rhythmmakertools import SustainMask +silence = SilenceMask.silence +silence_all = SilenceMask.silence_all +silence_except = SilenceMask.silence_except +silence_every = SilenceMask.silence_every +silence_first = SilenceMask.silence_first +silence_last = SilenceMask.silence_last +sustain = SustainMask.sustain +sustain_all = SustainMask.sustain_all +sustain_every = SustainMask.sustain_every +sustain_first = SustainMask.sustain_first +sustain_last = SustainMask.sustain_last # import custom exceptions into the builtins module import os diff --git a/abjad/tools/rhythmmakertools/AccelerandoRhythmMaker.py b/abjad/tools/rhythmmakertools/AccelerandoRhythmMaker.py index 8eadec5d8c0..02fbe89dbac 100644 --- a/abjad/tools/rhythmmakertools/AccelerandoRhythmMaker.py +++ b/abjad/tools/rhythmmakertools/AccelerandoRhythmMaker.py @@ -2493,8 +2493,8 @@ def logical_tie_masks(self): ... use_feather_beams=True, ... ), ... logical_tie_masks=[ - ... rhythmmakertools.silence_first(), - ... rhythmmakertools.silence_last(), + ... abjad.silence_first(), + ... abjad.silence_last(), ... ], ... interpolation_specifiers=[ ... rhythmmakertools.InterpolationSpecifier( @@ -2728,7 +2728,7 @@ def logical_tie_masks(self): ... use_feather_beams=True, ... ), ... logical_tie_masks=[ - ... rhythmmakertools.silence_every([2], period=3), + ... abjad.silence_every([2], period=3), ... ], ... interpolation_specifiers=[ ... rhythmmakertools.InterpolationSpecifier( diff --git a/abjad/tools/rhythmmakertools/EvenDivisionRhythmMaker.py b/abjad/tools/rhythmmakertools/EvenDivisionRhythmMaker.py index 7cfc0d5862a..9e74ddd596e 100644 --- a/abjad/tools/rhythmmakertools/EvenDivisionRhythmMaker.py +++ b/abjad/tools/rhythmmakertools/EvenDivisionRhythmMaker.py @@ -947,7 +947,7 @@ def division_masks(self): >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( ... division_masks=[ - ... rhythmmakertools.silence_every([0], period=2), + ... abjad.silence_every([0], period=2), ... ], ... ) @@ -999,7 +999,7 @@ def division_masks(self): >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( ... division_masks=[ - ... rhythmmakertools.sustain_every([0], period=2), + ... abjad.sustain_every([0], period=2), ... ], ... ) @@ -1050,7 +1050,7 @@ def division_masks(self): :: >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( - ... division_masks=rhythmmakertools.silence_all(), + ... division_masks=abjad.silence_all(), ... ) :: @@ -1837,7 +1837,7 @@ def logical_tie_masks(self): >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( ... logical_tie_masks=[ - ... rhythmmakertools.silence_every([0], period=3), + ... abjad.silence_every([0], period=3), ... ], ... ) @@ -1901,7 +1901,7 @@ def logical_tie_masks(self): >>> pattern_2 = abjad.index_first(2) >>> pattern_3 = abjad.index_last(2) >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 - >>> mask = rhythmmakertools.silence(pattern) + >>> mask = abjad.silence(pattern) >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( ... logical_tie_masks=mask, ... ) @@ -2023,7 +2023,7 @@ def logical_tie_masks(self): :: >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( - ... logical_tie_masks=rhythmmakertools.silence_every( + ... logical_tie_masks=abjad.silence_every( ... indices=[3], ... period=4, ... ), diff --git a/abjad/tools/rhythmmakertools/IncisedRhythmMaker.py b/abjad/tools/rhythmmakertools/IncisedRhythmMaker.py index 7c93aaf9405..9ec515a134e 100644 --- a/abjad/tools/rhythmmakertools/IncisedRhythmMaker.py +++ b/abjad/tools/rhythmmakertools/IncisedRhythmMaker.py @@ -1100,7 +1100,7 @@ def logical_tie_masks(self): ... talea_denominator=16, ... ), ... logical_tie_masks=[ - ... rhythmmakertools.silence_every([1], period=2), + ... abjad.silence_every([1], period=2), ... ], ... ) diff --git a/abjad/tools/rhythmmakertools/NoteRhythmMaker.py b/abjad/tools/rhythmmakertools/NoteRhythmMaker.py index 22ff4600557..6de891f7d37 100644 --- a/abjad/tools/rhythmmakertools/NoteRhythmMaker.py +++ b/abjad/tools/rhythmmakertools/NoteRhythmMaker.py @@ -684,7 +684,7 @@ def division_masks(self): :: >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[rhythmmakertools.silence_all()], + ... division_masks=[abjad.silence_all()], ... ) :: @@ -1134,7 +1134,7 @@ def logical_tie_masks(self): :: >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... logical_tie_masks=rhythmmakertools.silence_every([0], period=2) + ... logical_tie_masks=abjad.silence_every([0], period=2) ... ) :: @@ -1176,7 +1176,7 @@ def logical_tie_masks(self): :: >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... logical_tie_masks=rhythmmakertools.silence_all(), + ... logical_tie_masks=abjad.silence_all(), ... ) :: diff --git a/abjad/tools/rhythmmakertools/SilenceMask.py b/abjad/tools/rhythmmakertools/SilenceMask.py index 52e2f745f95..cfe7653c2b6 100644 --- a/abjad/tools/rhythmmakertools/SilenceMask.py +++ b/abjad/tools/rhythmmakertools/SilenceMask.py @@ -107,3 +107,1113 @@ def use_multimeasure_rests(self): Set to true, false or none. ''' return self._use_multimeasure_rests + + ### PUBLIC METHODS ### + + @staticmethod + def silence(indices=None, inverted=None): + r'''Makes silence mask that matches `indices`. + + .. container:: example + + Silences divisions 1 and 2: + + :: + + >>> mask = abjad.silence([1, 2]) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[1, 2], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Silences divisions -1 and -2: + + :: + + >>> mask = abjad.silence([-1, -2]) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[-1, -2], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Works with pattern input: + + :: + + >>> pattern_1 = abjad.index_all() + >>> pattern_2 = abjad.index_first() + >>> pattern_3 = abjad.index_last() + >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 + >>> mask = abjad.silence(pattern) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.CompoundPattern( + ( + abjad.Pattern( + indices=[0], + period=1, + ), + abjad.Pattern( + indices=[0], + ), + abjad.Pattern( + indices=[-1], + ), + ), + operator='xor', + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Works with pattern input and inverted flag: + + :: + + >>> pattern_1 = abjad.index_all() + >>> pattern_2 = abjad.index_first() + >>> pattern_3 = abjad.index_last() + >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 + >>> mask = abjad.silence(pattern, inverted=True) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.CompoundPattern( + ( + abjad.Pattern( + indices=[0], + period=1, + ), + abjad.Pattern( + indices=[0], + ), + abjad.Pattern( + indices=[-1], + ), + ), + inverted=True, + operator='xor', + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + Returns silence mask. + ''' + import abjad + indices = indices or [] + prototype = (patterntools.Pattern, patterntools.CompoundPattern) + if isinstance(indices, prototype): + pattern = indices + else: + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + ) + pattern = abjad.new(pattern, inverted=inverted) + return SilenceMask(pattern=pattern) + + @staticmethod + def silence_all(inverted=None, use_multimeasure_rests=None): + r'''Makes silence that matches all indices. + + .. container:: example + + Silences all divisions: + + :: + + >>> mask = abjad.silence_all() + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[0], + period=1, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Silences all divisions with multimeasure rests: + + :: + + >>> mask = abjad.silence_all( + ... use_multimeasure_rests=True, + ... ) + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + + :: + + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + R1 * 7/16 + } + { + \time 3/8 + R1 * 3/8 + } + { + \time 7/16 + R1 * 7/16 + } + { + \time 3/8 + R1 * 3/8 + } + } + + Returns silence mask. + ''' + pattern = patterntools.Pattern( + indices=[0], + inverted=inverted, + period=1, + ) + mask = SilenceMask( + pattern=pattern, + use_multimeasure_rests=use_multimeasure_rests, + ) + return mask + + @staticmethod + def silence_every( + indices, + period=None, + inverted=None, + use_multimeasure_rests=None, + ): + r'''Makes silence mask that matches `indices` at `period`. + + .. container:: example + + Silences every second division: + + :: + + >>> mask = abjad.silence_every(indices=[1], period=2) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[1], + period=2, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Silences every second and third division: + + :: + + >>> mask = abjad.silence_every(indices=[1, 2], period=3) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[1, 2], + period=3, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Silences every division except the last: + + :: + + >>> mask = abjad.silence_every(indices=[-1], inverted=True) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[-1], + inverted=True, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + } + + Returns silence mask. + ''' + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + period=period, + ) + mask = SilenceMask( + pattern=pattern, + use_multimeasure_rests=use_multimeasure_rests, + ) + return mask + + @staticmethod + def silence_except(indices=None): + r'''Makes silence mask that matches all indices except `indices`. + + .. container:: example + + Silences divisions except 1 and 2: + + :: + + >>> mask = abjad.silence_except([1, 2]) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[1, 2], + inverted=True, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> staff = lilypond_file[Staff] + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Silences divisions except -1 and -2: + + :: + + >>> mask = abjad.silence_except([-1, -2]) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[-1, -2], + inverted=True, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Works with pattern input: + + :: + + >>> pattern_1 = abjad.index_all() + >>> pattern_2 = abjad.index_first() + >>> pattern_3 = abjad.index_last() + >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 + >>> mask = abjad.silence_except(pattern) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.CompoundPattern( + ( + abjad.Pattern( + indices=[0], + period=1, + ), + abjad.Pattern( + indices=[0], + ), + abjad.Pattern( + indices=[-1], + ), + ), + inverted=True, + operator='xor', + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + Equivalent to ``silence(..., inverted=True)``. + + Returns silence mask. + ''' + import abjad + indices = indices or [] + prototype = (patterntools.Pattern, patterntools.CompoundPattern) + if isinstance(indices, prototype): + pattern = indices + else: + pattern = patterntools.Pattern( + indices=indices, + ) + pattern = abjad.new(pattern, inverted=True) + return SilenceMask(pattern=pattern) + + @staticmethod + def silence_first(n=1, inverted=None, use_multimeasure_rests=None): + r'''Makes silence mask that matches the first `n` indices. + + .. container:: example + + Silences first division: + + :: + + >>> mask = abjad.silence_first() + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[0], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Silences first two divisions: + + :: + + >>> mask = abjad.silence_first(n=2) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[0, 1], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Silences no first divisions: + + :: + + >>> mask = abjad.silence_first(n=0) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + Returns silence mask. + ''' + indices = list(range(n)) + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + ) + mask = SilenceMask( + pattern=pattern, + use_multimeasure_rests=use_multimeasure_rests, + ) + return mask + + @staticmethod + def silence_last(n=1, inverted=None, use_multimeasure_rests=None): + r'''Makes silence mask that matches the last `n` indices. + + .. container:: example + + Silences last division: + + :: + + >>> mask = abjad.silence_last() + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[-1], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Silences last two divisions: + + :: + + >>> mask = abjad.silence_last(n=2) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[-2, -1], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Silences no last divisions: + + :: + + >>> mask = abjad.silence_last(n=0) + + :: + + >>> f(mask) + rhythmmakertools.SilenceMask( + pattern=abjad.Pattern( + indices=[], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + Returns silence mask. + ''' + indices = list(reversed(range(-1, -n-1, -1))) + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + ) + mask = SilenceMask( + pattern=pattern, + use_multimeasure_rests=use_multimeasure_rests, + ) + return mask diff --git a/abjad/tools/rhythmmakertools/SustainMask.py b/abjad/tools/rhythmmakertools/SustainMask.py index f3992926268..14ff0301b31 100644 --- a/abjad/tools/rhythmmakertools/SustainMask.py +++ b/abjad/tools/rhythmmakertools/SustainMask.py @@ -61,3 +61,861 @@ def pattern(self): Returns pattern. ''' return self._pattern + + ### PUBLIC METHODS ### + + @staticmethod + def sustain(indices=None, inverted=None): + r'''Makes sustain mask that matches `indices`. + + .. container:: example + + Sustains divisions 1 and 2: + + :: + + >>> mask = abjad.sustain([1, 2]) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[1, 2], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Sustains divisions -1 and -2: + + :: + + >>> mask = abjad.sustain([-1, -2]) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[-1, -2], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Works with pattern input: + + :: + + >>> pattern_1 = abjad.index_all() + >>> pattern_2 = abjad.index_first() + >>> pattern_3 = abjad.index_last() + >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 + >>> mask = abjad.sustain(pattern) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.CompoundPattern( + ( + abjad.Pattern( + indices=[0], + period=1, + ), + abjad.Pattern( + indices=[0], + ), + abjad.Pattern( + indices=[-1], + ), + ), + operator='xor', + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + } + + .. container:: example + + Works with pattern input and inverted flag: + + :: + + >>> pattern_1 = abjad.index_all() + >>> pattern_2 = abjad.index_first() + >>> pattern_3 = abjad.index_last() + >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 + >>> mask = abjad.sustain(pattern, inverted=True) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.CompoundPattern( + ( + abjad.Pattern( + indices=[0], + period=1, + ), + abjad.Pattern( + indices=[0], + ), + abjad.Pattern( + indices=[-1], + ), + ), + inverted=True, + operator='xor', + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + } + + Returns sustain mask. + ''' + import abjad + indices = indices or [] + prototype = (patterntools.Pattern, patterntools.CompoundPattern) + if isinstance(indices, prototype): + pattern = indices + else: + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + ) + pattern = abjad.new(pattern, inverted=inverted) + return SustainMask(pattern=pattern) + + @staticmethod + def sustain_all(inverted=None): + r'''Makes sustain mask that matches all indices. + + .. container:: example + + Without mask: + + >>> rhythm_maker = rhythmmakertools.TupletRhythmMaker( + ... tuplet_ratios=[(3, 1)], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + + :: + + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + \tweak text #tuplet-number::calc-fraction-text + \times 7/8 { + c'4. + c'8 + } + } + { + \time 3/8 + \tweak text #tuplet-number::calc-fraction-text + \times 3/4 { + c'4. + c'8 + } + } + { + \time 7/16 + \tweak text #tuplet-number::calc-fraction-text + \times 7/8 { + c'4. + c'8 + } + } + { + \time 3/8 + \tweak text #tuplet-number::calc-fraction-text + \times 3/4 { + c'4. + c'8 + } + } + } + + .. container:: example + + With mask: + + :: + + >>> mask = abjad.sustain_all() + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[0], + period=1, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.TupletRhythmMaker( + ... division_masks=[mask], + ... tuplet_ratios=[(3, 1)], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + + :: + + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + Returns sustain mask. + ''' + pattern = patterntools.Pattern( + indices=[0], + inverted=inverted, + period=1, + ) + mask = SustainMask(pattern=pattern) + return mask + + @staticmethod + def sustain_every(indices, period, inverted=None): + r'''Makes sustain mask that matches `indices` at `period`. + + .. container:: example + + Sustains every second division: + + :: + + >>> mask = abjad.sustain_every(indices=[1], period=2) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[1], + period=2, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Sustains every second and third division: + + :: + + >>> mask = abjad.sustain_every(indices=[1, 2], period=3) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[1, 2], + period=3, + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + Returns sustain mask. + ''' + indices = list(indices) + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + period=period, + ) + mask = SustainMask(pattern=pattern) + return mask + + @staticmethod + def sustain_first(n=1, inverted=None): + r'''Makes sustain mask that matches the first `n` indices. + + .. container:: example + + Sustains first division: + + :: + + >>> mask = abjad.sustain_first() + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[0], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( + ... denominators=[16], + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + { + c'16 [ + c'16 + c'16 + c'16 + c'16 + c'16 ] + } + } + { + \time 7/16 + { + c'16 [ + c'16 + c'16 + c'16 + c'16 + c'16 + c'16 ] + } + } + { + \time 3/8 + { + c'16 [ + c'16 + c'16 + c'16 + c'16 + c'16 ] + } + } + } + + .. container:: example + + Sustains first two divisions: + + :: + + >>> mask = abjad.sustain_first(n=2) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[0, 1], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( + ... denominators=[16], + ... division_masks=[mask], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + { + \time 7/16 + { + c'16 [ + c'16 + c'16 + c'16 + c'16 + c'16 + c'16 ] + } + } + { + \time 3/8 + { + c'16 [ + c'16 + c'16 + c'16 + c'16 + c'16 ] + } + } + } + + Returns sustain mask. + ''' + indices = list(range(n)) + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + ) + mask = SustainMask(pattern=pattern) + return mask + + @staticmethod + def sustain_last(n=1, inverted=None): + r'''Makes sustain mask that matches the last `n` indices. + + .. container:: example + + Sustains last division: + + :: + + >>> mask = abjad.sustain_last() + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[-1], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Sustains last two divisions: + + :: + + >>> mask = abjad.sustain_last(n=2) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[-2, -1], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + c'4.. + } + { + \time 3/8 + c'4. + } + } + + .. container:: example + + Sustains no last divisions: + + :: + + >>> mask = abjad.sustain_last(n=0) + + :: + + >>> f(mask) + rhythmmakertools.SustainMask( + pattern=abjad.Pattern( + indices=[], + ), + ) + + :: + + >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( + ... division_masks=[ + ... abjad.silence_all(), + ... mask, + ... ], + ... ) + >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] + >>> selections = rhythm_maker(divisions) + >>> lilypond_file = rhythmmakertools.make_lilypond_file( + ... selections, + ... divisions, + ... ) + >>> show(lilypond_file) # doctest: +SKIP + + .. docs:: + + >>> f(lilypond_file[Staff]) + \new RhythmicStaff { + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + { + \time 7/16 + r4.. + } + { + \time 3/8 + r4. + } + } + + Returns sustain mask. + ''' + indices = list(reversed(range(-1, -n-1, -1))) + pattern = patterntools.Pattern( + indices=indices, + inverted=inverted, + ) + mask = SustainMask(pattern=pattern) + return mask diff --git a/abjad/tools/rhythmmakertools/TaleaRhythmMaker.py b/abjad/tools/rhythmmakertools/TaleaRhythmMaker.py index ea7e9000a0c..bcc1c91891d 100644 --- a/abjad/tools/rhythmmakertools/TaleaRhythmMaker.py +++ b/abjad/tools/rhythmmakertools/TaleaRhythmMaker.py @@ -1435,7 +1435,7 @@ def division_masks(self): ... denominator=16, ... ), ... division_masks=[ - ... rhythmmakertools.sustain_every([1], period=2), + ... abjad.sustain_every([1], period=2), ... ], ... ) @@ -1551,7 +1551,7 @@ def division_masks(self): ... ), ... split_divisions_by_counts=[9], ... division_masks=[ - ... rhythmmakertools.sustain_every([1], period=2), + ... abjad.sustain_every([1], period=2), ... ], ... ) @@ -2263,7 +2263,7 @@ def logical_tie_masks(self): >>> rhythm_maker = rhythmmakertools.TaleaRhythmMaker( ... logical_tie_masks=[ - ... rhythmmakertools.silence_every([2], period=3), + ... abjad.silence_every([2], period=3), ... ], ... talea=rhythmmakertools.Talea( ... counts=[1, 2, 3, 4], @@ -2317,8 +2317,8 @@ def logical_tie_masks(self): >>> rhythm_maker = rhythmmakertools.TaleaRhythmMaker( ... logical_tie_masks=[ - ... rhythmmakertools.silence_first(), - ... rhythmmakertools.silence_last(), + ... abjad.silence_first(), + ... abjad.silence_last(), ... ], ... talea=rhythmmakertools.Talea( ... counts=[1, 2, 3, 4], diff --git a/abjad/tools/rhythmmakertools/TupletRhythmMaker.py b/abjad/tools/rhythmmakertools/TupletRhythmMaker.py index 414b4019dba..6d37eea77b0 100644 --- a/abjad/tools/rhythmmakertools/TupletRhythmMaker.py +++ b/abjad/tools/rhythmmakertools/TupletRhythmMaker.py @@ -719,7 +719,7 @@ def division_masks(self): ... beam_each_division=False, ... ), ... division_masks=[ - ... rhythmmakertools.silence_every([1], period=2), + ... abjad.silence_every([1], period=2), ... ], ... ) diff --git a/abjad/tools/rhythmmakertools/__init__.py b/abjad/tools/rhythmmakertools/__init__.py index 1a21e4faccd..d3fa4b5cdd0 100644 --- a/abjad/tools/rhythmmakertools/__init__.py +++ b/abjad/tools/rhythmmakertools/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from abjad.tools import systemtools - systemtools.ImportManager.import_structured_package( __path__[0], globals(), diff --git a/abjad/tools/rhythmmakertools/silence.py b/abjad/tools/rhythmmakertools/silence.py deleted file mode 100644 index 4bfb3fc13d2..00000000000 --- a/abjad/tools/rhythmmakertools/silence.py +++ /dev/null @@ -1,269 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools -from abjad.tools.topleveltools import new - - -def silence(indices=None, inverted=None): - r'''Makes silence mask that matches `indices`. - - .. container:: example - - Silences divisions 1 and 2: - - :: - - >>> mask = rhythmmakertools.silence([1, 2]) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[1, 2], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Silences divisions -1 and -2: - - :: - - >>> mask = rhythmmakertools.silence([-1, -2]) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[-1, -2], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Works with pattern input: - - :: - - >>> pattern_1 = abjad.index_all() - >>> pattern_2 = abjad.index_first() - >>> pattern_3 = abjad.index_last() - >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 - >>> mask = rhythmmakertools.silence(pattern) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.CompoundPattern( - ( - abjad.Pattern( - indices=[0], - period=1, - ), - abjad.Pattern( - indices=[0], - ), - abjad.Pattern( - indices=[-1], - ), - ), - operator='xor', - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Works with pattern input and inverted flag: - - :: - - >>> pattern_1 = abjad.index_all() - >>> pattern_2 = abjad.index_first() - >>> pattern_3 = abjad.index_last() - >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 - >>> mask = rhythmmakertools.silence(pattern, inverted=True) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.CompoundPattern( - ( - abjad.Pattern( - indices=[0], - period=1, - ), - abjad.Pattern( - indices=[0], - ), - abjad.Pattern( - indices=[-1], - ), - ), - inverted=True, - operator='xor', - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - Returns silence mask. - ''' - from abjad.tools import rhythmmakertools - indices = indices or [] - prototype = (patterntools.Pattern, patterntools.CompoundPattern) - if isinstance(indices, prototype): - pattern = indices - else: - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - ) - pattern = new(pattern, inverted=inverted) - return rhythmmakertools.SilenceMask(pattern=pattern) diff --git a/abjad/tools/rhythmmakertools/silence_all.py b/abjad/tools/rhythmmakertools/silence_all.py deleted file mode 100644 index 2bd427baf50..00000000000 --- a/abjad/tools/rhythmmakertools/silence_all.py +++ /dev/null @@ -1,118 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def silence_all(inverted=None, use_multimeasure_rests=None): - r'''Makes silence that matches all indices. - - .. container:: example - - Silences all divisions: - - :: - - >>> mask = rhythmmakertools.silence_all() - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[0], - period=1, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Silences all divisions with multimeasure rests: - - :: - - >>> mask = rhythmmakertools.silence_all( - ... use_multimeasure_rests=True, - ... ) - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - - :: - - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - R1 * 7/16 - } - { - \time 3/8 - R1 * 3/8 - } - { - \time 7/16 - R1 * 7/16 - } - { - \time 3/8 - R1 * 3/8 - } - } - - Returns silence mask. - ''' - from abjad.tools import rhythmmakertools - pattern = patterntools.Pattern( - indices=[0], - inverted=inverted, - period=1, - ) - mask = rhythmmakertools.SilenceMask( - pattern=pattern, - use_multimeasure_rests=use_multimeasure_rests, - ) - return mask diff --git a/abjad/tools/rhythmmakertools/silence_every.py b/abjad/tools/rhythmmakertools/silence_every.py deleted file mode 100644 index 42175da16bc..00000000000 --- a/abjad/tools/rhythmmakertools/silence_every.py +++ /dev/null @@ -1,184 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def silence_every( - indices, - period=None, - inverted=None, - use_multimeasure_rests=None, - ): - r'''Makes silence mask that matches `indices` at `period`. - - .. container:: example - - Silences every second division: - - :: - - >>> mask = rhythmmakertools.silence_every(indices=[1], period=2) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[1], - period=2, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Silences every second and third division: - - :: - - >>> mask = rhythmmakertools.silence_every(indices=[1, 2], period=3) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[1, 2], - period=3, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Silences every division except the last: - - :: - - >>> mask = rhythmmakertools.silence_every(indices=[-1], inverted=True) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[-1], - inverted=True, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - } - - Returns silence mask. - ''' - from abjad.tools import rhythmmakertools - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - period=period, - ) - mask = rhythmmakertools.SilenceMask( - pattern=pattern, - use_multimeasure_rests=use_multimeasure_rests, - ) - return mask diff --git a/abjad/tools/rhythmmakertools/silence_except.py b/abjad/tools/rhythmmakertools/silence_except.py deleted file mode 100644 index 183c58ba22f..00000000000 --- a/abjad/tools/rhythmmakertools/silence_except.py +++ /dev/null @@ -1,203 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools -from abjad.tools.topleveltools import new - - -def silence_except(indices=None): - r'''Makes silence mask that matches all indices except `indices`. - - .. container:: example - - Silences divisions except 1 and 2: - - :: - - >>> mask = rhythmmakertools.silence_except([1, 2]) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[1, 2], - inverted=True, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> staff = lilypond_file[Staff] - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Silences divisions except -1 and -2: - - :: - - >>> mask = rhythmmakertools.silence_except([-1, -2]) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[-1, -2], - inverted=True, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Works with pattern input: - - :: - - >>> pattern_1 = abjad.index_all() - >>> pattern_2 = abjad.index_first() - >>> pattern_3 = abjad.index_last() - >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 - >>> mask = rhythmmakertools.silence_except(pattern) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.CompoundPattern( - ( - abjad.Pattern( - indices=[0], - period=1, - ), - abjad.Pattern( - indices=[0], - ), - abjad.Pattern( - indices=[-1], - ), - ), - inverted=True, - operator='xor', - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - Equivalent to ``silence(..., inverted=True)``. - - Returns silence mask. - ''' - from abjad.tools import rhythmmakertools - indices = indices or [] - prototype = (patterntools.Pattern, patterntools.CompoundPattern) - if isinstance(indices, prototype): - pattern = indices - else: - pattern = patterntools.Pattern( - indices=indices, - ) - pattern = new(pattern, inverted=True) - return rhythmmakertools.SilenceMask(pattern=pattern) diff --git a/abjad/tools/rhythmmakertools/silence_first.py b/abjad/tools/rhythmmakertools/silence_first.py deleted file mode 100644 index d8f7ede56e6..00000000000 --- a/abjad/tools/rhythmmakertools/silence_first.py +++ /dev/null @@ -1,176 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def silence_first(n=1, inverted=None, use_multimeasure_rests=None): - r'''Makes silence mask that matches the first `n` indices. - - .. container:: example - - Silences first division: - - :: - - >>> mask = rhythmmakertools.silence_first() - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[0], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Silences first two divisions: - - :: - - >>> mask = rhythmmakertools.silence_first(n=2) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[0, 1], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Silences no first divisions: - - :: - - >>> mask = rhythmmakertools.silence_first(n=0) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - Returns silence mask. - ''' - from abjad.tools import rhythmmakertools - indices = list(range(n)) - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - ) - mask = rhythmmakertools.SilenceMask( - pattern=pattern, - use_multimeasure_rests=use_multimeasure_rests, - ) - return mask diff --git a/abjad/tools/rhythmmakertools/silence_last.py b/abjad/tools/rhythmmakertools/silence_last.py deleted file mode 100644 index 4374d138f2e..00000000000 --- a/abjad/tools/rhythmmakertools/silence_last.py +++ /dev/null @@ -1,176 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def silence_last(n=1, inverted=None, use_multimeasure_rests=None): - r'''Makes silence mask that matches the last `n` indices. - - .. container:: example - - Silences last division: - - :: - - >>> mask = rhythmmakertools.silence_last() - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[-1], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Silences last two divisions: - - :: - - >>> mask = rhythmmakertools.silence_last(n=2) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[-2, -1], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Silences no last divisions: - - :: - - >>> mask = rhythmmakertools.silence_last(n=0) - - :: - - >>> f(mask) - rhythmmakertools.SilenceMask( - pattern=abjad.Pattern( - indices=[], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - Returns silence mask. - ''' - from abjad.tools import rhythmmakertools - indices = list(reversed(range(-1, -n-1, -1))) - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - ) - mask = rhythmmakertools.SilenceMask( - pattern=pattern, - use_multimeasure_rests=use_multimeasure_rests, - ) - return mask diff --git a/abjad/tools/rhythmmakertools/sustain.py b/abjad/tools/rhythmmakertools/sustain.py deleted file mode 100644 index 14fcad206bc..00000000000 --- a/abjad/tools/rhythmmakertools/sustain.py +++ /dev/null @@ -1,275 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools -from abjad.tools.topleveltools import new - - -def sustain(indices=None, inverted=None): - r'''Makes sustain mask that matches `indices`. - - .. container:: example - - Sustains divisions 1 and 2: - - :: - - >>> mask = rhythmmakertools.sustain([1, 2]) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[1, 2], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Sustains divisions -1 and -2: - - :: - - >>> mask = rhythmmakertools.sustain([-1, -2]) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[-1, -2], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Works with pattern input: - - :: - - >>> pattern_1 = abjad.index_all() - >>> pattern_2 = abjad.index_first() - >>> pattern_3 = abjad.index_last() - >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 - >>> mask = rhythmmakertools.sustain(pattern) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.CompoundPattern( - ( - abjad.Pattern( - indices=[0], - period=1, - ), - abjad.Pattern( - indices=[0], - ), - abjad.Pattern( - indices=[-1], - ), - ), - operator='xor', - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - } - - .. container:: example - - Works with pattern input and inverted flag: - - :: - - >>> pattern_1 = abjad.index_all() - >>> pattern_2 = abjad.index_first() - >>> pattern_3 = abjad.index_last() - >>> pattern = pattern_1 ^ pattern_2 ^ pattern_3 - >>> mask = rhythmmakertools.sustain(pattern, inverted=True) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.CompoundPattern( - ( - abjad.Pattern( - indices=[0], - period=1, - ), - abjad.Pattern( - indices=[0], - ), - abjad.Pattern( - indices=[-1], - ), - ), - inverted=True, - operator='xor', - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - } - - Returns sustain mask. - ''' - from abjad.tools import rhythmmakertools - indices = indices or [] - prototype = (patterntools.Pattern, patterntools.CompoundPattern) - if isinstance(indices, prototype): - pattern = indices - else: - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - ) - pattern = new(pattern, inverted=inverted) - return rhythmmakertools.SustainMask(pattern=pattern) diff --git a/abjad/tools/rhythmmakertools/sustain_all.py b/abjad/tools/rhythmmakertools/sustain_all.py deleted file mode 100644 index d4123f1d1e3..00000000000 --- a/abjad/tools/rhythmmakertools/sustain_all.py +++ /dev/null @@ -1,130 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def sustain_all(inverted=None): - r'''Makes sustain mask that matches all indices. - - .. container:: example - - Without mask: - - >>> rhythm_maker = rhythmmakertools.TupletRhythmMaker( - ... tuplet_ratios=[(3, 1)], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - - :: - - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - \tweak text #tuplet-number::calc-fraction-text - \times 7/8 { - c'4. - c'8 - } - } - { - \time 3/8 - \tweak text #tuplet-number::calc-fraction-text - \times 3/4 { - c'4. - c'8 - } - } - { - \time 7/16 - \tweak text #tuplet-number::calc-fraction-text - \times 7/8 { - c'4. - c'8 - } - } - { - \time 3/8 - \tweak text #tuplet-number::calc-fraction-text - \times 3/4 { - c'4. - c'8 - } - } - } - - .. container:: example - - With mask: - - :: - - >>> mask = rhythmmakertools.sustain_all() - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[0], - period=1, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.TupletRhythmMaker( - ... division_masks=[mask], - ... tuplet_ratios=[(3, 1)], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - - :: - - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - Returns sustain mask. - ''' - from abjad.tools import rhythmmakertools - pattern = patterntools.Pattern( - indices=[0], - inverted=inverted, - period=1, - ) - mask = rhythmmakertools.SustainMask(pattern=pattern) - return mask diff --git a/abjad/tools/rhythmmakertools/sustain_every.py b/abjad/tools/rhythmmakertools/sustain_every.py deleted file mode 100644 index 8fd476eee03..00000000000 --- a/abjad/tools/rhythmmakertools/sustain_every.py +++ /dev/null @@ -1,124 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def sustain_every(indices, period, inverted=None): - r'''Makes sustain mask that matches `indices` at `period`. - - .. container:: example - - Sustains every second division: - - :: - - >>> mask = rhythmmakertools.sustain_every(indices=[1], period=2) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[1], - period=2, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Sustains every second and third division: - - :: - - >>> mask = rhythmmakertools.sustain_every(indices=[1, 2], period=3) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[1, 2], - period=3, - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - Returns sustain mask. - ''' - from abjad.tools import rhythmmakertools - indices = list(indices) - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - period=period, - ) - mask = rhythmmakertools.SustainMask(pattern=pattern) - return mask diff --git a/abjad/tools/rhythmmakertools/sustain_first.py b/abjad/tools/rhythmmakertools/sustain_first.py deleted file mode 100644 index c0034e3c60c..00000000000 --- a/abjad/tools/rhythmmakertools/sustain_first.py +++ /dev/null @@ -1,160 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def sustain_first(n=1, inverted=None): - r'''Makes sustain mask that matches the first `n` indices. - - .. container:: example - - Sustains first division: - - :: - - >>> mask = rhythmmakertools.sustain_first() - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[0], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( - ... denominators=[16], - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - { - c'16 [ - c'16 - c'16 - c'16 - c'16 - c'16 ] - } - } - { - \time 7/16 - { - c'16 [ - c'16 - c'16 - c'16 - c'16 - c'16 - c'16 ] - } - } - { - \time 3/8 - { - c'16 [ - c'16 - c'16 - c'16 - c'16 - c'16 ] - } - } - } - - .. container:: example - - Sustains first two divisions: - - :: - - >>> mask = rhythmmakertools.sustain_first(n=2) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[0, 1], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.EvenDivisionRhythmMaker( - ... denominators=[16], - ... division_masks=[mask], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - { - \time 7/16 - { - c'16 [ - c'16 - c'16 - c'16 - c'16 - c'16 - c'16 ] - } - } - { - \time 3/8 - { - c'16 [ - c'16 - c'16 - c'16 - c'16 - c'16 ] - } - } - } - - Returns sustain mask. - ''' - from abjad.tools import rhythmmakertools - indices = list(range(n)) - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - ) - mask = rhythmmakertools.SustainMask(pattern=pattern) - return mask diff --git a/abjad/tools/rhythmmakertools/sustain_last.py b/abjad/tools/rhythmmakertools/sustain_last.py deleted file mode 100644 index ac44de88f63..00000000000 --- a/abjad/tools/rhythmmakertools/sustain_last.py +++ /dev/null @@ -1,183 +0,0 @@ -# -*- coding: utf-8 -*- -from abjad.tools import patterntools - - -def sustain_last(n=1, inverted=None): - r'''Makes sustain mask that matches the last `n` indices. - - .. container:: example - - Sustains last division: - - :: - - >>> mask = rhythmmakertools.sustain_last() - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[-1], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Sustains last two divisions: - - :: - - >>> mask = rhythmmakertools.sustain_last(n=2) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[-2, -1], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - c'4.. - } - { - \time 3/8 - c'4. - } - } - - .. container:: example - - Sustains no last divisions: - - :: - - >>> mask = rhythmmakertools.sustain_last(n=0) - - :: - - >>> f(mask) - rhythmmakertools.SustainMask( - pattern=abjad.Pattern( - indices=[], - ), - ) - - :: - - >>> rhythm_maker = rhythmmakertools.NoteRhythmMaker( - ... division_masks=[ - ... rhythmmakertools.silence_all(), - ... mask, - ... ], - ... ) - >>> divisions = [(7, 16), (3, 8), (7, 16), (3, 8)] - >>> selections = rhythm_maker(divisions) - >>> lilypond_file = rhythmmakertools.make_lilypond_file( - ... selections, - ... divisions, - ... ) - >>> show(lilypond_file) # doctest: +SKIP - - .. docs:: - - >>> f(lilypond_file[Staff]) - \new RhythmicStaff { - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - { - \time 7/16 - r4.. - } - { - \time 3/8 - r4. - } - } - - Returns sustain mask. - ''' - from abjad.tools import rhythmmakertools - - indices = list(reversed(range(-1, -n-1, -1))) - pattern = patterntools.Pattern( - indices=indices, - inverted=inverted, - ) - mask = rhythmmakertools.SustainMask(pattern=pattern) - return mask diff --git a/abjad/tools/rhythmmakertools/test/test_rhythmmakertools_DurationSpellingSpecifier.py b/abjad/tools/rhythmmakertools/test/test_rhythmmakertools_DurationSpellingSpecifier.py index 6822c3c7266..6126196910b 100644 --- a/abjad/tools/rhythmmakertools/test/test_rhythmmakertools_DurationSpellingSpecifier.py +++ b/abjad/tools/rhythmmakertools/test/test_rhythmmakertools_DurationSpellingSpecifier.py @@ -1,8 +1,11 @@ +# -*- coding: utf-8 -*- +import abjad from abjad import * def test_rhythmmakertools_DurationSpellingSpecifier_01(): - r'''DurationSpellingSpecifier does not leave parent references.''' + r'''DurationSpellingSpecifier does not leave parent references. + ''' beam_specifier = rhythmmakertools.BeamSpecifier( beam_each_division=True, @@ -17,7 +20,7 @@ def test_rhythmmakertools_DurationSpellingSpecifier_01(): spell_metrically='unassignable', ) - logical_tie_masks = [rhythmmakertools.silence_every([0], period=2)] + logical_tie_masks = [abjad.silence_every([0], period=2)] talea = rhythmmakertools.Talea(counts=[1, 2, 3, 4], denominator=16) diff --git a/abjad/tools/systemtools/StorageFormatAgent.py b/abjad/tools/systemtools/StorageFormatAgent.py index d151376f707..ebbfadef8f4 100644 --- a/abjad/tools/systemtools/StorageFormatAgent.py +++ b/abjad/tools/systemtools/StorageFormatAgent.py @@ -528,7 +528,7 @@ def get_import_statements(self): >>> rhythm_maker = rhythmmakertools.TupletRhythmMaker( ... tuplet_ratios=[(3, 2)], ... division_masks=[ - ... rhythmmakertools.silence_every([1], period=2), + ... abjad.silence_every([1], period=2), ... ], ... ) >>> f(rhythm_maker)