From 5204d3b1df83c41efb0c5c4ed73f026b5cf389cd Mon Sep 17 00:00:00 2001 From: cfillion Date: Thu, 22 Jun 2017 04:39:12 -0400 Subject: [PATCH] release toggle visibility of empty non-folder tracks v1.1 --- ... visibility of empty non-folder tracks.lua | 77 +++++++++++++++++++ ...e visiblity of empty non-folder tracks.lua | 44 ----------- 2 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 Tracks Properties/cfillion_Toggle visibility of empty non-folder tracks.lua delete mode 100644 Tracks Properties/cfillion_Toggle visiblity of empty non-folder tracks.lua diff --git a/Tracks Properties/cfillion_Toggle visibility of empty non-folder tracks.lua b/Tracks Properties/cfillion_Toggle visibility of empty non-folder tracks.lua new file mode 100644 index 000000000..68b65d77c --- /dev/null +++ b/Tracks Properties/cfillion_Toggle visibility of empty non-folder tracks.lua @@ -0,0 +1,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() diff --git a/Tracks Properties/cfillion_Toggle visiblity of empty non-folder tracks.lua b/Tracks Properties/cfillion_Toggle visiblity of empty non-folder tracks.lua deleted file mode 100644 index 5417caa0f..000000000 --- a/Tracks Properties/cfillion_Toggle visiblity of empty non-folder tracks.lua +++ /dev/null @@ -1,44 +0,0 @@ --- @description Toggle visiblity of empty non-folder tracks --- @version 1.0 --- @author cfillion --- @link Forum Thread http://forum.cockos.com/showthread.php?t=187651 --- @donation https://www.paypal.me/cfillion - -local UNDO_STATE_TRACKCFG = 1 -local empty_tracks, setVisible = {}, 0 - -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") - - if fx_count + item_count + env_count + math.max(depth, 0) + is_armed == 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 - -local pointName = ({reaper.get_action_context()})[2]:match('([^/\\_]+).lua$') -reaper.Undo_EndBlock(pointName, UNDO_STATE_TRACKCFG) - -reaper.TrackList_AdjustWindows(false) -reaper.UpdateArrange()