35 lines
906 B
Lua
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)))
|