forked from ReaTeam/ReaScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfillion_Toggle visibility of empty non-folder tracks.lua
77 lines (66 loc) · 2.65 KB
/
cfillion_Toggle visibility of empty non-folder tracks.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
-- @description Toggle visibility of empty non-folder tracks
-- @version 1.1
-- @author cfillion
-- @link
-- cfillion.ca https://cfillion.ca/
-- Forum Thread http://forum.cockos.com/showthread.php?t=187651
-- @donation https://www.paypal.me/cfillion
-- @provides
-- [main] .
-- [main] . > cfillion_Toggle visibility of empty non-folder tracks matching '•'.lua
-- @changelog
-- Fixed embarassing typo in the name ('visiblity' -> 'visibility')
-- Added a "matching '•'" variant of the script at the request of blumpy
-- @about
-- # Toggle visibility of empty non-folder tracks
--
-- This script toggles the TCP and MCP visibility of tracks matching all of the
-- following criteria:
--
-- - Track has no FX on it
-- - Track does not contain any media item
-- - Track has no envelopes
-- - Track is not a folder
-- - Track is not record armed
--
-- A variant of the script is provided which additionally requires tracks to
-- contain the character • (bullet) in their name. Custom variants can be
-- created by copying the script with the desired track name search string
-- between the apostrophes in the filename.
local UNDO_STATE_TRACKCFG = 1
local script_name = ({reaper.get_action_context()})[2]:match("([^/\\_]+).lua$")
local empty_tracks, setVisible = {}, 0
local match = script_name:match("matching '([^']+)'")
for ti=0,reaper.CountTracks()-1 do
local track = reaper.GetTrack(0, ti)
local fx_count = reaper.TrackFX_GetCount(track)
local item_count = reaper.CountTrackMediaItems(track)
local env_count = reaper.CountTrackEnvelopes(track)
local depth = reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH")
local is_armed = reaper.GetMediaTrackInfo_Value(track, "I_RECARM")
local name = ({reaper.GetSetMediaTrackInfo_String(track, 'P_NAME', '', false)})[2]
local matches = (function()
if not match or name:find(match) then
return 0
else
return 1
end
end)()
if fx_count + item_count + env_count + math.max(depth, 0) + is_armed + matches == 0 then
local mcpVis = reaper.GetMediaTrackInfo_Value(track, 'B_SHOWINMIXER')
local tcpVis = reaper.GetMediaTrackInfo_Value(track, 'B_SHOWINMIXER')
if mcpVis + tcpVis == 0 then
setVisible = 1
end
table.insert(empty_tracks, track)
end
end
if #empty_tracks == 0 then return reaper.defer(function() end) end
reaper.Undo_BeginBlock()
for i,track in ipairs(empty_tracks) do
reaper.SetMediaTrackInfo_Value(track, 'B_SHOWINMIXER', setVisible)
reaper.SetMediaTrackInfo_Value(track, 'B_SHOWINTCP', setVisible)
end
reaper.Undo_EndBlock(script_name, UNDO_STATE_TRACKCFG)
reaper.TrackList_AdjustWindows(false)
reaper.UpdateArrange()