Old 02-20-2021, 12:28 PM   #1
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default simple undo question

what does the zero mean in this line?
Code:
reaper.Undo_EndBlock( "Description here", 0 )
i've borrowed code from various posted scripts in trying to learn and create some functionality i need and found this line somewhere. meo-ada mespotine posted a link (thanks!) to undo documentation that has lots of options but this option is not listed there. curious.

thanks,
babag
babag is offline   Reply With Quote
Old 02-20-2021, 02:16 PM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

From the function signature you can see it's the extraflags parameter which schwa has explained here (but strangely isn't documented in the API doc afaik).
nofish is offline   Reply With Quote
Old 02-20-2021, 02:25 PM   #3
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

You don't have to use these flags, they're optional.
vitalker is offline   Reply With Quote
Old 02-20-2021, 02:36 PM   #4
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

yeah, nofish. no zero in any of the doc i've seen. the schwa post you link indicates that you can sum the flags by adding them, like passing a flag of 5 by summing 1 + 4. there are flags for -1 and 1 which, i'd think, would sum to 0 but, since the -1 flag calls all options, it shouldn't be necessary to add anything to it as far as i can tell. strange.

thanks, vitalker. at this point i just want to know about the zero. maybe i just happened to copy a bit of code that is actually a mistake.

thanks,
babag
babag is offline   Reply With Quote
Old 02-20-2021, 02:46 PM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Ah yes, 0 isn't there in schwa's explaination, hadn't noticed, sorry.
nofish is offline   Reply With Quote
Old 02-20-2021, 03:11 PM   #6
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by babag View Post
the schwa post you link indicates that you can sum the flags by adding them, like passing a flag of 5 by summing 1 + 4. there are flags for -1 and 1 which, i'd think, would sum to 0 but, since the -1 flag calls all options, it shouldn't be necessary to add anything to it as far as i can tell. strange.
Each flag is a single bit. 0 has all bits cleared, so it specifies none of the possible undo state flags. -1 in binary is all bits set (two's complement) so it specifies all of them (even those that don't exist yet).

Code:
UNDO_STATE_ALL        11111111 11111111 11111111 11111111 ( -1) (or 0xFFFFFFFF, aka 4294967295)
UNDO_STATE_TRACKCFG   00000000 00000000 00000000 00000001 (  1)
UNDO_STATE_FX         00000000 00000000 00000000 00000010 (  2)
UNDO_STATE_ITEMS      00000000 00000000 00000000 00000100 (  4)
UNDO_STATE_MISCCFG    00000000 00000000 00000000 00001000 (  8)
UNDO_STATE_FREEZE     00000000 00000000 00000000 00010000 ( 16)
UNDO_STATE_TRACKENV   00000000 00000000 00000000 00100000 ( 32)
UNDO_STATE_FXENV      00000000 00000000 00000000 01000000 ( 64)
UNDO_STATE_POOLEDENVS 00000000 00000000 00000000 10000000 (128)
Combining is done by ORing the bits of two or more flags. Addition does the same thing too if both numbers have no set bits in common.

Last edited by cfillion; 02-20-2021 at 03:27 PM.
cfillion is offline   Reply With Quote
Old 02-20-2021, 03:14 PM   #7
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by babag View Post
there are flags for -1 and 1 which, i'd think, would sum to 0 but, since the -1 flag calls all options, it shouldn't be necessary to add anything to it as far as i can tell. strange.
It's not addition as such. The flags are a bitfield value, that's why they're all powers of two.

Bitfields are stored in unsigned variables like byte, word, dword etc. and -1 is an invalid value for an unsigned type, so the value wraps around and the variable gets set to its maximum value, all the bits get set to 1, which is why -1 sets all the flags.

Zero just clears all the flags.

Adding flags can get you in a mess if you're not careful. OR is safer because if you accidentally add the same flag twice, it won't matter:

Code:
a = 0;
a = a + 1; // a is 1
a = a + 1; // a is 2
b = 0;
b = b | 1; // b is 1
b = b | 1; // b is still 1
edit: Ha! cfillion posted while I was typing!
IXix is offline   Reply With Quote
Old 02-20-2021, 03:17 PM   #8
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by nofish View Post
Ah yes, 0 isn't there in schwa's explaination, hadn't noticed, sorry.
Actually I think it is easy to understand. All of those numbers are powers of 2, so 0 means none of them.
Quote:
Originally Posted by https://www.reaper.fm/sdk/reascript/reascript.php
undo flags for Undo_EndBlock() et al:

1: track configurations
2: track FX
4: track items
8: project states
16: freeze states
vitalker is offline   Reply With Quote
Old 02-20-2021, 03:18 PM   #9
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by IXix View Post
Zero just clears all the flags.
What does it mean though? I understood none of the flags is included, but what 0 does to undo block?
vitalker is offline   Reply With Quote
Old 02-20-2021, 03:20 PM   #10
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

ok. so, if 0 is none of them, what does it do and why is it used? mistake?

this is getting way beyond my abilities but i did get the bit about summing directly from schwa's post:
Quote:
...you could pass flag=5 (1+4) for example. If your script may have affected everything but freeze state, automation items and ARA state, you could pass flag=111 (1+2+4+8+32+64), etc.
he was probably just simplifying for the sake of expediency.

thanks,
babag
babag is offline   Reply With Quote
Old 02-20-2021, 03:25 PM   #11
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by vitalker View Post
What does it mean though? I understood none of the flags is included, but what 0 does to undo block?
Quote:
Originally Posted by babag View Post
ok. so, if 0 is none of them, what does it do and why is it used? mistake?

I would have thought it did nothing. I guess it means you don't care about the flags? Not sure.
IXix is offline   Reply With Quote
Old 02-20-2021, 04:01 PM   #12
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

So if 0 does nothing, are these undo-blocks actually not working in that case? Would be kind of weird...
__________________
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-20-2021, 04:27 PM   #13
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
So if 0 does nothing, are these undo-blocks actually not working in that case? Would be kind of weird...
Yeah, I dunno. You'd have to ask the big fellas about that.
IXix is offline   Reply With Quote
Old 02-20-2021, 04:52 PM   #14
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by IXix View Post
Yeah, I dunno. You'd have to ask the big fellas about that.
HELP US JUSTIN-SCHWA-KENOBI! YOU ARE OUR LAST HOPE!
__________________
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-21-2021, 05:33 AM   #15
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Would be nice then if 0 completely disabled the creation of an undo point in the action history (that would be my expectation from the previous explainations) but I think I've tried it once and it didn't happen.
nofish is offline   Reply With Quote
Old 02-21-2021, 05:46 AM   #16
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by nofish View Post
Would be nice then if 0 completely disabled the creation of an undo point in the action history (that would be my expectation from the previous explainations) but I think I've tried it once and it didn't happen.
Sure, we should have no undo points scripts.
vitalker is offline   Reply With Quote
Old 02-22-2021, 02:10 PM   #17
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

so... nothing definitive on the 0? i have a fewe scripts i was waiting to finalize and thought to hold them until i got a final answer on this but, maybe not. would love to know what's up.

thanks,
babag
babag is offline   Reply With Quote
Old 02-22-2021, 02:12 PM   #18
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by babag View Post
so... nothing definitive on the 0? i have a fewe scripts i was waiting to finalize and thought to hold them until i got a final answer on this but, maybe not. would love to know what's up.
I think if you set 0, it means you use default mode for creating undo points.
vitalker is offline   Reply With Quote
Old 02-22-2021, 03:03 PM   #19
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,227
Default

thanks, vitalker. is that a consensus among everyone here? can't figure out if i should use -1, 0, or just leave it blank.

thanks again,
babag
babag is offline   Reply With Quote
Old 02-22-2021, 03:07 PM   #20
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 13,333
Default

Quote:
Originally Posted by babag View Post
thanks, vitalker. is that a consensus among everyone here? can't figure out if i should use -1, 0, or just leave it blank.
I doubt you can leave it blank. I'd just use 0.
vitalker is offline   Reply With Quote
Old 02-22-2021, 03:24 PM   #21
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 1,180
Default

It seems to me some actions that don't really change the project like selecting items don't create an undo point. Leaving it blank then works. Other actions do create an undo and then if you leave it blank you get "reascript: run" or something more specific in the undo anyway.
__________________
Mixing / Brush and Beater Drums Online: www.outoftheboxsounds.com
Triode 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 02:02 AM.


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