Skip to content

Instantly share code, notes, and snippets.

@capital-G
Created February 14, 2022 16:06
Show Gist options
  • Save capital-G/68b55fd07fcd0b7ff317231dd7a5e8b9 to your computer and use it in GitHub Desktop.
Save capital-G/68b55fd07fcd0b7ff317231dd7a5e8b9 to your computer and use it in GitHub Desktop.
SC: Automatic transformation of arguments to NamedControls
q = q?();
q[\autoKr] = {|ugen, prefix=nil, rate=\ar, args=nil, specs=nil|
var argumentList = [];
var defaultArgs = ();
var method;
// TODO specs are not working? :/
args = args?();
specs = specs?();
// search for method
method = ugen.class.methods.select({|m| m.name==rate}).first;
if(method.isNil, {
^Error("Did not found method \"%\" in %".format(rate, ugen.name)).throw;
});
// get default params and overwrite them if necessary
method.keyValuePairsFromArgs.pairsDo({|k, v|
defaultArgs[k] = v
});
args.pairsDo({|k, v|
defaultArgs[k] = v;
});
// construct a list of parameters
defaultArgs.pairsDo({|k, v|
var name;
name = if(prefix.notNil, {"%_%".format(prefix, k)}, {k});
argumentList = argumentList.add(k);
argumentList = argumentList.add(NamedControl.kr(name, v).spec_(specs[k]));
});
// call method with list of arguments
ugen.performList(rate).(argumentList);
};

Ndef(\autoKrTest, { q[\autoKr].(Gendy3, args: (\freq: 400, \ampDist: 0.3)); }).play.gui;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment