-- Rykord - ImGui Media Explorer -- folders are represented as tree nodes -- items are…
- User
-- Rykord - ImGui Media Explorer
-- folders are represented as tree nodes -- items are selectables -- play functionality with volume knob and autoplay -- drag and drop functionalities -- drop to the arrange view (priority) -- drop to the media explorer -- search bar functionality
-- Store the reference to the currently playing preview local current_preview = nil
-- Variables for search functionality local search_query = ""
-- Function to create a directory tree and search for files recursively function create_directory_tree(path, depth) -- Enumerate subdirectories and files local idx = 0 while true do local file = reaper.EnumerateFiles(path, idx) if not file then break end
code-- Check if the file matches the search query if (file:match("%.wav$") or file:match("%.mp3$")) and (search_query == "" or file:lower():find(search_query:lower(), 1, true)) then if reaper.ImGui_Selectable(ctx, file) then -- Preview the selected file preview_file(path .. "/" .. file) end end idx = idx + 1 end -- Enumerate subdirectories idx = 0 while true do local subdir = reaper.EnumerateSubdirectories(path, idx) if not subdir then break end local full_path = path .. "/" .. subdir if reaper.ImGui_TreeNode(ctx, subdir) then create_directory_tree(full_path, depth + 1) reaper.ImGui_TreePop(ctx) end idx = idx + 1 endend
-- Function to preview a selected file within Reaper function preview_file(file) -- Stop any currently playing preview if current_preview then reaper.CF_Preview_StopAll() current_preview = nil end
code-- Create a PCM_Source from the file local source = reaper.PCM_Source_CreateFromFile(file) -- Create a preview object current_preview = reaper.CF_CreatePreview(source) -- Start the preview local play_success = reaper.CF_Preview_Play(current_preview) if not play_success then reaper.ShowMessageBox("Failed to play preview: " .. file, "Error", 0) end - Assistant
To achieve this, you can modify the
create_directory_treefunction to check if there are any files in the folder that match the search query before displaying the folder as a tree node. Here's an updated version of the function that implements this logic:lua