Best way to update a Label from model?


I have a Metronome class built around Vinn’s lovely metronome which nicely chuggs along. I have another class called TransportControl which sets up a global transport bar (play/record buttons and a bpm TextEditor which broadcasts changes to the Metronome class when changed). The Transport bar also has a Label which is supposed to display the current Bar.Beat info.

So Metronome has a ListenerList which the TransportControl registers with and is notified each beat. In the notification callback in TransportControl, I get passed the current beat number, and use that to increment my beat/bar label using setText. If I don’t call MessageManagerLock before setText however, the program crash’s saying that “// if component methods are being called from threads other than the message thread, you’ll need to use a MessageManagerLock object to make sure it’s thread-safe.

If I lock the MessageManager before setText() then I get really unexpected results and stability issues in my program. Audio writing for example goes haywire… is this completely the wrong approach in trying to have my metronome notify and update my display (in another class) that it should update itself? Thanks!


So I made my Metronome a ChangeBroadcaster and my TransportControl a ChangeListener to see if it would behave differently than the ListenerList and it seems to be just fine. The way I have it set up now, when the Metronome is notified, it doesn’t request the beat number from the Transport or get passed the beat number, it just keeps its own running count internally. Originally I wasn’t sure if the ChangeBroadcaster/listener could keep up with super fast calls (not that i expect people to actually go up to 999bpm) but for passing data in callbacks, I’ve used ListenerList’s in the past as changebroadcaster’s seemed to either drop or not send some messages (for example, using it to broadcast osc messages sending every 7 samples @44.1k). In any case, this is working fine so Ill probably keep it, but would love to get your thoughts?