Created
February 14, 2022 16:06
-
-
Save capital-G/68b55fd07fcd0b7ff317231dd7a5e8b9 to your computer and use it in GitHub Desktop.
SC: Automatic transformation of arguments to NamedControls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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