-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggle_folder_track.lua
50 lines (37 loc) · 1.53 KB
/
toggle_folder_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
local function main()
local track = reaper.GetSelectedTrack(0, 0)
-- check is track is a folder
if reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") == 1 then
reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(-1)
local newState = ToggleState(track)
local _, name = reaper.GetTrackName(track)
local stateName
if newState then stateName = 'expanded' else stateName = 'collapsed' end
reaper.PreventUIRefresh(0)
reaper.TrackList_AdjustWindows(false)
reaper.Undo_EndBlock("Folder track '" .. name .. "' " .. stateName, 1)
end
end
function ToggleState(parent)
local folder = 'folder.png'
local _, iconCurrent = reaper.GetSetMediaTrackInfo_String(parent, "P_ICON", folder, false)
if not iconCurrent or iconCurrent == "" then return end
local isCollapsed = iconCurrent == folder
local _, iconCached = reaper.GetSetMediaTrackInfo_String(parent, "P_EXT:ORIGINAL_ICON", "", false)
if isCollapsed then
if not iconCached or iconCached == "" then return end
else
-- cache original icon
reaper.GetSetMediaTrackInfo_String(parent, "P_EXT:ORIGINAL_ICON", iconCurrent, true)
end
-- change icon for track
local newIcon
if isCollapsed then newIcon = iconCached else newIcon = folder end
reaper.GetSetMediaTrackInfo_String(parent, "P_ICON", newIcon, true)
-- return new state
return isCollapsed
end
function SetTrackVisibility(track)
end
main()