Last active
May 8, 2020 01:14
-
-
Save cfillion/5bc9c2b50ca399eb5d3798ca8afd9211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @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