Jump to content

defaultValue not working

Danny Wyatt

Recommended Posts



so first you have to realize something about all plugins in general. All plugins have a concept known as "Parameters". Parameters are data connectors that plugins expose to the host so that the host DAW can set them and automate them. Every plugin you have ever used has a list of parameters, which may or may not even be displayed by the plugin's actual GUI. The plugin Window in LogicPro has a way to view those parameters are raw sliders. Here is the Pianoteq7 plugin parameter list for example:




Likewise if you open the automation list for that plugin you will see the same list of "parameters", which are all automatable:




Scripter Parameters


Like all good plugins, the Scripter plugin has the ability to expose parameters to the host DAW, except that we are able to modify what that list of parameters will be by using the PluginParameters array.


var PluginParameters = [];

  name: "TestParam",
  type: "lin",
  minValue: 0,
  maxValue: 127,
  numberOfSteps: 127




The Scripter plugin does not have a custom GUI like most plugins, it simply displays the same "control" GUI that you can select for other plugins if you want using the View menu. Note that the Scripter plugin window does not have a way to change that. What we see on the Scripter GUI is basically the raw basic list of plugin parameters....and we can edit the values of those parameters, the same way you can edit plugin parameters of other plugins when in "control" mode (as shown above)


So the point to make here is that the PluginParameters array is not really a "GUI" creation paradigm per say, its simply a parameter list definition paradigm...and LogicPro happens to provide a way for any plugin to display all the parameters in a list, which we see above.


What are Plugin Parameter really then?


Plugin Parameters are the mechanism by which all plugins communicate various non-audio and non-midi data with the host DAW. This is how automation works. Its also how you can setup a plugin, set a bunch of things in the GUI, program your FX or synth for example, and then when you save the host DAW project, the current settings of those parameters are saved with the project. That way when you load the project later, not only is the plugin loaded into the track, but the last "settings" you had set will also be reloaded into the plugin. Those settings are basically those Parameter values as they were at the time you saved the project. When you save a plugin "preset", that is also basically saving those parameter values as a preset, so that you can load the plugin and load a particular preset, which loads the list of parameter data values at the time it was saved.


By convention, nearly all plugins follow this pattern of using the Parameter list to stash certain kinds of data that you want the DAW to be able to interact with, and also by convention plugins when reloaded in a saved project will read the list of parameter values that the host DAW is remembering, restoring the plugin to the last state it was in. When you load a plugin the first time, it starts with a clean slate or perhaps some default values.


What does Scripter do?


So this is what happens with Scripter. When you first load a new script into Scripter, it will construct a list of Parameters if you have defined the PluginParameters array. And while it is doing that, it will use the defaultValue to determine the very first initialization value to use for each parameter. After that point in time however, the host is in control of those parameters a bit more. After that point in time, the Parameter list is connected to the host automation and to being saved with the project as parameter values for that particular plugin instance. In the case of Scripter, executing RunScript, will not reset that value!


Hitting RunScript will recompile the script, it will reset all the other vars, but it will not reset the Parameter values.


Notice also that if you save the script as a Scripter preset, the parameter values are also stored with that! So if you load one of the saved Scripter presets, it loads the script, compiles it AND also loads the parameter values that were present at the time you saved the Scripter preset.


That is actually a good thing, not a bad thing. You want to be able to use a scripter script, adjust the parameter values and save the preset or save the project and when you recall that project have the slider values be where they were the last time you used the project. You would NOT want the script to force the default script values every time you load the project.


And then later on hitting Run Script again will recompile the script, which resets all the script vars, but does not reset the parameter values, which are linked to the host daw's automation, etc.


Alright so what can you do to force it to reset?


First check out the following setting in your script which does in fact cause all the parameter values to be reset if that is what you want to do:


ResetParameterDefaults = true;


The above setting changes the behavior of Scripter in some way so that it will always reset the parameter values to the defaults whenever you load that script. Maybe this will be what you want, but see above what I said about the fact that if you save the project and reload it later...then the slider values will be reset back to the defaults...which is probably not what you want most of the time.


what else can you do?


You can use the SetParameter command to use script code to push data values into the parameter list at any time. Well almost any time. It turns out you cannot call SetParameter during the initial run of the script, its not available to work until the script has completely initialized. But you can use the Reset() function and force values in there:


function Reset() {
   SetParameter(0, 43);


The above Reset function will be called whenever you bypass or unbypass the plugin and also when you hit PLAY on the transport. That is according to the Scripter API manual. So in the above example, the value of 43 is pushed into the first parameter (identified by zero). But again, you may not want the default value always pushed into it every time you hit PLAY. So I find that hard to deal with.


There is an undocumented Initialize function, which might work, I can't remember at the moment if you can call SetParameter yet inside that function, but it is called only once while running your script the first time... its worth a try if you want to make sure that every time you hit RunScript, you can force a certain value into the parameter. But again note this may interfere with when you try to reload a project later and you want the last known slider value to be loaded with it.


function Initialize() {


The reality is that once you have finished coding your script, you will want to have the saved parameter values the last known slider value, always loaded with your script and functioning that way, as all plugins do. However, while you are writing the script and tweaking it and trying things, you may rather wish that it would reload the defaultValue each time, in which case use the ResetParameterDefaults setting I mentioned above while you're working on the script and then turn that off later when you're done coding and just want the script to behave more like a normal plugin that remembers your slider settings when you reload the project.


I realize this can be a little overwhelming and confusing to think about and I get it..I have spent a lot of time trying to figure out clever ways to bootstrap values into the parameter list or to use the parameter list to save a lot to detailed data..and in general it has been a big rabbit hole of complexity that wasn't worth it. I generally just try to use normal javascript variables to hard code values that I want to always start out the same way every time the script is executed with RunScript. I use Parameters to store values that I think I want the user to set, to be saved with the preset, saved with the project and appear on the GUI..and remembered from their last setting EVEN IF the runScript button is clicked again, which most users don't do anyway...its just you while you're working on the script.


Then if you need to get tricky you can use SetParameter to force some values into the parameter list under certain circumstances as you see fit.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...