Old 10-22-2016, 05:07 AM   #1
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default Pattern matching question

Hi Lua pattern matching experts:

I'm trying to pull out a sequence of characters from the following string but can't get anything to work...

JS Delay/delay_sustain custom
120.000000 -44.000000 10.000000 10.000000 0.000000 0.000000 0.000000 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I'm trying to pull out the bit in bold.

I have tried:

JS.*%/+(.*)%s-

and various variations - but it always returns nil or the entire string from 'delay_sustain custom...'.

any ideas?

Thanks
Leon.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 08:26 AM   #2
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by Veto View Post
It's not a one liner but hey...
PHP Code:
local s="JS Delay/delay_sustain custom\n120.000000 -44.000000 10.000000 10.000000 0.000000 0.000000 0.000000"
local fpath=s:match("JS%s(.-)%s")  -- gets full path of effect
local filename
=fpath:match("([^/]+)$") -- gets filename 
Thanks a lot - will give that a try. Looks better than looping through checking each character against ' ' - which I was going to end up doing :/
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 08:43 AM   #3
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by Veto View Post
It's not a one liner but hey...
PHP Code:
local s="JS Delay/delay_sustain custom\n120.000000 -44.000000 10.000000 10.000000 0.000000 0.000000 0.000000"
local fpath=s:match("JS%s(.-)%s")  -- gets full path of effect
local filename
=fpath:match("([^/]+)$") -- gets filename 
Awesome - worked a treat - and much more elegant than what I was going to do after giving up on the one liner!

Thanks again
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 11:04 AM   #4
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by Veto View Post
IIRC you only had issues with JSFX. So I assumed there is always the "JS " bit.
Is there any check happen before that code?

If not, this would work with all kind of FX's (hopefully):
PHP Code:
local s="BlaFX \"test5 bla.txt\" \"\"\n1.000000 0.000000 20.000000 64.000000 64.000000 0.000000 0.000000 1.000000 3.000000 0.000000 - - - - - "
local s=s:match("%s.*")
local fpath 
if s:sub(2,2)=="\"" then
  fpath
=s:match("%s\"(.-)\"")
else
  
fpath=s:match("%s(.-)%s")
end
filename
=fpath:match("([^/]+)$"
8 lines and still counting
What I got is

local _, fxname = reaper.TrackFX_GetFXName(tr, i, '')
local fxchunk = GetChunkPresetData(chunk, i)
local fxn
if string.sub(fxname,1,3) == 'VST' then
fxn = string.match(fxname, '.*: (.*) %(')
elseif string.sub(fxchunk,1,2) == 'JS' then
fxn = string.match(fxchunk, 'JS.*%/+(.-) "')
if fxn == nil then
fxn = string.match(fxchunk, 'JS%s(.-)%s')
fxn = string.match(fxn, '([^/]+)$')
end
end

as far as i know - there shouldn't be any spaces in the actual filenames - but I could be wrong with user created jsfx. There can be spaces in the renamed FX - so the bit after the jsfx filename might be a space followed by quotes and new name. Why can't it be as simple as VST - which I can just take the bit between 'VST: ' and '(' (from the FXName API) - which seems consistant for all VST's I've got (and I have a large variety).

Arse = no that won't work well with renamed plugs either - so will need to check the fxchunk for that also - but still easier than JS. Should just need to check fxchunk instead of fxname. May as well just get rid of the fxname API bit.

Will try to sort tomorrow.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 11:16 AM   #5
eugen2777
Human being with feelings
 
eugen2777's Avatar
 
Join Date: Aug 2012
Posts: 271
Default

lb0, link
__________________
ReaScripts
eugen2777 is offline   Reply With Quote
Old 10-22-2016, 11:22 AM   #6
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by eugen2777 View Post
lb0, link
Hey - thanks. Will analyse. Quick scan suggests that my pulling out of fx chunk is ok.

I currently have vst successfully read using:

if string.sub(fxchunk,1,3) == 'VST' then
fxn = string.match(fxchunk, '.*: (.-) %(')

(My retrieve FXchunk function omits the < and >)

The VST name is taken from 'VST: ' until the first ' (' which seems to work for all my vsts - including those bridged (x86) ones.

But if that code is more versatile and will work in more cases - I'll look into it.

Thanks again.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 05:27 PM   #7
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by Veto View Post
In my opinion operating on the chunk and the corresponding string processing is always a bit risky (and probably also more inefficient).
Atm your code would fail on AU effects and on renamed non-JSFX's.
I don't know what the code should do exactly, but wouldn't it be possible with GUIDs (TrackFX_GetFXGUID)?

EDIT: Nope my fault, GetChunkPresetData() works as expected.
EDIT2: Just saw your other thread, it would not be possible with GUIDs. So here's my take:
PHP Code:
  local _chunk reaper.GetTrackStateChunk(tr,'',false)
  
local fxchunk GetChunkPresetData(chunki)
  
local fxchunk=fxchunk:match("%s.*")
  
local fxn
  
if fxchunk:sub(2,2)=="\"" then
    fxn
=fxchunk:match("%s\"(.-)\"")
  else
    
fxn=fxchunk:match("%s(.-)%s")
  
end
  fxn
=fxn:match("([^/]+)$"
Thanks - I forgot about AU as I've never used them (always have and always will be windows here).

But if I can get hold of some AU format chunks then should be able to add these assuming they're stored similarly as part of the chunk data.

Basically - what Stripper does when it saves a strip - is store each plugin name (in the format that is required by the TrackFX_AddByName API call) that is required as part of the strip.

I don't want to save any parameter modulation values, learns or anything else like that (as I consider a strip to be just the plugins and their controls on the grid) - so saving the whole track chunk is not what is required - but I do need to import each fx's chunk data so that the preset is loaded exactly as it was when the strip is saved - so the bit pulled by GetChunkPresetData() is required (just the bit between <VST...> or <JS...>).

When a strip is loaded into a new track (or even the same track - remember a strip is free to be used as many times as you like in whatever track) - I use the TrackFX_AddByName API to load an instance of each fx in the strip - then overwrite the preset chunk data for each new fx plug - so things like Nebula etc load up the correct data.

This all works very well so far - it's just been a little awkward handling instances where the fx plugin has been renamed in the fxchain. This is why I need to parse the fxchunk data to get the name required to load a new instance of the plugins. I cannot rely on TrackFX_GetFXName as a renamed plugin returns this new name - which cannot then be used by TrackFX_AddByName.

So I think apart from dealing with AU's - which I'll need help with from someone that uses them, I pretty much have it all working as long as pulling the required FX name for use in reloading the fx gets the correct fx name. - which it does currently in all instances I've tried with the first suggested code you provided earlier.

As mentioned - I haven't yet come across any JS plugins that allow spaces in the plugin name required to load the plug. All spaces are represented by _ or omitted. Of course I don't know if this is a required standard - and all user JSFX plugs will also be like this. Those I've got in my Reaper/Effects folder are fine.

Cheers,
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal

Last edited by lb0; 10-22-2016 at 05:52 PM.
lb0 is offline   Reply With Quote
Old 10-22-2016, 05:38 PM   #8
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by Veto View Post
In my opinion operating on the chunk and the corresponding string processing is always a bit risky (and probably also more inefficient).
Atm your code would fail on AU effects and on renamed non-JSFX's.
I don't know what the code should do exactly, but wouldn't it be possible with GUIDs (TrackFX_GetFXGUID)?

EDIT: Nope my fault, GetChunkPresetData() works as expected.
EDIT2: Just saw your other thread, it would not be possible with GUIDs. So here's my take:
PHP Code:
  local _chunk reaper.GetTrackStateChunk(tr,'',false)
  
local fxchunk GetChunkPresetData(chunki)
  
local fxchunk=fxchunk:match("%s.*")
  
local fxn
  
if fxchunk:sub(2,2)=="\"" then
    fxn
=fxchunk:match("%s\"(.-)\"")
  else
    
fxn=fxchunk:match("%s(.-)%s")
  
end
  fxn
=fxn:match("([^/]+)$"
Also - I'm pretty sure I've fixed the renamed VST name - now reading the name from the chunk <VST: plugin name (other data such as x86 or company name)...>
Here I'm pulling out the bit between the 'VST*: ' up to the first ' (' - this always seems to correspond to the required name for loading the plugin. Works for VSTs VSTi's and VST3's as far as my tests have shown - even when they're renamed as the matching pattern doesn't need to change for these as I'm not needing to read right up to the new plugin name (unlike JSFX).
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 05:46 PM   #9
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Oh - and finally - efficiency is not a key requirement of this bit of code - it is only run when saving or loading a strip - which is unlikely to happen at a time critical point. You'll probably notice that the overall efficiency of my code during EDIT modes is far less than when in LIVE mode. This is because controls can move around - backgrounds can change etc. Whereas in LIVE mode the only changeable parts are the control's values and readouts themselves (which I have optimised as much as is reasonable - although I will always implement new more efficient techniques if I think of any - hence why the drawing routines for the controls have been updated several times).

I don't expect anyone to do any editing during a live performance/mixing scenario - so I don't mind if the code is less efficient (which it will be due to the extra possibilies in edit mode).

Blimey - that was a load of pointless drivel - sorry - but just explaining that I don't feel the efficiency of the load/save strip is that important.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 10-22-2016, 07:15 PM   #10
eugen2777
Human being with feelings
 
eugen2777's Avatar
 
Join Date: Aug 2012
Posts: 271
Default

Lua very effective for the strings, it will not be a problem.
__________________
ReaScripts
eugen2777 is offline   Reply With Quote
Old 10-23-2016, 04:53 PM   #11
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,202
Default

Quote:
Originally Posted by Veto View Post
Hi lb0,

yes a JSFX can include a space in it's name! One of quite a few would be Anomaly's Surround Pan 2. The plugin will not load if restored from any strip.

I can agree on that, when loading a strip, performance don't need to be priority by all means.

Concerning AU's, I figure it has a similar token, my guess would be <AU /bla/bla/pluginName renamedPluginName .....>
or <AU "/bla/bla/plugin Name" "renamed PluginName" .....>

cheers
V
Thanks Veto - you are of course correct as I had a problem with just such a JSFX plug earlier. But it seems all I need to do is take your first two line solution and then check for a trailing " and remove if it's there. So thanks again for your help with this. I'm sure there will be other problems - but we're getting them covered slowly
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 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 08:21 AM.


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