Logic Punch Pad

@xzenile / logic-punch-padv1.0.1Public

Logic Pro on macOS. Mouse4 sets the punch-in locator, Mouse5 sets the punch-out locator, and pressing both toggles Autopunch.

Files

Version 1.0.1 (current)

daw-logic-punch-pad.luau3.6 KB

--[[
  rebind: min_sdk=3.11.1
  rebind: name=Logic Punch Pad
  rebind: version=1.0.1
  rebind: author=PLACEHOLDER
  rebind: description=Logic Pro on macOS. Mouse4 sets the punch-in locator, Mouse5 sets the punch-out locator, and pressing both toggles Autopunch.
  rebind: process=Logic Pro
  rebind: permissions=none
  rebind: instance=single
]]

-- Logic Punch Pad (macOS only)
-- Keys are Logic Pro's own defaults, from Apple's Global Commands page
-- (U.S. default preset):
-- https://support.apple.com/guide/logicpro/global-commands-lgcp02bf31b6/mac
--   Set Punch In Locator by Playhead                 Control-Option-Command-I
--   Set Punch In Locator by Rounded Playhead         Control-Option-Shift-Command-I
--   Set Punch Out Locator by Playhead                Control-Option-Command-O
--   Set Punch Out Locator Point by Rounded Playhead  Control-Option-Shift-Command-O
--   Toggle Autopunch Mode                            Control-Option-Command-P
-- A single button acts when you let go, so pressing both never also sets a locator.

local cfg = rb.ui.schema({
  rounded = rb.ui.toggle(false, {
    label = "Snap locators to the rounded playhead", group = "Locators",
    tooltip = "Uses Logic's 'by Rounded Playhead' commands (adds Shift).",
  }),
  swap = rb.ui.toggle(false, {
    label = "Swap buttons (Mouse5 = in, Mouse4 = out)", group = "Buttons",
    tooltip = "Takes effect after you restart the script.",
  }),
  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.",
  }),
})

rb.timer.every(500, function()
  if cfg.reset then
    cfg.rounded = false
    cfg.swap = false
    cfg.show_toast = true
    cfg.reset = false
    rb.ui.notify("Logic Punch Pad reset to defaults.", "success")
  end
end)

local MAC = rb.info.platform == "macos"
local NOT_MAC = "Logic Punch Pad works on macOS only. Nothing is bound here."

local function say(text: string)
  if cfg.show_toast then
    rb.overlay.toast(text, { title = "Logic Punch Pad", duration = 1200 })
  end
end

local function locator(which: string)
  local base = if cfg.rounded then "LCtrl+LAlt+LShift+LWin+" else "LCtrl+LAlt+LWin+"
  if which == "in" then
    rb.hid.combo(base .. "I")
    say("Punch in set")
  else
    rb.hid.combo(base .. "O")
    say("Punch out set")
  end
end

if not MAC then
  rb.on("start", function()
    rb.overlay.toast(NOT_MAC, { title = "Logic Punch Pad" })
    rb.ui.notify(NOT_MAC, "warning")
  end)
  print(NOT_MAC)
else
  local IN_BTN = if cfg.swap then "Mouse5" else "Mouse4"
  local OUT_BTN = if cfg.swap then "Mouse4" else "Mouse5"
  local chord_used = false -- set when both were down; the releases then do nothing

  local function press(other: string)
    return function()
      if rb.input.is_down(other) then
        chord_used = true
        rb.hid.combo("LCtrl+LAlt+LWin+P")
        say("Autopunch toggled")
      end
    end
  end

  local function release(which: string, other: string)
    return function()
      if chord_used then
        -- Clear once both buttons are up.
        if not rb.input.is_down(other) then
          chord_used = false
        end
        return
      end
      locator(which)
    end
  end

  rb.bind(IN_BTN, press(OUT_BTN), { release = release("in", OUT_BTN) })
  rb.bind(OUT_BTN, press(IN_BTN), { release = release("out", IN_BTN) })
  print("Logic Punch Pad ready. " .. IN_BTN .. " = punch in, " .. OUT_BTN .. " = punch out, both = Autopunch.")
end

3 files, 5.8 KB.