Skip to content

Commit a1053c9

Browse files
authored
Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua (ReaTeam#1174)
* Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua * Update BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua
1 parent c3d92f0 commit a1053c9

File tree

1 file changed

+87
-19
lines changed

1 file changed

+87
-19
lines changed

FX/BuyOne_Update FX chain at object selection when one FX window at a time enabled.lua

+87-19
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,49 @@
22
ReaScript name: Update FX chain at object selection when one FX window at a time enabled
33
Author: BuyOne
44
Website: https://forum.cockos.com/member.php?u=134058
5-
Version: 1.2
6-
Changelog: #Added option to prevent updating a docked FX chain when the docker is closed
5+
Version: 1.3
6+
Changelog: #Added support for empty FX chains as a new setting
7+
#Added support for ignoring selection if no FX chain window is open, as a new setting
8+
#Added a setting to ignore track FX chains
9+
#Added a setting to prefer open track FX chain and prevent replacing it with take FX chain
10+
#Fixed bug of inability to close Master/Monitoring FX chains
711
Licence: WTFPL
812
REAPER: at least v5.962
13+
Extensions: jsReaScriptAPI recommended
914
Screenshots: https://git.io/JXjO6
10-
About: REAPER stock preferences allow changing open FX chain on track selection when options
15+
About: REAPER stock preferences allow changing open FX chain on track selection when options
1116
"Only allow one FX chain window open at a time" and "Open track FX window on track
1217
selection change" are enabled at Preferences -> Plug-ins. But they only affect track
13-
main FX chain. This sctript additionally covers track input/Monitoring FX chains and
18+
main FX chain. This script additionally covers track input/Monitoring FX chains and
1419
take FX chain.
20+
1521
Meant to be used only when the option "Only allow one FX chain window open at a time"
1622
is enabled at Preferences -> Plug-ins in a global FX chain kind of setup.
1723
Normally when option "Only allow one FX chain window open at a time" is enabled,
1824
to update currently open FX chain window with another FX chain, FX button must be
1925
clicked on the TCP or on the item.
26+
2027
This script makes this a bit simpler by allowing to update the window with object
2128
selection, which requires less precision than clicking the tiny FX buttons,
22-
besides ensuring that the FX chain is readily accessible.
29+
besides ensuring that the FX chain is readily accessible.
30+
31+
The script doesn't interfere with the option "Open track FX window on track
32+
selection change", it affects track FX chains regardless of whether it's enabled
33+
unless IGNORE_TRACKS setting is enabled in the USER SETTINGS and on top of that
34+
it supports Master, Monitor and input FX chains.
35+
2336
For best experience FX chain window should be docked, but the updating will work
2437
just as good with a floating FX chain window.
38+
2539
To use it in a docker it's usually sufficient to dock any FX chain window,
2640
the rest will stay docked automatically, yet sometimes adjustment of a few
2741
individual FX windows may be required.
42+
2843
Active take FX chain is always loaded at item selection. The type of track FX chain
2944
to be loaded at track selection is determined by the USER SETTING below, but
3045
you'll still be able to load track FX chain of the other type normally by clicking
3146
FX button of the corresponding track.
47+
3248
The currently open FX chain window can be temporarily closed with a click on FX button
3349
or a by closing its tab in the docker, until another object is selected.
3450
Clicking FX button is also a way to re-open a closed FX chain of the same selected
@@ -42,17 +58,16 @@ About: REAPER stock preferences allow changing open FX chain on track selection
4258
FX chain window always becomes focused when updated, which means that if
4359
it's docked and open but not active (hidden) in a tabbed docker it will
4460
become active (visible), if it's docked in a closed docker the docker will
45-
open, and if it's floating it will come in front of other windows.
61+
open, and if it's floating it will come in front of other windows.
4662
4763
When FX chain changes in a docker it flickers because one is closed and another
4864
is opened. This is REAPER's behavior which can't be controlled with a script.
4965
5066
The FX chain of the last selected track which stays selected, can be re-opened
51-
with a click on the TCP after the FX chain was replaced with take FX chain,
52-
however not vice versa. In order to re-open take FX chain of the last selected
67+
with a click on the TCP after the FX chain was replaced with a take FX chain,
68+
however not vice versa. In order to re-open a take FX chain of the last selected
5369
item/active take after it was replaced with a track FX chain such item must be
5470
deselected and selected again.
55-
5671
]]
5772

5873
-----------------------------------------------------------------------------
@@ -65,21 +80,50 @@ About: REAPER stock preferences allow changing open FX chain on track selection
6580
-- otherwise track main FX chain (incl. Master track FX chain) -- default
6681
TRACK_FX_CHAIN = ""
6782

83+
-- Enable to make the script ignore track FX chains entirely;
84+
-- in this case TRACK_FX_CHAIN setting above will be ignored
85+
-- and track FX chains will only load at track selection
86+
-- if the setting "Open track FX window on track selection change"
87+
-- is enabled at Preferences -> Plug-ins
88+
IGNORE_TRACKS = ""
89+
90+
-- If enabled, currently open track FX chain will get priority
91+
-- and item selection won't replace it with take FX chain;
92+
-- the setting applies regardless of the above settings;
93+
-- if js_ReaScriptAPI extension is not installed and RESPECT_EMPTY_FX_CHAINS
94+
-- setting is enabled below, this setting won't apply to open
95+
-- empty track FX chains
96+
PREFER_OPEN_TRACK_CHAIN = ""
97+
6898
-- To be able to also load take FX chain on item selection,
6999
-- only active take FX chain in a multi-take item can be loaded
70100
TAKE_FX_CHAIN = "1"
71101

102+
-- Switch to FX chain of selected object
103+
-- even if its FX chain is empty
104+
RESPECT_EMPTY_FX_CHAINS = ""
105+
72106
-- If enabled, FX chain window can be updated by change in selection performed
73-
-- by means other than mouse click
107+
-- by means other than mouse click,
108+
-- e.g. with actions 'Track: Go to next/previous track',
109+
-- 'Item navigation: Select and move to next/previous item'
110+
-- 'Item navigation: Select and move to item in next/previous track'
74111
CHANGE_IN_SELECTION_CHANGES_FOCUS = ""
75112

76113
-- To only have FX chain updated when the docker is open,
77-
-- meant to prevent opening and updating a docked FX chain window
114+
-- meant to prevent opening and updating a docked FX chain window
78115
-- when the docker is closed
79116
-- will affect floating FX chain window as well
80117
-- so only useful when one is docked
81118
ONLY_WHEN_DOCKER_OPEN = ""
82119

120+
-- Enable to make the script only update FX chain if FX chain window
121+
-- is already open, and ignore object selection if none is open;
122+
-- if js_ReaScriptAPI extension is not installed and RESPECT_EMPTY_FX_CHAINS
123+
-- setting is enabled above, the script will only update FX chain
124+
-- on object selection if currently open chain isn't empty
125+
ONLY_WHEN_FX_CHAIN_OPEN = ""
126+
83127
-----------------------------------------------------------------------------
84128
-------------------------- END OF USER SETTINGS -----------------------------
85129
-----------------------------------------------------------------------------
@@ -104,15 +148,37 @@ f:close()
104148
return cont:match(key..'=(%d+)')
105149
end
106150

151+
152+
function GetMonFXProps() -- get mon fx accounting for floating window, reaper.GetFocusedFX() doesn't detect mon fx in builds prior to 6.20
153+
154+
-- r.TrackFX_GetOpen(master_tr, integer fx)
155+
local master_tr = r.GetMasterTrack(0)
156+
local src_mon_fx_idx = r.TrackFX_GetRecChainVisible(master_tr)
157+
local is_mon_fx_float
158+
if src_mon_fx_idx < 0 then -- fx chain closed or no focused fx -- if this condition is removed floated fx gets priority
159+
for i = 0, r.TrackFX_GetRecCount(master_tr) do
160+
if r.TrackFX_GetFloatingWindow(master_tr, 0x1000000+i) then
161+
src_mon_fx_idx = i; is_mon_fx_float = true break end
162+
end
163+
end
164+
return src_mon_fx_idx, is_mon_fx_float
165+
end
166+
167+
107168
-- Thanks to mespotine for figuring out config variables
108169
-- https://github.com/mespotine/ultraschall-and-reaper-docs/blob/master/Docs/Reaper-ConfigVariables-Documentation.txt
109170

110171
if Check_reaper_ini('fxfloat_focus')&2 == 0 then r.MB(space(6)..'The script only makes sense when option\n\n"Only allow one FX chain window open at a time"\n\n'..space(9)..'is enabled at Preferences -> Plug-ins', 'ERROR',0)
111-
return r.defer(function() if not bla then return end end) end
172+
return r.defer(function() if not bla then return end end) end
112173

113174
main_ch = #TRACK_FX_CHAIN:gsub(' ','') == 0
175+
ignore_tr = #IGNORE_TRACKS:gsub(' ','') > 0
176+
pref_open_tr_ch = #PREFER_OPEN_TRACK_CHAIN:gsub(' ','') > 0
114177
take_ch = #TAKE_FX_CHAIN:gsub(' ','') > 0
178+
empty_ch = #RESPECT_EMPTY_FX_CHAINS:gsub(' ','') > 0
115179
change_focus = #CHANGE_IN_SELECTION_CHANGES_FOCUS:gsub(' ','') > 0
180+
chain_op = #ONLY_WHEN_FX_CHAIN_OPEN:gsub(' ','') > 0
181+
jsAPI = r.APIExists('JS_Window_Find')
116182

117183
local init_tr
118184
local init_take = r.GetSelectedMediaItem(0,0) and r.GetActiveTake(r.GetSelectedMediaItem(0,0)) -- ensures that track selection gets priority and there's no competition between track and take fx chains of selected objects when the script is launched because act_take ~= init_take condition won't be true
@@ -131,20 +197,22 @@ local act_take = item and r.GetActiveTake(item)
131197
local curr_ctx = r.GetCursorContext()
132198
local curr_ctx = change_focus and sel_tr ~= init_tr and r.SetCursorContext(0)
133199
or change_focus and act_take ~= init_take and r.SetCursorContext(1) or curr_ctx
134-
135-
if sel_tr and (sel_tr ~= init_tr or curr_ctx ~= init_ctx) and curr_ctx == 0 -- curr_ctx ~= init_ctx makes sure track and take fx chains can be switched even if object selection hasn't changed
200+
local chain_op = chain_op and (r.GetFocusedFX() > 0 or GetMonFXProps() >= 0 or jsAPI and r.JS_Window_GetTitle(r.JS_Window_Find('FX: ', false)):match('FX: [ItemMonigsTrack]+')) or not chain_op -- empty FX chains are ignored by GetFocusedFX() so have to be detected via window props search
201+
local pref_open_tr_ch = pref_open_tr_ch and (r.GetFocusedFX() == 1 or GetMonFXProps() >= 0 or jsAPI and r.JS_Window_GetTitle(r.JS_Window_Find('FX: ', false)):match('FX: [TrackMonigste]+')) -- see prev comment
202+
203+
if not ignore_tr and sel_tr and (sel_tr ~= init_tr or curr_ctx ~= init_ctx) and curr_ctx == 0 and DOCKER_STATE and chain_op -- curr_ctx ~= init_ctx makes sure track and take fx chains can be switched even if object selection hasn't changed
136204
then
137-
local master, track -- specifically declared, otherwise empty fx chains get opened, because the vars become global and don't depend on the below condition any longer
138-
if main_ch and r.TrackFX_GetCount(sel_tr) > 0 then
205+
local master, track -- specifically declared, otherwise empty fx chains get opened even if not enabled, because the vars become global and don't depend on the below condition any longer
206+
if main_ch and (empty_ch or not empty_ch and r.TrackFX_GetCount(sel_tr) > 0) then
139207
master, track = 40846, 40291 -- Track: View FX chain for master track / Track: View FX chain for current/last touched track
140-
elseif r.TrackFX_GetRecCount(sel_tr) > 0 then
208+
elseif not main_ch and (empty_ch or not empty_ch and r.TrackFX_GetRecCount(sel_tr) > 0) then
141209
master, track = 41882, 40844 -- View: Show monitoring FX chain / Track: View input FX chain for current/last touched track
142210
end
143211
local upd = master and tr_name[2] == 'MASTER' and r.Main_OnCommand(master,0) or track and r.Main_OnCommand(track,0)
144212
init_tr = sel_tr
145213
init_ctx = curr_ctx
146214
end
147-
if take_ch and act_take and act_take ~= init_take and r.TakeFX_GetCount(act_take) > 0 and curr_ctx == 1 -- curr_ctx ~= init_ctx condition isn't used so take FX chain doesn't compete with track FX chain completely preventing it from loading in tabbed dock layout
215+
if not pref_open_tr_ch and take_ch and act_take and act_take ~= init_take and (empty_ch or not empty_ch and r.TakeFX_GetCount(act_take) > 0) and curr_ctx == 1 and DOCKER_STATE and chain_op -- curr_ctx ~= init_ctx condition isn't used so take FX chain doesn't compete with track FX chain completely preventing it from loading in tabbed dock layout
148216
then
149217
r.Main_OnCommand(40638,0) -- Item: Show FX chain for item take
150218
init_take = act_take
@@ -153,7 +221,7 @@ or change_focus and act_take ~= init_take and r.SetCursorContext(1) or curr_ctx
153221

154222
if r.CountSelectedMediaItems(0) == 0 then init_take = nil end -- reset, ensures that FX chain of the last selected item can be re-opened after the item was deselected and selected again
155223
--[needed when curr_ctx ~= init_ctx isn't used as a condition to switch to take fx chain since it's commented out in the track fx chain selection routine to prevent auto-switching to take fx chain in tabbed docker layout]
156-
if r.CountSelectedTracks(0) == 0 then init_tr = nil end -- reset, ensures that FX chain of the last selected track can be re-opened after the track was deselected and selected again
224+
if r.CountSelectedTracks2(0, true) == 0 then init_tr = nil end -- wantmaster true; reset, ensures that FX chain of the last selected track can be re-opened after the track was deselected and selected again;
157225

158226
r.defer(UPDATE_FX_CHAIN)
159227

0 commit comments

Comments
 (0)