Plug-ins, Hosts, Apps,
Hardware, Soundware
Developers
(Brands)
Videos Groups
Whats's in?
Banks & Patches
Download & Upload
Music Search
KVR
   
KVR Forum » DSP and Plug-in Development
Thread Read
Rookie question - Circular Dependencies involving the Editor
LittleStudios
KVRist
- profile
- pm
- e-mail
- www
PostPosted: Thu Aug 02, 2012 6:16 pm reply with quote
How do you avoid Circular Dependencies in this situation? I have a feeling that in the Editor class I'm going to need a pointer to the Plugin class... but that's just a guess, and probably a bad on at that.

Plugin class needs to include the Editor class for this to work.
editor = new Editor (this);Or for this to work.
setEditor (new Editor (this));
Editor class needs to include the Plugin class to access parameters for this to work.button = new COnOffButton (r14, this, kParameter, buttonImage,0);
Also which is the preferred method of notifying the plugin of the editor?
editor = new Editor (this); or setEditor (new Editor (this)); I've seen both.
^ Joined: 03 Apr 2010  Member: #229114  Location: Auburn, Maine, United States
LemonLime
KVRist
- profile
- pm
- e-mail
PostPosted: Thu Aug 02, 2012 8:47 pm reply with quote
Quote:

Also which is the preferred method of notifying the plugin of the editor?
editor = new Editor (this); or setEditor (new Editor (this)); I've seen both.


This is how I set up the editor in the plugin's constructor:

extern AEffGUIEditor* createEditor (AudioEffectX*);
setEditor (createEditor (this));


Quote:

Editor class needs to include the Plugin class to access parameters for this to work.button = new COnOffButton (r14, this, kParameter, buttonImage,0);


And yes, the editor class needs to reference the plugin class with "this", so for example to create a knob I have:

CRect r (0, 0, background->getWidth (), background->getHeight ());
r.offset (20, 130);
CKnob* knob1 = new CKnob (r, this, GAIN, background, handle, CPoint (0, 0));
newFrame->addView (knob1);


You don't need to "avoid" the circular dependencies of the "this" pointer. In fact, it's required and you can see it in use in the VST GUI tutorials. Unless you're not clear about what the "this" pointer actually is, and in these two cases they point to different objects. The "this" pointer, when used within a class, is simply a pointer to that class. So when creating the editor, "this" is a pointer to the plugin class you've derived from AudioEffectX. When setting up an object in the editor, "this" is a pointer to the editor class you've set up, inherited from AEffGUIEditor.
^ Joined: 15 Apr 2012  Member: #278696  Location: Toronto, ON
stratum
KVRist
- profile
- pm
PostPosted: Thu Aug 02, 2012 11:59 pm reply with quote
LittleStudios wrote:
How do you avoid Circular Dependencies in this situation? I have a feeling that in the Editor class I'm going to need a pointer to the Plugin class... but that's just a guess, and probably a bad on at that.

Plugin class needs to include the Editor class for this to work.
editor = new Editor (this);Or for this to work.
setEditor (new Editor (this));
Editor class needs to include the Plugin class to access parameters for this to work.button = new COnOffButton (r14, this, kParameter, buttonImage,0);
Also which is the preferred method of notifying the plugin of the editor?
editor = new Editor (this); or setEditor (new Editor (this)); I've seen both.


You absolutely avoid circular dependencies only when you work for a company whose quality assurance team is trying to show off object oriented design skills that they don't actuallty have in technical reviews that they are not qualified for. When that happens and if you still must have a circular dependency, then you call it "observer pattern", MVC or another buzzword that they think they know (but dont) and silently watch the way they are baffled with a very serious face that shows no sign of amusement.
----
~stratum~
^ Joined: 29 May 2012  Member: #281392  
LittleStudios
KVRist
- profile
- pm
- e-mail
- www
PostPosted: Fri Aug 03, 2012 4:13 am reply with quote
Every now and then with pointers I get confused, so yeah the this pointer throws me off. I really need to get a better understanding of it. I'm sure many people find it to be a simple concept.
Last edited by LittleStudios on Fri Aug 03, 2012 5:28 am; edited 2 times in total
^ Joined: 03 Apr 2010  Member: #229114  Location: Auburn, Maine, United States
stratum
KVRist
- profile
- pm
PostPosted: Fri Aug 03, 2012 4:49 am reply with quote
LittleStudios wrote:
Every now and then with pointers I get confused, so yeah the this pointer throws me off. I really need to get a better understanding of it. I'm sure many people find it to be a simple concept.


In a garbage collecting language like java a circular dependency could cause a memory leak if the circular link is not explicitly broken by the programmer at the time the objects are no longer needed. In c++ there is no such concern because the programmer is already responsible for memory management, unless you are using reference counted smart pointers, in which case the circular link needs to be explicitly broken as in java.

Others would say circular dependencies are bad programming practice and would religiously defend their views. In my opinion there are no hard and fast rules and there is no list of "10 commandments to be obeyed" in programming.
----
~stratum~
^ Joined: 29 May 2012  Member: #281392  
LittleStudios
KVRist
- profile
- pm
- e-mail
- www
PostPosted: Fri Aug 03, 2012 5:29 am reply with quote
It's not that I can't get a custom GUI to work, I can. I've followed the Steinberg provided examples. The problem is, I don't understand why it works, and that's my goal. For example the Plugin's Editor class constructor is defined like this (I've used a generic name for the editor):PluginEditor::PluginEditor (AudioEffect* effect):AEffGUIEditor(effect)
{
   // Omitted the code here
}
So what I think this is saying is when an instance of the PluginEditor class is created, this constructor is called and it accepts as an argument a pointer to the AudioEffect class. I'm not sure what this part is saying: :AEffGUIEditor(effect)Ok now for the call in the Plugin class. editor = new PluginEditor (this); So I've looked and editor is a member of the audioeffect class and it's a pointer to the AEffEditor class. So we're telling editor to point to the PluginEditor, but I'm not sure what the following is saying:new PluginEditor (this);Thanks for everyone's patience. I understand that this forum isn't about teaching C++, but when I try and ask over at cpluplus.com it requires far more explanation about the classes just to ask a question about syntax.
^ Joined: 03 Apr 2010  Member: #229114  Location: Auburn, Maine, United States
matt42
KVRian
- profile
- pm
PostPosted: Fri Aug 03, 2012 6:43 am reply with quote
new PluginEditor(this)
You're allocating memory and creating an instance of a plugin editor, the constructor takes a pointer to an audio effect as it's argument. The this pointer is just a pointer to your audio effect class.
^ Joined: 09 Jan 2006  Member: #93807  
LemonLime
KVRist
- profile
- pm
- e-mail
PostPosted: Fri Aug 03, 2012 6:50 am reply with quote
LittleStudios wrote:
I'm not sure what this part is saying: :AEffGUIEditor(effect)


This is just another way of initializing member variables of a class in its constructor.

Quote:
So I've looked and editor is a member of the audioeffect class and it's a pointer to the AEffEditor class. So we're telling editor to point to the PluginEditor, but I'm not sure what the following is saying:new PluginEditor (this);Thanks for everyone's patience. I understand that this forum isn't about teaching C++, but when I try and ask over at cpluplus.com it requires far more explanation about the classes just to ask a question about syntax.


You're creating an instance of the PluginEditor ("new" allocates memory and places it on the heap) and creating a link between the editor and your effect by passing it the "this" pointer. If you look in the VST GUI SDK you will notice that it has as a protected attribute, AudioEffect effect. This is how it essentially communicates between your effect class and your GUI class.
^ Joined: 15 Apr 2012  Member: #278696  Location: Toronto, ON
All times are GMT - 8 Hours

Printable version
Page 1 of 1
Display posts from previous:   
ReplyNew TopicPrevious TopicNext Topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Username: Password:  
KVR Developer Challenge 2012