A technical support community for Apple Logic Pro users.

 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Sun Sep 16, 2018 1:34 pm

I know scripter very well thank you very much. I wrote this a long time ago so I will have to review it later to see what point I was trying to make. I will be happy to clarify it for you
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Sun Sep 16, 2018 2:35 pm

Yea I guess I don't understand what point or question you're trying to make. I do not think you have understood my post from a year ago, and I do not really understand the point you're making now.

The point I made a year ago is that when you setup PluginParameters array, the values contained therein are stored internally by Scripter in some kind of structure and you use the GetParameter function to obtain values from that structure, which should, theoretically, return the values as they appear in the GUI.

However, what I found a year ago is that calling GetParameter outside of the callback functions can result in an error. My thought is that Scripter does not have that structure fully initialized until such time that callbacks have begun, so if you have some code in your script that executes at the global level, it gets called when the script is first loaded. You can put all kinds of code at that level, which can initialize variables and so forth or actually can do quite a lot of different things. Typically that is how and when to initialize PluginParameters array, for example. However, calling GetParameter() calls do not function during that phase, the internal structure is not fully ready for it. Once that phase is over and the callbacks are happening, then calling GetParameter() works as intended.

For that reason I have offered an approach that I often use, which is that when I initialize PluginParameters array. I also add an additional "data" attribute to each element of the PluginParameters array, which holds the actual data value. That way during the startup phase I can just reference that value directly and avoid calling GetParameters. By using the strategy I employed, that data attribute is always kept up to date with the current value and it can be reference directly without having to ever use GetParameters() at all, and can be used during global startup phase.

Hope that clarifies it for you..
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Sun Sep 16, 2018 3:17 pm

ValliSoftware wrote:
Let's step back for a minute on this.
So you've added a menu item on PluginParameters, no problem with that but the next line, less than a nano second at computer speed, you want to test to see if anyone used the mouse to make a selection on your "test" menu item?


You are missing the point. The GetParameter() call does not tell you, ever, whether someone has changed the UI element. It it supposed to tell you what the current value is, regardless of whether it has been changed recently or not.

A lot of people use the UI as the holding place of that current value, and the only place to "get" it is to call GetParameter() to give you the current value of that UI element. Unfortunately Calling GetParameter() will not work properly until some point in time after which callbacks have begun getting called. If you don't need to access that value prior to callbacks getting called, then its a moot point. But if you do, then you need to keep it in a separate variable and keep the variable and UI in sync. There are undoubtedly other ways to work around this limitation, but I have presented the way that I have made my standard approach for handling data values in the GUI. This is like a data/view design pattern. I use the PluginParameters array itself to hold the data and keep it in sync with changes by the user through appropriate callbacks.

Hope that makes sense to you.
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
88keys
Posts: 29
Joined: Wed Jul 17, 2013 12:35 pm

Re: GetParameter, when is it active?

Fri May 15, 2020 1:07 pm

This is an old post and it's been a long time since I've played with Scripter. But 10.5 and Sampler have gotten me interested again in possibilities. This is a great thread. What Dewdman42 is craving is a legitimate data "model" that we have proper access to in trying to conform Scripter to a more MVC pattern. As it stands, Scripter's managing of data and UI bindings reminds me more of a framework like React . . . but not really. I just mean that, as he explains, data values feel like they are almost being "stored" in the UI. I like his suggestion of 'mirroring' the PluginParameters array with a custom, global array of parameter data that we can access traditionally when we want with typical syntax. I also tested the second approach of simply adding custom properties to the original parameter objects and mirroring data there. That's nice too.

As I started exploring scripter for real last night, I was amazed that I couldn't just do
PluginParameters[3].value
for example to get what I wanted. Where is the formal API documentation for this with its organized lists of objects and methods? Aside from the LP Effects Manual, scripter section and the tutorial examples, I can't find anything significant.

GetParameter() with its string argument that has to match something in the PluginParameters array feels so hackish. And for that matter, creating plugin parameters and specifying their type with a string ("lin", "target" etc.) is so contrary to just instantiating objects: new LinSlider(), new Target(). It's like I want to abstract this whole thing and write an interface on top of Scripter that works more like what we are used to. Just sayin.
 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Fri May 15, 2020 1:20 pm

I have a simple design pattern and work around here: viewtopic.php?f=45&t=143989

check that out and let me know if you have any questions. GetParameter is very expensive in terms of CPU use also, my above pattern works around that.
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Fri May 15, 2020 1:29 pm

Keep in mind also the following.. The Parameters array serves two actual purposes. One is to configure the GUI, but the other is to store the values of the GUI. This is all fine, but that is also how you save settings in your DAW project. All plugins generally will save the "settings" of the plugin with the DAW project, so that when you reload the project, each plugin loads with the settings you were using last time you used the DAW project. Scripter works the same way. So the values of the the GUI...are saved with the project. That is important in a lot of cases.

So basically you have to access the data from there in the script. But GetParameter is a very computationally expensive operation which is why i did the work around mentioned above, which operates much much more efficiently to grab that value from the loaded settings.

You always have the option to store values in a different place other then as a so called "Parameter", but then the data will not be saved with the project. Which may or may not be totally fine..just depends on what it is.
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Fri May 15, 2020 1:39 pm

A few more comments...

88keys wrote:
As I started exploring scripter for real last night, I was amazed that I couldn't just do
PluginParameters[3].value
for example to get what I wanted. Where is the formal API documentation for this with its organized lists of objects and methods? Aside from the LP Effects Manual, scripter section and the tutorial examples, I can't find anything significant.


The actual data is not normally stored in the PluginParameters[] array. Scripter stores it internally in some way. The PluginParameters array is normally only used to configure the GUI itself...not the data.

The workaround I linked above, basically is a design pattern to stash the data into the PluginParameters array AS A COPY of the true data that Scripter is keeping internally. This is only as a convenience to use in code in a faster way. Ultimately, Scripter will save with the DAW project the value that is it keeping internally and we have no other way to access that data then by calling GetParameter.

GetParameter() with its string argument that has to match something in the PluginParameters array feels so hackish.


You can also reference the Parameter by id number which is the manner I prefer because I assume it will be faster javascript for one thing. Sometimes its a hassle to keep track of which UI element is which id # though, especially during development as you are adding or removing things from the UI.

And for that matter, creating plugin parameters and specifying their type with a string ("lin", "target" etc.) is so contrary to just instantiating objects: new LinSlider(), new Target(). It's like I want to abstract this whole thing and write an interface on top of Scripter that works more like what we are used to. Just sayin.


Yea a proper OOP model would have been cool, I don't disagree, but this is javascript after all. I have spent quite a lot of time experimenting with Scripter and trying various OOP design patterns and it always turns out to be way more trouble then its worth. For one thing, we can't include files to re-use classes between projects easily. I have found that from a practical perspective, its just easier to use javascript's flexibility and break some OOP rules...get it done in less code. The target audience for this API is also never going to be able to understand some of the OOP principles of abstraction, so in some ways...from an OOP perspective you might consider it "hackish" but from a simple usability perspective, its very straight forward as is...and OOP knowledge is not neccessary. There are a lot of things that could make Scripter a lot more useful with better OOP built in classes and support. But in reality, its not there..and anyway, with all the UI limitations I have more or less come to realize that most projects of any substantial scope should just be done in C++ instead of Scripter.
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
88keys
Posts: 29
Joined: Wed Jul 17, 2013 12:35 pm

Re: GetParameter, when is it active?

Mon May 18, 2020 10:47 am

Yeah. I like the workaround. Just add a .data property to each object in the array. For that matter, I might just access the value directly. without the getter function. This should work too:

var PluginParameters = [{name:"slider", type: "lin", data: 4}]; //example
var mySlider = PluginParameters[0];

function ParameterChanged(id, val) {
    PluginParameters[id].data = val;
}

//mySlider.data gives current value whenever I want it
//at least this works in regular js where mySlider simply references/points to PluginParameters[0]


When you refer to a real project in C++ . . . (or Swift for that matter) I guess we can write actual Midi Plugins too. I didn't realize that they are just part of the the Audio Unit spec.
 
User avatar
Dewdman42
Topic Author
Posts: 2370
Joined: Tue Sep 09, 2014 3:01 pm
Location: Park City, UT

Re: GetParameter, when is it active?

Mon May 18, 2020 10:53 am

I would still use the getter function because it does the job of initializing the data member on first use. That is important when opening a daw project and you want to get the saved parameter value rather then the hard coded value from the script.

Check out JUCE for an easy intro to c++ midi plugins
5,1 MacPro 3.46ghz x 12 128gb ram, OSX 10.14, Logic Pro 10.4.8, Mainstage3, Cubase10, StudioOne, Reaper, DP9, VEP, VSL, too many plugins to list
 
User avatar
88keys
Posts: 29
Joined: Wed Jul 17, 2013 12:35 pm

Re: GetParameter, when is it active?

Mon May 18, 2020 12:27 pm

JUCE looks very cool, thanks.

On the one hand, I've always been a fan of using a native code base. But my day job is teaching programming in a high school. After 4 years of mobile development separately for both iOS development and Android, I'm now teaching a class using Flutter. I still smile every time I complete a build for both platforms.