Undo
Group script-driven changes into a single undo point with Undo_BeginBlock and Undo_EndBlock.
Kind: how-to
Undo points are created for ReaScripts by default. To prevent the automatic addition of an undo point, a script can call defer()/ reaper.defer()/ RPR_defer().
There are also API functions for manually creating undo points, as well as API functions to Undo and Redo previous points.
The best way to manually create an undo point for your script is to call Undo_BeginBlock() before most of your code, and Undo_EndBlock() after your code finishes.
- These functions operate on the active project only (if multiple tabs are open) -- do not switch project tabs from your code while in an Undo block.
- You must always pair
Undo_BeginBlockwithUndo_EndBlock. If you callUndo_BeginBlockand then fail to callUndo_EndBlock, an undo block will be left open, which may cause undesired undo behaviors. - The final parameter of
Undo_EndBlockis a bitmask of what you would like to add to the undo state. If you are simply calling other actions (viaMain_OnCommandor similar functions), this should be 0. If you modify the state of the project directly, it's safest to set the bitmask to -1. A more specific combination of flags may be an optimization, depending on what your script is doing. - Always give the "desc" parameter of
Undo_EndBlocka valid (non-empty) descriptive string.
Lua example:
reaper.Undo_BeginBlock()
m = reaper.GetMasterTrack(0)
reaper.TrackFX_GetByName(m, "ReaEQ", 1)
reaper.Undo_EndBlock("Add ReaEQ FX to the master track", -1)
undo flags for Undo_EndBlock() et al:
- 1: track configurations
- 2: track FX
- 4: track items
- 8: project states
- 16: freeze states