setAttribute function questions
-
Hello! I got a small problem:
This works ->
selectedFx.setAttribute(0,value);
selectedFx.setAttribute(selectedFx.Saturation,value);But I want it to be dynamic.
something like this -> selectedFx.setAttribute(selectedFx.fxParamName,value)
fxParamName contains a string.
Console.print(fxParamName);
Interface: WetAmount (or something else, because dynamic)But this doesn't work. It always refers to attribute 0.
The problem here is that I'm not using all attributes for every effect and I don't want to repeat myself in the callback.inline function onfxKnobControl(component, value) { local fxType = cmbFxSlot[index].getItemText(); local fxParamName = component.get("text").replace("knb_",""); local selectedFx = Synth.getEffect("fx"+getSelectedFxSlot()+"_"+fxType); selectedFx.setAttribute(selectedFx.fxParamName,value); //selectedFx.setAttribute(0,value); };
Is there a way to make it work?
-
Firstly put all of the FX into an object, using the FX's name as the key.
const myFX = { "saturation" : Synth.getEffect(etc, etc.), "nextFx" : Synth.getEffect(etc, etc.) };
Then make another object, using the fx name as the key, and put all the parameter names in an array.
const myParams = { "saturation" : ["Saturation", "Drive", "Delay"], // Obviously put these in the correct order and use the correct names "nextFx" : ["param3", "param2", "param3"] };
Now you can access any effect and any of its parameter indexes using a combination of the effect's name, and the parameter's name.
So for example if you want to set the saturation fx drive parameter (I don't know if it actually has this parameter, this is just a demo).
myFx.saturation.setAttribute(myParams.saturation.indexOf("Drive"), value);
-
@d-healey Yeah! Will try this! Thanks David!