Old 02-03-2020, 06:39 PM   #1
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,269
Default Get/Set Snap/Grid setting -- IE. How to use SNM_GetDoubleConfigVar()

HI gang,

I would like to set some key commands to certain Snap/Grid settings.

Stevie was kind enough to point me in the direction of how to look up and set Snap/Grid checkboxes here:
However, I'm utterly clueless on how to use these commands... most notably:
Code:
reaper.SNM_GetDoubleConfigVar("projshowgrid",0) 
and these too:

Code:
reaper.SNM_GetIntConfigVar(string varname, integer errvalue)
reaper.SNM_GetIntConfigVar("projshowgrid", 0)
Can someone post an uber simple script that polls the (say) "cursor to grid" checkbox?

Thanks for any help or pointers.

Cheers,

Andrew K
__________________
Cheers,
Andrew K
v6.03+dev0114 - January 14 2020 • Mac 10.12.+ • i7 Quad 2.9GHz • 24GB
Thonex is offline   Reply With Quote
Old 02-03-2020, 08:55 PM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,950
Default

mespotine has documented it here:
https://mespotin.uber.space/Ultrasch...l#projshowgrid
For the "cursor to grid" checkbox it says &4.

It's a bit field, meaning (in short) every bit of that number represents a state (e.g. of a tickbox).

Then bitwise operations can be used to 'do something' with the bits.

E.g. bitwise AND to query a bit state, bitwise OR to set a bit state etc.

So:
Code:
-- TEST
state = reaper.SNM_GetIntConfigVar("projshowgrid", -666)&4 -- bitwise AND, query bit, returns 4/non zero if enabled, 0 if disabled

-- TOGGLE
-- toggleOK = reaper.SNM_SetIntConfigVar("projshowgrid", reaper.SNM_GetIntConfigVar("projshowgrid", -666)~4) -- bitwise NOT, flip bit

-- ENABLE
-- enableOK = reaper.SNM_SetIntConfigVar("projshowgrid", reaper.SNM_GetIntConfigVar("projshowgrid", -666)|4) -- bitwise OR, set bit

-- DISABLE
-- disableOK = reaper.SNM_SetIntConfigVar("projshowgrid", (reaper.SNM_GetIntConfigVar("projshowgrid", -666)&(~4))) -- bitwise AND NOT, clear bit

Last edited by nofish; 02-03-2020 at 09:02 PM.
nofish is offline   Reply With Quote
Old 02-03-2020, 09:34 PM   #3
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,269
Default

Quote:
Originally Posted by nofish View Post
mespotine has documented it here:
https://mespotin.uber.space/Ultrasch...l#projshowgrid
For the "cursor to grid" checkbox it says &4.

It's a bit field, meaning (in short) every bit of that number represents a state (e.g. of a tickbox).

Then bitwise operations can be used to 'do something' with the bits.

E.g. bitwise AND to query a bit state, bitwise OR to set a bit state etc.

So:
Code:
-- TEST
state = reaper.SNM_GetIntConfigVar("projshowgrid", -666)&4 -- bitwise AND, query bit, returns 4/non zero if enabled, 0 if disabled

-- TOGGLE
-- toggleOK = reaper.SNM_SetIntConfigVar("projshowgrid", reaper.SNM_GetIntConfigVar("projshowgrid", -666)~4) -- bitwise NOT, flip bit

-- ENABLE
-- enableOK = reaper.SNM_SetIntConfigVar("projshowgrid", reaper.SNM_GetIntConfigVar("projshowgrid", -666)|4) -- bitwise OR, set bit

-- DISABLE
-- disableOK = reaper.SNM_SetIntConfigVar("projshowgrid", (reaper.SNM_GetIntConfigVar("projshowgrid", -666)&(~4))) -- bitwise AND NOT, clear bit

Wow... thanks nofish!

I'll read over this very slowly. It's been a long day and I'm a little spent right now, but will delve into this tomorrow. Thanks for the tests! I'm sure that will help me out tons!!

Cheers,

Andrew K
__________________
Cheers,
Andrew K
v6.03+dev0114 - January 14 2020 • Mac 10.12.+ • i7 Quad 2.9GHz • 24GB
Thonex is offline   Reply With Quote
Old 02-04-2020, 09:52 AM   #4
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,269
Default

Brilliant!!!

I now get it. Thanks for the bitwise links! At first I was confused by the -666, then I realized that's what you chose as the return value if there is an error. Yes?

Everything else make sense. And thanks for the syntax. No way I would have figured out the DISABLE syntax!

Thanks again nofish!

Cheers,

Andrew K
__________________
Cheers,
Andrew K
v6.03+dev0114 - January 14 2020 • Mac 10.12.+ • i7 Quad 2.9GHz • 24GB
Thonex is offline   Reply With Quote
Old 02-04-2020, 10:45 AM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,950
Default

Quote:
Originally Posted by Thonex View Post
At first I was confused by the -666, then I realized that's what you chose as the return value if there is an error. Yes?
Yep. It's seems to be quite common to use as error code (probably because it's rather unlikely it's a 'real' value coincidently), e.g. in SWS its all over the place.

Quote:
And thanks for the syntax. No way I would have figured out the DISABLE syntax!
With the disable syntax I had to struggle the most too at first.

Glad it helped, you're welcome.
nofish 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 01:28 AM.


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