From 73916df9417b21c0e19717d581bcbfcc0f08ffd6 Mon Sep 17 00:00:00 2001 From: amagalma Date: Wed, 3 Jul 2024 12:38:34 +0300 Subject: [PATCH] Release Paste video processor parameter values to focused video FX or to all selected items v1.00 (#1414) --- ...used video FX or to all selected items.lua | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 Video/amagalma_Paste video processor parameter values to focused video FX or to all selected items.lua diff --git a/Video/amagalma_Paste video processor parameter values to focused video FX or to all selected items.lua b/Video/amagalma_Paste video processor parameter values to focused video FX or to all selected items.lua new file mode 100644 index 000000000..0665d2c02 --- /dev/null +++ b/Video/amagalma_Paste video processor parameter values to focused video FX or to all selected items.lua @@ -0,0 +1,178 @@ +-- @description Paste video processor parameter values to focused video FX or to all selected items +-- @author amagalma +-- @version 1.00 +-- @donation https://www.paypal.me/amagalma + + +local ext_state = reaper.GetExtState( "amagalma_copyVideoParameterValues", "values" ) +if ext_state == "" then + reaper.MB( "You haven't copied any video processor parameter values.", "Nothing done!", 0 ) + return +end + +local saved, saved_cnt = {}, 0 +for entry in ext_state:gmatch("[^|]+") do + local name, value = entry:match("([^:]+):([^:]+)") + saved_cnt = saved_cnt + 1 + saved[saved_cnt] = { name = name, val = tonumber(value) } +end + +-------- + +local x, y = reaper.GetMousePosition() +local retval, trackidx, itemidx, takeidx, fxidx, parm = reaper.GetTouchedOrFocusedFX( 1 ) + +if retval then -- work with focused fx_chain + local track = reaper.GetTrack( 0, trackidx ) + if takeidx == -1 then -- track FX + + local _, fx_ident = reaper.TrackFX_GetNamedConfigParm( track, fxidx, "fx_ident" ) + if fx_ident ~= "__builtin_video_processor" then + reaper.MB("The focused FX is not a video processor.", "Nothing done", 0) + return + else + local num_param = reaper.TrackFX_GetNumParams( track, fxidx )-3 + if num_param ~= saved_cnt then + reaper.MB("The focused video FX has a different number of\nparameters than the one that was copied.", "Nothing done", 0) + return + else + for p = 1, num_param do + local _, param_name = reaper.TrackFX_GetParamName( track, fxidx, p-1 ) + if param_name ~= saved[p].name then + reaper.MB("The focused video FX has a different named parameters\nthan the one that was copied.", "Nothing done", 0) + return + end + reaper.Undo_BeginBlock() + reaper.PreventUIRefresh( 1 ) + for p = 0, num_param-1 do + reaper.TrackFX_SetParam( track, fxidx, p, saved[p+1].val ) + end + reaper.PreventUIRefresh( -1 ) + reaper.Undo_EndBlock( "Changed video parameter values", 2 ) + reaper.TrackCtl_SetToolTip( "Pasted values to focused track FX", x, y, true ) + return + end + end + end + else -- ItemFX + local item = reaper.GetTrackMediaItem( track, itemidx ) + local take = reaper.GetTake( item, takeidx ) + local _, fx_ident = reaper.TakeFX_GetNamedConfigParm( take, fxidx, "fx_ident" ) + if fx_ident ~= "__builtin_video_processor" then + reaper.MB("The focused FX is not a video processor.", "Nothing done", 0) + return + else + local num_param = reaper.TakeFX_GetNumParams( take, fxidx )-3 + if num_param ~= saved_cnt then + reaper.MB("The focused video FX has a different number of\nparameters than the one that was copied.", "Nothing done", 0) + return + else + for p = 1, num_param do + local _, param_name = reaper.TakeFX_GetParamName( take, fxidx, p-1 ) + if param_name ~= saved[p].name then + reaper.MB("The focused video FX has a different named parameters\nthan the one that was copied.", "Nothing done", 0) + return + end + reaper.PreventUIRefresh( 1 ) + for p = 0, num_param-1 do + reaper.TakeFX_SetParam( take, fxidx, p, saved[p+1].val ) + end + reaper.PreventUIRefresh( -1 ) + reaper.Undo_OnStateChange_Item( 0, "Changed video parameter values", item ) + reaper.TrackCtl_SetToolTip( "Pasted values to focused take FX", x, y, true ) + return + end + end + end + end +else -- work with selected items + local item_cnt = reaper.CountSelectedMediaItems( 0 ) + if item_cnt == 0 then + reaper.MB("No items selected!", "Nothing done", 0) + return + end + local to_process, to_process_cnt = {}, 0 + for i = 0, item_cnt-1 do + local item = reaper.GetSelectedMediaItem( 0, i ) + local take = reaper.GetActiveTake( item ) + if take then + for fx = 0, reaper.TakeFX_GetCount( take )-1 do + local _, fx_ident = reaper.TakeFX_GetNamedConfigParm( take, fx, "fx_ident" ) + if fx_ident == "__builtin_video_processor" then + local num_param = reaper.TakeFX_GetNumParams( take, fx )-3 + local same_parm_names = true + if num_param == saved_cnt then + for p = 1, num_param do + local _, param_name = reaper.TakeFX_GetParamName( take, fx, p-1 ) + if param_name ~= saved[p].name then + same_parm_names = false + break + end + end + else + same_parm_names = false + end + if same_parm_names then + to_process_cnt = to_process_cnt + 1 + to_process[to_process_cnt] = { take = take, fxid = fx } + end + end + end + -- check if dedicated processor + local source = reaper.GetMediaItemTake_Source( take ) + local source_type = reaper.GetMediaSourceType( source ) + if source_type == "VIDEOEFFECT" then + local parameters, last_param = {} + local _, chunk = reaper.GetItemStateChunk( item, "", false ) + local start_noting = false + local same_parm_names = true + for line in chunk:gmatch("[^\n\r]+") do + if line == "