FL Window Wheel

@xzenile / fl-window-wheelv1.1.0Public

In FL Studio, hold Mouse5 and scroll to flip between Playlist, Channel Rack, Piano roll and Mixer, with a toast naming each one.

Files

Version 1.1.0 (current)

daw-fl-window-wheel.luau6.8 KB

--[[
  rebind: min_sdk=3.11.1
  rebind: name=FL Window Wheel
  rebind: version=1.1.0
  rebind: author=PLACEHOLDER
  rebind: description=In FL Studio, hold Mouse5 and scroll to flip between Playlist, Channel Rack, Piano roll and Mixer, with a toast naming each one.
  rebind: process=FL64
  rebind: process=FL.exe
  rebind: process=FL Studio
  rebind: permissions=none
  rebind: instance=single
]]

-- FL Window Wheel
-- Hold the hold button (Mouse5 by default) and turn the wheel. Each step sends
-- FL Studio's own window key, so FL brings that window up.
-- Keys are from Image-Line's shortcut page (Window Navigation):
-- https://www.image-line.com/fl-studio-learning/fl-studio-online-manual/html/basics_shortcuts.htm
--   F5 Toggle Playlist, F6 Toggle Step Sequencer (Channel Rack),
--   F7 Toggle Piano roll, F9 Show/hide Mixer. Same keys on Windows and macOS.
-- Nothing is sent unless you are holding the button and scrolling.
--
-- These FL keys toggle: pressing the key of the window already in front hides it.
-- Rebind can read FL's main window title (rb.system.window) but not which panel
-- inside FL has focus, so the script assumes the "Starting window" is in front and
-- the first step goes to the window after it (or before it, scrolling the other
-- way). It never presses the starting window's key first. The assumption resets
-- when FL loses focus and after the idle time set in Options.

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 -- the window we last brought up; nil = assume the starting window
local last_switch = 0

-- FL lost focus: we no longer know which FL window will be in front.
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
  -- Where we assume FL is now: the last window we brought up, else the starting window.
  local assumed = current_name or cfg.start_window or "Playlist"
  local here = indexOf(list, assumed)
  local nextIndex
  if here then
    -- One window in the wheel and it is already in front: pressing it again would hide it.
    if #list == 1 then
      return
    end
    nextIndex = ((here - 1 + dir) % #list) + 1
  else
    -- The assumed window is not in the wheel, so none of the wheel's windows is in front.
    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
  -- nil callback: Rebind takes the button and does nothing else (rb.bind docs).
  rb.bind(HOLD, nil)
end

print("FL Window Wheel ready. Hold " .. HOLD .. " and scroll in FL Studio.")

3 files, 9.8 KB.