Receiving events in the Main Component from another Introjucer component

Hi all


Consider we have a Main Component in which we have included some other Introjucer components.
Is there any way to receive into Main Component, any event produced by these Introjucer components ?

Especially when a component like this, composed of several instances of a class..

Is this a 'how do I send messages between objects' kind of question?  In which case I think you've got these options: 

  • Pass a pointer to the child objects, via the constructor of your child, back to it's parent or 'owner'.  Call functions on the owner.  This is the most direct way, and very debugger friendly. 
  • Use the Listener pattern (search for ListenerList<Listener> in the JUCE source for a zillion examples).  This is a very JUCE way of doing things. 
  • Pass a C++11 lambda to the other objects and have it called when something happens.  
  • Use ChangeBroadcaster
  • Use AsyncUpdater (useful when there are threading issues to manage). 
  • Use a shared data object with some notification built in: Value or ValueTree.   They have listener methods.
  • Use the ApplicationCommandManager
  • Use an internal application messaging system of your own ... 

Does that help?

3 Likes

Thanks for the patient and detailed tips, Jim!

It does seem like we have a lot of people asking the same kind of "how do I communicate between things" question recently. Good to have newbies discovering JUCE, but hard to know how to answer such general questions!

I went thru this problem recently.   this was my solution.  it's the last idea that bazrush offered:

http://www.juce.com/comment/314669#comment-314669

 

Hi all,

Indeed the topic I posted is an issue of "how do I send messages between objects" as bazrush put it. 

More specifically, the problem that I encountered, which forced me to put it on the forum, is the following:

I have designed a component consisting of a label and a rotated slider, with the following functionality:

  • The middle of the slider corresponds to zero. The move of left-right decreases/increases the value of the label. 
  • The movement of the mouse up and down in relation to the label, also similarly alters the value of the label.

This component is included as Introjucer component many times inside the MainComponent, at design time using the “GUI editor/Add new component/New Introjucer component” menu-path.

Now, I am going on to use such components with more than one label/input-info, into my Audio application.

At the moment, I use the ChangeBroadcaster/ChangeListener to receive all the info I need to process.  
Because of no one of the ChangeBroadcaster and ActionBroadcaster meet my needs at all, I am trying to use the Message class.

Of course, I will explore the other suggested solutions, especially the two first, which seem to me as more suitable and convenient.

However, I still wonder if the method I used is the best or is there something else more appropriate. Especially now that I have outlined in detail the original problem, I wonder even more.

Note that, as a newbie to the JUICE, sometimes I will put an issue to the forum to confirm the correctness of the solution I thought, by a specialist. As you know It is very unpleasant to go on with the implementation of an application, while having the feeling that something was not done in the right way.

So, personally, I appreciate any response I receiving to my questions.

 

Thanks for your attention

 

George

 

I think I was one of those newbies :-) Went for option 1 (i.e. passing a pointer to the child).

But still not quite sure, what is the best way. So if you find time someday, to write a tutorial or FAQ about it, that would be very appreciated.

If you like, while I'm working, when I see a good example, I'll stick it on my wiki.  Then at some point if it's useful someone, and after a bit of a collaborative review, can tart it up and turn it into a juce.com page somewhere. 

In fact: 

http://zee.credland.net/jwiki/index.php/Sending_Messages

Feel free to fill in any blanks, add new headings and generally make it better :) 

I'd definitely suggest looking into Juce's Value and ValueTree classes.  Not only will they perform message passing, but also they will give you access to a simple way of state saving, and also an Undo/Redo manager can easily be added. 

 

 


I have read in this forum that the use of Value and ValueTree classes in audio processing applications should be avoided, because they add CPU overhead.
JUCE has many ways to do the same thing. Which of them can be used depends on the needs of the application, and - I think -, on the temperament of the designer/programmer.
 

Thank you! Great read!

1 Like

Oh!  Thank you very much.

It is what I want. I will  study it carefully.

1 Like