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

function Loop() local txt = " " local retval, tracknumber, fxnumber, paramnumber =…

  1. User

    function Loop() local txt = " " local retval, tracknumber, fxnumber, paramnumber = reaper.GetLastTouchedFX() if retval then if (tracknumber >> 16) == 0 then -- Track FX or Input FX local track = reaper.CSurf_TrackFromID(tracknumber, false) local _, track_name = reaper.GetTrackName(track) if tracknumber == 0 then track_name = 'Master Track' else track_name = ''..tostring(tracknumber)..' | '..track_name end local _, fx_name = reaper.TrackFX_GetFXName(track, fxnumber, "") local _, param_name = reaper.TrackFX_GetParamName(track, fxnumber, paramnumber, "") local fx_id = "" if (fxnumber >> 24) == 1 then fx_id = "Input FX: " end local _, f_value = reaper.TrackFX_GetFormattedParamValue(track, fxnumber, paramnumber,'') txt = track_name..' | '..fx_id..fx_name..'\n'..param_name..' : '..f_value else -- ITEM FX >>>>> local track = reaper.CSurf_TrackFromID((tracknumber & 0xFFFF), false) local _, track_name = reaper.GetTrackName(track) track_name = 'Track '..tostring(tracknumber & 0xFFFF) ..' - ' ..track_name local takenumber = (fxnumber >> 16) fxnumber = (fxnumber & 0xFFFF) local item_index = (tracknumber >> 16)-1 local item = reaper.GetTrackMediaItem(track, item_index) local take = reaper.GetTake(item, takenumber) local _, fx_name = reaper.TakeFX_GetFXName(take, fxnumber, "") local _, take_param_name = reaper.TakeFX_GetParamName(take, fxnumber, paramnumber, "") local _, f_value = reaper.TakeFX_GetFormattedParamValue(take, fxnumber, paramnumber,'') txt = track_name..'\nItem '..tostring(item_index+1).." Take "..tostring(takenumber+1)..'\nFX: '..fx_name..'\nParam: '..take_param_name..' Value: '..f_value end end local str_w, str_h = gfx.measurestr(txt) gfx.x, gfx.y = (1), (gfx.h - str_h) / 2 gfx.drawstr(txt) gfx.update() if gfx.getchar() >= 0 then reaper.defer(Loop) end end

    local title = 'Last Touched Param' local wnd_w, wnd_h = 300,20 local __, __, scr_w, scr_h = reaper.my_getViewport(0, 0, 0, 0, 0, 0, 0, 0, 1) gfx.init(title, wnd_w, wnd_h, 0, (scr_w - wnd_w) / 2, (1)) gfx.setfont(1,"calibri", 13)

    -- Optional: set window topmost if reaper.APIExists('JS_Window_FindTop') then local hwnd = reaper.JS_Window_FindTop(title, true) if hwnd then reaper.JS_Window_SetZOrder(hwnd, "TOPMOST", hwnd) end end Loop()

    turn this reaper lua script into a rtk borderless window lua script

  2. Assistant

    To convert the given Reaper Lua script into an RTK (ReaScript Toolkit) borderless window script, we'll utilize the RTK library to manage the graphical interface elements. Here's a basic conversion of the script to use RTK for rendering the interface:

    Note: You'll need to have the RTK library available and loaded before running this script. This assumes that you have the RTK library set up and ready to use. You can find RTK on GitHub or the Reaper forums. This conversion assumes RTK version 2.x for Reaper scripts.

    -- Load RTK library
    local rtk = require('rtk')
    
    -- Create a window
    local window = rtk.Window {
        title = "Last Touched Param",
        w = 300,
        h = 20,
        borderless = true,
        resizable = false,
        visible = true
    }
    
    -- Add a label to display the parameter text
    local label = rtk.Label {
        text = "",
        x = 5,
        y = (window.h - 13) / 2,  -- Center vertically
        font = rtk.Font("calibri", 13),
        halign = rtk.Widget.CENTER
    }
    window:add(label)
    
    -- Function to update the last touched FX parameter
    local function update_last_touched()
        local txt = " "
        local retval, tracknumber, fxnumber, paramnumber = reaper.GetLastTouchedFX()
        if retval then
            if (tracknumber >> 16) == 0 then -- Track FX or Input FX
                local track = reaper.CSurf_TrackFromID(tracknumber, false)
                local _, track_name = reaper.GetTrackName(track)
                if tracknumber == 0 then track_name = 'Master Track' else track_name = ''..tostring(tracknumber)..' | '..track_name end
                local _, fx_name = reaper.TrackFX_GetFXName(track, fxnumber, "")
                local _, param_name = reaper.TrackFX_GetParamName(track, fxnumber, paramnumber, "")
                local fx_id = "" if (fxnumber >> 24) == 1 then fx_id = "Input FX: " end
                local _, f_value = reaper.TrackFX_GetFormattedParamValue(track, fxnumber, paramnumber,'')
                txt = track_name..' |  '..fx_id..fx_name..'\n'..param_name..' : '..f_value
            else
                local track = reaper.CSurf_TrackFromID((tracknumber & 0xFFFF), false)
                local _, track_name = reaper.GetTrackName(track)
                track_name = 'Track '..tostring(tracknumber & 0xFFFF) ..' - ' ..track_name
                local takenumber = (fxnumber >> 16)
                fxnumber = (fxnumber & 0xFFFF)
                local item_index = (tracknumber >> 16)-1
                local item = reaper.GetTrackMediaItem(track, item_index)
                local take = reaper.GetTake(item, takenumber)
                local _, fx_name = reaper.TakeFX_GetFXName(take, fxnumber, "")
                local _, take_param_name = reaper.TakeFX_GetParamName(take, fxnumber, paramnumber, "")
                local _, f_value = reaper.TakeFX_GetFormattedParamValue(take, fxnumber, paramnumber,'')
                txt = track_name..'\nItem '..tostring(item_index+1).."  Take "..tostring(takenumber+1)..'\nFX: '..fx_name..'\nParam: '..take_param_name..' Value: '..f_value
            end
        end
        label.text = txt
        label:sync()
    end
    
    -- Main loop for updating the GUI
    local function mainloop()
        update_last_touched()
        if reaper.defer(mainloop) then
            window:open()
        end
    end
    
    -- Start the loop
    mainloop()
    

    Explanation:

    1. RTK Window Initialization:

      • We create a borderless window using rtk.Window with specified dimensions and a label inside to display our text. The label design centers vertically using calculated positions based on text size.
    2. Update Function:

      • The update_last_touched() function is responsible for checking the last touched FX parameter and updating the label.text inside the window accordingly.
    3. Main Loop:

      • The mainloop function continuously updates the last touched parameter and ensures the window stays open, using reaper.defer() for continual updates in intervals.
    4. Text Rendering:

      • The label in RTK is part of the widget toolkit, which simplifies setting its position, font, and alignment.

    Ensure that RTK is configured in your Reaper environment before running the script. You can adjust the dimensions and styling as needed depending on your GUI requirements.