Open mespotine opened 4 years ago
Totally agree. I just spent hours trying to figure out why I can't write to the sws-autocoloricon.ini file.
As an example, consider adding an AutoColor entry. This test assumes you already have some entry, and will simply add an entry:
swscolorini = 'sws-autocoloricon.ini'
inipath = reaper.get_ini_file()
ini_path = inipath:gsub("(.+)([/\\])(.+)$", "%1%2"..swscolorini)
fileptr = io.open(ini_path)
if fileptr then
SWScontent = fileptr:read("*a")
fileptr:close()
reaper.ShowConsoleMsg('SWS Auto Color Icon Ini before:\n'..SWScontent..'\n')
cnt = string.match(SWScontent, "AutoColorCount=(%d+)")
if not cnt then cnt=1 else cnt=tonumber(cnt)+1 end
sec="SWS"
key="AutoColor "..cnt
val="0 Guitars 16744448 \"\" \"\" \"\""
reaper.BR_Win32_WritePrivateProfileString(sec, key, val, ini_path)
key="AutoColorCount"
val = tostring(cnt)
reaper.BR_Win32_WritePrivateProfileString(sec, key, val, ini_path)
fileptr = io.open(ini_path)
if fileptr then
SWScontent = fileptr:read("*a")
fileptr:close()
reaper.ShowConsoleMsg('SWS Auto Color Icon Ini after:\n'..SWScontent..'\n')
end
end
This will write successfully to the file, but Reaper does not see the changes - they get discarded upon opening the SWS Auto Color Layout window or restarting Reaper.
So I think there really needs to be a way to modify some of these ini files in code.
There are some nice things in SWS that can be set via UI.
For instance, I can set a startup-action, autocolors, nudge and fades, etc.
Problem is, you can set many of them only via UI. So I would ask for a Get/Set-function, that allows you setting the values via ReaScript at runtime.
a function like
boolean retval, string value = reaper.SWS_GetSetConfigVariable(boolean is_set, string configfile, string section, string key, boolean persist)
which allows setting a value, located by its config-file-entry.
So, if I want to set a new fade-in-time, as set in SWS Extension Command Parameters, I write the following:
´retval, value = reaper.SWS_GetSetConfigVariable(true, "Xenakios_Commands.ini", "XENAKIOSCOMMANDS", "1.2345", false)´
Which updates the internal value for it to 1.2345. And when I set persist=true, it also updated the config-file at the same time. Another way would be to have an action, which forces rereading all set config-values, so I could set them in the config-files and run the action to update it. That way, I could have dynamically set nudging/fade/etc-settings, depending on how I need them.
Currently I would need to restart Reaper for a change of these values.