Losing Gui Events

I created a Midi Monitor as part of my plugin that flashes a signaling button once a Midi message is received.
To achieve that the processor produces an ActionBroadcaster event in processBlock() that triggers a color change in the listening Button widget. The Button flags itself through repaint() to be updated eventually.
I have now found that sometimes the button won’t flash on incoming midi messages.
I assume in that in those cases the second repaint is added to the message queue before it has been flushed. How would I make sure the on and off repaints are executeted with a minimum delay inbetween them? I rather would not extend the flash duration. Thanks!

here is some code:

// animate button
void actionListenerCallback(const String& message) {
    btnPulse->setColours(colFlash, colFlash, colFlash);
    btnPulse->repaint();
    startTimer(100);
}
// timer callback resets button highlight
void timerCallback() override {
    btnPulse->setColours(colNormal, colOver, colDown);
    btnPulse->repaint();
    stopTimer();
}

have you checked out the demo’s MIDI example, and how they pass midi events from the handleIncomingMidiMessage() callback to the MessageManager thread() via AsyncUpdater?

Yep I have looked into the example. I did not however follow it because I don’t think it is applicable in my use case. The Midi Demo receives the midi message one by one from the device manager while the plugin gets a midi buffer from the host. I have therefore based my implementation on the various Synthesizer plugin examples.

I have now solved my problem. The button now handles the flashing by itself and starts the timer in the paint method rather than in the actionListenerCallback. This ensures there is always a delay between the toggles of the flash state.
Here is the code in case anybody might find it useful:

void actionListenerCallback(const String& message) {
    btnPulse->flash();
}
(...)
class FlashingButton : public ShapeButton,
                       private Timer 
{
private:
    void flash() {
	isFlashing = true;
	setColours(colFlash, colFlash, colFlash);
	repaint();
    }
    void paint(Graphics& g) override {
	if (isFlashing) {
	    isFlashing = false;
	    startTimer(100);
	}
	ShapeButton::paint(g);
    }
    // timer callback resets button highlight
    void timerCallback() override {
	stopTimer();
	setColours(colNormal, colOver, colDown);
	repaint();
    }
(...)
    bool isFlashing;
};
1 Like