From this post:
https://forum.cockos.com/showpost.ph...60&postcount=4
If I want to set FX name programatically, it still require chunking, because
Code:
reaper.TrackFX_SetNamedConfigParm(track, fx-1, 'fx_name', buf)
doesn`t seems to work.
Example below -
Remove FX prefixes on focused FX track.lua:
Code:
function main()
retval, tracknumber, itemnumber, fxnumber = reaper.GetFocusedFX2()
if retval == 0 then return end
if tracknumber < 0 then return end
if tracknumber == 0 then track = reaper.GetMasterTrack(0) else track = reaper.GetTrack(0,tracknumber-1)end
if not track then return end
for fx = 1, reaper.TrackFX_GetCount( track ) do
local retval, buf = reaper.TrackFX_GetNamedConfigParm(track, fx-1, 'fx_name')
if buf:match('[%d%a]+%:%s.*') then
buf = buf:match('[%d%a]+%:%s(.*)')
--reaper.TrackFX_SetNamedConfigParm(track, fx-1, 'fx_name', buf)
SetFXName(track, fx-1, buf)
end
end
end
-----------------------------------------------------------------------
function SetFXName(track, fx, new_name)
if not new_name then return end
local edited_line,edited_line_id, segm
-- get ref guid
if not track or not tonumber(fx) then return end
local FX_GUID = reaper.TrackFX_GetFXGUID( track, fx )
if not FX_GUID then return else FX_GUID = FX_GUID:gsub('-',''):sub(2,-2) end
local plug_type = reaper.TrackFX_GetIOSize( track, fx )
-- get chunk t
local retval, chunk = reaper.GetTrackStateChunk( track, '', false )
local t = {} for line in chunk:gmatch("[^\r\n]+") do t[#t+1] = line end
-- find edit line
local search
for i = #t, 1, -1 do
local t_check = t[i]:gsub('-','')
if t_check:find(FX_GUID) then search = true end
if t[i]:find('<') and search and not t[i]:find('JS_SER') then
edited_line = t[i]:sub(2)
edited_line_id = i
break
end
end
-- parse line
if not edited_line then return end
local t1 = {}
for word in edited_line:gmatch('[%S]+') do t1[#t1+1] = word end
local t2 = {}
for i = 1, #t1 do
segm = t1[i]
if not q then t2[#t2+1] = segm else t2[#t2] = t2[#t2]..' '..segm end
if segm:find('"') and not segm:find('""') then if not q then q = true else q = nil end end
end
if plug_type == 2 then t2[3] = '"'..new_name..'"' end -- if JS
if plug_type == 3 then t2[5] = '"'..new_name..'"' end -- if VST
local out_line = table.concat(t2,' ')
t[edited_line_id] = '<'..out_line
local out_chunk = table.concat(t,'\n')
--msg(out_chunk)
reaper.SetTrackStateChunk( track, out_chunk, false )
end
-----------------------------------------------------------------------
main()