forked from ReaTeam/ReaScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamagalma_Float centered exclusively the previous FX for the current track.lua
145 lines (135 loc) · 4.69 KB
/
amagalma_Float centered exclusively the previous FX for the current track.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-- @description Float centered exclusively the previous FX for the current track
-- @author amagalma
-- @version 1.1
-- @changelog skip offline FX
-- @donation https://www.paypal.me/amagalma
-- @about
-- 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)
--
-- - 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
-- - FX that are offline are skipped
-- - requires JS_ReaScriptAPI
if not reaper.APIExists( "JS_Window_Find" ) then
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 )
local ok, err = reaper.ReaPack_AddSetRepository( "ReaTeam Extensions", "https://github.com/ReaTeam/Extensions/raw/master/index.xml", true, 1 )
if ok then reaper.ReaPack_BrowsePackages( "js_ReaScriptAPI" )
else reaper.MB( err, "Something went wrong...", 0)
end
return reaper.defer(function() end)
end
-- Make sure there is a track
local track = reaper.GetSelectedTrack( 0, 0 ) or reaper.GetLastTouchedTrack()
if not track then return end
function close_tr_fx(tr) -- me2beats function
local fx = reaper.TrackFX_GetCount(tr)
for i = 0,fx-1 do
if reaper.TrackFX_GetOpen(tr, i) then
reaper.TrackFX_SetOpen(tr, i, 0)
end
if reaper.TrackFX_GetChainVisible(tr)~=-1 then
reaper.TrackFX_Show(tr, 0, 0)
end
end
local rec_fx, i_rec = reaper.TrackFX_GetRecCount(tr)
for i = 0,rec_fx-1 do
i_rec = i+16777216
if reaper.TrackFX_GetOpen(tr, i_rec) then
reaper.TrackFX_SetOpen(tr, i_rec, 0)
end
if reaper.TrackFX_GetRecChainVisible(tr)~=-1 then
reaper.TrackFX_Show(tr, i_rec, 0)
end
end
end
function close_tk_fx(tk) -- me2beats function
if not tk then return end
local fx = reaper.TakeFX_GetCount(tk)
for i = 0,fx-1 do
if reaper.TakeFX_GetOpen(tk, i) then
reaper.TakeFX_SetOpen(tk, i, 0)
end
if reaper.TakeFX_GetChainVisible(tk)~=-1 then
reaper.TakeFX_Show(tk, 0, 0)
end
end
end
function previous_fx(tr)
local fx_cnt = reaper.TrackFX_GetCount(tr)
local current = 0
for i = 0, fx_cnt-1 do
if reaper.TrackFX_GetOpen(tr, i) then
reaper.TrackFX_SetOpen(tr, i, 0)
current = i
end
end
current = current == 0 and fx_cnt-1 or current - 1
local times = 0
while reaper.TrackFX_GetOffline( tr, current ) do
times = times + 1
current = current == 0 and fx_cnt-1 or current - 1
if times == fx_cnt then
current = -1
break
end
end
if current == -1 then
reaper.TrackFX_Show( tr, 0, 1 )
return false
else
reaper.TrackFX_Show( tr, current, 3 )
return true
end
end
------- MAIN FUNCTION ---------
reaper.Undo_BeginBlock()
reaper.PreventUIRefresh( 1 )
local fx_cnt = reaper.TrackFX_GetCount( track )
local success
if fx_cnt > 0 then
--close all other fx windows
local tracks = reaper.CountTracks()
for i = 0, tracks do
local tr = reaper.CSurf_TrackFromID( i, false )
if tr ~= track then
close_tr_fx(tr)
else
success = previous_fx(tr)
end
local tr_items = reaper.CountTrackMediaItems(tr)
for j = 0, tr_items-1 do
local tr_item = reaper.GetTrackMediaItem(tr, j)
local takes = reaper.GetMediaItemNumTakes(tr_item)
for k = 0, takes-1 do
close_tk_fx(reaper.GetTake(tr_item,k))
end
end
end
-- Center floating FX
local hwnd
if not success then
if track == reaper.GetMasterTrack( 0 ) then
hwnd = reaper.JS_Window_Find( "FX: Master Track", true )
else
hwnd = reaper.JS_Window_Find( "FX: Track " .. reaper.CSurf_TrackToID( track, false ), true )
end
else
if track == reaper.GetMasterTrack( 0 ) then
hwnd = reaper.JS_Window_Find( " - Master Track [", false )
else
for i = 0, fx_cnt-1 do
hwnd = reaper.TrackFX_GetFloatingWindow( track, i )
if hwnd then break end
end
end
end
local _, width, height = reaper.JS_Window_GetClientSize( hwnd ) -- Get floating FX size
local _, _, scrw, scrh = reaper.my_getViewport(0, 0, 0, 0, 0, 0, 0, 0, 0) -- Get screen size
reaper.JS_Window_Move( hwnd, math.floor((scrw-width)/2), math.floor((scrh-height)/2) )
if not success then
reaper.MB( "All FX are offline for this track.", "Cannot navigate to previous FX!", 0 )
end
else -- open FX Chain to add FX
reaper.Main_OnCommand(40291, 0) -- Track: View FX chain for current/last touched track
end
reaper.PreventUIRefresh( -1 )
reaper.Undo_EndBlock("Float centered exclusively the previous FX for current track", 2)