Old 11-10-2016, 04:17 AM   #1
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 733
Default Preference setting help - WRITING to reaper.ini

Thanks to @X-Raym I've got this far.

This script is trying to change these "Tint" values. (Well, just one for now - "Tint media item background to Take Color")



It successfully 'Gets' the right value but doesn't seem to write or 'Set' one.

Code:
CurSetting = reaper.SNM_GetIntConfigVar( "tinttcp", -666 )
 
num=CurSetting
bits=12 --The number of bit we need to make this setingwork

-- When the "tinttcp" number from the reaper.ini is converted to binary, the 
-- 256 value digit will correspond to  "Tint media item background to Take Color".
-- First, let's convert to bits...  
function toBits(num, bits)
    -- returns a table of bits
    local t={} -- will contain the bits
    for b=bits,1,-1 do
        rest=math.fmod(num,2)
        t[b]=rest
        num=(num-rest)/2
    end
    if num==0 then return t else return {'Not enough bits to represent this number'}end
end
bits=toBits(num, bits)

NinthBit = tonumber(table.concat(bits):sub(9,10)) --This is the bit will value of 256

reaper.ShowConsoleMsg(table.concat(bits).."\n"..NinthBit.."\n")

if NinthBit == 1 then
    reaper.ShowConsoleMsg("Tack Color BG is ON")
    
elseif NinthBit == 0 then
  reaper.ShowConsoleMsg("Tack Color BG is OFF")
  
  NewSetting = CurSetting+256 --Get ready to turn it on. +256 will mean 9th bit will be "ON"
  reaper.ShowConsoleMsg(NewSetting)
  
  reaper.SNM_SetDoubleConfigVar( "tinttcp", 1940 )--1940 is a placeholder value to be replaced with NewSetting
  
 
end
Does it need the equivolent of the "apply" button?

Quiting/Reaper Reaper doesn't help. Values are still not written.

Using the pref window, values when setting manually only change in the .ini when apply is pressed.

Last edited by Stroudy; 11-10-2016 at 08:15 AM.
Stroudy is offline   Reply With Quote
Old 11-11-2016, 12:45 PM   #2
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 733
Default

No one with any thoughts on writing to the reaper.ini?
Stroudy is offline   Reply With Quote
Old 11-11-2016, 01:07 PM   #3
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

I don't have the answer but I would be extremely careful and standoffish about writing to it as the slightest bug in your script is going to corrupt the install.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 11-11-2016, 04:01 PM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

I don't know about SNM_SetDoubleConfigVar, but BR_Win32_WritePrivateProfileString works here. It changes the .ini immediately but the new settings are only applied on the next startup.
cfillion is offline   Reply With Quote
Old 11-11-2016, 05:25 PM   #5
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 733
Default

That's good to know.

We need something which essentially is the same as pressing the 'Apply' button in Preferences.

Really this should be a toggleable option that can be changed on the fly like Show/Hide Grid.

Take colours are useful but times it's easier to look at item or track colour. Particularly when you're making structural edits.
Stroudy is offline   Reply With Quote
Old 11-11-2016, 11:46 PM   #6
stephane
Human being with feelings
 
Join Date: May 2010
Location: France
Posts: 97
Default

I'm using this piece of code for reading/writing in reaper.ini

Code:
local retval, stringOut = reaper.BR_Win32_GetPrivateProfileString("section", "key", "",  reaper.get_ini_file())
Code:
reaper.BR_Win32_WritePrivateProfileString( "section", "key", stringOut, reaper.get_ini_file() )
Because you're changing programmatically colors, a refresh of reaper could be necessary by calling this following lines

Code:
reaper.TrackList_AdjustWindows(true)
reaper.UpdateArrange()
stephane is offline   Reply With Quote
Old 02-08-2017, 11:29 PM   #7
TobyAM
Human being with feelings
 
Join Date: Feb 2017
Location: Hollywood, CA
Posts: 125
Default reloading INI

stephane, using your helpful tips I've created a script that successfully modifies the INI, particularly setting the HUI track offset value.

The only problem is this setting take effect (although checking the .INI file, the value has indeed changed)

Since the HUI settings don't effect Reaper visually at all, it seems your 'refresh' code doesn't work here. (?)

Does anyone know of a way for this change of value to take effect immediately?

Here's the code:
Code:
inipath = reaper.get_ini_file()

reaper.BR_Win32_WritePrivateProfileString( "reaper", "csurf_1", "HUI 12 8 0 2", inipath )

reaper.TrackList_AdjustWindows(true)
reaper.UpdateArrange()

Last edited by TobyAM; 02-08-2017 at 11:30 PM. Reason: code formatting
TobyAM is offline   Reply With Quote
Old 06-15-2017, 04:18 PM   #8
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,340
Default

Ok.., so I know how to use reaper.BR_Win32_GetPrivateProfileString() to retrieve a single value, but is it possible to retrieve multiple values and store them in a table? Say I have the following in my .ini...,

[MySec]
this=37
that=0.37
other=9.99

If it's possible could someone please provide an example that outputs all three keys and their values to the console?

Thank you
Anton9 is offline   Reply With Quote
Old 06-15-2017, 04:40 PM   #9
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

@Anton9 It's the same thing for a single value or many values. Just call the function multiple times until you get the values you need.

Here I do a loop over all the keys in a `config` table, replacing the default values with the ones in the ini file if it's there:
Code:
local config = {
  this=1, -- fill with default values
  that=2,
  other=3,
}

for key, _ in pairs(config) do
  config[key] = ({reaper.BR_Win32_GetPrivateProfileString(SECTION_NAME, key, config[key], FILE_PATH)})[2]
  reaper.ShowConsoleMsg(string.format('%s = %s\n', key, config[key]))
end
You might also be interested in SetExtState and GetExtState.

Last edited by cfillion; 06-15-2017 at 05:07 PM.
cfillion is offline   Reply With Quote
Old 06-15-2017, 06:32 PM   #10
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,340
Default

Thanks cfillion, but I'm not receiving the expected output.

I replaced SECTION_NAME with MySec and pointed it to the correct path but the values in the console output aren't being replaced with the ones from my .ini.
Also each time I run it the order of the keys is being shuffled.
Anton9 is offline   Reply With Quote
Old 06-16-2017, 02:07 PM   #11
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Double-check all parameters given to BR_Win32_GetPrivateProfileString are correct.
The arbitrary order is actually a feature of Lua's pairs iterator, apparently to avoid some security issues. If you need constant ordering, use numerical keys in the table and ipairs instead.

Last edited by cfillion; 06-16-2017 at 02:13 PM.
cfillion 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:21 AM.


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