1
1
-- @description Lil FX Slot Homie
2
2
-- @author Sexan
3
- -- @version 1.2
3
+ -- @version 1.2.1
4
4
-- @link https://forum.cockos.com/showthread.php?p=2680992#post2680992
5
5
-- @changelog
6
- -- Imgui Shims
7
- -- Implement FX Browser parser
6
+ -- Scroll to selected items if they are not in view
7
+ -- Fix ESC Clear/close script
8
8
9
9
local SLOT = 1
10
10
@@ -58,7 +58,7 @@ if r.file_exists(fx_browser_script_path) then
58
58
dofile (fx_browser_script_path )
59
59
end
60
60
61
- local ctx = r .ImGui_CreateContext (' Lil FX Slot Homie' , r . ImGui_ConfigFlags_NavEnableKeyboard () )
61
+ local ctx = r .ImGui_CreateContext (' Lil FX Slot Homie' )
62
62
63
63
local FX_LIST = ReadFXFile ()
64
64
@@ -121,7 +121,7 @@ local function SetMinMax(Input, Min, Max)
121
121
return Input
122
122
end
123
123
124
- local FILTER = ' '
124
+ FILTER = ' '
125
125
local function AddFxToTracks (fx )
126
126
if r .CountTracks (0 ) == 1 and r .CountSelectedTracks (0 ) == 0 then
127
127
local track = r .GetTrack (0 , 0 )
@@ -166,11 +166,36 @@ local function AllowChildFocus(i)
166
166
end
167
167
end
168
168
169
+ function SetMinMax (Input , Min , Max )
170
+ if Input >= Max then
171
+ Input = Max
172
+ elseif Input <= Min then
173
+ Input = Min
174
+ else
175
+ Input = Input
176
+ end
177
+ return Input
178
+ end
179
+
180
+ local function scroll (pos )
181
+ if not reaper .ImGui_IsItemVisible (ctx ) then
182
+ reaper .ImGui_SetScrollHereY (ctx ,pos )
183
+ end
184
+
185
+ end
186
+
169
187
local filter_h = 60
170
188
local MAX_FX_SIZE = 300
171
189
function FilterBox ()
172
190
CheckKeyNumbers ()
173
191
r .ImGui_SetNextWindowSize (ctx , 0 , filter_h )
192
+ if r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_Escape ()) then
193
+ if # FILTER == 0 then
194
+ CLOSE = true
195
+ else
196
+ FOCUS = true
197
+ end
198
+ end
174
199
if r .ImGui_BeginPopup (ctx , " popup" ) then
175
200
r .ImGui_Text (ctx , " ADD TO SLOT : " .. (SLOT < 100 and tostring (SLOT ) or " LAST" ))
176
201
r .ImGui_SameLine (ctx , 0 , 20 )
@@ -179,33 +204,42 @@ function FilterBox()
179
204
end
180
205
r .ImGui_PushItemWidth (ctx , MAX_FX_SIZE )
181
206
if r .ImGui_IsWindowAppearing (ctx ) then r .ImGui_SetKeyboardFocusHere (ctx ) end
182
- -- IF KEYBOARD FOCUS IS ON CHILD ITEMS SET IT HERE
183
- if r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_Escape ()) then r .ImGui_SetKeyboardFocusHere (ctx ) end
184
- _ , FILTER = r .ImGui_InputText (ctx , ' ##input' , FILTER )
185
- if r .ImGui_IsItemFocused (ctx ) then
186
- ALLOW_IN_LIST , PASS_FOCUS = nil , nil
187
- -- IF FOCUS IS ALREADY HERE CLOSE POPUP
188
- if r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_Escape ()) then r .ImGui_CloseCurrentPopup (ctx ) end
207
+ if FOCUS then
208
+ r .ImGui_SetKeyboardFocusHere (ctx )
209
+ FOCUS = nil
189
210
end
211
+ if CLOSE then
212
+ r .ImGui_CloseCurrentPopup (ctx )
213
+ end
214
+ _ , FILTER = r .ImGui_InputText (ctx , ' ##input' , FILTER )
190
215
191
216
local filtered_fx = Filter_actions (FILTER )
217
+ ADDFX_Sel_Entry = SetMinMax (ADDFX_Sel_Entry or 1 , 1 , # filtered_fx )
192
218
filter_h = # filtered_fx == 0 and 60 or (# filtered_fx > 40 and 20 * 17 or (17 * # filtered_fx ) + 55 )
193
-
194
- if r .ImGui_BeginChild (ctx , " aaaaa" ) then
195
- -- DANCING AROUND SOME LIMITATIONS OF SELECTING CHILDS
196
- if r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_DownArrow ()) then
197
- if not ALLOW_IN_LIST then ALLOW_IN_LIST = true end
198
- end
199
- for i = 1 , # filtered_fx do
200
- AllowChildFocus (i )
201
- r .ImGui_PushID (ctx , i )
202
- if r .ImGui_Selectable (ctx , filtered_fx [i ].name , true , nil , MAX_FX_SIZE ) then
203
- AddFxToTracks (filtered_fx [i ].name )
204
- end
205
- r .ImGui_PopID (ctx )
206
- end
207
- r .ImGui_EndChild (ctx )
208
- end
219
+
220
+ if r .ImGui_BeginChild (ctx , " aaaaa" ) then
221
+ for i = 1 , # filtered_fx do
222
+ r .ImGui_PushID (ctx , i )
223
+ if r .ImGui_Selectable (ctx , filtered_fx [i ].name , i == ADDFX_Sel_Entry , nil , MAX_FX_SIZE ) then
224
+ AddFxToTracks (filtered_fx [i ].name )
225
+ end
226
+ r .ImGui_PopID (ctx )
227
+ if i == ADDFX_Sel_Entry then
228
+ scroll (scroll_pos )
229
+ end
230
+ end
231
+ if r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_Enter ()) then
232
+ AddFxToTracks (filtered_fx [ADDFX_Sel_Entry ].name )
233
+ ADDFX_Sel_Entry = nil
234
+ elseif r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_UpArrow ()) then
235
+ ADDFX_Sel_Entry = ADDFX_Sel_Entry - 1
236
+ elseif r .ImGui_IsKeyPressed (ctx , r .ImGui_Key_DownArrow ()) then
237
+ ADDFX_Sel_Entry = ADDFX_Sel_Entry + 1
238
+ end
239
+ r .ImGui_EndChild (ctx )
240
+ end
241
+
242
+
209
243
r .ImGui_EndPopup (ctx )
210
244
r .defer (FilterBox )
211
245
end
0 commit comments