 |
|
|
05-17-2020, 12:57 PM
|
#1
|
Human being with feelings
Join Date: Dec 2017
Posts: 83
|
Trouble with SNM_GetIntConfigVar()
I was testing "REAPER v6.10/x64" on Windows in a portable install. One of my scripts ran into problems, which I tracked back to strange results from SNM_GetIntConfigVar(). I was trying to get the value of "midiouts" from my "reaper.ini" file:
Code:
Interactive ReaScript v0.8.3 by cfillion
Type Lua code, !ACTION or .help
> reaper.CF_GetSWSVersion("")
"2.12.0.0"
> reaper.SNM_GetIntConfigVar("midiouts", -1)
-1
> reaper.SNM_GetIntConfigVar("midiouts", 123)
123
And yet an excerpt from my reaper.ini does show the lines:
Code:
[REAPER]
midiouts=1056760
So I don't know why SNM_GetIntConfigVar doesn't seem to be finding "midiouts".
It does find it ok on "REAPER 5.99x64" with SWS "2.10.0.1":
Code:
> reaper.SNM_GetIntConfigVar("midiouts", 123)
1056760
Thanks for any help.
|
|
|
05-17-2020, 01:06 PM
|
#2
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 5,874
|
The midiouts-configvar is the one currently in memory, it does not necessarily reflect the same value in the reaper.ini
The reaper.ini-entry is loaded once at start, so I would guess, that some script changes the config-var, without changin it in the reaper.ini as well. As soon as it's changed as config-var, it is different from the one in reaper.ini without having a negative effect on Reaper.
What I'm wondering though, that the values are so high. According to my docs, midiouts can only be 1 or 0.
https://mespotin.uber.space/Ultrasch....html#midiouts
Which menu let's you change the reaper.ini-value as well? Would love to add this missing information to my docs.
|
|
|
05-17-2020, 02:01 PM
|
#3
|
Human being with feelings
Join Date: Dec 2017
Posts: 83
|
Thanks for the response.
Quote:
Originally Posted by Meo-Ada Mespotine
I would guess, that some script changes the config-var, without changin it in the reaper.ini as well. As soon as it's changed as config-var, it is different from the one in reaper.ini without having a negative effect on Reaper.
|
In my example, I wasn't really running a serious script, but just calling SNM_GetIntConfigVar interactively.
Quote:
What I'm wondering though, that the values are so high. According to my docs, midiouts can only be 1 or 0.
|
midiouts is a bit map for up to 32 midi hardware devices. Each bit position gives the "enabled" status of that device (0 or 1). The returned number can be large, because it's a decimal value of the binary bit map.
Quote:
Which menu let's you change the reaper.ini-value as well? Would love to add this missing information to my docs.
|
Preferences|Audio|MIDI_Devices let's you change the enabled status (under the "Mode" column).
|
|
|
05-17-2020, 02:40 PM
|
#4
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 5,874
|
Quote:
Originally Posted by tparker24
Preferences|Audio|MIDI_Devices let's you change the enabled status (under the "Mode" column).
|
Thanks, will look into it. Maybe I see more of its behavior, when toying around with it. There a few configvars who behave a little strangely, maybe this is one of them.
|
|
|
05-17-2020, 03:33 PM
|
#5
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,191
|
midiouts is a 64-bit value and SNM_GetIntConfigVar returns a 32-bit integer. SWS 2.11+ checks the size to prevent buffer overflows when writing.
In reaper.ini (likely because the Windows API .ini integer functions are 32-bit), midiouts is split into two 32-bit values: midiouts and midiouts_h (storing the the low and high doublewords respectively).
Extensions-exported API functions cannot have 64-bit integer values as arguments or return value. This might be an oversight or a bug though, because the REAPER-exported RecursiveCreateDirectory takes a 64-bit integer as second argument.
SNM_GetDoubleConfigVar reads 64-bit values but you'd have deal with the floating point representation.
A workaround could be to add {Get,Set}LongConfigVar functions that split the value:
Code:
> -- midiouts is 0x1000001fe
> reaper.SNM_GetLongConfigVar('midiouts')
{true, 510, 1}
Last edited by cfillion; 05-17-2020 at 04:05 PM.
|
|
|
05-17-2020, 04:21 PM
|
#6
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 5,874
|
+1 for SNM_GetLongConfigVar, this seems to be a very helpful thing. With that, I could improve my configvars-docs with 64bit-integers as well.
The 64bit-behavior probably also explains, why I didn't notice that this variable can store much more...
Last edited by Meo-Ada Mespotine; 05-17-2020 at 04:32 PM.
|
|
|
05-17-2020, 08:02 PM
|
#7
|
Human being with feelings
Join Date: Dec 2017
Posts: 83
|
cfillion, thanks for the info. I wondered what that midiout_h was.
I see now that there are over 20 of these <item>_h things in reaper.ini. So that may affect many more folks. However, many of those items seem to be "false positives" in that I think the "_h" just stands for "height". But the bulk (over 1,000) of the items don't have the corresponding "-h". How is the user to know, in advance, which do and which don't?
Another thing, the previous SNM_GetIntConfigVar apparently worked differently, because it does return midiouts (and I guess, just ignores midiouts_h?), whereas the new SNM_GetIntConfigVar returns an error.
I don't know which behavior is better: return half the data, or return nothing -- probably the latter. But it may break lots of existing reascripts?
This seems like it's becoming quite difficult. The user will need to somehow know in advance whether the item they want is 64-bit (with the halves) or not.
Or maybe they can just always use your proposed SNM_GetLongConfigVar, and check both halves -- assuming that it will also handle a 32-bit and just return 0 if there is no "upper half"?.
[Sorry for the rant]
|
|
|
05-17-2020, 08:37 PM
|
#8
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,191
|
Here are test builds for the new functions (Linux and Windows): https://github.com/reaper-oss/sws/pu...ment-630351908.
Quote:
Originally Posted by tparker24
The user will need to somehow know in advance whether the item they want is 64-bit (with the halves) or not.
|
Yeah, configvars are completely undocumented, so it's a good thing there are custom documentations like mespotine's.
Quote:
Originally Posted by tparker24
Or maybe they can just always use your proposed SNM_GetLongConfigVar, and check both halves -- assuming that it will also handle a 32-bit and just return 0 if there is no "upper half"?.
|
The hardened implementation requires the sizes to exactly match. SNM_GetLongConfigVar (and the corresponding Set function) return false if the configvar is 32-bit. There is no way to distinguish a 64-bit integer value with a 64-bit floating point one though... but at least I think this behavior is the safest and least surprising.
Last edited by cfillion; 05-18-2020 at 11:15 AM.
|
|
|
05-17-2020, 08:52 PM
|
#9
|
Human being with feelings
Join Date: Dec 2017
Posts: 83
|
Thanks so much.
Quote:
Originally Posted by cfillion
|
I'd like to help test, but frankly I'm at a loss on how to get the test build on github. Please advise.
Quote:
Originally Posted by cfillion
I think this behavior is the safest and least surprising.
|
That's the ticket!
|
|
|
05-17-2020, 08:55 PM
|
#10
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,191
|
Quote:
Originally Posted by tparker24
I'd like to help test, but frankly I'm at a loss on how to get the test build on github. Please advise.
|
Click on the line with "Visual Studio 2019, ARCH=x64" (for Windows 64-bit) and download the .exe installer. Then the install process is as usual.
|
|
|
05-17-2020, 09:02 PM
|
#11
|
Human being with feelings
Join Date: Dec 2017
Posts: 83
|
Got it, thanks!
|
|
|
05-18-2020, 10:14 PM
|
#12
|
Human being with feelings
Join Date: Dec 2017
Posts: 83
|
The test version of SNM_GetLongConfigVar is working great in python!
Thanks a bunch.
|
|
|
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 04:21 AM.
|