I have posted briefly about this before, and there seem to be a few threads discussing some of the issues surrounding this, but they seem to be side-discussions. I apologise if this is regarded as a duplication.
I am having issues with implementing undo and redo behaviour in a plugin using the AudioProcessorValueTreeState class. To illustrate this I have modified the Juce demo plugin using AudioProcessorValueTreeState, and tried to implement undo and redo functionality as I have in my own plugin. The modified demo can be found here:
The demo now includes an undo and redo button which are enabled if canUndo() and canRedo() respectively return true. When a slider drag ends, a timer is started and in its callback beginNewTransaction() is called in order to separate transactions.
The issues I am having are as follows:
After an instance of the plugin is loaded in the DAW, canUndo() returns true even though no parameters have been altered by the user. This means the undo button is enabled, but clicking it results in no change (other than the undo button being subsequently disabled).
If the user performs one parameter change and attempts to undo it, the action is successfully undone, but it is not possible to redo this action. canRedo() returns true momentarily and the redo button is enabled, but after a fraction of time canRedo() returns false and the redo button is disabled. Only multiple (> 1) valid undo() calls result in redo functionality working as expected.
Is this the expected behaviour, or have I implemented something incorrectly? Or is it a bug in Juce (very unlikely)? If anyone has the chance to run the code to assist in figuring it out, or just glance at it to see if I have done something obviously incorrect, I will appreciate it greatly.