Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfillion/5bc9c2b50ca399eb5d3798ca8afd9211 to your computer and use it in GitHub Desktop.
Save cfillion/5bc9c2b50ca399eb5d3798ca8afd9211 to your computer and use it in GitHub Desktop.
-- @version 0.2beta
-- @author cfillion
local RECURSIVE = false
local NESTED_RULES = {
['folder level 1'] = {
['folder level 2'] = {
'track to select',
},
},
}
function deepSearch(rules, trackIndex, depth)
while true do
local track = reaper.GetTrack(nil, trackIndex)
if not track then return trackIndex end
local trackDepth = track and reaper.GetTrackDepth(track)
if trackDepth < depth then return trackIndex end
local trackDepthChange = reaper.GetMediaTrackInfo_Value(track, 'I_FOLDERDEPTH')
local trackName = ({reaper.GetSetMediaTrackInfo_String(track, 'P_NAME', '', false)})[2]
trackIndex = trackIndex + 1
if trackDepth == depth then
for ruleKey, ruleValue in pairs(rules) do
if type(ruleKey) == 'string' and trackDepthChange == 1 and trackName:match(ruleKey) then
trackIndex = deepSearch(ruleValue, trackIndex, trackDepth + 1)
elseif type(ruleKey) == 'number' then
if trackName:match(ruleValue) then
reaper.SetTrackSelected(track, true)
end
end
end
elseif RECURSIVE then
deepSearch(NESTED_RULES, trackIndex - 1, trackDepth)
end
end
end
reaper.PreventUIRefresh(1)
deepSearch(NESTED_RULES, 0, 0)
reaper.PreventUIRefresh(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment