All possible divisions of a number.

Jan 16, 2013 at 11:40pm

All possible divisions of a number.

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?


Jan 17, 2013 at 1:02am

Sounds like you’re basically building a euclidian rhythm generator?

Jan 17, 2013 at 1:06am

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 at 2:08am

I think this thread may have what you want–

Jan 17, 2013 at 2:46pm

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 at 9:37am

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 at 10:47am

AFAIK : Javascript is defered in the main thread ; so i’m not sure it’s a good idea.

If you need a small depth and if you define a limit, i would use the max object implementation (not recursive) and consider to write a C/Java external only if you really need more efficiency (or a biggest tree).

Jan 18, 2013 at 4:58pm

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.

– Pasted Max Patch, click to expand. –
Jan 19, 2013 at 6:45am


Slightly improved my patch (with a depth of 8 in this example). Take care ; this algorithm is exponential by the depth. You quickly get a spinning wheel of death (4^16 is 4294967296).

– Pasted Max Patch, click to expand. –
Jan 21, 2013 at 7:00pm

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 at 10:19pm

Man, those are both just brilliant! My head is spinning…


You must be logged in to reply to this topic.