Search guides and the APICtrl K
  1. API reference
  2. Plugin model

undo.h

UndoHistory: undo and redo for a plugin's own editor.

#include <sonore/undo.h>
On this page

Design notes

What this is not

It is NOT undo for parameter automation. A host already owns that: a knob moved through the parameter API is recorded by the DAW, appears in its undo stack, and is undone with the DAW's own shortcut. A plugin keeping a second stack for the same edits would fight it, and the user would discover which one their keyboard was talking to by losing work.

It IS undo for everything the host cannot see -- the things that live in a StateBag. Which sample is loaded in which slot, the shape somebody drew in an envelope editor, the step pattern in a sequencer. A host has no concept of those, so nothing undoes them unless the plugin does.

Snapshots, not commands

Whole-state snapshots rather than an undoable-action interface. A generated plugin's editor is a web page written by a language model; asking it to implement a correct inverse for every edit is asking for the class of bug where redo produces something that was never on screen. Storing what the state WAS cannot get that wrong.

The cost is memory, bounded by a step limit and by the fact that a StateBag holds names and paths rather than audio.

Types 1

A bounded stack of state snapshots.

begin() records where the state was BEFORE an edit, which is the only order that works: a snapshot taken afterwards has already lost the thing undo is supposed to restore.

↑↓ to move↵ to openEvery public name in the headers, and every guide