All possible divisions of a number.

Jan 16 2013 | 11:40 pm
Hi guys.
I'm trying to make a patch that generates rhythms that fit within a specified bar length and only use note values that are pre selected.
So for example if I have a bar of 4/4 and I have half-notes, quarter notes and eighth notes I would have all possible rhythmic variations using these note divisions that fit within the 4/4 bar. Ie. one would be: X x x x X x X X another could be X x X x X x x x etc. etc. until all variations are reached.
I've been trying to create a patch that does this by looping back over an algorithm. But can't seem to get there. Would javascript be more useful for this sort of thing?
Thanks.

• Jan 17 2013 | 1:02 am
Sounds like you're basically building a euclidian rhythm generator?
• Jan 17 2013 | 1:06 am
I guess so. And I've looked into the euclidean algorithm. But that distributes beats equally across a given bar length. What I want to find out about is being able to quantize these distributions using a selected variety of divisions and then to iterate through all possible variations to be probably stored in a dict or a coll.
I'm just wondering what sort of approach I should take to this. and if anyone has made anything similar before.
• Jan 17 2013 | 2:08 am
• Jan 17 2013 | 2:46 pm
Aha, thanks Terry. That seems to have done it! It is a case for a looping algorithm then I see. I wonder if this would be more efficient in js as opposed to max? What do you think?
Thanks again.
• Jan 18 2013 | 9:37 am
yes is definitely lends itself to a recursive treatment in a text-based language like javascript, but I've no experience with that-- I assume it would be faster (certainly would be in C, and I presumably Java too).
It's a pretty simple algorithm, and if you're doing it to generate rhythms, I can't really see the advantage using js (aside from compactness), even in real-time applications. for a more informed opinion someone with js experience would be better qualified to comment
• Jan 18 2013 | 4:58 pm
This should get you started, it's a brute force approach which will put all the permutations into a coll. You could use filtering on the output of the uzi's to get rid of lengths you are not interested in.
• Jan 21 2013 | 7:00 pm
Thanks guys. Both are fantastic approaches. I'll do some modifications and shall report back with the patch I'm using this method in.
• Jan 26 2013 | 10:19 pm
Man, those are both just brilliant! My head is spinning...