Skip to content

Instantly share code, notes, and snippets.

@mumblequatch
Last active May 26, 2026 23:32
Show Gist options
  • Select an option

  • Save mumblequatch/f415d8b91086ccac67c638d2c0c191b7 to your computer and use it in GitHub Desktop.

Select an option

Save mumblequatch/f415d8b91086ccac67c638d2c0c191b7 to your computer and use it in GitHub Desktop.
Reaper: delete empty tracks that nothing depends on
-- Delete tracks that are empty and have no dependencies.
-- Skips tracks that:
-- * contain media items
-- * are folder parents (would orphan children)
-- * receive sends from other tracks
-- * have any visible envelope with points
local r = reaper
local function track_has_envelope_points(track)
local env_count = r.CountTrackEnvelopes(track)
for i = 0, env_count - 1 do
local env = r.GetTrackEnvelope(track, i)
if r.CountEnvelopePoints(env) > 0 then return true end
end
return false
end
local function track_is_deletable(track)
if r.CountTrackMediaItems(track) > 0 then return false end
if r.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") == 1 then return false end
if r.GetTrackNumSends(track, -1) > 0 then return false end
if track_has_envelope_points(track) then return false end
return true
end
r.Undo_BeginBlock()
r.PreventUIRefresh(1)
local deleted = 0
local total = r.CountTracks(0)
for i = total - 1, 0, -1 do
local track = r.GetTrack(0, i)
if track and track_is_deletable(track) then
r.DeleteTrack(track)
deleted = deleted + 1
end
end
r.PreventUIRefresh(-1)
r.TrackList_AdjustWindows(false)
r.UpdateArrange()
r.Undo_EndBlock("Delete empty tracks with no dependencies", -1)
r.ShowMessageBox(("Deleted %d empty track(s)."):format(deleted), "Delete Empty Tracks", 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment