Forums > MaxMSP

Creating random preset (arbitrary number of parameters)?

April 30, 2014 | 7:44 am

What’s the best practice for creating a random ‘preset’ of all available parameters (that can be an arbitrary number)?

I can create individual RNGs for each parameter, but this is quite clunky as each time I add a new component I need to create another RNG.

I’m using autopattr/pattrstorage and I know I can get pattrstorage to spit out all the presets using [getslotnamelist], but is there a way to get it to spit out the (scripting) names of all the objects exposed to it by autopattr?

And is there then a way to generate an arbitrary amount of random parameters to send to all of those objects?


April 30, 2014 | 9:02 am

(dump) !


April 30, 2014 | 9:04 am

then you’ll need to get the name of each object from the dumped message, but this should be ok (zl slice 1) ; then second outlet of dump to get that parameter’s number of paramteres ; then jstrigger or expr to generate random value for each value of list. This can get tricky depending on the number of different kind of parameters you have, setting highest/lowest desired value easily. But (dump) should help a lot anyway :)


April 30, 2014 | 9:24 am

That gives me a long string with the bpatcher name and some colons in the mix (like below).

I’d always just use the same two bpatchers (fx_input and fx_output) so I suppose I can try to strip that part of the string off (though not sure how to split a string that way).

I’ll take a look at jstrigger (not used it before). Most of the parameters are between 0. to 1. though there are a a couple booleans (on/off) and one umenu with 8 items.

print: fx_input::pitch
print: fx_input::pitchblend
print: fx_input::pitchdirty
print: fx_input::pitchpreset
print: fx_input::pitchshift
print: fx_input::stutter
print: fx_input::stutterdd
print: fx_input::stutterdensity
print: fx_input::stutterkill
print: fx_input::stutteroverdub
print: fx_input::stutterrand
print: fx_input::stutterrate
print: fx_input::stutterrec
print: fx_output::dirt
print: fx_output::dirtbass
print: fx_output::dirtc
print: fx_output::dirtg
print: fx_output::dirtmode
print: fx_output::dirtt
print: fx_output::lofi
print: fx_output::lofibit1
print: fx_output::lofibit2
print: fx_output::lofibitwise
print: fx_output::lofimp3ify
print: fx_output::lofisample
print: dump


April 30, 2014 | 9:59 am

Ok, a bit of javascript later I can send ‘dump’ and feed the output to this javascript file and it sends to each named object (though doesn’t work for boolean/umenu).

So glad I learned some javascript!

// define inlets and outlets
inlets = 1;
outlets = 1;

// send a random value to a given scripting name
function randomPreset(name) {
if (name == "done"){
// do nothing!
} else {
if (name.indexOf(‘fx_input::’) > -1) {
var trimmed;
trimmed = name.replace(‘fx_input::’,");
outlet(0, "script send " + trimmed + " " + Math.random());
} else {
var trimmed;
trimmed = name.replace(‘fx_output::’,");
outlet(0, "script send " + trimmed + " " + Math.random());
}
}
}


April 30, 2014 | 10:59 am

This is even better, more elegant and allows for any subpatcher name.

// define inlets and outlets
inlets = 1;
outlets = 1;

// send a random value to a given scripting name
function randomPreset(name) {
var sliced = name.split("::");
outlet(0, "script send " + sliced[1] + " " + Math.random());
}


April 30, 2014 | 11:00 am

ye, for umenu and boolean i imagin you need to send an int… if you had your booleans always named in a similar fashion, maybe you could test the name of received object and send an int if it needs it ? if not, maybe they would send an error message when receiving float – then you could test if there was an error, in which case it would retry a random value, this time an int ? or hmmh maybe there is a function, maybe a message to [thispatcher] or [pattrstorage] or in javascript, which gives you the type of object in return of a given script name ?
i know nothing about javascript – can just do some basic stuff with jstrigger, which if you know some js will become a very useful object i suppose :)


April 30, 2014 | 11:01 am

I only had 4 non-float things, so I’m just manually banging those with decide/random.

I found this webpage suuuuper useful for learning javascript (which is super easy to implement in Max).

http://www.codeacademy.com


April 30, 2014 | 5:04 pm

indeed very well done !


May 3, 2014 | 7:35 am

After learning a bit of regexp in another thread, here is a native version of the same thing.

– Pasted Max Patch, click to expand. –

June 19, 2014 | 1:10 pm

Just chiming back into this thread to say I figured out a version that determines the type of parameter (int or float) and then sends a corresponding random value to it (so floats get between 0. and 1., and ints get either 0 or 1).

– Pasted Max Patch, click to expand. –

Viewing 11 posts - 1 through 11 (of 11 total)