1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
local RESTART_TIP = "Takes effect after you restart the script."
local cfg = rb.ui.schema({
hold_button = rb.ui.select("Mouse5", { "Mouse5", "Mouse4" }, {
label = "Hold button", group = "Controls",
tooltip = RESTART_TIP,
}),
block_hold_click = rb.ui.toggle(false, {
label = "Block the hold button's own click", group = "Controls",
tooltip = RESTART_TIP,
}),
invert = rb.ui.toggle(false, {
label = "Invert wheel direction", group = "Controls",
tooltip = "Off: wheel down moves to the next window.",
}),
step_ms = rb.ui.slider(150, {
label = "Minimum time between switches", group = "Controls",
min = 0, max = 600, step = 10, suffix = " ms",
tooltip = "Stops one fast flick from skipping past several windows.",
}),
start_window = rb.ui.select("Playlist", { "Playlist", "Channel Rack", "Piano roll", "Mixer" }, {
label = "Starting window", group = "Where the wheel starts",
tooltip = "FL's window keys toggle, so pressing the key of the window in front would hide it. Rebind can't see which FL window is in front, so the wheel assumes this one is and the first scroll goes to the next window. Scroll the other way to go to the previous one.",
}),
idle_s = rb.ui.slider(10, {
label = "Forget position after idle", group = "Where the wheel starts",
min = 0, max = 120, step = 1, suffix = " s",
tooltip = "After this long without a switch, and whenever FL loses focus, the wheel assumes the Starting window is in front again. 0 = only when FL loses focus.",
}),
use_playlist = rb.ui.toggle(true, { label = "Playlist (F5)", group = "Windows in the wheel" }),
use_rack = rb.ui.toggle(true, { label = "Channel Rack (F6)", group = "Windows in the wheel" }),
use_piano = rb.ui.toggle(true, { label = "Piano roll (F7)", group = "Windows in the wheel" }),
use_mixer = rb.ui.toggle(true, { label = "Mixer (F9)", group = "Windows in the wheel" }),
show_toast = rb.ui.toggle(true, { label = "Toast the window name", group = "Feedback" }),
toast_ms = rb.ui.slider(900, {
label = "Toast length", group = "Feedback", min = 300, max = 3000, step = 100, suffix = " ms",
show_if = "show_toast",
}),
reset = rb.ui.toggle(false, {
label = "Reset to defaults", group = "Reset",
tooltip = "Options can't press buttons, so this switch resets and turns itself off.",
}),
})
local WINDOWS = {
{ id = "use_playlist", name = "Playlist", key = "F5" },
{ id = "use_rack", name = "Channel Rack", key = "F6" },
{ id = "use_piano", name = "Piano roll", key = "F7" },
{ id = "use_mixer", name = "Mixer", key = "F9" },
}
rb.timer.every(500, function()
if cfg.reset then
cfg.hold_button = "Mouse5"
cfg.block_hold_click = false
cfg.invert = false
cfg.step_ms = 150
cfg.start_window = "Playlist"
cfg.idle_s = 10
for _, w in ipairs(WINDOWS) do
cfg[w.id] = true
end
cfg.show_toast = true
cfg.toast_ms = 900
cfg.reset = false
rb.ui.notify("FL Window Wheel reset to defaults.", "success")
end
end)
local HOLD = if cfg.hold_button == "Mouse4" then "Mouse4" else "Mouse5"
local current_name = nil
local last_switch = 0
rb.on("blur", function()
current_name = nil
end)
local function enabled()
local list = {}
for _, w in ipairs(WINDOWS) do
if cfg[w.id] then
table.insert(list, w)
end
end
return list
end
local function indexOf(list, name: string?): number?
for i, w in ipairs(list) do
if w.name == name then
return i
end
end
return nil
end
local function step(dir: number)
local now = rb.system.time()
if now - last_switch < (cfg.step_ms or 0) then
return
end
local list = enabled()
if #list == 0 then
rb.overlay.toast("No windows are on in Options.", { title = "FL Window Wheel", duration = 1500 })
return
end
if cfg.invert then
dir = -dir
end
local idle_ms = (cfg.idle_s or 0) * 1000
if idle_ms > 0 and now - last_switch > idle_ms then
current_name = nil
end
local assumed = current_name or cfg.start_window or "Playlist"
local here = indexOf(list, assumed)
local nextIndex
if here then
if #list == 1 then
return
end
nextIndex = ((here - 1 + dir) % #list) + 1
else
nextIndex = if dir > 0 then 1 else #list
end
local w = list[nextIndex]
current_name = w.name
last_switch = now
rb.hid.combo(w.key)
if cfg.show_toast then
rb.overlay.toast({ { w.name, "accent", true }, " " .. w.key }, {
title = "FL Window Wheel", duration = cfg.toast_ms or 900,
})
end
end
local function holding(): boolean
return rb.input.is_down(HOLD)
end
rb.bind("WheelDown", function()
step(1)
end, { when = holding })
rb.bind("WheelUp", function()
step(-1)
end, { when = holding })
if cfg.block_hold_click then
rb.bind(HOLD, nil)
end
print("FL Window Wheel ready. Hold " .. HOLD .. " and scroll in FL Studio.")