Retrieving value from child class with timer

Hi. Before I ask anything I’d like to give a massive thumbs up to Jules for such a ridiculously good package. :mrgreen: I was introduced to JUCE last year at uni and love the flexibility and scope it has!

Anyways, just a quick noobish question…

I have a class that updates with a timer and saves a value to a string. I want to pass this string to the parent class every time the timer callback is called. Is there a way for a broadcaster to send the massage to the parent class? Or for it to send a global broadcast? I can’t think of a way to retrieve the value other than setting up another timer that calls an accessor function but this would lead to timing problems.

(it’s a self contained step sequencer [child] that I want to send data out of periodically.)

Just call a method in the parent class to give it the new value…?

I thought a child could not access parent’s methods? The parent does not know when to access as the timing is all done in the child class.

I may have explained this wrong. There is no inheritance, the sequencer is essentially a new component and can be added to a project in a similar way to TextButtons etc.

Maybe this can help you?
http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=6863

[quote=“mibix”]I thought a child could not access parent’s methods? The parent does not know when to access as the timing is all done in the child class.

I may have explained this wrong. There is no inheritance, the sequencer is essentially a new component and can be added to a project in a similar way to TextButtons etc.[/quote]

It sounds to me like you want your component to have Listeners that you can add and remove and when you broadcast your message, all the Listener objects will receive a callback. Juce has full support for creating your own listeners have a look at ListenerList (juce_ListenerList.h) and also you can study one of the existing juce components (for example, juce::Button) to see how these listeners are used.

I've struggled so much with a similar question,  so I'll post the answer I found to help other noobs like me. Don't know if it's the best way.

The problem is you have, for instance, a label inside a small component which is inside a big component, and you want to add the big component as a listener to the label, but it's impossible. 

The answer is to make the small component inherit from ChangeBroadcaster and the big one inherit from ChangeListener, and add the big component as a change listener to the small. When the small component listens to the label, it should call sendChangeMessage() to warn the big one it should do something. Then, the big component may call any methods inside itself or inside the small, including some function you might create for returning the label's text, if it's private.

This is my first post, thanks to the more experienced for all the answers I've read on this forum so far.