-- 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
-- Function to get subdirectories of a directory function GetSubdirectories(dir) local subdirs = {} local i = 0 repeat local subdir = reaper.EnumerateSubdirectories(dir, i) if subdir then table.insert(subdirs, dir .. "/" .. subdir) end i = i + 1 until not subdir return subdirs end
function GetFiles(dir) local files = {} local i = 0 repeat local file = reaper.EnumerateFiles(dir, i) if file then table.insert(files, file) end i = i + 1 until not file return files end
function DrawDirectoryTree(dir) if reaper.file_exists(dir) then reaper.ImGui_Text(ctx, "File: " .. dir) return end
-- Check if the directory opens local open = reaper.ImGui_TreeNode(ctx, dir) if open then -- Read directories local subdirs = GetSubdirectories(dir) for _, subdir in ipairs(subdirs) do DrawDirectoryTree(subdir) end -- Read files local files = GetFiles(dir) for _, file in ipairs(files) do if reaper.ImGui_Selectable(ctx, file) then selected = file end end reaper.ImGui_TreePop(ctx) endend
function main()
reaper.ImGui_SetNextWindowDockID(ctx, -7) local retval, is_open = reaper.ImGui_Begin(ctx, "Media Explorer") if retval then -- Create the search bar local search_buf = reaper.ImGui_InputText(ctx, "##search", "") local root_dir = "E:\\Sample Packs\\COLLECTION" -- Change this to your media directory DrawDirectoryTree(root_dir) -- If you want to implement volume knob, autoplay, -- draggable functionalities, you can extend this part. reaper.defer(main) end reaper.ImGui_End(ctx)end
ctx = reaper.ImGui_CreateContext("ctx") main()
what would i have to add to the script to be able to drag an item from the reaimgui window to a track in reaper so that the audio file would be inserted on a track? shortest answer please
- Assistant
To add drag-and-drop functionality so that an audio file can be dragged from the ReaImGui window into a track in REAPER, you would need to make use of ImGui's drag-and-drop API functions. Specifically, you'll want to use
ImGui_BeginDragDropSourceandImGui_BeginDragDropTarget. Here is the shortest way to implement the drag-and-drop functionality into your current script: - User
nice! now give me the functions that handles the drop target and inserts the dragged file into a track
- Assistant
- User
- Assistant
- User
- Assistant
- User
i still can't drag the file into the timeline like i can in a media explorer. why? give me the shortest explanation
- Assistant
The primary reason you can't drag files into the REAPER timeline directly from an ImGui window like you can from the Media Explorer is because the drag-and-drop functionality in the ImGui library doesn't interface directly with REAPER's native drag-and-drop system. This means REAPER doesn't recognize the drag-and-drop operation from the ImGui context as it would from its own Media Explorer or OS file explorer.
Explanation:
-
ImGui Context: The drag-and-drop functionality provided by ImGui operates within the ImGui context. It doesn't communicate with the operating system or the host application's (REAPER's) drag-and-drop mechanisms.
-
- User
is is possible to make them interact? show me how with less than 100 characters
- Assistant
Direct integration isn't feasible within the 100-character limit, but here's the shortest possible functional workaround:
function InsertFileAtCursor(file) reaper.Main_OnCommand(40058, 0) reaper.InsertMedia(file, 0) endThis function approximates the interaction by moving the edit cursor to the mouse position and inserting the media at the cursor. For full drag-and-drop integration, extensive custom implementation beyond scripting capabilities would be required.
- User
ok, give me a bit longer answer
- Assistant
- User
is there a way to do it without the reaimgui drop and drag funcionality?
- Assistant
- User
maybe we can use the drag and drop of the reaimgui if there is something like:
- if i initiate a drag and drop in the reaimgui window, if the reaimgui window isn't hovered and im still holding the left mouse, the focus goes to the reaper main window and the item i selected in the reaimgui window is dropped into the mouse position where i let go of the left click
- Assistant
- User
while trying the drag and drop, i got this when dropping the file into the reaper timeline 73: bad argument #1 to 'InsertMedia' (string expected, got nil)
- Assistant
- User
the draggin and droping into the timeline is not working, give me the solution in less than 500 characters
- Assistant
Sure, here's a concise solution to simulate dragging and dropping from ImGui into REAPER's timeline: