Old 01-19-2019, 03:53 PM   #1
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default Prevent Undo list entries

Hi

I have a script which I'd like NOT to generate an entry in the Undo history.

This seems easy to do - just don't include the "Begin Undo Block" and "End Undo Block" code.

However, during the script I use the function

reaper.SelectAllMediaItems(0,0) to clear the selection

and this DOES generate an entry in the Undo list.

Is it possible to stop any "native actions" (such as that function to deselect all) within the script from creating Undo points?

Thanks
Andy
andyp24 is online now   Reply With Quote
Old 01-20-2019, 02:53 AM   #2
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,463
Default

Try this in the end of your script:
Code:
reaper.defer(function() end)
amagalma is offline   Reply With Quote
Old 01-20-2019, 03:00 AM   #3
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

OK, thanks I'll try it.

Can you explain why that might have the desired effect?

Deferring a non-existent function - why would that affect Undo entries, and would it have any impact on Reaper's performance? (My understanding is that defer functions are called roughly 30 times a second, so will that have a noticeable impact even if the function that's called does nothing?)

Cheers
Andy
andyp24 is online now   Reply With Quote
Old 01-20-2019, 07:05 AM   #4
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 11,804
Default

The correct way is to restore the state to where you started before calling endblock -- if the user has undo for selection state configured, then you really do want to have an undo point added when you clear the selected item states (as otherwise you will end up in inconsistent states).

The defer trick (which is harmless, it only runs the script once) does work, because undo points are not added automatically for scripts that are deferred (since they might want to wait until a longer process is done).
Justin is online now   Reply With Quote
Old 01-20-2019, 07:54 AM   #5
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

Thanks Justin

I'm not sure I understand though.

My script uses the reaper.SetMediaItemsSelected (0,0) function in the middle of it, but by the end of the script I have restored the original selection (which I saved to an array at the beginning).

Yet, without any Undo code on the script the Reaper Undo window shows entries for Deselect All Items, but not anything for the other things the script is doing (such as nudging, selecting things again etc).

Andy
andyp24 is online now   Reply With Quote
Old 01-20-2019, 10:20 AM   #6
bFooz
Human being with feelings
 
bFooz's Avatar
 
Join Date: Jul 2010
Location: Slovakia
Posts: 732
Default

There are some functions which generates undo points despite the script being deferred.

Most recently I found reaper.ReorderSelectedTracks() doing that and some time before another function but cannot remember what it was, probably something with item manipulation. Also reaper.Main_OnCommand() calls does generate undo.

So, is it expected that these few functions does generate undo even if they are in ad deferrescript or is it a bug?
__________________
Donations | Mixing & Mastering Services
bFooz is online now   Reply With Quote
Old 01-20-2019, 12:02 PM   #7
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,402
Default

I think in your case you could avoid creating the undo point replacing reaper.SelectAllMediaItems(0,0) with looping through all items and set them unselected with SetMediaItemInfo_Value() (using B_UISEL)

edit:
Or SetMediaItemSelected()

Last edited by nofish; 01-20-2019 at 12:08 PM.
nofish is offline   Reply With Quote
Old 01-20-2019, 12:08 PM   #8
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

Thanks - yes, I could do that, I just thought the native function would be quicker (to write, and to perform!)

Will give it a go, though.

Andy
andyp24 is online now   Reply With Quote
Old 01-20-2019, 12:18 PM   #9
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,402
Default

Quote:
Originally Posted by andyp24 View Post
I just thought the native function would be quicker (to write, and to perform!)
I go along with this of course.
Just wanted to mention as possible workaround.

I too wish we had more control over when undo points are created or not, e.g.
https://forum.cockos.com/showthread.php?t=215672
nofish is offline   Reply With Quote
Old 01-20-2019, 01:47 PM   #10
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 744
Default

Yes, the Undo/Redo/NoUndo-behavior of Reaper definetely needs some more love, as the scripter's needs surpassed the current possibilities by far in the meantime...
__________________
Ultraschall-API: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs for Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-20-2019, 04:12 PM   #11
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Axis Mundi
Posts: 5,469
Default

Any way to do this in a Cycle Action?
__________________
TwilightMysterySchool
foxAsteria is online now   Reply With Quote
Old 01-20-2019, 04:21 PM   #12
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 11,804
Default

Quote:
Originally Posted by andyp24 View Post
My script uses the reaper.SetMediaItemsSelected (0,0) function in the middle of it, but by the end of the script I have restored the original selection (which I saved to an array at the beginning).
If you use Undo_BeginBlock(), then save selection,clear selection, restore selection, and do Undo_EndBlock(), then it should eliminate the undo state point (unless something else changed). You can right click the undo point in the undo history and go to the "Undo state information" submenu to see what changed (click an item and it'll show you a diff).
Justin is online now   Reply With Quote
Old 01-20-2019, 04:49 PM   #13
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 478
Default

Quote:
Originally Posted by mespotine View Post
Yes, the Undo/Redo/NoUndo-behavior of Reaper definetely needs some more love
If it was in the action list. Another checkbox next to "consolidate undo points" that says "no undo"

I guess it's a big one to implement otherwise it would be there already..
__________________
Brush and Beater Drums Online: www.outoftheboxdrums.co.uk
Triode is offline   Reply With Quote
Old 01-21-2019, 01:55 AM   #14
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

Quote:
Originally Posted by Justin View Post
If you use Undo_BeginBlock(), then save selection,clear selection, restore selection, and do Undo_EndBlock(), then it should eliminate the undo state point (unless something else changed). You can right click the undo point in the undo history and go to the "Undo state information" submenu to see what changed (click an item and it'll show you a diff).
Thanks Justin

The script nudges edges of some items, and then nudges a different selection of whole items.

So, between saving the selection, deselecting everything and restoring the original selection, quite a few things happen. It just seems odd that the only one of the actions I'm performing in the script to leave a trace in the Undo History is that SetMediaItemsSelected (0,0) line.
andyp24 is online now   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:47 PM.


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