Files
midigrid/MidiGrid_ToggleMode.lua
T
Talon 8fd6f947ed Accessible grid-based MIDI entry mode for REAPER
Keyboard- and speech-driven step entry for the MIDI editor, built for use
with OSARA. Arrows walk grid cells and scale degrees, Enter toggles notes,
and every position is spoken and auditioned.

Uses REAPER's own edit cursor and active_note_row rather than private cursor
state, so grid mode and OSARA editing stay in sync. Grid size comes from
MIDI_GetGrid(), so existing grid keybindings drive it. When grid mode is off,
every bound key forwards to its previous action.

Preview timing lives in a background daemon so the action scripts can exit
immediately -- a script still alive on the next keypress triggers REAPER's
"already running" prompt and breaks key repeat.
2026-08-14 18:13:45 +02:00

35 lines
906 B
Lua

-- MIDI Grid: toggle grid entry mode on/off
local dir = ({ reaper.get_action_context() })[2]:match("@?(.*[\\/])")
local G = dofile(dir .. "midigrid_lib.lua")
local now = not G.isActive()
G.set("active", now and 1 or 0)
if not now then
G.say("Grid mode off")
return
end
local hwnd, take, err = G.editor()
if not take then
-- Mode is still armed; it simply has nothing to act on yet.
G.say("Grid mode on, " .. err)
return
end
-- Park the pitch cursor on a scale tone so the very first up/down press
-- moves by a sensible degree rather than off a foreign note.
local p = G.getPitch(hwnd)
if not G.inScale(p) then
local up = G.scaleStep(p, 1)
if up then p = up ; G.setPitch(hwnd, p) end
end
local g = G.gridQN(take)
G.say(("Grid mode on, %s, grid %s, %s, %s, %s"):format(
G.scaleName(),
G.gridLabel(g),
G.isHold() and "hold on" or "hold off",
G.noteName(p),
G.cellPosText(take)))