Created
April 7, 2017 05:23
-
-
Save zenon/7a5fb06a5b30216573a85635ac3f5f22 to your computer and use it in GitHub Desktop.
More complete spread function
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
def spread3(num_accents, size, *args) | |
args_h = resolve_synth_opts_hash_or_array(args) | |
beat_rotations = args_h[:rotate] | |
res = [] | |
# if someone requests 8 or more accents in a bar of 8 beats | |
# default to filling the output with accents | |
# (rotation is futile here) | |
if num_accents >= size # changed to >=, so v2 is not empty below | |
res = [true] * size | |
return res.ring | |
end | |
# new part | |
v1 = [[true]] * num_accents | |
v2 = [[false]] * (size - num_accents) | |
# If v2 not empty (thats given here), call at least once. | |
(v1, v2) = redistribute(v1,v2) | |
# End condition: v2 empty or has just one element | |
while v2.length > 1 | |
(v1, v2) = redistribute(v1,v2) | |
end | |
res = (v1 + v2).flatten | |
if beat_rotations && beat_rotations.is_a?(Numeric) | |
beat_rotations = beat_rotations.abs | |
while beat_rotations > 0 | |
beat_rotations -= 1 if res.rotate!.first == true | |
end | |
res.ring | |
else | |
res.ring | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment