Created
August 1, 2018 23:47
-
-
Save josiah-wolf-oberholtzer/43a591fcc1d5cfbb32dae3c4dae531c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abjad | |
import abjadext.rmakers | |
import itertools | |
note_rmaker = abjadext.rmakers.NoteRhythmMaker( | |
tie_specifier=abjadext.rmakers.TieSpecifier( | |
tie_across_divisions=True, | |
tie_consecutive_notes=True, | |
), | |
) | |
talea_rmaker = abjadext.rmakers.TaleaRhythmMaker( | |
talea=abjadext.rmakers.Talea(counts=[1], denominator=16), | |
) | |
mask = abjadext.rmakers.SilenceMask(pattern=abjad.index_all()) | |
silence_rmaker = abjadext.rmakers.NoteRhythmMaker(division_masks=[mask]) | |
timespan_list = abjad.TimespanList([ | |
abjad.AnnotatedTimespan( | |
start_offset=(0, 4), | |
stop_offset=(3, 4), | |
annotation=note_rmaker, | |
), | |
abjad.AnnotatedTimespan( | |
start_offset=(3, 4), | |
stop_offset=(5, 4), | |
annotation=note_rmaker, | |
), | |
abjad.AnnotatedTimespan( | |
start_offset=(5, 4), | |
stop_offset=(7, 4), | |
annotation=talea_rmaker, | |
), | |
abjad.AnnotatedTimespan( | |
start_offset=(10, 4), | |
stop_offset=(12, 4), | |
annotation=note_rmaker, | |
), | |
]) | |
timespan_list.extend(~timespan_list) | |
timespan_list.sort() | |
split_timespans = abjad.TimespanList() | |
for shard in timespan_list.split_at_offsets([(4, 4), (8, 4)]): | |
split_timespans.extend(shard) | |
split_timespans.sort() | |
staff = abjad.Staff() | |
# Group timespans by the equality of their annotations | |
for annotation, timespans in itertools.groupby( | |
split_timespans, | |
key=lambda x: getattr(x, 'annotation', None) | |
): | |
# Pull the timespans out of the subgroup iterator | |
print('Before:', timespans) | |
timespans = list(timespans) | |
print('After:', timespans) | |
# Get the durations from my timespan subgroup | |
cell_durations = [timespan.duration for timespan in timespans] | |
# Get an rmaker or convert None into a silence rmaker | |
rmaker = annotation | |
if rmaker is None: | |
rmaker = silence_rmaker | |
# Call my rmaker against my list of durations | |
rmaker_music = rmaker(cell_durations) | |
# Extend the results of the rmaker into my staff | |
staff.extend(rmaker_music) | |
abjad.show(staff) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment