45 lines
1.4 KiB
Lua
45 lines
1.4 KiB
Lua
-- setparam.lua : set soothe2 FX params by name (normalized 0..1), save-as, quit.
|
|
-- Env: S2_SET "name=value;name=value" (value normalized 0..1)
|
|
-- S2_OUT full path to save the modified project copy to
|
|
local spec = os.getenv("S2_SET") or ""
|
|
local outpath = os.getenv("S2_OUT")
|
|
local log = io.open("/tmp/opencode/setparam.log", "w")
|
|
log:setvbuf("line")
|
|
|
|
local tr = reaper.GetTrack(0, 0)
|
|
if tr == nil then
|
|
log:write("NO TRACK\n") ; log:close() ; return
|
|
end
|
|
|
|
local function find_idx(name)
|
|
local np = reaper.TrackFX_GetNumParams(tr, 0)
|
|
for p = 0, np - 1 do
|
|
local _, pn = reaper.TrackFX_GetParamName(tr, 0, p, "")
|
|
if pn:lower() == name:lower() then return p end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
for pair in spec:gmatch("[^;]+") do
|
|
local name, val = pair:match("^(.-)=(.-)$")
|
|
val = tonumber(val)
|
|
local idx = find_idx(name)
|
|
if idx == nil then
|
|
log:write(string.format("param %-16s NOT FOUND\n", name))
|
|
else
|
|
reaper.TrackFX_SetParam(tr, 0, idx, val)
|
|
local rv = reaper.TrackFX_GetParam(tr, 0, idx)
|
|
local _, fmt = reaper.TrackFX_GetFormattedParamValue(tr, 0, idx, "")
|
|
log:write(string.format("set %-16s -> raw=%.6f fmt=%s\n", name, rv, fmt))
|
|
end
|
|
end
|
|
|
|
if outpath and outpath ~= "" then
|
|
reaper.Main_SaveProjectEx(0, outpath, 0)
|
|
log:write("saved " .. outpath .. "\n")
|
|
end
|
|
log:close()
|
|
local t0 = reaper.time_precise()
|
|
while reaper.time_precise() - t0 < 2 do reaper.defer(function() end) end
|
|
reaper.Main_OnCommand(40004, 0) -- File: Quit REAPER
|