Skip to content

Commit b60f9d8

Browse files
authored
Create BuyOne_Toggle (Un)Bypass input FX for selected tracks.lua (ReaTeam#1065)
1 parent 4ea246b commit b60f9d8

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
--[[
2+
ReaScript name: Toggle (Un)Bypass input FX for selected tracks (27 scripts for various permutations)
3+
Author: BuyOne
4+
Website: https://forum.cockos.com/member.php?u=134058
5+
Version: 1.0
6+
Changelog: Initial release
7+
Licence: WTFPL
8+
REAPER: at least v5.962
9+
About: To complement similar actions of the SWS extension for the track main FX chain.
10+
Supports Monitoring FX if the Master track is selected.
11+
If slots with greater number are required, duplicate the sctipt which
12+
performs the desired action and change the FX slot number in its name.
13+
Toggle scripts affecting all input FX on selected tracks target each FX
14+
individually so their state is reversed independently of the other FX state.
15+
Metapackage: true
16+
Provides: . > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX bypass for selected tracks.lua
17+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX 1 bypass for selected tracks.lua
18+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX 2 bypass for selected tracks.lua
19+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX 3 bypass for selected tracks.lua
20+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX 4 bypass for selected tracks.lua
21+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX for selected tracks.lua
22+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX 1 for selected tracks.lua
23+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX 2 for selected tracks.lua
24+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX 3 for selected tracks.lua
25+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX 4 for selected tracks.lua
26+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX for selected tracks.lua
27+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX 1 for selected tracks.lua
28+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX 2 for selected tracks.lua
29+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX 3 for selected tracks.lua
30+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX 4 for selected tracks.lua
31+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX bypass (except 1) for selected tracks.lua
32+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX bypass (except 2) for selected tracks.lua
33+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX bypass (except 3) for selected tracks.lua
34+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Toggle input FX bypass (except 4) for selected tracks.lua
35+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX (except 1) for selected tracks.lua
36+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX (except 2) for selected tracks.lua
37+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX (except 3) for selected tracks.lua
38+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Bypass input FX (except 4) for selected tracks.lua
39+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX (except 1) for selected tracks.lua
40+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX (except 2) for selected tracks.lua
41+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX (except 3) for selected tracks.lua
42+
. > BuyOne_Toggle (Un)Bypass input FX for selected tracks/BuyOne_Unbypass input FX (except 4) for selected tracks.lua
43+
]]
44+
45+
46+
47+
function Msg(param, cap) -- caption second or none
48+
local cap = cap and type(cap) == 'string' and #cap > 0 and cap..' = ' or ''
49+
reaper.ShowConsoleMsg(cap..tostring(param)..'\n')
50+
end
51+
52+
local r = reaper
53+
54+
function Error_Tooltip(text)
55+
local x, y = r.GetMousePosition()
56+
r.TrackCtl_SetToolTip(text:upper():gsub('.','%0 '), x, y, true) -- spaced out // topmost true
57+
end
58+
59+
local _, scr_name, sect_ID, cmd_ID, _,_,_ = r.get_action_context()
60+
local scr_name = scr_name:match('.+[\\/](.+)%.lua') -- whole script name without path and extension
61+
62+
local fx_idx = scr_name:match('input FX (%d+)') or scr_name:match('%(except (%d+)%)')
63+
local except = scr_name:match('%(except %d+%)')
64+
local toggle = scr_name:match('Toggle input FX')
65+
local unbypass = scr_name:match('Unbypass input FX')
66+
local bypass = scr_name:match('Bypass input FX')
67+
local fx_idx = fx_idx and 0x1000000+tonumber(fx_idx)-1
68+
69+
local tr_cnt = r.CountSelectedTracks2(0, true) -- wantmaster true
70+
71+
local err = tr_cnt == 0 or not toggle and not unbypass and not bypass
72+
73+
if err then
74+
Error_Tooltip(tr_cnt == 0 and '\n\n no selected tracks \n\n' or not toggle and not unbypass and '\n\n invalid script name \n\n')
75+
return r.defer(function() do return end end) end
76+
77+
78+
r.PreventUIRefresh(1)
79+
r.Undo_BeginBlock()
80+
81+
local fx_cnt = 0
82+
83+
for i = 0, tr_cnt-1 do -- wantmaster true
84+
local tr = r.GetSelectedTrack(0,i) or r.GetMasterTrack(0)
85+
if except then
86+
for i = 0, r.TrackFX_GetRecCount(tr)-1 do
87+
fx_cnt = fx_cnt+1
88+
if i+0x1000000 ~= fx_idx then
89+
local state = toggle and not r.TrackFX_GetEnabled(tr, i+0x1000000) or unbypass and true or false
90+
r.TrackFX_SetEnabled(tr, i+0x1000000, state)
91+
end
92+
end
93+
elseif fx_idx then
94+
for i = 0, r.TrackFX_GetRecCount(tr)-1 do
95+
if i+0x1000000 == fx_idx then found = 1 break end
96+
end
97+
if tr_cnt == 1 and not found then Error_Tooltip('\n\n no fx in slot '..(fx_idx-0x1000000+1)..' \n\n') return r.defer(function() do return end end) end
98+
local state = toggle and not r.TrackFX_GetEnabled(tr, fx_idx) or unbypass and true or false -- 'not' is meant to flip the state
99+
r.TrackFX_SetEnabled(tr, fx_idx, state)
100+
else -- all fx
101+
for i = 0, r.TrackFX_GetRecCount(tr)-1 do
102+
fx_cnt = fx_cnt+1
103+
local state = toggle and not r.TrackFX_GetEnabled(tr, i+0x1000000) or unbypass and true or false
104+
r.TrackFX_SetEnabled(tr, i+0x1000000, state)
105+
end
106+
end
107+
end
108+
109+
if fx_cnt == 0 then
110+
Error_Tooltip('\n\n no input fx in selected tracks \n\n')
111+
return r.defer(function() do return end end) end
112+
113+
r.Undo_EndBlock(scr_name, -1)
114+
r.PreventUIRefresh(-1)
115+
116+
117+
118+
119+

0 commit comments

Comments
 (0)