View Single Post
Old 09-19-2020, 07:44 AM   #15
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 Coachz View Post
So the -666 is the return value from getting and then you are ORing it with the one.
The -666 is just an arbitrarily chosen errvalue which is returned in case SNM_GetIntConfigVar() fails (see doc).
So a more non-lazy version of it would be:
Code:
-- enable show grid line spacing
projshowgridConfig = reaper.SNM_GetIntConfigVar("projshowgrid", -666)
if projshowgridConfig ~= -666 then -- got value ok, we can continue
  -- set 1st bit of projshowgridConfig to 1 (by bitwise ORing with 1)
  enableOK = reaper.SNM_SetIntConfigVar("projshowgrid", projshowgridConfig|1)
  -- may check if enableOK returned true...
end
Quote:
And if you wanted to set another property you would OR it with whatever its associated value was like maybe 256 right?
In principle yes, but note that for Enable snapping the doc says:
Quote:
&256=0, Enable snapping(on) - checked
&256=1, Enable snapping(off) - unchecked
So in this case you have to do a bitwise AND NOT for enabling snapping (clear the 9th bit):

Code:
-- enable snapping
projshowgridConfig = reaper.SNM_GetIntConfigVar("projshowgrid", -666)
if projshowgridConfig ~= -666 then -- got value ok, we can continue
  enableOK = reaper.SNM_SetIntConfigVar("projshowgrid", projshowgridConfig&(~256))
  -- may check if enableOK returned true...
end
or the lazy version:
Code:
enableOK = reaper.SNM_SetIntConfigVar("projshowgrid", (reaper.SNM_GetIntConfigVar("projshowgrid", -666)&(~256))) -- bitwise AND NOT, clear bit

Last edited by nofish; 09-19-2020 at 07:57 AM.
nofish is offline   Reply With Quote