Skip to content

Commit cbf882a

Browse files
authored
Update BuyOne_Load FX chain on selected objects via file dialogue (guide inside).lua (ReaTeam#1053)
* Update BuyOne_Load FX chain on selected objects via file dialogue (guide inside).lua * Update BuyOne_Load FX chain on selected objects via file dialogue (guide inside).lua * Update BuyOne_Load FX chain on selected objects via file dialogue (guide inside).lua * Update BuyOne_Load FX chain on selected objects via file dialogue (guide inside).lua
1 parent e4b657b commit cbf882a

File tree

1 file changed

+207
-74
lines changed

1 file changed

+207
-74
lines changed

Diff for: FX/BuyOne_Load FX chain on selected objects via file dialogue (guide inside).lua

+207-74
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
ReaScript name: Load FX chain on selected objects via file dialogue (guide inside)
33
Author: BuyOne
44
Website: https://forum.cockos.com/member.php?u=134058
5-
Version: 1.0
6-
Changelog: Initial release
5+
Version: 1.1
6+
Changelog: #Added a setting for custom FXChains folder
7+
#Fixed breaking plugin parameter link
78
About:
8-
Allows loading selected FX chain on selected objects. Detailed description is available inside the script.
99
10+
Allows loading selected FX chain on selected objects.
11+
12+
The script had been developed before the option to add FX and FX chain preset
13+
to multiple tracks/takes at once was introduced in REAPER build 6.12c.
14+
Still the script expands on this native feature in that it allows adding FX chain
15+
preset to tracks and takes and to track main and input/Monitoring FX chain
16+
in one go. It also provides a setting for configuring custom FXChains folder
17+
different from the default one located in the REAPER resourse directory.
18+
1019
* By default the script works in add/replace mode adding FX chain to selected
1120
objects which don't have any and replacing current FX chain in those which do.
1221
@@ -20,8 +29,11 @@ About:
2029
2130
* The USER SETTINGS options TRACK_MAIN_FX, TRACK_INPUT_MON_FX, TAKE_FX allow to
2231
enable/disable loading FX chain as a particular FX chain type.
32+
33+
* The USER SETTINGS option CUSTOM_FX_CHAIN_DIR allows using a custom FXChains
34+
folder as a primary location for loading FX chain presets.
2335
24-
* If item has several takes the FX chain is only applied to the selected one.
36+
* If an item has several takes the FX chain is only applied to the active one.
2537
2638
* To include Monitor FX chain in selected objects select Master track. Be aware
2739
that if TRACK_MAIN_FX option is enabled the same FX chain will also be loaded
@@ -40,15 +52,20 @@ Extensions: SWS/S&M (not obligatory but recommended)
4052
------------------------------ USER SETTINGS --------------------------------
4153
-----------------------------------------------------------------------------
4254

43-
-- To disable any of the options remove the character between the quotation
44-
-- marks next to it.
55+
-- Insert full path to your custom FXChains folder between the double square
56+
-- brackets;
57+
-- if empty or malformed REAPER's default FXChains folder will be used
58+
CUSTOM_FX_CHAIN_DIR = [[]]
59+
60+
-- To disable any of the following options remove the character between
61+
-- the quotation marks next to it.
4562
-- Conversely, to enable one place any alphanumeric character between those.
4663
-- Try to not leave empty spaces.
4764

48-
DIALOGUE = "" -- choose mode of operation at runtime when ADD_APPEND is enabled
49-
ADD_APPEND = "" -- add/append mode instead of add/replace
65+
DIALOGUE = "1" -- choose mode of operation at runtime when ADD_APPEND is enabled
66+
ADD_APPEND = "1" -- add/append mode instead of add/replace
5067
TRACK_MAIN_FX = "1" -- load as track main FX chain
51-
TRACK_INPUT_MON_FX = "1" -- load as track input FX and Master track Monitor FX chains
68+
TRACK_INPUT_MON_FX = "" -- load as track input FX and Master track Monitor FX chains
5269
TAKE_FX = "1" -- load as take FX chain
5370

5471
-----------------------------------------------------------------------------
@@ -63,6 +80,25 @@ end
6380

6481
local r = reaper
6582

83+
-- Validate path supplied in the user settings
84+
function Validate_Folder_Path(path) -- returns empty string if path is empty and nil if it's not a string
85+
if type(path) == 'string' then
86+
local path = path:match('^%s*(.-)%s*$') -- remove leading/trailing spaces
87+
-- return not path:match('.+[\\/]$') and path:match('[\\/]') and path..path:match('[\\/]') or path -- add last separator if none
88+
-- more efficient:
89+
return path..(not path:match('.+[\\/]$') and path:match('[\\/]') or '') -- add last separator if none
90+
end
91+
end
92+
93+
function Dir_Exists(path) -- short
94+
local path = path:match('^%s*(.-)%s*$') -- remove leading/trailing spaces
95+
local sep = path:match('[\\/]')
96+
local path = path:match('.+[\\/]$') and path:sub(1,-2) or path -- last separator is removed to return 1 (valid)
97+
local _, mess = io.open(path)
98+
return mess:match('Permission denied') and path..sep -- dir exists // this one is enough
99+
end
100+
101+
66102
local function GetObjChunk(retval, obj)
67103
-- https://forum.cockos.com/showthread.php?t=193686
68104
-- https://raw.githubusercontent.com/EUGEN27771/ReaScripts_Test/master/Functions/FXChain
@@ -71,7 +107,7 @@ local function GetObjChunk(retval, obj)
71107
-- Try standard function -----
72108
local t = retval == 1 and {r.GetTrackStateChunk(obj, '', false)} or {r.GetItemStateChunk(obj, '', false)} -- isundo = false
73109
local ret, obj_chunk = table.unpack(t)
74-
if ret and obj_chunk and #obj_chunk > 4194303 and not r.APIExists('SNM_CreateFastString') then return 'err_mess'
110+
if ret and obj_chunk and #obj_chunk >= 4194303 and not r.APIExists('SNM_CreateFastString') then return 'err_mess'
75111
elseif ret and obj_chunk and #obj_chunk < 4194303 then return ret, obj_chunk -- 4194303 bytes = (4096 kb * 1024 bytes) - 1 byte
76112
end
77113
-- If chunk_size >= max_size, use wdl fast string --
@@ -100,12 +136,108 @@ local function SetObjChunk(retval, obj, obj_chunk)
100136
end
101137

102138

103-
local function UpdateTempTrackChunk(tr_chunk, fx_ch_chunk)
139+
function Error_Tooltip(text)
140+
local x, y = r.GetMousePosition()
141+
--r.TrackCtl_SetToolTip(text:upper(), x, y, true) -- topmost true
142+
r.TrackCtl_SetToolTip(text:upper():gsub('.','%0 '), x, y, true) -- spaced out // topmost true
143+
end
144+
145+
146+
local function UpdateTrackMainFXChainChunk(tr_chunk, fx_ch_chunk, ADD_APPEND) -- track main fx
147+
148+
local fx_chunk = tr_chunk:match('(<FXCHAIN.-DOCKED%s%d)\n>') or -- residual data after main fx chain is deleted
149+
tr_chunk:match('<FXCHAIN\n.-(BYPASS.-)\n<FXCHAIN_REC') or -- main fx and input fx; FXCHAIN\n- excludes input fx section name, here and elsewhere
150+
tr_chunk:match('<FXCHAIN\n.-(BYPASS.-)\n<ITEM') or -- main fx, no input fx but items
151+
tr_chunk:match('<FXCHAIN\n.-(BYPASS.-)\n>\n$') or -- main fx, no input fx & no items; \n$ accounts for trailing empty line
152+
tr_chunk:match('(<TRACK.-)\n<FXCHAIN_REC') or -- no main fx but input fx
153+
tr_chunk:match('(<TRACK.-)\n<ITEM') or -- neither main fx nor input fx but items
154+
tr_chunk:match('(<TRACK.-)\n>\n<TRACK') or -- neither fx nor items
155+
tr_chunk:match('(<TRACK.-)\n>') -- neither fx nor items and last track
156+
-- OR
157+
-- tr_chunk:sub(1,-4) -- 4 because the chunk is returned with trailing empty line, so 1 = \n, 2 = >, 3 = \n and 4 = last character on the last track chunk line before >
158+
local fx_chunk_orig = fx_chunk:gsub('[%(%)%+%-%[%]%.%^%$%*%?%%]','%%%0')
159+
local fx_ch_chunk1 = fx_ch_chunk:gsub('%%','%%%%')..'\n>' -- ADD_REPLACE
160+
161+
if ADD_APPEND then
162+
local fx_ch_chunk = fx_chunk:match('<FXCHAIN_REC') and fx_chunk:match('(BYPASS.*WAK[%s%d]*)\n>\n<FXCHAIN_REC')..fx_ch_chunk..'\n>' or (fx_chunk:match('BYPASS') and fx_chunk:match('(BYPASS.*WAK[%s%d]*)[\n>]*')..fx_ch_chunk..'\n>' or fx_ch_chunk)
163+
fx_ch_chunk1 = fx_ch_chunk:gsub('%%','%%%%')
164+
end
165+
166+
local fx_ch_chunk2 = (fx_chunk..'\n'..fx_ch_chunk):gsub('%%','%%%%')
167+
local fx_ch_chunk3 = (fx_chunk..'\n<FXCHAIN\n'..fx_ch_chunk..'\n>'):gsub('%%','%%%%')
168+
local tr_chunk = fx_chunk:match('BYPASS') and tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk1) or fx_chunk:match('FXCHAIN') and tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk2) or ((fx_chunk:match('<TRACK') and tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk3)))
169+
170+
return tr_chunk
171+
172+
end
173+
174+
175+
function UpdateTrackInputFXChainChunk(tr_chunk, fx_ch_chunk, ADD_APPEND) -- track input fx
176+
177+
local fx_chunk = tr_chunk:match('<FXCHAIN_REC.-(BYPASS.-)\n<ITEM') or -- input fx and items
178+
tr_chunk:match('<FXCHAIN_REC.-(BYPASS.-)\n>\n$') or -- input fx & no items; \n$ accounts for trailing empty line
179+
tr_chunk:match('(<TRACK.-)[\n>]*\n<ITEM') or -- no input fx and items, accounting for main fx
180+
tr_chunk:match('(<TRACK.-)\n>[\n>]*\n$') -- neither input fx nor items, accounting for main fx incl. residual data after main fx chain is deleted
181+
local fx_chunk_orig = fx_chunk:gsub('[%(%)%+%-%[%]%.%^%$%*%?%%]','%%%0')
182+
local fx_ch_chunk1 = fx_ch_chunk:gsub('%%','%%%%')..'\n>' -- ADD_REPLACE
183+
184+
if ADD_APPEND then
185+
local fx_ch_chunk = (fx_chunk:match('BYPASS') and not fx_chunk:match('TRACK')) and fx_chunk:match('(BYPASS.*WAK[%s%d]*)[\n>]*')..fx_ch_chunk..'\n>' or fx_ch_chunk
186+
fx_ch_chunk1 = fx_ch_chunk:gsub('%%','%%%%')
187+
end
188+
189+
local closure1 = fx_chunk:match('<FXCHAIN\n') and '\n>' or ''
190+
local closure2 = closure1 == '\n>' and '' or '\n>'
191+
local fx_ch_chunk2 = (fx_chunk..closure1..'\n<FXCHAIN_REC\n'..fx_ch_chunk..closure2):gsub('%%','%%%%')
192+
local tr_chunk = not fx_chunk:match('TRACK') and tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk1) or tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk2)
193+
194+
return tr_chunk
195+
196+
end
197+
198+
199+
function UpdateMasterTrackFXChainChunk(tr_chunk, fx_ch_chunk, ADD_APPEND) -- Master track fx
200+
201+
local fx_chunk = tr_chunk:match('<FXCHAIN.-(BYPASS.*WAK[%s%d]*)\n>') or -- fx chain; \n$ accounts for trailing empty line
202+
tr_chunk:match('<FXCHAIN\n(.-)\n>\n$') or -- residual data after fx chain is deleted; \n$ accounts for trailing empty line
203+
tr_chunk:sub(1,-4) -- no fx chain and no residual fx chain but other data or no other data; 4 because the chunk is returned with trailing empty line, so 1 = \n, 2 = >, 3 = \n and 4 = last character on the last track chunk line before >
204+
205+
local fx_chunk_orig = fx_chunk:gsub('[%(%)%+%-%[%]%.%^%$%*%?%%]','%%%0')
206+
local fx_ch_chunk1 = fx_ch_chunk:gsub('%%','%%%%')..'\n>'
207+
208+
if ADD_APPEND then
209+
local fx_ch_chunk = fx_chunk:match('BYPASS') and fx_chunk..fx_ch_chunk..'\n>' or fx_ch_chunk
210+
fx_ch_chunk1 = fx_ch_chunk:gsub('%%','%%%%')
211+
end
212+
213+
local fx_ch_chunk2 = (fx_chunk..'\n<FXCHAIN\n'..fx_ch_chunk..'\n>'):gsub('%%','%%%%')
214+
local tr_chunk = fx_chunk:match('BYPASS') and tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk1) or tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk2)
215+
216+
return tr_chunk
217+
218+
end
219+
220+
221+
function UpdateTakeFXChainChunk(item_chunk, take_GUID, fx_ch_chunk, ADD_APPEND) -- take fx
222+
223+
local fx_chunk = item_chunk:match('('..take_GUID..'.-)\nTAKE') or -- there's next take
224+
item_chunk:match('('..take_GUID..'.*)') -- there's no next take
104225

105-
local fx_chunk = tr_chunk:match('(<TRACK.-)\n>')
106226
local fx_chunk_orig = fx_chunk:gsub('[%(%)%+%-%[%]%.%^%$%*%?%%]','%%%0')
107-
local fx_ch_chunk = (fx_chunk..'\n<FXCHAIN\n'..fx_ch_chunk..'\n>'):gsub('%%','%%%%')
108-
return tr_chunk:gsub(fx_chunk_orig, fx_ch_chunk)
227+
local fx_ch_chunk_1 = fx_ch_chunk:gsub('%%','%%%%') -- to be used when there're take fx
228+
229+
if ADD_APPEND then
230+
fx_ch_chunk_1 = fx_chunk:match('BYPASS') and (fx_chunk:match('BYPASS.*WAK[%s%d]-')..fx_ch_chunk):gsub('%%','%%%%')
231+
end
232+
233+
local fx_ch_chunk_2 = (fx_chunk:match(take_GUID..'.->')..'\n<TAKEFX\n'..fx_ch_chunk..'>'):gsub('%%','%%%%') -- to be used when there're no take fx
234+
local upd_fx_chunk = fx_chunk:match('BYPASS') and fx_chunk:gsub('BYPASS.*WAK[%s%d]-', fx_ch_chunk_1) or
235+
fx_chunk:gsub(take_GUID..'.->', fx_ch_chunk_2)
236+
237+
local upd_fx_chunk = upd_fx_chunk:gsub('%%','%%%%')
238+
local item_chunk = item_chunk:gsub(fx_chunk_orig, upd_fx_chunk)
239+
240+
return item_chunk
109241

110242
end
111243

@@ -115,7 +247,7 @@ local ADD_APPEND = ADD_APPEND:gsub('[%s]','') ~= ''
115247
local TRACK_MAIN_FX = TRACK_MAIN_FX:gsub('[%s]','') ~= ''
116248
local TRACK_INPUT_MON_FX = TRACK_INPUT_MON_FX:gsub('[%s]','') ~= ''
117249
local TAKE_FX = TAKE_FX:gsub('[%s]','') ~= ''
118-
250+
local CUSTOM_FX_CHAIN_DIR = #CUSTOM_FX_CHAIN_DIR:gsub('[%s]','') > 0 and CUSTOM_FX_CHAIN_DIR
119251

120252
local sel_trk_cnt = r.CountSelectedTracks2(0,true) -- incl. Master
121253
local sel_itms_cnt = r.CountSelectedMediaItems(0)
@@ -129,8 +261,14 @@ local sel_itms_cnt = r.CountSelectedMediaItems(0)
129261
local path = reaper.GetResourcePath()
130262
local sep = r.GetOS():match('Win') and '\\' or '/'
131263

264+
local fx_chain_dir = CUSTOM_FX_CHAIN_DIR and Dir_Exists(Validate_Folder_Path(CUSTOM_FX_CHAIN_DIR)) or path..sep..'FXChains'..sep
265+
266+
if CUSTOM_FX_CHAIN_DIR and fx_chain_dir == path..sep..'FXChains'..sep then
267+
Error_Tooltip('\n\n custom fx chain \n\n directory isn\'t valid \n\n opening default directory \n\n')
268+
end
269+
132270
::RETRY::
133-
local retval, file = r.GetUserFileNameForRead(path..sep..'FXChains'..sep, 'Select and load FX chain', '.RfxChain')
271+
local retval, file = r.GetUserFileNameForRead(fx_chain_dir, 'Select and load FX chain', '.RfxChain')
134272
if not retval then r.defer(function() end) return end
135273
if not file:match('%.RfxChain$') then resp = r.MB(' The selected file desn\'t\n\n appear to be an FX chain.\n\n Click "OK" to retry.','ERROR',1)
136274
if resp == 1 then goto RETRY
@@ -141,7 +279,7 @@ local retval, file = r.GetUserFileNameForRead(path..sep..'FXChains'..sep, 'Selec
141279
local file = io.open(file, 'r')
142280
local fx_ch_chunk = file:read('*a')
143281
file:close()
144-
if fx_ch_chunk == '' then resp = r.MB('The FX chain file is empty.\n\n Click "OK" to retry.','ERROR',1)
282+
if fx_ch_chunk == '' then resp = r.MB('The FX chain file is empty.\n\nClick "OK" to retry.','ERROR',1)
145283
if resp == 1 then goto RETRY
146284
else r.defer(function() end) return end
147285
end
@@ -153,72 +291,69 @@ file:close()
153291
end
154292

155293
r.PreventUIRefresh(1)
156-
157-
-- Insert temp track an load FX chain to it
158-
159-
r.InsertTrackAtIndex(r.GetNumTracks(), false) -- insert new track at the end of track list and hide it
160-
local temp_track = r.GetTrack(0,r.CountTracks(0)-1)
161-
r.SetMediaTrackInfo_Value(temp_track, 'B_SHOWINMIXER', 0)
162-
r.SetMediaTrackInfo_Value(temp_track, 'B_SHOWINTCP', 0)
163-
-- load FX chain on the temp track
164-
local ret, tr_chunk = GetObjChunk(1, temp_track)
165-
if ret == 'err_mess' then Err_mess() r.defer(function() end) return end
166-
local tr_chunk = UpdateTempTrackChunk(tr_chunk, fx_ch_chunk)
167-
SetObjChunk(1, temp_track, tr_chunk)
168-
169294
r.Undo_BeginBlock()
170295

171-
-- Copy FX from the temp track to selected objects
172-
173296
if sel_trk_cnt > 0 then
174297
for i = 0, sel_trk_cnt-1 do
175-
local tr = r.GetSelectedTrack(0,i) or r.GetMasterTrack(0)
176-
local fx_cnt = r.TrackFX_GetRecCount(tr)
177-
if TRACK_MAIN_FX then
178-
if not ADD_APPEND then
179-
for i = fx_cnt-1,0,-1 do -- delete all fx
180-
r.TrackFX_Delete(tr, i)
298+
local tr = r.GetSelectedTrack(0,i) or r.GetMasterTrack(0) -- or r.GetSelectedTrack2(0,i,1) -- incl. Master
299+
local ret, tr_chunk = GetObjChunk(1, tr)
300+
if ret == 'err_mess' then Err_mess() r.defer(function() end) return -- if chunk size limit is exceeded
301+
elseif ret and tr_chunk ~= '' then
302+
-- extract main fx chunk
303+
if reaper.CSurf_TrackToID(tr, true) ~= 0 then -- if not Master track
304+
if TRACK_MAIN_FX then -- track main fx chain
305+
tr_chunk = UpdateTrackMainFXChainChunk(tr_chunk, fx_ch_chunk, ADD_APPEND)
181306
end
182-
end
183-
for i = 0, r.TrackFX_GetCount(temp_track)-1 do -- copy fx from temp track to mon fx chain
184-
local dest_idx = ADD_APPEND and i+fx_cnt or i
185-
r.TrackFX_CopyToTrack(temp_track, i, tr, dest_idx, false)
186-
end
187-
end
188-
if TRACK_INPUT_MON_FX then
189-
local fx_cnt = r.TrackFX_GetRecCount(tr)
190-
if not ADD_APPEND then
191-
for i = fx_cnt-1,0,-1 do -- delete all input/monitor fx
192-
r.TrackFX_Delete(tr, i+0x1000000) -- or i+16777216
307+
if TRACK_INPUT_MON_FX then -- track input fx chain
308+
tr_chunk = UpdateTrackInputFXChainChunk(tr_chunk, fx_ch_chunk, ADD_APPEND)
309+
end
310+
-- Master track
311+
elseif r.CSurf_TrackToID(tr, true) == 0 then -- if Master track
312+
if TRACK_MAIN_FX then -- Master track main fx
313+
tr_chunk = UpdateMasterTrackFXChainChunk(tr_chunk, fx_ch_chunk, ADD_APPEND)
314+
end
315+
if TRACK_INPUT_MON_FX then -- monitor fx chain
316+
r.InsertTrackAtIndex(r.GetNumTracks(), false) -- insert new track at the end of track list and hide it
317+
local temp_track = r.GetTrack(0,r.CountTracks(0)-1)
318+
r.SetMediaTrackInfo_Value(temp_track, 'B_SHOWINMIXER', 0)
319+
r.SetMediaTrackInfo_Value(temp_track, 'B_SHOWINTCP', 0)
320+
-- insert FX chain on the temp track
321+
local ret, tr_chunk = GetObjChunk(1, temp_track)
322+
local tr_chunk = UpdateTrackMainFXChainChunk(tr_chunk, fx_ch_chunk)
323+
SetObjChunk(1, temp_track, tr_chunk)
324+
local mon_fx_cnt = r.TrackFX_GetRecCount(tr)
325+
local mon_fx_vis = r.TrackFX_GetRecChainVisible(tr)
326+
if not ADD_APPEND then
327+
for i = mon_fx_cnt-1,0,-1 do -- delete all mon fx
328+
r.TrackFX_Delete(tr, i+0x1000000) -- or i+16777216
329+
end
330+
end
331+
for i = 0, r.TrackFX_GetCount(temp_track)-1 do -- copy fx from temp track to mon fx chain
332+
local dest_idx = ADD_APPEND and i+mon_fx_cnt or i
333+
r.TrackFX_CopyToTrack(temp_track, i, tr, dest_idx+0x1000000, false) -- or i+16777216
334+
end
335+
r.DeleteTrack(temp_track)
336+
-- a crude means to update mon fx button coloration from grey to either green or red as it fails to update automatically
337+
r.TrackFX_Show(tr, 0x1000000, 1)
338+
r.TrackFX_Show(tr, 0x1000000, 0)
339+
local reopen_mon_fx = mon_fx_vis >= 0 and r.TrackFX_Show(tr, mon_fx_vis, 1)
193340
end
194341
end
195-
for i = 0, r.TrackFX_GetCount(temp_track)-1 do -- copy fx from temp track to mon fx chain
196-
local dest_idx = ADD_APPEND and i+fx_cnt or i
197-
r.TrackFX_CopyToTrack(temp_track, i, tr, dest_idx+0x1000000, false) -- or i+16777216
198-
end
199-
-- a crude means to update mon fx button coloration from grey to either green or red as it fails to update automatically
200-
if reaper.CSurf_TrackToID(tr, true) == 0 then -- if Master track and so Minitor FX chain
201-
local mon_fx_vis = r.TrackFX_GetRecChainVisible(tr) -- get index of fx open in the mon fx chain to reopen after update below
202-
r.TrackFX_Show(tr, 0x1000000, 1)
203-
r.TrackFX_Show(tr, 0x1000000, 0)
204-
local reopen_mon_fx = mon_fx_vis >= 0 and r.TrackFX_Show(tr, mon_fx_vis, 1)
205-
end
206-
end
207-
end
342+
local ret = SetObjChunk(1, tr, tr_chunk)
343+
end -- chunk ret cond end
344+
end -- track loop end
208345
end
209346

210347
if sel_itms_cnt > 0 and TAKE_FX then
211348
for i = 0, sel_itms_cnt-1 do
212-
local take = r.GetActiveTake(r.GetSelectedMediaItem(0,i))
213-
local fx_cnt = r.TakeFX_GetCount(take)
214-
if not ADD_APPEND then
215-
for i = fx_cnt-1,0,-1 do -- delete all fx
216-
r.TakeFX_Delete(take, i)
217-
end
218-
end
219-
for i = 0, r.TrackFX_GetCount(temp_track)-1 do -- copy fx from temp track to mon fx chain
220-
local dest_idx = ADD_APPEND and i+fx_cnt or i
221-
r.TrackFX_CopyToTake(temp_track, i, take, dest_idx, false)
349+
local item = r.GetSelectedMediaItem(0,i)
350+
local ret, item_chunk = GetObjChunk(2, item)
351+
if ret == 'err_mess' then Err_mess() r.defer(function() end) return -- if chunk size limit is exceeded
352+
elseif ret and item_chunk ~= '' then
353+
local take = r.GetActiveTake(item)
354+
local take_GUID = select(2,r.GetSetMediaItemTakeInfo_String(take, 'GUID', '', false)):gsub('[%-]','%%%0')
355+
local item_chunk = UpdateTakeFXChainChunk(item_chunk, take_GUID, fx_ch_chunk, ADD_APPEND)
356+
local ret = SetObjChunk(2, item, item_chunk)
222357
end
223358
end
224359
end
@@ -232,8 +367,6 @@ r.Undo_BeginBlock()
232367

233368
r.Undo_EndBlock(undo,-1)
234369

235-
r.DeleteTrack(temp_track)
236370
r.PreventUIRefresh(-1)
237371

238372

239-

0 commit comments

Comments
 (0)