Old 04-21-2018, 05:46 AM   #1
inertia
Human being with feelings
 
Join Date: Oct 2013
Posts: 801
Default Pattern capture help

I am trying to write a script to clean up the plugin naming system for all tracks in a Reaper project. I am writing the script in Lua and figuring out everything as I go along but trying to get to grips with the pattern matcher/capture is a bit of a challenge.

I am trying to clean up a list of strings :

VST: VMR (Slate Digital)
VST: FabFilter Pro-C 2 (Mono) (FabFilter)
VST: VMR (Slate Digital)
VST: FabFilter Pro-MB (FabFilter)
VST: StereoChannel (Sleepy-Time Records)
VST: VMR (Slate Digital)
VST: VMR (Slate Digital)

and I basically want to get rid of everything except the plugin name by removing the plugin type (VST: ), retain the name and remove anything in parethesis after.

VMR
FabFilter Pro-C 2
VMR
FabFilter Pro-MB
StereoChannel
VMR
VMR

So far I have

cleanname = string.match(fx_name, ' .*%(')

Which produces the following result :

VMR (
FabFilter Pro-C 2 (Mono) (
VMR (
FabFilter Pro-MB (
StereoChannel (
VMR (
VMR (

So it's nearly there but not good enough. It also seems to be retaining the space after ":"

Lastly, I cannot find any API call to rename the plugin after I have cleaned it.


Any help is appreciated.

Last edited by inertia; 04-21-2018 at 05:51 AM.
inertia is offline   Reply With Quote
Old 04-21-2018, 06:07 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

The aliases are stored in the Reaper folder: reaper-vstplugins64.ini. Changing names in that file (which you could do with io.write) and refreshing the plugin list in Reaper seems to update them fine.

There's also reaper-vstrenames64.ini, but I'm not sure what its purpose is.

As for your pattern, it's doing that because you're telling it "give me any amount of characters followed by a (". You just need to add a "capture" to your pattern - it tells Lua "here's the overall pattern to look for, but I only want this bit of it".

": (.*)%s%("

This says

1. Find a : followed by a space
2. After that, give me as many characters as you can until you...
3. Find a space followed by an opening (


Code:
local names = {
"VST: VMR (Slate Digital)",
"VST: FabFilter Pro-C 2 (Mono) (FabFilter)",
"VST: VMR (Slate Digital)",
"VST: FabFilter Pro-MB (FabFilter)",
"VST: StereoChannel (Sleepy-Time Records)",
"VST: VMR (Slate Digital)",
"VST: VMR (Slate Digital)"
}

for i = 1, #names do
   
    local str = string.match( names[i] , ": (.*)%s%(")
    reaper.ShowConsoleMsg(tostring(str).."\n")    
    
end

-->

VMR
FabFilter Pro-C 2 (Mono)
VMR
FabFilter Pro-MB
StereoChannel
VMR
VMR
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 04-21-2018, 06:23 AM   #3
inertia
Human being with feelings
 
Join Date: Oct 2013
Posts: 801
Default

Thanks for your reply. I am aware that you can rename the plugins in the ini file but this is only partially what I want to achieve.

If this file changes from a rescan or an update to a plugin is installed then I have to redo everything manually in Notepad again at another stage.

Also, cleaning up the ini file too much removes functionality like grouping by company name, which is useful.

The pattern matcher is more what I am looking for but I'd like to remove everything after it finds the first parenthesis. This version still retains (Mono) in the title.

This seems to be the easy bit. It seems much trickier to update the plugin window and rename the FX instances. I haven't found out anything close to that yet.
inertia is offline   Reply With Quote
Old 04-21-2018, 06:32 AM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Change the capture to (.-) and it will look for the first ( instead of the last one.

As for the rest of your idea... I don't think it's possible with the API. An extension could perhaps add some functionality there, but until that happens you're probably out of luck.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 04-21-2018, 06:37 AM   #5
inertia
Human being with feelings
 
Join Date: Oct 2013
Posts: 801
Default

Thanks again,

I found this :

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
end


But it doesn't seem to do anything. I am at the limit on this now and not really sure what that code is actually doing haha.
inertia is offline   Reply With Quote
Old 04-21-2018, 06:41 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

It would just rename the instance of that effect on that track, but the function as written doesn't actually DO that - it copies the track chunk, edits it, and never applies that copy to the track.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 04-21-2018, 06:42 AM   #7
inertia
Human being with feelings
 
Join Date: Oct 2013
Posts: 801
Default

Yeah, I got that working now. I should be able to use this to do what I need.

Thanks again for your help!
inertia is offline   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 11:11 AM.


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