Hands-Busy Pedal

@xzenile / hands-busy-pedalv1.0.0Public

One pedal or Rebind Link pad: tap to record or stop, double-tap to drop a marker, hold to go back to the start. Needs hardware mode.

Files

Version 1.0.0 (current)

daw-hands-busy-pedal.luau6.0 KB

--[[
  rebind: min_sdk=3.12.0
  rebind: name=Hands-Busy Pedal
  rebind: version=1.0.0
  rebind: author=PLACEHOLDER
  rebind: description=For REAPER and Logic Pro. One pedal or Rebind Link pad: tap to record or stop, double-tap to drop a marker, hold to go back to the start. Needs hardware mode.
  rebind: process=reaper
  rebind: process=Logic Pro
  rebind: permissions=none
  rebind: instance=single
]]

-- Hands-Busy Pedal
-- One pinned key, three gestures. Each gesture sends the DAW's own default key.
--
-- REAPER (Windows keys; macOS uses Cmd where Windows uses Ctrl)
--   Record start/stop  Ctrl+R   Cockos REAPER Quick Start guide:
--   Create marker      M        https://www.cockos.com/reaper/guides/REAPER%20Quick%20Start.pdf
--   Go project start   W        (W or Home)
--   macOS Cmd+R: community-sourced. It comes from the "REAPER OS X Default
--   Keyboard Shortcuts Summary" on a Cockos user page, not an official Cockos doc:
--   https://user.cockos.com/~glazfolk/ReaperKeyboardShortcutsOSX.pdf
--
-- Logic Pro (Apple, Global Commands, U.S. default preset)
--   https://support.apple.com/guide/logicpro/global-commands-lgcp02bf31b6/mac
--   Record             R
--   Play or Stop       Space bar   (used to stop a take that R started)
--   Create Marker      Option-Apostrophe
--   Go to Beginning    Return
--
-- Timing: a tap waits for the double-tap window before it fires, so a double tap
-- never also starts a recording.

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 -- Logic has no single record/stop key, so we track it

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
  -- Backup check with the clock, in case the hold timer was held up.
  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"
-- A pinned value ("<key>@<device id>") is read by rb.bind as the device filter.
rb.bind(PEDAL, onPress, { release = onRelease })

print("Hands-Busy Pedal ready on " .. PEDAL .. ". Needs hardware mode.")

3 files, 8.5 KB.