|
|
|
10-18-2015, 02:22 PM
|
#1
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
No Undo point! "Defer"? How?
Hello!
I would like to run some custom actions and some cycle actions that I have created, but would like not to have any undo point created. I have heard that this could be possible with "defer", but how?
For example, could it be?:
function run()
(
Main_OnCommand(NamedCommandLookup("My action"), 0);
);
defer("run();");
Would this work?
|
|
|
10-19-2015, 06:04 AM
|
#2
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Found this
How could I use it in my case?
|
|
|
10-20-2015, 04:33 AM
|
#3
|
Human being with feelings
Join Date: Aug 2013
Posts: 339
|
Why complicate matters with a function that runs in the background?
All you have to do is add this at the end (or similar):
Code:
function NoUndo()(abs(0)); defer("NoUndo()");
That is an empty function.
Here's a simple script that, for example, toggles MIDI Editor view on/off even if none of it is open yet:
Code:
MIDIEditor_GetActive() ? Main_OnCommand(40716, 0) : Main_OnCommand(40153, 0);
function NoUndo()(abs(0)); defer("NoUndo()");
You don't need any "run" function. Just insert any code and put that at the end.
|
|
|
10-20-2015, 11:25 AM
|
#4
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
I've tried it but the cycle action still appears in my Undo History...
P.S. It seems to work with other actions except Cycle actions.. I think I have to translate my Cycle actions to scripts.. :/
Last edited by amagalma; 10-20-2015 at 11:33 AM.
|
|
|
10-20-2015, 12:20 PM
|
#5
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Yay! At last! I can have my custom play/stop actions (cubase style) without flooding the undo history!! )))
|
|
|
11-07-2015, 07:56 PM
|
#6
|
Human being with feelings
Join Date: Jun 2012
Posts: 2,173
|
Really? This is the secret then?
Surprised it hasn't generated more excitement.
Thanks...
I hope someday someone will explain defer for noobs.
|
|
|
02-17-2016, 11:35 AM
|
#7
|
Human being with feelings
Join Date: Jun 2015
Posts: 685
|
*excited!*
|
|
|
01-22-2018, 07:49 PM
|
#8
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
I'm also super excited
However, this method does not seem to work with "reaper.ToggleTrackSendUIMute".
It automatically generates a "toggle send mute" entry in the undo history.
|
|
|
01-22-2018, 09:53 PM
|
#9
|
Human being with feelings
Join Date: Jun 2012
Posts: 2,173
|
As you found in the other thread, there are a number of things like that. Csurf functions are another one. Even some selection mainoncommands.
I don't understand the undo mechanism, but it seems to be a bad idea to try to skirt undo points entirely for things like this. You might be able to with some other function, but it might switch to its previous state later when you undo something else.
|
|
|
01-23-2018, 07:58 AM
|
#10
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
I know what you mean, I won't force it, if it doesn't work.
It's just that I find it needless to clutter the undo history with
a "bypass sends" command
|
|
|
01-23-2018, 08:51 AM
|
#11
|
Human being with feelings
Join Date: Jun 2012
Posts: 2,173
|
I have not tried it too many times, but it didn't work out when I did. One public example is in mehmethan's folder collapse script request. I thought it was worthless to have undo points for collapsing folders. But if I skipped them entirely, I found undoing a track volume change later might change the folders back to where they were before the script.
I suppose my previous post was too narrowly centered on one shot actions. It is proven useful in say a background script to reduce the number of points to a minimum. I think that's the whole reason it is the way it is. It's not the empty function that does it, it's the fact that the script includes defer. You could defer the whole main function. But I usually use this method, because I wonder if it might delay the execution speed of the main function, for instance in a macro where it needs to happen immediately.
So depending on what exactly you are up to, it might be possible to reduce the amount of points, but I recall a few complaints where even an undo block sandwich could not stop multiple points. I think that is kind of rare.
Maybe one of breeders functions or some other thingy might allow you to try to skip points for your example if you want to try for yourself. Can't check right now.
|
|
|
01-23-2018, 08:51 PM
|
#12
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Valid points FnA!
The script I'm working on is actually very simple. It gets all sends on selected tracks and mutes them:
Code:
for i = 0, reaper.CountSelectedTracks(0)-1 do -- loop through all selected tracks
track = reaper.GetSelectedTrack(0,i) -- save actual track to "track"
if track then -- if track exists
sends = reaper.GetTrackNumSends(track, 0) -- get amount of sends of selected track
for i = 0, sends do
reaper.ToggleTrackSendUIMute(track, i) -- toggle mute all sends
end
end
end
|
|
|
01-23-2018, 08:58 PM
|
#13
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
SetTrackSendInfo_Value doesn't create undo points.
Code:
local track = reaper.GetTrack(0, 0)
local muted = 1 == reaper.GetTrackSendInfo_Value(track, 0, 0, 'B_MUTE')
reaper.SetTrackSendInfo_Value(track, 0, 0, 'B_MUTE', muted and 0 or 1)
reaper.defer(function() end)
|
|
|
01-23-2018, 08:58 PM
|
#14
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Tried that, same result
Both do not work with defer.
|
|
|
01-23-2018, 10:29 PM
|
#15
|
Human being with feelings
Join Date: Jun 2012
Posts: 2,173
|
Well, you are both right.
I ran this on 2 tracks with 3 sends each. (for completeness, I think you need to put something in to check for hardware outputs and start your index after that for normal sends. Hm. Maybe not for every function. Something to double check...) With the "toggle" function (commented out), it makes 6 undo points right away. Some things appear to have something like UndoBlock or OnStateChange built in. In the form here with the uncommented function, it makes no undo point on execution, but after running it:
draw in 4 midi items
undo two of those
check sends: fine, still muted.
mute a track, undo that
check sends: not muted.
Code:
for i = 0, reaper.CountSelectedTracks(0)-1 do -- loop through all selected tracks
track = reaper.GetSelectedTrack(0,i) -- save actual track to "track"
if track then -- if track exists
sends = reaper.GetTrackNumSends(track, 0) -- get amount of sends of selected track
for i = 0, sends-1 do
--reaper.ToggleTrackSendUIMute(track, i) -- toggle mute all sends
reaper.SetTrackSendInfo_Value(track, 0, i, 'B_MUTE', muted and 0 or 1)
end
end
end
reaper.defer(function() end)
Last edited by FnA; 01-23-2018 at 11:43 PM.
|
|
|
10-28-2019, 06:08 AM
|
#16
|
Human being with feelings
Join Date: Jan 2013
Posts: 1,126
|
The thing with this "defer" trick is that if you run the script several times very quickly, you get the "Terminate running Script" dialog. This can be misleading to new user. Any ways to avoid this?
|
|
|
10-28-2019, 07:07 AM
|
#17
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
|
|
|
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 03:59 AM.
|