Old 01-19-2019, 03:53 PM   #1
andyp24
Human being with feelings
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
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 offline   Reply With Quote
Old 01-20-2019, 02:53 AM   #2
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

Try this in the end of your script:
Code:
reaper.defer(function() end)
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 01-20-2019, 03:00 AM   #3
andyp24
Human being with feelings
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
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 offline   Reply With Quote
Old 01-20-2019, 07:05 AM   #4
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,716
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 offline   Reply With Quote
Old 01-20-2019, 07:54 AM   #5
andyp24
Human being with feelings
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
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 offline   Reply With Quote
Old 01-20-2019, 10:20 AM   #6
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
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?
bFooz is offline   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: 12,093
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
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
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 offline   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: 12,093
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
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,612
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...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada 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: Oblivion
Posts: 10,248
Default

Any way to do this in a Cycle Action?
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 01-20-2019, 04:21 PM   #12
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,716
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 offline   Reply With Quote
Old 01-20-2019, 04:49 PM   #13
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,175
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..
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode is offline   Reply With Quote
Old 01-21-2019, 01:55 AM   #14
andyp24
Human being with feelings
 
andyp24's Avatar
 
Join Date: Mar 2016
Posts: 1,239
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 offline   Reply With Quote
Old 11-28-2020, 11:12 AM   #15
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

It seems to be that the defer trick isn't needed anymore.


A script without call the undo function doesn't make the project dirty or create entry in history list.

which is nice !
X-Raym is offline   Reply With Quote
Old 11-28-2020, 01:07 PM   #16
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by X-Raym View Post
It seems to be that the defer trick isn't needed anymore.


A script without call the undo function doesn't make the project dirty or create entry in history list.

which is nice !

Really?? That's amazing!

I have noticed when scripting that some SWS functions seem to create their own undo points... even if I don't add an undoBlock.... I've had to recreate those functions on my own in my scripts the avoid creating those undo points... I imagine they must have their own undo blocks built in....
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 11-28-2020, 02:59 PM   #17
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@sonictim


At least according to my tests on a very simple get items/set position function



the defer solution hasn't been satisfying anyway, cause if the script is run twice in a custom actions, you would have the "there is already one running script" popup... Not good.



Quote:
I imagine they must have their own undo blocks built in....

Yes, I assume that in this case the built-in undo point is on.
X-Raym is offline   Reply With Quote
Old 11-28-2020, 03:05 PM   #18
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,612
Default

We definitely need our exclude-from-undo-functions.

No matter how clever Reaper tries to manage that stuff, I think it's still better to have full control over certain things.

It would also make undoing faster, if I could skip steps that I only did to make things in the first place.
Like changing track-selection and then reverting it. I don't think Reaper needs to do these steps backwards when undoing in most cases.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 11-28-2020, 03:38 PM   #19
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,175
Default

Quote:
Originally Posted by X-Raym View Post
It seems to be that the defer trick isn't needed anymore.


A script without call the undo function doesn't make the project dirty or create entry in history list.

which is nice !
In which reaper version has this started being so??
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode is offline   Reply With Quote
Old 11-28-2020, 03:49 PM   #20
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@Triode


I don't know, I just realized it.


My code was minimal:


Code:
item = reaper.GetMediaItem(0,0)
pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
reaper.SetMediaItemPosition( item, pos + 1, true )

X-Raym is offline   Reply With Quote
Old 11-28-2020, 04:17 PM   #21
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,175
Default

Ok this looks good
Are you on a dev version there?
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode is offline   Reply With Quote
Old 11-28-2020, 04:19 PM   #22
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@Triode
Nope, just regular 6.16.
X-Raym is offline   Reply With Quote
Old 11-28-2020, 04:20 PM   #23
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,175
Default

Okidoke thank you
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode is offline   Reply With Quote
Old 11-29-2020, 12:36 AM   #24
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
We definitely need our exclude-from-undo-functions.

No matter how clever Reaper tries to manage that stuff, I think it's still better to have full control over certain things.
Couldn't agree more! reaper.Undo_ExcludeBegin()
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 02-10-2021, 12:52 AM   #25
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Code:
slots = 4
function main()
  local count_track = reaper.CountSelectedTracks2(0, 0)
  local track = reaper.GetSelectedTrack2(0, 0, 0)
  if track then  
    for i = 0, count_track - 1 do
      track = reaper.GetSelectedTrack2(0, i, 0)
      count_fx = reaper.TrackFX_GetCount(track)
      if count_fx < slots then
        for j = count_fx + 1, slots do
          reaper.TrackFX_AddByName(track, "JS:-", 0, -999 - j)
        end
      end
    end
  end
  reaper.defer(main)
end

main()
Does anyone know why this code generates undo points? It shows 4 entries in Undo history (4 Add FX). Is it possible to avoid creating undo points here?
vitalker is offline   Reply With Quote
Old 02-10-2021, 03:50 AM   #26
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@Triode
My bad. I realize that it doesnt created unfo point IF run from reascript IDE.... But if run from action lits, it put a dummy named action entry.

@vitalker
It seems under the hood, AddTrackFX create undo points... maybe not expected... Not sure if there can be a workarround...
X-Raym is offline   Reply With Quote
Old 02-10-2021, 03:53 AM   #27
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by X-Raym View Post
It seems under the hood, AddTrackFX create undo points... maybe not expected... Not sure if there can be a workarround...
It's really bad. Is it possible then to remove these points immediately via ReaScript?
vitalker is offline   Reply With Quote
Old 02-10-2021, 04:09 AM   #28
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,175
Default

I've been finding that for simple (non-sws) track and item select in scripts when run from an action there is no undo point added.
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode is offline   Reply With Quote
Old 02-10-2021, 04:12 AM   #29
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by Triode View Post
I've been finding that for simple (non-sws) track and item select in scripts when run from an action there is no undo point added.
I'm not asking about selecting tracks, but about adding fx. It seems there is no way to add fx without creating undo points.
vitalker is offline   Reply With Quote
Old 02-10-2021, 04:17 AM   #30
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

Quote:
Originally Posted by vitalker View Post
It's really bad. Is it possible then to remove these points immediately via ReaScript?
Nope...

I haven't tested it but I suspect that if you injected the FX info in the track state chunk, it wouldn't create the undo points.
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 02-10-2021, 04:59 AM   #31
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@vitalker
Maybe complex but... witch track chunk modification, you can add FX without Add FX function....
Not sure how detailes the FX chunk have to befor REAPER to actually insert the item, but I have done it with fully written chunks (from fx chain file)
But maybe only adding an FX chunk with the right name... ?


Ultraschall has FX chunk function BTW.
X-Raym is offline   Reply With Quote
Old 02-10-2021, 05:04 AM   #32
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by X-Raym View Post
@vitalker
Maybe complex but... witch track chunk modification, you can add FX without Add FX function....
Not sure how detailes the FX chunk have to befor REAPER to actually insert the item, but I have done it with fully written chunks (from fx chain file)
But maybe only adding an FX chunk with the right name... ?


Ultraschall has FX chunk function BTW.
Oh cool, thanks for the answer!
vitalker is offline   Reply With Quote
Old 02-10-2021, 05:09 AM   #33
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by amagalma View Post
I haven't tested it but I suspect that if you injected the FX info in the track state chunk, it wouldn't create the undo points.
Nice, thanks. Are you talking about this? https://forum.cockos.com/showthread.php?t=201961
vitalker is offline   Reply With Quote
Old 02-10-2021, 02:40 PM   #34
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

See my Toggle enclose focused FX with AB_LM Level Matching VST scripts in ReaPack. But the older versions, because in the latest versions I use the reaper API (that did not exist when I created them).

When working with chunks, this comes handy.
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 02-10-2021, 03:49 PM   #35
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by amagalma View Post
See my Toggle enclose focused FX with AB_LM Level Matching VST scripts in ReaPack. But the older versions, because in the latest versions I use the reaper API (that did not exist when I created them).

When working with chunks, this comes handy.
Wow, thanks! Very nice tool. I already used mpl's code for track chunks to rename FX, because there is no API function for it.
vitalker is offline   Reply With Quote
Old 02-10-2021, 04:20 PM   #36
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,612
Default

Quote:
Originally Posted by vitalker View Post
Wow, thanks! Very nice tool. I already used mpl's code for track chunks to rename FX, because there is no API function for it.
In Ultraschall-API, you can use these to rename fx:

Getting:
https://mespotin.uber.space/Ultrasch...lternativeName
https://mespotin.uber.space/Ultrasch...lternativeName

Setting:
https://mespotin.uber.space/Ultrasch...lternativeName
https://mespotin.uber.space/Ultrasch...lternativeName

Had been requested recently, so I added it.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-11-2021, 12:43 AM   #37
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
In Ultraschall-API, you can use these to rename fx:
Thank you very much! Maybe an extra question: what function is used for fx injection? X-Raym wrote you have one that doesn't create undo points.

Last edited by vitalker; 02-11-2021 at 03:18 AM.
vitalker is offline   Reply With Quote
Old 02-11-2021, 04:37 AM   #38
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,612
Default

I don't know what X-Raym is referring too, I guess he meant that I have a lot of functions to deal with FXStateChunks, that can be committed without undo.

Here's the introduction chapters for how to program them:
https://mespotin.uber.space/Ultrasch...X_Introduction

However, you probably can add fx only, if you already have a statechunk entry for such an fx available(from an exported FXStateChunk or whatever) as there's no chance to create it yourself with most fx. Reaper actually needs to create some binary data for vsts, etc, which can't be created with API.

So you either create a list of fx-statechunk-lines for the fx that you want to insert without undo and insert the when needed(and are stuck to the setting the fx had, when you created these fx-statechunk-lines), or you are still stuck with the "traditional" way of adding fx.


This is the best time to mention my long-term most beloved Feature Request: ExcludeUndoPoints:

https://forum.cockos.com/showthread....hlight=Exclude

This would solve your issue much better.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-11-2021, 05:38 AM   #39
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post

https://forum.cockos.com/showthread....hlight=Exclude

This would solve your issue much better.
This and some other things like determine fx in fx list under mouse cursor.
vitalker is offline   Reply With Quote
Old 03-06-2021, 12:10 PM   #40
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,114
Default

Quote:
Originally Posted by bFooz View Post
Most recently I found reaper.ReorderSelectedTracks() doing that
...
So, is it expected that these few functions does generate undo even if they are in ad deferrescript or is it a bug?
i can relate so much, just hit this snag myself
Buy One 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 07:33 PM.


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