Automation and momentary buttons


#1

I have a mometary button which is represented via a plugin parameter which can be automated. When I update the state of the button from receiving automation I set the state by calling "setToggleState" with sendChangeNotification = false so as not to notify of changes and cause a further automation event back to the host. There is a problem here because to receive both the down and up state changes I have to overload the "buttonStateChanged" function, but this is always called from "setToggleState" even though I say don't send a change notification! So this seems fundamentally broken for this basic use case, is there something I'm missing on how to receive both down and up messages from a button while still respecting not sending change notifications?

//==============================================================================
void Button::setToggleState (const bool shouldBeOn,
                             const bool sendChangeNotification)
{
    if (shouldBeOn != lastToggleState)
    {
        if (getToggleState() != shouldBeOn)  // this test means that if the value is void rather than explicitly set to
            isOn = shouldBeOn;               // false, it won't be changed unless the required value is true.
        lastToggleState = shouldBeOn;
        repaint();
        WeakReference<Component> deletionWatcher (this);
        if (sendChangeNotification)
        {
            sendClickMessage (ModifierKeys());
            if (deletionWatcher == nullptr)
                return;
        }
        if (lastToggleState)
        {
            turnOffOtherButtonsInGroup (sendChangeNotification);
            if (deletionWatcher == nullptr)
                return;
        }
        sendStateMessage();
    }
}

#2

Thanks - yes, I think that method should honour the notification flag and not make that callback if it's unwanted. Cheers, I've updated that now.