Old 04-18-2018, 02:58 PM   #1
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default Undo_ in ReaScript issue... SOLVED

It seems to be that 5.40 is the last version that Undo_ in ReaScript works properly on my 'pute. Can anyone else confirm or deny?

Issue: with -1 as the flag the Undo block is not recorded at all. With 0 set it is recorded but without a name ("ReaScript: run"). The correct name is still shown in the menu bar.

edit: MarkTrackItemsDirty is needed after using functions (defo MIDI_SetAllEvts) for Undo to work.

Last edited by snooks; 04-19-2018 at 07:49 AM.
snooks is offline   Reply With Quote
Old 04-18-2018, 03:07 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Works fine here.

Code:
-- (constants from reaper_plugin.h)
local UNDO_STATE_ALL      = -1
local UNDO_STATE_TRACKCFG =  1 -- has track/master vol/pan/routing, ALL envelopes (matser included)
local UNDO_STATE_FX       =  2 -- track/master fx
local UNDO_STATE_ITEMS    =  4 -- track items
local UNDO_STATE_MISCCFG  =  8 -- loop selection, markers, regions, extensions!
local UNDO_STATE_FREEZE   = 16 -- freeze state -- note that isfreeze is used independently, this is only used for the undo system to serialize the already frozen state

reaper.Undo_BeginBlock()

-- do something here

reaper.Undo_EndBlock("Name of the undo point", UNDO_STATE_ALL)
cfillion is offline   Reply With Quote
Old 04-18-2018, 03:16 PM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I'm seeing the same issue here. An Undo block with -1 doesn't consistently generate anything in the undo history - some of my scripts work properly and some don't even manage a "Reascript: run" event.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 04-18-2018, 03:49 PM   #4
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Interesting, it might be just in the Windows version then. Could Lokasenna or anyone else that sees this test 5.40 to see if it's fixed and 5.50 to see if it's broken?
snooks is offline   Reply With Quote
Old 04-18-2018, 10:36 PM   #5
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Found old script that had UndoEndBlock2 with 0. Makes "ReaScript run" point. Pretty sure it used to enter the specified string.

Scripts using -1 work, but only if actually doing something undoable. Wanted to make named undo point with input box that didn't actually have a change in it, but it don't work that way.

I see there's a menu thingy in the undo history window where you can see some info about each state now.

Win 7 x64
FnA is offline   Reply With Quote
Old 04-18-2018, 11:00 PM   #6
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Could you upload an example of a script (or code snippet) that is not setting Undo properly?

I've also encountered some Undo issues, discussed in the thread ReaScript: Undo_EndBlock with flags != -1 are not added to undo history. The problem wasn't solved, but Justin answered:

Quote:
Originally Posted by Justin View Post
If you don't call with flags=-1, it will look at undo flags set by the actions you're using in the middle of the block. Depending on what you're doing, you might not be marking things dirty correctly (which means the things edited won't be checked for changes, which would cause an undo point not to be added as you describe) -- what's happening in the middle of that block?
The bug might therefore be in the functions that are called inside the Undo block, rather than Undo itself. Although, Undo_OnStateChange_Item and Undo_OnStateChange2 appear to work more reliably.

Last edited by juliansader; 04-18-2018 at 11:19 PM.
juliansader is offline   Reply With Quote
Old 04-19-2018, 02:33 AM   #7
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Good point, the scripts that aren't working use MIDI_SetAllEvts, here's a simple example where undo works in 5.40, but not 5.50+...

Code:
reaper.Undo_BeginBlock()

  local ame = reaper.MIDIEditor_GetActive()
  local take = reaper.MIDIEditor_GetTake(ame)
  local evt1 =  string.pack("i4Bs4", 2000, 0, string.char(0x90)..string.char(0x60)..string.char(0x7f))
  local evt2 =  string.pack("i4Bs4", 4000, 0, string.char(0x80)..string.char(0x60)..string.char(0x00))
  reaper.MIDI_SetAllEvts(take, evt1 .. evt2)

reaper.Undo_EndBlock("Undo test", -1)
But it's okay, because MarkTrackItemsDirty makes it work (thanks for the link).
snooks is offline   Reply With Quote
Old 01-28-2020, 10:30 AM   #8
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

It's funny, but it also works for Reaper actions. For example, action 40179 resets the notes selection after the UNDO, but my script -
Code:
reaper.PreventUIRefresh(1);

   reaper.MIDIEditor_LastFocused_OnCommand(40179,0)

reaper.PreventUIRefresh(-1);
reaper.Undo_OnStateChange2(0,'Pitch +12')
doesn’t
cool is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.