write me a script that
- User
write me a script that
- Assistant
Of course! I can help you write a script. To give you the best assistance, could you please specify what kind of script you need?
Here are a few examples of what you might be looking for:
- A short film or movie script
- A stage play script
- A script for a YouTube video or a vlog
- A script for a podcast episode
- A Python or other programming language script
Please provide the details and any specific requirements or themes you have in mind!
- User
-- 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
-- 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
-- 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) endend
function main() reaper.ImGui_SetNextWindowDockID(ctx, -7) local retval, is_open = reaper.ImGui_Begin(ctx, "Media Explorer", true)
if is_open then -- Search input box local changed, text = reaper.ImGui_InputText(ctx, "Search", search_query, 256) if changed then search_query = text end -- Adjust the indentation spacing -- Call the function to create the directory tree and search for files create_directory_tree("E:\\Sample Packs\\COLLECTION", 0) reaper.defer(main) end reaper.ImGui_End(ctx)end
- Assistant
Certainly! Below is a complete script that integrates with Reaper's Lua API and ImgGui for the search functionality you're aiming for. This script allows the user to explore and search through a directory of audio files, then preview them within Reaper.
-- Ensure the ReaImGui extension is installed in your Reaper setup if not reaper.APIExists("ImGui_CreateContext") then reaper.ShowMessageBox("ReaImGui extension not found. Please install it and try again.", "Error", 0) return end -- Create an ImGui context ctx = reaper.ImGui_CreateContext('Media Explorer') -- Variables for search functionality local search_query = "" local current_preview = nil -- 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 -- 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 end end -- 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 -- 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 end function main() reaper.ImGui_SetNextWindowDockID(ctx, -7) local retval, is_open = reaper.ImGui_Begin(ctx, "Media Explorer", true) if is_open then -- Search input box local changed, text = reaper.ImGui_InputText(ctx, "Search", search_query, 256) if changed then search_query = text end -- Call the function to create the directory tree and search for files create_directory_tree("E:\\Sample Packs\\COLLECTION", 0) reaper.defer(main) end reaper.ImGui_End(ctx) end -- Run the main function reaper.defer(main)Make sure you have the ReaImGui extension installed in your Reaper environment as this script depends on that. This script will create a UI window using ImGui and allow you to explore the directory specified ("E:\Sample Packs\COLLECTION") and preview audio files matching the query entered in the search box. Adjust the path according to your file structure.