Advertisement
Guest User

Autorename FX names

a guest
Apr 21st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. function SetFXName(track, fx, new_name)
  2. -- get re
  3. if not track or not tonumber(fx) then return end
  4.  
  5. reaper.ShowConsoleMsg("\n\nplugin "..fx.."\n")
  6.  
  7. reaper.ShowConsoleMsg("new "..new_name.."\n")
  8.  
  9. local FX_GUID = reaper.TrackFX_GetFXGUID( track, tonumber(fx) )
  10.  
  11. if not FX_GUID then return else FX_GUID = FX_GUID:gsub('-',''):sub(2,-2) end
  12.  
  13. reaper.ShowConsoleMsg("FX_GUID "..FX_GUID.."\n")
  14.  
  15. plug_type = reaper.TrackFX_GetIOSize( track, fx )
  16.  
  17. -- get chunk t
  18. local _, chunk = reaper.GetTrackStateChunk( track, '', false )
  19. local t = {} for line in chunk:gmatch("[^\r\n]+") do
  20. t[#t+1] = line
  21.  
  22. reaper.ShowConsoleMsg("RESULT "..line.."\n")
  23. end
  24. -- find edit line
  25.  
  26. for i = #t, 1, -1 do
  27. local t_check = t[i]:gsub('-','')
  28.  
  29. if t_check:find(FX_GUID) then
  30. search = true
  31. -- if search then reaper.ShowConsoleMsg("found\n") end
  32. end
  33.  
  34. if t[i]:find('<') and search and not t[i]:find('JS_SER') then
  35. edited_line = t[i]:sub(2)
  36. edited_line_id = i
  37.  
  38. -- reaper.ShowConsoleMsg("edited_line_id "..edited_line.."\n")
  39.  
  40. break
  41. end
  42. end
  43. -- parse line
  44.  
  45. if not edited_line then return end
  46.  
  47. local t1 = {}
  48. for word in edited_line:gmatch('[%S]+') do
  49. t1[#t1+1] = word
  50. end
  51.  
  52. t2 = {}
  53. for i = 1, #t1 do
  54. segm = t1[i]
  55. if not q then
  56. t2[#t2+1] = segm
  57. else
  58. t2[#t2] = t2[#t2]..' '..segm
  59. end
  60. if segm:find('"') and not segm:find('""') then
  61. if not q then q = true else q = nil end
  62. end
  63. end
  64.  
  65.  
  66. if plug_type == 2 then t2[3] = '"'..new_name..'"' end -- if JS
  67. if plug_type == 3 then t2[5] = '"'..new_name..'"' end -- if VST
  68.  
  69. local out_line = table.concat(t2,' ')
  70.  
  71. reaper.ShowConsoleMsg(out_line.."\n")
  72.  
  73. t[edited_line_id] = '<'..out_line
  74. reaper.SetTrackStateChunk( track, table.concat(t,'\n'), false )
  75. reaper.UpdateArrange()
  76. end
  77.  
  78. function cleanup(name)
  79. newname = name:gsub("_", " ")
  80. return newname
  81. end
  82.  
  83. function sleep(n)
  84. if n > 0 then os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL") end
  85. end
  86.  
  87. reaper.ClearConsole()
  88.  
  89. for i = 1,reaper.CountTracks(0),1
  90. do
  91. track = reaper.GetTrack(0,i-1)
  92.  
  93. for plugin_index = 1,reaper.TrackFX_GetCount(track),1
  94. do
  95. retval, fxname = reaper.TrackFX_GetFXName(track, (plugin_index-1), "")
  96. cleanname = (string.match(cleanup(fxname), ': (.-)%s%('))
  97.  
  98. if cleanname or not cleanname == '' then
  99. SetFXName(track, plugin_index-1, cleanname)
  100. end
  101. reaper.ShowConsoleMsg("\n")
  102. end
  103.  
  104. end
  105.  
  106.  
  107. reaper.ShowConsoleMsg("Finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement