How to perform an undo action on AudioProcessorValueTreeState AudioProcessorParameters?

Hi,

Is it possible to undo AudioProcessorParameter changes via the UndoManager in the
AudioProcessorValueTreeState? Or for what takes the AudioProcessorValueTreeState the UndoManager?

    AudioProcessor&processor = ...;
    UndoManager*undoManager = ...;
    AudioProcessorValueTreeState* state 
        = new AudioProcessorValueTreeState(processor,undoManager);

    AudioProcessorParameter* param = state->createAndAddParameter(...);
    param->setValue( x );

    // this does not work
    bool success = undoManager->undo();

Cheers

You need to call startTransaction so it knows which batch of actions to undo.

Like this? (startTransaction I could not find.)

    AudioProcessor&processor = ...;
    UndoManager*undoManager = ...;
    AudioProcessorValueTreeState* state 
        = new AudioProcessorValueTreeState(processor,undoManager);

    AudioProcessorParameter* param = state->createAndAddParameter(...);
    undoManager->beginNewTransaction();
    param->setValue( x );
    undoManager->beginNewTransaction();
    param->setValue( y );

    // this does not work
    bool success = undoManager->undo();

Hi, back to this.

The ValueTree (state) in AudioProcessorValueTreeState is not valid by default - is this right? Have I to initialize the tree with a valid one? Otherwise the AudioProcessorValueTreeState constructor should look like this:

AudioProcessorValueTreeState::AudioProcessorValueTreeState (AudioProcessor& p, UndoManager* um)
    :  ...,
      state("state") // I miss this initialisation
{ 
   // ...
}

Or do I understand the concept wrong?

Thanks!

That’s what I missed at first. Add your parameters with createAndAddParameters(). And then create a ValueTree with processorState.state = ValueTree(“FilterParameters”);

Achder is right, you have to set it to a valid one. This is because if you serialize it (e.g. to XML) the root node needs to have a valid tag name. This is also the same thing that makes a ValueTree valid or invalid.

I think you get an assert if you set the state before the createParameters IIRC, so I usually add at the end of the constructor:

myAPValueTreeState.state = ValueTree ("MyPluginName");

HTH