Creating random preset (arbitrary number of parameters)?

Rodrigo's icon

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?

vichug's icon

(dump) !

vichug's icon

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 :)

Rodrigo's icon

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

Rodrigo's icon

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());
        }
    }
}

Rodrigo's icon

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());
}

vichug's icon

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 :)

Rodrigo's icon

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).

vichug's icon

indeed very well done !

Rodrigo's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

Rodrigo's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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).