|
02-24-2017, 04:49 AM
|
#1
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
How would you share a "global" variable for each plugin instance?
Hi all,
I'd like to share for every classes within the same plugin's instance scope a common/global variable.
Such as "gLastTriggeredVoiceIndex" within my VoiceManager class, accessible for each other classes that needs it (Filters, Envelopes, and so on), but of course without passing to them a reference/pointer (keeping all stuff separated).
Each instance of the plugin should have its own VoiceManager instance, so its own gLastTriggeredVoiceIndex (not shared across all instances so).
Do you know any way in IPlug/C++?
static (internal) or external linkage won't works, since it will be the same for every plugin intance.
Thanks
|
|
|
02-24-2017, 05:10 AM
|
#2
|
Human being with feelings
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
|
Maybe writing to a project itself with
reaper.SetExtState( section, key, value, persist )
would be useful.
|
|
|
02-24-2017, 05:12 AM
|
#3
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by bFooz
Maybe writing to a project itself with
reaper.SetExtState( section, key, value, persist )
would be useful.
|
I'm using VST "standards" and FL Studio/Live. And should works for any DAW.
Thus, not specific for Reaper
|
|
|
02-24-2017, 08:41 AM
|
#4
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by Nowhk
but of course without passing to them a reference/pointer (keeping all stuff separated).
|
The problem sounds like you should just do the pointer/reference passing. Why would you want to avoid doing that anyway, if the last voice variable is just an int? It would be more painful if the passed variable was something more complicated like a pointer to an object, that all the other involved classes would then need to know about.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
02-24-2017, 08:50 AM
|
#5
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by Xenakios
The problem sounds like you should just do the pointer/reference passing. Why would you want to avoid doing that anyway, if the last voice variable is just an int? It would be more painful if the passed variable was something more complicated like a pointer to an object, that all the other involved classes would then need to know about.
|
Let say I have a VoiceManager class (which got that index), which has 16 Voice object,; each of them got 10 Envelopes and 4 LFOs: I need to pass that reference to all Voice/Envelope/LFO class every time I instance them, creating a sort of "linking" between VoiceManager and Voice/Envelope/LFO classes.
This create a relationship that I'd like to avoid, that's all Since that variable is the same (for this purpose, customers will only "read" it), would be pretty fast make it global.
|
|
|
02-24-2017, 09:01 AM
|
#6
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by Nowhk
I need to pass that reference to all Voice/Envelope/LFO class every time I instance them, creating a sort of "linking" between VoiceManager and Voice/Envelope/LFO classes.
This create a relationship that I'd like to avoid, that's all Since that variable is the same (for this purpose, customers will only "read" it), would be pretty fast make it global.
|
Sure, sounds like a familiar problem. But within a plugin type context I haven't really found another way than to pass around a pointer to the variable of interest. (In standalone applications I've used global variables and "extern" a bit too eagerly, just because it's possible...) If there's some other technique that I may have forgotten, it'd be interesting if someone will mention that.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
02-25-2017, 11:54 AM
|
#7
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Yep, would be nice to know
|
|
|
02-27-2017, 06:02 PM
|
#8
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
How about using a "signals and slots" approach ?
e.g.
https://github.com/pbhogan/Signals
|
|
|
02-28-2017, 01:33 AM
|
#9
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by nofish
|
I already use EventEmitter for binds and OnParamChange callbacks. But within ProcessDoubleReplace this approach become really expensive for CPU...
|
|
|
02-28-2017, 03:09 PM
|
#10
|
Human being with feelings
Join Date: Feb 2014
Posts: 63
|
Each instance could write it's gLastTriggeredVoiceIndex to a shared static array member variable, assuming each plugin gets an incremented index number on instantiation, using a static counter variable.
Last edited by gstuff; 02-28-2017 at 03:20 PM.
|
|
|
03-01-2017, 12:51 AM
|
#11
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by gstuff
Each instance could write it's gLastTriggeredVoiceIndex to a shared static array member variable, assuming each plugin gets an incremented index number on instantiation, using a static counter variable.
|
Nice idea, but than its the same problem: I need to share to every classes the index number of the current instance (which must be global per instance, as for gLastTriggeredVoiceIndex)
|
|
|
03-01-2017, 03:53 AM
|
#12
|
Human being with feelings
Join Date: Feb 2014
Posts: 63
|
That's just an extra static member int that can be set by the active instance, you aren't passing object references around. I've used a similar technique successfully in one of my plugins.
|
|
|
03-01-2017, 06:58 AM
|
#13
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by gstuff
That's just an extra static member int that can be set by the active instance, you aren't passing object references around. I've used a similar technique successfully in one of my plugins.
|
A static member is the same for every class you will instanciate on the same "context" (process/thread). On different plugin instance, the static member is the same.
It would depends on how DAW will handle the process/thread when you open a new instance of the plugin I think; on FL Studio for example the "context" is the same, so it won't work...
|
|
|
03-01-2017, 08:28 AM
|
#14
|
Human being with feelings
Join Date: Feb 2014
Posts: 63
|
That's correct, static member variables are shared by all instances in the same process. This allows you to count/track your instances and use an array/vector to hold data specific to each instance in one global location, without using pointers directly, akin to an Observer pattern using pull (polling). If that's not what you're trying to do then please ignore.
Last edited by gstuff; 03-01-2017 at 08:34 AM.
|
|
|
03-01-2017, 08:33 AM
|
#15
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by gstuff
That's correct, static member variables are shared by all instances in the same process. This allows you to count/track your instances and use an array/vector to hold data specific to each instance in one global location, without using pointers directly to objects. If that's not what you're trying to do then please ignore.
|
I meant: when I need (later) to access to this array/vector on a single instance, I need to do pPlugInstance->mIndex. So every object need to know about pPlugInstance. Thus, its like to pass that reference instead of gLastTriggeredVoiceIndex; thus, in the end, change nothing I always need to pass a "reference".
|
|
|
03-01-2017, 08:55 AM
|
#16
|
Human being with feelings
Join Date: Feb 2014
Posts: 63
|
Quote:
Originally Posted by Nowhk
I meant: when I need (later) to access to this array/vector on a single instance, I need to do pPlugInstance->mIndex. So every object need to know about pPlugInstance. Thus, its like to pass that reference instead of gLastTriggeredVoiceIndex; thus, in the end, change nothing I always need to pass a "reference".
|
There's no reference to pass. Each instance only needs to know its own integer index, it can then read through the array when it needs see others instances gLastTriggeredVoiceIndex value or write it's own.
|
|
|
03-01-2017, 09:06 AM
|
#17
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by gstuff
Each instance only needs to know its own integer index
|
Of course, but how would my Filter know about integer index (for the current instance) if I don't pass to it?
|
|
|
03-01-2017, 09:19 AM
|
#18
|
Human being with feelings
Join Date: Feb 2014
Posts: 63
|
Quote:
Originally Posted by Nowhk
Of course, but how would my Filter know about integer index (for the current instance) if I don't pass to it?
|
Because in the constructor of your plugin class you increment a static member variable and save the value in a member variable. So each instance gets a unique index number based on total number of instances. I use a similar approach in my Auto Time adjuster plugin.
Last edited by gstuff; 03-01-2017 at 09:27 AM.
|
|
|
03-01-2017, 09:25 AM
|
#19
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by gstuff
Because in the constructor of your plugin class you increment a static member variable and save the value in a member variable. So each instance gets a unique index number based on total number of instances.
|
Yes sir, but every kind of class within my plugin (Filter? Envelope? Voice?) need to know about my "plugin class". Thus, I need to pass it as reference (to every component). Which is what I don't want
|
|
|
03-01-2017, 09:32 AM
|
#20
|
Human being with feelings
Join Date: Feb 2014
Posts: 63
|
You started of asking for a way to do this "without passing to them a reference/pointer (keeping all stuff separated)." Best of luck.
|
|
|
03-01-2017, 09:46 AM
|
#21
|
Human being with feelings
Join Date: Mar 2016
Posts: 234
|
Quote:
Originally Posted by gstuff
You started of asking for a way to do this "without passing to them a reference/pointer (keeping all stuff separated)." Best of luck.
|
Yep. But if I save to pass it via reference but instead I pass the whole class via reference, nothing change so much. The "problem" is to pass a reference, not a kind (int) of reference. Thanks for the help anyway!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:22 AM.
|