Skip to content

Commit a92c94e

Browse files
authored
Release Float centered exclusively the previous FX for the current track v1.1 (ReaTeam#476)
skip offline FX
1 parent c8a90a1 commit a92c94e

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

Diff for: FX/amagalma_Float centered exclusively the previous FX for the current track.lua

+56-37
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
--[[
2-
ReaScript Name: Float centered exclusively the previous FX for the current track
3-
Version: 1.0
4-
Author: amagalma
5-
About:
6-
Closes all open floating FX and FX chains and floats centered in the screen the previous FX for the current track (first selected or last touched)
1+
-- @description Float centered exclusively the previous FX for the current track
2+
-- @author amagalma
3+
-- @version 1.1
4+
-- @changelog skip offline FX
5+
-- @donation https://www.paypal.me/amagalma
6+
-- @about
7+
-- Closes all open floating FX and FX chains and floats centered in the screen the previous FX for the current track (first selected or last touched)
8+
--
9+
-- - works similarly to "SWS/S&M: Float next FX (and close others) for selected tracks" but centers correctly the Master FX and works with last touched track too
10+
-- - FX that are offline are skipped
11+
-- - requires JS_ReaScriptAPI
712

8-
- works similarly to "SWS/S&M: Float next FX (and close others) for selected tracks" but centers correctly the Master FX and works with last touched track too
9-
- requires JS_ReaScriptAPI
10-
--]]
11-
--------------------------------------------------------------------------------------
1213

13-
14-
local reaper = reaper
15-
16-
17-
-- Check if JS_ReaScriptAPI is installed
18-
if not reaper.APIExists("JS_ReaScriptAPI_Version") then
19-
local answer = reaper.MB( "You have to install JS_ReaScriptAPI for this script to work. Would you like to open the relative web page in your browser?", "JS_ReaScriptAPI not installed", 4 )
20-
if answer == 6 then
21-
local url = "https://forum.cockos.com/showthread.php?t=212174"
22-
if string.match(reaper.GetOS(), "OSX" ) == "OSX" then
23-
os.execute('open "" "' .. url .. '"')
24-
else
25-
os.execute('start "" "' .. url .. '"')
26-
end
14+
if not reaper.APIExists( "JS_Window_Find" ) then
15+
reaper.MB( "Please, right-click and install 'js_ReaScriptAPI: API functions for ReaScripts'. Then restart Reaper and run the script again. Thanks!", "You need to install the JS_ReaScriptAPI", 0 )
16+
local ok, err = reaper.ReaPack_AddSetRepository( "ReaTeam Extensions", "https://github.com/ReaTeam/Extensions/raw/master/index.xml", true, 1 )
17+
if ok then reaper.ReaPack_BrowsePackages( "js_ReaScriptAPI" )
18+
else reaper.MB( err, "Something went wrong...", 0)
2719
end
28-
return
20+
return reaper.defer(function() end)
2921
end
3022

3123

@@ -78,24 +70,40 @@ function previous_fx(tr)
7870
current = i
7971
end
8072
end
81-
if current == 0 then current = fx_cnt end
82-
reaper.TrackFX_Show( tr, current-1, 3 )
73+
current = current == 0 and fx_cnt-1 or current - 1
74+
local times = 0
75+
while reaper.TrackFX_GetOffline( tr, current ) do
76+
times = times + 1
77+
current = current == 0 and fx_cnt-1 or current - 1
78+
if times == fx_cnt then
79+
current = -1
80+
break
81+
end
82+
end
83+
if current == -1 then
84+
reaper.TrackFX_Show( tr, 0, 1 )
85+
return false
86+
else
87+
reaper.TrackFX_Show( tr, current, 3 )
88+
return true
89+
end
8390
end
8491

8592
------- MAIN FUNCTION ---------
8693

8794
reaper.Undo_BeginBlock()
8895
reaper.PreventUIRefresh( 1 )
8996
local fx_cnt = reaper.TrackFX_GetCount( track )
97+
local success
9098
if fx_cnt > 0 then
9199
--close all other fx windows
92100
local tracks = reaper.CountTracks()
93-
for i = 0, tracks-1 do
94-
local tr = reaper.GetTrack(0,i)
101+
for i = 0, tracks do
102+
local tr = reaper.CSurf_TrackFromID( i, false )
95103
if tr ~= track then
96104
close_tr_fx(tr)
97105
else
98-
previous_fx(tr)
106+
success = previous_fx(tr)
99107
end
100108
local tr_items = reaper.CountTrackMediaItems(tr)
101109
for j = 0, tr_items-1 do
@@ -108,17 +116,28 @@ if fx_cnt > 0 then
108116
end
109117
-- Center floating FX
110118
local hwnd
111-
if track == reaper.GetMasterTrack( 0 ) then
112-
hwnd = reaper.JS_Window_Find( " - Master Track [", false )
113-
else
114-
for i = 0, fx_cnt-1 do
115-
hwnd = reaper.TrackFX_GetFloatingWindow( track, i )
116-
if hwnd then break end
119+
if not success then
120+
if track == reaper.GetMasterTrack( 0 ) then
121+
hwnd = reaper.JS_Window_Find( "FX: Master Track", true )
122+
else
123+
hwnd = reaper.JS_Window_Find( "FX: Track " .. reaper.CSurf_TrackToID( track, false ), true )
124+
end
125+
else
126+
if track == reaper.GetMasterTrack( 0 ) then
127+
hwnd = reaper.JS_Window_Find( " - Master Track [", false )
128+
else
129+
for i = 0, fx_cnt-1 do
130+
hwnd = reaper.TrackFX_GetFloatingWindow( track, i )
131+
if hwnd then break end
132+
end
133+
end
117134
end
118-
end
119135
local _, width, height = reaper.JS_Window_GetClientSize( hwnd ) -- Get floating FX size
120136
local _, _, scrw, scrh = reaper.my_getViewport(0, 0, 0, 0, 0, 0, 0, 0, 0) -- Get screen size
121137
reaper.JS_Window_Move( hwnd, math.floor((scrw-width)/2), math.floor((scrh-height)/2) )
138+
if not success then
139+
reaper.MB( "All FX are offline for this track.", "Cannot navigate to previous FX!", 0 )
140+
end
122141
else -- open FX Chain to add FX
123142
reaper.Main_OnCommand(40291, 0) -- Track: View FX chain for current/last touched track
124143
end

0 commit comments

Comments
 (0)