Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

oi

  1. User

    oi

  2. Assistant

    Oi! Como posso te ajudar hoje?

  3. 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

        -- 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
    
        -- 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

    ctx = reaper.ImGui_CreateContext("ctx") main()

  4. Assistant

    Seu código está bem estruturado! Vou adicionar algumas melhorias e completar as partes que estavam faltando, como a funcionalidade de ajuste do volume e a funcionalidade de arrastar e soltar. Abaixo está o código revisado e completo:

    -- 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
    local current_volume = 1.0
    
    -- 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
                
                -- Drag and drop functionality
                if reaper.ImGui_BeginDragDropSource(ctx) then
                    reaper.ImGui_SetDragDropPayload(ctx, "FILE", path .. "/" .. file)
                    reaper.ImGui_Text(ctx, "Dragging " .. file)
                    reaper.ImGui_EndDragDropSource(ctx)
                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)
        reaper.CF_SetPreviewVolume(current_preview, current_volume)
    
        -- 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, reaper.ImGui_Cond_FirstUseEver())
        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
    
            -- Volume knob
            local changed, new_volume = reaper.ImGui_VSliderFloat(ctx, "Volume", 1.0, current_volume, 0.0, 1.0)
            if changed then
                current_volume = new_volume
                if current_preview then
                    reaper.CF_SetPreviewVolume(current_preview, current_volume)
                end
            end
    
            -- Handle dropped files
            if reaper.ImGui_BeginDragDropTarget(ctx) then
                local payload_type, file_path, _ = reaper.ImGui_AcceptDragDropPayload(ctx, "FILE")
                if payload_type == "FILE" then
                    -- Handle file drop into REAPER arrange view
                    reaper.InsertMedia(file_path, 0)
                end
                reaper.ImGui_EndDragDropTarget(ctx)
            end
    
            -- Call the function to create the directory tree and search for files
            create_directory_tree("E:\\Sample Packs\\COLLECTION", 0)
        end
    
        reaper.ImGui_End(ctx)
        reaper.defer(main)
    end
    
    ctx = reaper.ImGui_CreateContext("ctx")
    main()
    

    Melhorias e Funcionalidades Adicionadas:

    • Controle de Volume: Adicionei um controle de volume (VSlider) para ajustar o volume da pré-visualização.
    • Função de Arrastar e Soltar: Implementado drag and drop, permitindo arrastar arquivos para o arrange view do REAPER.
    • Pesquisa: O campo de pesquisa é mantido e atualizado conforme o usuário digita.

    Como Usar:

    1. Cole o código no editor de scripts do REAPER.
    2. Dê play para rodar o script.
    3. Utilize a interface para navegar pelos diretórios, buscar arquivos, pré-visualizar áudios e ajustar o volume, além de arrastar arquivos para o arrange view do REAPER.

    Espero que isso ajude! Se precisar de mais alguma coisa, estou à disposição.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.