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
186
187
188
189
190
191
192
193
194
195
local HW_TIP = "Needs hardware mode (Rebind Link). Pinned pedals, Link pads and F13 to F24 only arrive in hardware mode. Rebind restarts the script to apply a new key."
local cfg = rb.ui.schema({
pedal = rb.ui.keybind("F13", {
label = "Pedal key (needs hardware mode)", group = "Pedal",
tooltip = HW_TIP .. " Turn on Only from this device to pin it to your pedal or pad.",
}),
double_ms = rb.ui.slider(300, {
label = "Double-tap window", group = "Timing", min = 150, max = 700, step = 10, suffix = " ms",
tooltip = "A second tap inside this window drops a marker instead of recording. Taps wait this long before they fire.",
}),
hold_ms = rb.ui.slider(600, {
label = "Hold time", group = "Timing", min = 300, max = 2000, step = 50, suffix = " ms",
tooltip = "Hold the pedal this long to go back to the start.",
}),
reaper_start = rb.ui.select("W", { "W", "Home" }, {
label = "REAPER go-to-start key", group = "REAPER",
tooltip = "Both are REAPER defaults for Go to start of project (Cockos Quick Start).",
}),
show_toast = rb.ui.toggle(true, { label = "Toast each action", group = "Feedback" }),
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. The pedal key keeps its value.",
}),
})
rb.timer.every(500, function()
if cfg.reset then
cfg.double_ms = 300
cfg.hold_ms = 600
cfg.reaper_start = "W"
cfg.show_toast = true
cfg.reset = false
rb.ui.notify("Hands-Busy Pedal reset to defaults.", "success")
end
end)
local MAC = rb.info.platform == "macos"
local logic_recording = false
local function say(text: string)
if cfg.show_toast then
rb.overlay.toast(text, { title = "Hands-Busy Pedal", duration = 1200 })
end
end
local function daw(): string?
local front = rb.app.front()
if not front then
return nil
end
local n = string.lower(front.name or "")
if string.find(n, "reaper", 1, true) then
return "reaper"
end
if string.find(n, "logic", 1, true) then
return "logic"
end
return nil
end
local function act(kind: string)
local which = daw()
if not which then
say("Bring REAPER or Logic Pro to the front first.")
return
end
if which == "reaper" then
if kind == "tap" then
rb.hid.combo(if MAC then "LWin+R" else "LCtrl+R")
say("REAPER: record / stop")
elseif kind == "double" then
rb.hid.combo("M")
say("REAPER: marker")
else
rb.hid.combo(if cfg.reaper_start == "Home" then "Home" else "W")
say("REAPER: back to start")
end
else
if kind == "tap" then
if logic_recording then
rb.hid.combo("Space")
logic_recording = false
say("Logic: stop")
else
rb.hid.combo("R")
logic_recording = true
say("Logic: record")
end
elseif kind == "double" then
rb.hid.combo("LAlt+Apostrophe")
say("Logic: marker")
else
rb.hid.combo("Enter")
say("Logic: back to start")
end
end
end
local pressed_at = 0
local hold_fired = false
local hold_timer = nil
local tap_timer = nil
local taps = 0
local function onPress()
pressed_at = rb.system.time()
hold_fired = false
if hold_timer then
hold_timer:stop()
end
hold_timer = rb.timer.after(cfg.hold_ms or 600, function()
hold_timer = nil
hold_fired = true
taps = 0
if tap_timer then
tap_timer:stop()
tap_timer = nil
end
act("hold")
end)
end
local function onRelease()
if hold_timer then
hold_timer:stop()
hold_timer = nil
end
if hold_fired then
return
end
if rb.system.time() - pressed_at >= (cfg.hold_ms or 600) then
hold_fired = true
taps = 0
act("hold")
return
end
taps += 1
if taps >= 2 then
taps = 0
if tap_timer then
tap_timer:stop()
tap_timer = nil
end
act("double")
return
end
tap_timer = rb.timer.after(cfg.double_ms or 300, function()
tap_timer = nil
if taps == 1 then
taps = 0
act("tap")
end
end)
end
local PEDAL = if cfg.pedal and cfg.pedal ~= "" then cfg.pedal else "F13"
rb.bind(PEDAL, onPress, { release = onRelease })
print("Hands-Busy Pedal ready on " .. PEDAL .. ". Needs hardware mode.")