|
|
|
01-19-2019, 03:53 PM
|
#1
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,242
|
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
|
|
|
01-20-2019, 02:53 AM
|
#2
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Try this in the end of your script:
Code:
reaper.defer(function() end)
|
|
|
01-20-2019, 03:00 AM
|
#3
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,242
|
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
|
|
|
01-20-2019, 07:05 AM
|
#4
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,746
|
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).
|
|
|
01-20-2019, 07:54 AM
|
#5
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,242
|
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
|
|
|
01-20-2019, 10:20 AM
|
#6
|
Human being with feelings
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
|
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?
|
|
|
01-20-2019, 12:02 PM
|
#7
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,109
|
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.
|
|
|
01-20-2019, 12:08 PM
|
#8
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,242
|
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
|
|
|
01-20-2019, 12:18 PM
|
#9
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,109
|
Quote:
Originally Posted by andyp24
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
|
|
|
01-20-2019, 01:47 PM
|
#10
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
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...
|
|
|
01-20-2019, 04:12 PM
|
#11
|
Human being with feelings
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
|
Any way to do this in a Cycle Action?
|
|
|
01-20-2019, 04:21 PM
|
#12
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,746
|
Quote:
Originally Posted by andyp24
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).
|
|
|
01-20-2019, 04:49 PM
|
#13
|
Human being with feelings
Join Date: Jan 2012
Posts: 1,185
|
Quote:
Originally Posted by mespotine
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..
|
|
|
01-21-2019, 01:55 AM
|
#14
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,242
|
Quote:
Originally Posted by Justin
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.
|
|
|
11-28-2020, 11:12 AM
|
#15
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
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 !
|
|
|
11-28-2020, 01:07 PM
|
#16
|
Human being with feelings
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
|
Quote:
Originally Posted by X-Raym
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!
|
|
|
11-28-2020, 02:59 PM
|
#17
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@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.
|
|
|
11-28-2020, 03:05 PM
|
#18
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
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.
|
|
|
11-28-2020, 03:38 PM
|
#19
|
Human being with feelings
Join Date: Jan 2012
Posts: 1,185
|
Quote:
Originally Posted by X-Raym
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??
|
|
|
11-28-2020, 03:49 PM
|
#20
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@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 )
|
|
|
11-28-2020, 04:17 PM
|
#21
|
Human being with feelings
Join Date: Jan 2012
Posts: 1,185
|
Ok this looks good
Are you on a dev version there?
|
|
|
11-28-2020, 04:19 PM
|
#22
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@Triode
Nope, just regular 6.16.
|
|
|
11-28-2020, 04:20 PM
|
#23
|
Human being with feelings
Join Date: Jan 2012
Posts: 1,185
|
Okidoke thank you
|
|
|
11-29-2020, 12:36 AM
|
#24
|
Human being with feelings
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
|
Quote:
Originally Posted by Meo-Ada Mespotine
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!
|
|
|
02-10-2021, 12:52 AM
|
#25
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
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?
|
|
|
02-10-2021, 03:50 AM
|
#26
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@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...
|
|
|
02-10-2021, 03:53 AM
|
#27
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by X-Raym
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?
|
|
|
02-10-2021, 04:09 AM
|
#28
|
Human being with feelings
Join Date: Jan 2012
Posts: 1,185
|
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.
|
|
|
02-10-2021, 04:12 AM
|
#29
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by Triode
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.
|
|
|
02-10-2021, 04:17 AM
|
#30
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Quote:
Originally Posted by vitalker
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.
|
|
|
02-10-2021, 04:59 AM
|
#31
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@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.
|
|
|
02-10-2021, 05:04 AM
|
#32
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by X-Raym
@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!
|
|
|
02-10-2021, 05:09 AM
|
#33
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by amagalma
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
|
|
|
02-10-2021, 02:40 PM
|
#34
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
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.
|
|
|
02-10-2021, 03:49 PM
|
#35
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by amagalma
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.
|
|
|
02-11-2021, 12:43 AM
|
#37
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by Meo-Ada Mespotine
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.
|
|
|
02-11-2021, 04:37 AM
|
#38
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
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.
|
|
|
02-11-2021, 05:38 AM
|
#39
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by Meo-Ada Mespotine
|
This and some other things like determine fx in fx list under mouse cursor.
|
|
|
03-06-2021, 12:10 PM
|
#40
|
Human being with feelings
Join Date: Sep 2019
Posts: 1,146
|
Quote:
Originally Posted by bFooz
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
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 09:32 PM.
|