/
TJF Folder State Testing.lua
105 lines (66 loc) · 2.72 KB
/
TJF Folder State Testing.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
function Msg(param) reaper.ShowConsoleMsg(tostring(param).."\n") end
function ParentChildren(track)
local count = reaper.CountTracks(0)
local track = reaper.GetSelectedTrack(0,0)
local depth = reaper.GetTrackDepth(track)
local parent
if reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") == 1
then parent = track
elseif depth > 0 then parent = reaper.GetParentTrack(track)
else return false
end
if parent then
local parentdepth = reaper.GetTrackDepth(parent)
local parentnumber = reaper.GetMediaTrackInfo_Value(parent, "IP_TRACKNUMBER")
local number = parentnumber
depth = depth + 1
local children = {}
i=1
while depth ~= parentdepth and number <= reaper.CountTracks(0) do
track = reaper.GetTrack(0,number)
if track then
depth = reaper.GetTrackDepth(track)
children[i] = track
number = number + 1
i = i + 1
else depth = parentdepth
end
end--while
return parent, children
end--if
end--ParentChildrenTrackF
function GetVisibility(tracks)
for i=1, #tracks do
if not reaper.IsTrackVisible( tracks[i], false ) then return false end
end--for
return true
end--GetVisibilityKids()
function SetVisibility(tracks, bool)
for i=1, #tracks do
reaper.SetMediaTrackInfo_Value( tracks[i], "B_SHOWINTCP", bool )
end--for
end -- SetVisibility
function Main()
reaper.ClearConsole()
local parent, kids = ParentChildren(reaper.GetSelectedTrack(0,0))
if parent then
local compacted = reaper.GetMediaTrackInfo_Value(parent, "I_FOLDERCOMPACT")
if compacted ~= 2 then
reaper.SetMediaTrackInfo_Value(parent, "I_FOLDERCOMPACT", 2)
SetVisibility(kids, 1)
else
hide = GetVisibility(kids)
if hide then
SetVisibility(kids, 0)
else
SetVisibility(kids, 1)
reaper.SetMediaTrackInfo_Value(parent, "I_FOLDERCOMPACT", 0)
end
end--if
--local hide = GetVisibility(kids)
--SetVisibility(kids, hide)
reaper.SetOnlyTrackSelected(parent )
end--if
reaper.TrackList_AdjustWindows(0) -- Updates the window view (used when resizing tracks)
end--Main()
Main()