melody, inverse and permutation

Oct 6, 2010 at 2:26pm

melody, inverse and permutation


I’m trying to experiment with random melody creation, so I built a very very simple patch to create a melody and replay it as it was, inverted and permutated. I have two things not clear in my mind:
1) is there a way to make it simpler? i mean… it works but it looks complicated to me, no?
2) i don’t know why when playing computer MIDI instr it works, but if i send those messages to an external sampler inverse and permutated play on channel 16. always.

Any idea?

– Pasted Max Patch, click to expand. –
Oct 6, 2010 at 4:21pm

i cant look at max5 code, but this seems a lot of code for inversion … something
like [map 60 72 72 60] should perform a (very simple) melody inversion already.

Oct 6, 2010 at 9:10pm

I don’t have the [vs.between] abstraction/external, could you post/link to it?


Oct 6, 2010 at 10:21pm

ops, here it is.

  1. vs.between.pat
Mar 20, 2011 at 8:29am

you probably found your way already, but i wanted to do similar things and found a little snippet of code online and put in a js object. maybe helpful?


– Pasted Max Patch, click to expand. –

code for js:
var arr = new Array();
var output = new Array();

permute = function(v, m){
for(var p = -1, j, k, f, r, l = v.length, q = 1, i = l + 1; –i; q *= i);
for(x = [new Array(l), new Array(l), new Array(l), new Array(l)], j = q, k = l + 1, i = -1;
++i < l; x[2][i] = i, x[1][i] = x[0][i] = j /= --k);
for(r = new Array(q); ++p < q;)
for(r[p] = new Array(l), i = -1; ++i < l; !--x[1][i] && (x[1][i] = x[0][i],
x[2][i] = (x[2][i] + 1) % l), r[p][i] = m ? x[3][i] : v[x[3][i]])
for(x[3][i] = x[2][i], f = 0; !f; f = !f)
for(j = i; j; x[3][--j] == x[2][i] && (x[3][i] = x[2][i] = (x[2][i] + 1) % l, f = 1));
return r;

function list(){
arr = permute( arrayfromargs(arguments), 0);

Mar 20, 2011 at 9:41am

You might want to try bach ( ), a library of objects and patches for algorithmic composition. There are several tutorials dealing with melodics transformations.


Mar 20, 2011 at 6:14pm


I just had a look, didn’t know about it. Nice work!
Since a while I’m using FTM a lot, doesn’t seem to integrate nicely though, because of several reasons (data issues, ftm_object doesn’t go through unharmed). But it implements lots of things I would like to have at my disposal in FTM, so I’ll probably use it for these little things that you wanna do sometimes (like calculating all permutations of a series of five notes, see the above).




You must be logged in to reply to this topic.