From 7969dfffce792b6cb096e18179a7ecff74b14111 Mon Sep 17 00:00:00 2001 From: Goran Date: Wed, 17 Apr 2024 21:45:07 +0200 Subject: [PATCH 1/3] -- Imgui Shims -- Implement FX Browser parser --- FX/sexan_Lil FX Slot Homie.lua | 140 +++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 50 deletions(-) diff --git a/FX/sexan_Lil FX Slot Homie.lua b/FX/sexan_Lil FX Slot Homie.lua index 47866268f..5e23da8b4 100644 --- a/FX/sexan_Lil FX Slot Homie.lua +++ b/FX/sexan_Lil FX Slot Homie.lua @@ -1,79 +1,98 @@ -- @description Lil FX Slot Homie -- @author Sexan --- @version 1.0 +-- @version 1.2 -- @link https://forum.cockos.com/showthread.php?p=2680992#post2680992 +-- @changelog +-- Imgui Shims +-- Implement FX Browser parser local SLOT = 1 local r = reaper +local reaper_path = r.GetResourcePath() -local ctx = r.ImGui_CreateContext('Lil FX Slot Homie', r.ImGui_ConfigFlags_NavEnableKeyboard()) +local fx_browser_script_path = reaper_path .. "/Scripts/Sexan_Scripts/FX/Sexan_FX_Browser_ParserV7.lua" -function FX_NAME(str) - local vst_name - for name_segment in str:gmatch('[^%,]+') do - if name_segment:match("(%S+) ") then - if name_segment:match('"(JS: .-)"') then - vst_name = name_segment:match('"JS: (.-)"') and "JS:" .. name_segment:match('"JS: (.-)"') or nil - else - vst_name = name_segment:match("(%S+ .-%))") and "VST:" .. name_segment:match("(%S+ .-%))") or nil - end +function ThirdPartyDeps() + local reapack_process + local repos = { + { name = "Sexan_Scripts", url = 'https://github.com/GoranKovac/ReaScripts/raw/master/index.xml' }, + } + + for i = 1, #repos do + local retinfo, url, enabled, autoInstall = r.ReaPack_GetRepositoryInfo(repos[i].name) + if not retinfo then + retval, error = r.ReaPack_AddSetRepository(repos[i].name, repos[i].url, true, 0) + reapack_process = true end end - if vst_name then return vst_name end -end -function GetFileContext(fp) - local str = "\n" - local f = io.open(fp, 'r') - if f then - str = f:read('a') - f:close() + -- ADD NEEDED REPOSITORIES + if reapack_process then + --r.ShowMessageBox("Added Third-Party ReaPack Repositories", "ADDING REPACK REPOSITORIES", 0) + r.ReaPack_ProcessQueue(true) + reapack_process = nil end - return str end --- Fill function with desired database -function Fill_fx_list() - local tbl_list = {} - local tbl = {} +local function CheckDeps() + ThirdPartyDeps() + local deps = {} - local vst_path = r.GetResourcePath() .. "/reaper-vstplugins64.ini" - local vst_str = GetFileContext(vst_path) + if not r.ImGui_GetVersion then + deps[#deps + 1] = '"Dear Imgui"' + end + if not r.file_exists(fx_browser_script_path) then + deps[#deps + 1] = '"FX Browser Parser V7"' + end + if #deps ~= 0 then + r.ShowMessageBox("Need Additional Packages.\nPlease Install it in next window", "MISSING DEPENDENCIES", 0) + r.ReaPack_BrowsePackages(table.concat(deps, " OR ")) + return true + end +end +if CheckDeps() then return end - local vst_path32 = r.GetResourcePath() .. "/reaper-vstplugins.ini" - local vst_str32 = GetFileContext(vst_path32) +dofile(r.GetResourcePath() .. '/Scripts/ReaTeam Extensions/API/imgui.lua')('0.8.7') +if r.file_exists(fx_browser_script_path) then + dofile(fx_browser_script_path) +end - local jsfx_path = r.GetResourcePath() .. "/reaper-jsfx.ini" - local jsfx_str = GetFileContext(jsfx_path) +local ctx = r.ImGui_CreateContext('Lil FX Slot Homie', r.ImGui_ConfigFlags_NavEnableKeyboard()) - local au_path = r.GetResourcePath() .. "/reaper-auplugins64-bc.ini" - local au_str = GetFileContext(au_path) +local FX_LIST = ReadFXFile() - local plugins = vst_str .. vst_str32 .. jsfx_str .. au_str +if not FX_LIST then + FX_LIST = MakeFXFiles() +end - for line in plugins:gmatch('[^\r\n]+') do tbl[#tbl + 1] = line end +local function Lead_Trim_ws(s) return s:match '^%s*(.*)' end - -- CREATE NODE LIST - for i = 1, #tbl do - local fx_name = FX_NAME(tbl[i]) - if fx_name then - tbl_list[#tbl_list + 1] = fx_name +local tsort = table.sort +function SortTable(tab, val1, val2) + tsort(tab, function(a, b) + if (a[val1] < b[val1]) then + -- primary sort on position -> a before b + return true + elseif (a[val1] > b[val1]) then + -- primary sort on position -> b before a + return false + else + -- primary sort tied, resolve w secondary sort on rank + return a[val2] < b[val2] end - end - return tbl_list + end) end -local FX_LIST = Fill_fx_list() -local function Lead_Trim_ws(s) return s:match '^%s*(.*)' end - +local old_t = {} +local old_filter = "" local function Filter_actions(filter_text) + if old_filter == filter_text then return old_t end filter_text = Lead_Trim_ws(filter_text) local t = {} - if filter_text == "" then return t end + if filter_text == "" or not filter_text then return t end for i = 1, #FX_LIST do - local action = FX_LIST[i] - local name = action:lower() + local name = FX_LIST[i]:lower() --:gsub("(%S+:)", "") local found = true for word in filter_text:gmatch("%S+") do if not name:find(word:lower(), 1, true) then @@ -81,11 +100,28 @@ local function Filter_actions(filter_text) break end end - if found then t[#t + 1] = action end + if found then t[#t + 1] = { score = FX_LIST[i]:len() - filter_text:len(), name = FX_LIST[i] } end end + if #t >= 2 then + SortTable(t, "score", "name") -- Sort by key priority + end + old_t = t + old_filter = filter_text return t end +local function SetMinMax(Input, Min, Max) + if Input >= Max then + Input = Max + elseif Input <= Min then + Input = Min + else + Input = Input + end + return Input +end + +local FILTER = '' local function AddFxToTracks(fx) if r.CountTracks(0) == 1 and r.CountSelectedTracks(0) == 0 then local track = r.GetTrack(0, 0) @@ -137,6 +173,10 @@ function FilterBox() r.ImGui_SetNextWindowSize(ctx, 0, filter_h) if r.ImGui_BeginPopup(ctx, "popup") then r.ImGui_Text(ctx, "ADD TO SLOT : " .. (SLOT < 100 and tostring(SLOT) or "LAST")) + r.ImGui_SameLine(ctx, 0, 20) + if r.ImGui_Selectable(ctx, "RESCAN FX", false, 0, 65) then + FX_LIST = MakeFXFiles() + end r.ImGui_PushItemWidth(ctx, MAX_FX_SIZE) if r.ImGui_IsWindowAppearing(ctx) then r.ImGui_SetKeyboardFocusHere(ctx) end -- IF KEYBOARD FOCUS IS ON CHILD ITEMS SET IT HERE @@ -159,8 +199,8 @@ function FilterBox() for i = 1, #filtered_fx do AllowChildFocus(i) r.ImGui_PushID(ctx, i) - if r.ImGui_Selectable(ctx, filtered_fx[i], true, nil, MAX_FX_SIZE) then - AddFxToTracks(filtered_fx[i]) + if r.ImGui_Selectable(ctx, filtered_fx[i].name, true, nil, MAX_FX_SIZE) then + AddFxToTracks(filtered_fx[i].name) end r.ImGui_PopID(ctx) end From 3e5247096ff8dc1992ff045a1ac5e42f31897aa8 Mon Sep 17 00:00:00 2001 From: Goran Kovac Date: Mon, 29 Jul 2024 16:30:59 +0200 Subject: [PATCH 2/3] -- version 1.21 -- link https://forum.cockos.com/showthread.php?p=2680992#post2680992 -- changelog -- Scroll to selected items if they are not in view -- Fix ESC Clear/close script --- FX/sexan_Lil FX Slot Homie.lua | 92 +++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 29 deletions(-) diff --git a/FX/sexan_Lil FX Slot Homie.lua b/FX/sexan_Lil FX Slot Homie.lua index 5e23da8b4..85cee8d1f 100644 --- a/FX/sexan_Lil FX Slot Homie.lua +++ b/FX/sexan_Lil FX Slot Homie.lua @@ -1,10 +1,10 @@ -- @description Lil FX Slot Homie -- @author Sexan --- @version 1.2 +-- @version 1.21 -- @link https://forum.cockos.com/showthread.php?p=2680992#post2680992 -- @changelog --- Imgui Shims --- Implement FX Browser parser +-- Scroll to selected items if they are not in view +-- Fix ESC Clear/close script local SLOT = 1 @@ -58,7 +58,7 @@ if r.file_exists(fx_browser_script_path) then dofile(fx_browser_script_path) end -local ctx = r.ImGui_CreateContext('Lil FX Slot Homie', r.ImGui_ConfigFlags_NavEnableKeyboard()) +local ctx = r.ImGui_CreateContext('Lil FX Slot Homie') local FX_LIST = ReadFXFile() @@ -121,7 +121,7 @@ local function SetMinMax(Input, Min, Max) return Input end -local FILTER = '' +FILTER = '' local function AddFxToTracks(fx) if r.CountTracks(0) == 1 and r.CountSelectedTracks(0) == 0 then local track = r.GetTrack(0, 0) @@ -166,11 +166,36 @@ local function AllowChildFocus(i) end end +function SetMinMax(Input, Min, Max) + if Input >= Max then + Input = Max + elseif Input <= Min then + Input = Min + else + Input = Input + end + return Input +end + +local function scroll(pos) + if not reaper.ImGui_IsItemVisible(ctx) then + reaper.ImGui_SetScrollHereY(ctx,pos) + end + +end + local filter_h = 60 local MAX_FX_SIZE = 300 function FilterBox() CheckKeyNumbers() r.ImGui_SetNextWindowSize(ctx, 0, filter_h) + if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Escape()) then + if #FILTER == 0 then + CLOSE = true + else + FOCUS = true + end + end if r.ImGui_BeginPopup(ctx, "popup") then r.ImGui_Text(ctx, "ADD TO SLOT : " .. (SLOT < 100 and tostring(SLOT) or "LAST")) r.ImGui_SameLine(ctx, 0, 20) @@ -179,33 +204,42 @@ function FilterBox() end r.ImGui_PushItemWidth(ctx, MAX_FX_SIZE) if r.ImGui_IsWindowAppearing(ctx) then r.ImGui_SetKeyboardFocusHere(ctx) end - -- IF KEYBOARD FOCUS IS ON CHILD ITEMS SET IT HERE - if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Escape()) then r.ImGui_SetKeyboardFocusHere(ctx) end - _, FILTER = r.ImGui_InputText(ctx, '##input', FILTER) - if r.ImGui_IsItemFocused(ctx) then - ALLOW_IN_LIST, PASS_FOCUS = nil, nil - -- IF FOCUS IS ALREADY HERE CLOSE POPUP - if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Escape()) then r.ImGui_CloseCurrentPopup(ctx) end + if FOCUS then + r.ImGui_SetKeyboardFocusHere(ctx) + FOCUS = nil end + if CLOSE then + r.ImGui_CloseCurrentPopup(ctx) + end + _, FILTER = r.ImGui_InputText(ctx, '##input', FILTER) local filtered_fx = Filter_actions(FILTER) + ADDFX_Sel_Entry = SetMinMax(ADDFX_Sel_Entry or 1, 1, #filtered_fx) filter_h = #filtered_fx == 0 and 60 or (#filtered_fx > 40 and 20 * 17 or (17 * #filtered_fx) + 55) - - if r.ImGui_BeginChild(ctx, "aaaaa") then - -- DANCING AROUND SOME LIMITATIONS OF SELECTING CHILDS - if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_DownArrow()) then - if not ALLOW_IN_LIST then ALLOW_IN_LIST = true end - end - for i = 1, #filtered_fx do - AllowChildFocus(i) - r.ImGui_PushID(ctx, i) - if r.ImGui_Selectable(ctx, filtered_fx[i].name, true, nil, MAX_FX_SIZE) then - AddFxToTracks(filtered_fx[i].name) - end - r.ImGui_PopID(ctx) - end - r.ImGui_EndChild(ctx) - end + + if r.ImGui_BeginChild(ctx, "aaaaa") then + for i = 1, #filtered_fx do + r.ImGui_PushID(ctx, i) + if r.ImGui_Selectable(ctx, filtered_fx[i].name, i == ADDFX_Sel_Entry, nil, MAX_FX_SIZE) then + AddFxToTracks(filtered_fx[i].name) + end + r.ImGui_PopID(ctx) + if i == ADDFX_Sel_Entry then + scroll(scroll_pos) + end + end + if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Enter()) then + AddFxToTracks(filtered_fx[ADDFX_Sel_Entry].name) + ADDFX_Sel_Entry = nil + elseif r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_UpArrow()) then + ADDFX_Sel_Entry = ADDFX_Sel_Entry - 1 + elseif r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_DownArrow()) then + ADDFX_Sel_Entry = ADDFX_Sel_Entry + 1 + end + r.ImGui_EndChild(ctx) + end + + r.ImGui_EndPopup(ctx) r.defer(FilterBox) end @@ -217,4 +251,4 @@ local function loop() FilterBox() end -r.defer(loop) +r.defer(loop) \ No newline at end of file From 1dc3a0e013efe9b4e2afaa47af2f84eca2e7a644 Mon Sep 17 00:00:00 2001 From: Christian Fillion Date: Mon, 29 Jul 2024 10:37:17 -0400 Subject: [PATCH 3/3] s/1.21/1.2.1/ --- FX/sexan_Lil FX Slot Homie.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FX/sexan_Lil FX Slot Homie.lua b/FX/sexan_Lil FX Slot Homie.lua index 85cee8d1f..1a556b1df 100644 --- a/FX/sexan_Lil FX Slot Homie.lua +++ b/FX/sexan_Lil FX Slot Homie.lua @@ -1,6 +1,6 @@ -- @description Lil FX Slot Homie -- @author Sexan --- @version 1.21 +-- @version 1.2.1 -- @link https://forum.cockos.com/showthread.php?p=2680992#post2680992 -- @changelog -- Scroll to selected items if they are not in view @@ -251,4 +251,4 @@ local function loop() FilterBox() end -r.defer(loop) \ No newline at end of file +r.defer(loop)