Old 01-24-2017, 10:13 AM   #1
Nantho
Human being with feelings
 
Join Date: Mar 2013
Posts: 217
Default Rename FX instance ?

Hi scripting Gurus !

Does anybody know if there is a way to rename an FX instance with a script ?

Thanks
Nantho is online now   Reply With Quote
Old 01-24-2017, 10:16 AM   #2
OPI
Human being with feelings
 
OPI's Avatar
 
Join Date: Nov 2014
Posts: 1,900
Default

Just right click the fx and choose rename
OPI is offline   Reply With Quote
Old 01-24-2017, 10:40 AM   #3
Nantho
Human being with feelings
 
Join Date: Mar 2013
Posts: 217
Default

Thanks, but I already knew about that

I was talking about renaming an FX instance with a script cause I'm building a script that needs to be able to do so
Nantho is online now   Reply With Quote
Old 01-24-2017, 10:49 AM   #4
OPI
Human being with feelings
 
OPI's Avatar
 
Join Date: Nov 2014
Posts: 1,900
Default

ahh makes sense haha. Sometimes the answer is simple. Not this Time!
OPI is offline   Reply With Quote
Old 01-24-2017, 01:13 PM   #5
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

Parsing/editing track state chunk.
mpl is offline   Reply With Quote
Old 01-24-2017, 01:31 PM   #6
Nantho
Human being with feelings
 
Join Date: Mar 2013
Posts: 217
Default

Thanks mpl, I'm gonna take a look at this, but I'm afraid it's way out of my league

Right now, I'm using a trick : BetterTouchTool takes care of the "renaming" part of the job and the script I'm working on takes it from there. It works like a charm ! But I'd like to share my script with everyone so I must find a work around which uses "script only"...

So now that I've got the right direction, let's get to work
Nantho is online now   Reply With Quote
Old 01-24-2017, 11:19 PM   #7
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

I`m not good at string parsing but this should works (still very dangerous though)

Code:
  function SetFXName(track, fx, new_name)
    -- 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
      plug_type = reaper.TrackFX_GetIOSize( track, fx )
    -- get chunk t
      local _, chunk = reaper.GetTrackStateChunk( track, '', false )
      local t = {} for line in chunk:gmatch("[^\r\n]+") do t[#t+1] = line end
    -- find edit line
      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
      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
      reaper.SetTrackStateChunk( track, table.concat(t,'\n'), false )
      reaper.UpdateArrange()
  end 
  
-----------------------------------------------------------------------
  
  track = reaper.GetTrack(0,0) 
  fx_id = 2 -- fx is 0-based  
  SetFXName(track, fx_id, 'randomFX')
mpl is offline   Reply With Quote
Old 01-25-2017, 03:59 AM   #8
Nantho
Human being with feelings
 
Join Date: Mar 2013
Posts: 217
Default

Wah !! Thank you so much mpl, you're the Man !

Gonna try this asap and I'll let you know if it works. Anyway, it's a huge step forward and even if it doesn't work, it will certainly put me in the right direction ! Because I have to admit that my last night experiences were'nt so successful
Nantho is online now   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 09:02 AM.


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