Group mulitple setValueNotifyingHost calls into one UndoManager transaction

Hey there,

My plug-in currently has a randomize button that calls setValueNotifyingHost for five different parameters in my AudioProcessorValueTreeState. However, these are each stored as their own transactions in the associated UndoManager; it’d be preferable to group them into one transaction so that end-users can easily undo a randomize.

I can’t seem to figure out how to do so- how would it be done?


Doesn’t this what you need UndoManager::beginNewTransaction():

Starts a new group of actions that together will be treated as a single transaction.
All actions that are passed to the perform() method between calls to this method are grouped together and undone/redone together by a single call to undo() or redo().

I tried using that, but I believe I’m using the method incorrectly. I put a call to beingNewTransaction before and after my five setValueNotifyingHost calls, but this did not group them together- the parameter changes still undo one by one.

I’m uncertain of how to make setValueNotifyingHost into an UndoableAction for perform() either.

You can try this: AudioProcessorUndoAttachment
It works quite well for me. Cheers, Yair

hmm- thanks for the suggestion, but I am using an AudioProcessorValueTreeState as a means of keeping my GUI, the plugin and my host connected (for automation, persistent state between closing/opening projects, etc).

setValueNotifyingHost does create an undo transaction; the issue is that I’m unable to group multiple calls to it into one transaction. I don’t want to tamper with the users ability to just undo changing one parameter when they modify it by other means; but I would like to add support for undoing the effects of the button that changes five parameters.

This can be used instead of AudioProcessorValueTreeState’s undo support.

I also have button which change several parameters at once, and it works fine with it.

Note: Just checked my code and that button’s change first causes a beginParameterChangeGesture for all these parameters, then changes them, and then ends the gesture. That might be required to make it work well.