I altered a lua script to add a playspeed reset. It doesn't create an undo point if the playspeed is already 1.0. However, if I change the playspeed, then run this script, it will create an undo point for "set project playspeed". How should I alter this script so that there will never be a change to the undo state when I run it?
Reason: sometimes I need to undo a few steps, and use a script to play and listen to something at different rates, but without changing the undo history so that I can redo the last few edits I made after listening to the sound at different rates.
Here's the script as I have it now. Hopefully there is a simple fix to make this not create an undo point when the playspeed is changed.
Code:
local reaper = reaper
function NoUndoPoint() end
local playstate = reaper.GetPlayState()
if playstate > 0 then
-- check "amagalma_Toggle behavior of Play-Stop buttons" state
local cmdID = reaper.NamedCommandLookup("_RS4b332fb0ea338b4991de7e2e9cd81032d79647da")
local script_state = reaper.GetToggleCommandStateEx(0,cmdID)
if script_state == 1 then
reaper.Main_OnCommand(40434, 0) --View: Move edit cursor to play cursor
reaper.Main_OnCommand(1016, 0) --Transport: Stop
reaper.CSurf_OnPlayRateChange( 1 )
local pos = reaper.GetCursorPosition()
reaper.SetExtState("Play-Stop with memory", "Position2", tostring(pos), 0)
else
local pos = reaper.GetPlayPosition()
reaper.Main_OnCommand(1016, 0) --Transport: Stop
reaper.SetExtState("Play-Stop with memory", "Position2", tostring(pos), 0)
reaper.CSurf_OnPlayRateChange( 1 )
end
else
local pos = reaper.GetCursorPosition()
reaper.SetExtState("Play-Stop with memory", "Position", tostring(pos), 0)
reaper.CSurf_OnPlayRateChange( 1 )
reaper.Main_OnCommand(1007, 0) -- Transport: Play
end
reaper.defer(NoUndoPoint)