Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 02-25-2021, 05:00 AM   #1
bhuether
Human being with feelings
 
Join Date: Nov 2016
Posts: 226
Default Apply FXCHAIN from a template to a track, but don't overwrite existing FX?

Curious if this is readily possible?

I know there are various API calls for dealing with adding named FX, but I am talking about extracting a template's FXCHAIN and applying that to some track, and not overwriting the track's existing FX.

I suppose one way to do that is extract the existing FX, append to it the template's FX, and I can deal with that approach, but really hoping there is a slicker way, especially knowing that these fx strings can be enormous...
bhuether is offline   Reply With Quote
Old 02-25-2021, 06:54 AM   #2
bhuether
Human being with feelings
 
Join Date: Nov 2016
Posts: 226
Default

I see that FXCHAINs tend to start with BYPASS then end with WAKE.

Plus optional project specific COMMENT section before the last WAK line.

So that got me thinking.

Since add by FXName is faster than chunk calls (as I understand), then in lua I suppose once can extract the relevant FX part, and write to tmp file, then just use the tmp file to use add fx by name.

So you could get rid of the COMMENT part, and then get everything later in one string.match anchoring to '$'


Code:
tmplt_fx = tmplt_fx:gsub('[ ]-<CO.->%s-$', '  >')
Now we have straight forward situation where everything is between a BYPASS and final WAK line.

Code:
extractedFX = tmplt_fx:match('%s?BY.-\n[ ]*(.+)\n.-WA.*$')
Then I wonder if I could just do

Code:
fileptr = io.open(sometempfilepath,'w')
fileptr:write(tmplt_fx)
fileptr:close()
at which point I can use the add fx by name calls, then

Code:
os.remove(sometempfilepath)
when I no longer need the file.

Will try it out, but curious what others have found to be efficient way to do this when dealing with massive FXCHAIN chunks...
bhuether is offline   Reply With Quote
Old 02-25-2021, 08:40 AM   #3
bhuether
Human being with feelings
 
Join Date: Nov 2016
Posts: 226
Default

Ok, confirmed this approach works for template files:

Code:
cname='<FXCHAIN[^_]'
p = '  '..cname..'.-\r?\n  >\r?\n'  
bb,ee = string.find(tmplt, p)
if bb then
          tmplt_fx = string.sub(tmplt, bb,ee)
          -- keep FX env but get rid of fx env points
          p="[ ]-PT [^\n]*\n"
          tmplt_fx = tmplt_fx:gsub(p, '')
          tmplt_fx = tmplt_fx:gsub('[ ]-<CO.->%s-$', '  >')
          extractedFX = tmplt_fx:match('%s?(BY.-\n[ ]*(.+)\n.-WAK.-)\n.*$')
          if extractedFX then
            tmpfxfile = fxpath..string.match(os.tmpname(), '[^/]+$')..'.RfxChain'
            fxfileptr=io.open(tmpfxfile, 'w')
            fxfileptr:write(extractedFX)
            fxfileptr:close()
          end
end
given that you have tmplt as result of opening and reading a template file and you have defined fxpath. This results in fxchain file being saved which can readily be applied to a track using add fx by name API call. And of course you can delete the file later.

You could just use string.match instead of string.find to get the FXCHAIN, but I do as above since in my tests with large files find followed by sub got me the FXCHAIN quicker.

But I still think we need more API functions to deal with this sort of thing. Manipulating FX should be a core set of functions.

Note: above works assuming FXCHAIN was in template file, in which case as far as I can tell the opening and closing bracket are always indented by 2 spaces, and no other brackets in the FXCHAIN appear in that manner. When in track chunk as returned by GetTrackStateChunk, all spaces before params are removed, which makes it impossible to extract an FXCHAIN the way I do above, in which case you need to read in loop counting opening, closing brackets, which is not much more difficult, just much slower for large FXCHAINs.
bhuether 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 01:10 PM.


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