Keep the edit cursor when opening an item in grid mode
Opening an item in the MIDI editor parks the edit cursor at the item start, and the open action then made that stick. Listening to a phrase and hitting Alt+Shift+G to write on top of it meant arrowing back to where you already were, one cell at a time, on every entry. The cursor now stays where it was and is only tidied onto the nearest grid line, so the first left/right press moves a whole cell rather than a remainder. The action reads the cursor before the open command runs, since the open command is what moves it. snapCursorToCell rounds in quarter notes, like everything else here, so the landing spot survives a tempo change, and clamps the cell index into the item: the floor is the cell containing the item start, which is where the action used to land, and the ceiling is the last cell that starts inside the item. Clamping the index rather than the time means a cursor parked before an off-grid item start rounds forward into the first whole cell instead of into the partial one, where a note would begin outside the item. The action also re-reads the take from the editor handle now, so the grid size and the spoken position come from the take actually being edited rather than from the selected item's active take. Toggling grid mode on with Alt+G is left alone: it does not move the cursor at all, and cell() floors, so an off-grid cursor still works. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -229,6 +229,37 @@ function M.gotoCell(take, idx)
|
||||
reaper.SetEditCurPos(t, true, false)
|
||||
end
|
||||
|
||||
--[[
|
||||
Put the cursor on the nearest cell boundary to time t (the edit cursor by
|
||||
default), without leaving the item.
|
||||
|
||||
Entering grid mode uses this instead of jumping to the item start: wherever
|
||||
you were already listening stays where you are, only tidied onto a real cell
|
||||
so the first left/right press moves a whole cell rather than a remainder.
|
||||
|
||||
Returns the cell index landed on.
|
||||
]]
|
||||
function M.snapCursorToCell(take, t)
|
||||
local g = M.gridQN(take)
|
||||
local item = reaper.GetMediaItemTake_Item(take)
|
||||
local lo = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
|
||||
local hi = lo + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
|
||||
|
||||
t = t or reaper.GetCursorPosition()
|
||||
local idx = math.floor(reaper.TimeMap2_timeToQN(0, t) / g + 0.5)
|
||||
|
||||
-- A cursor outside the item pulls back to the first or last cell the item
|
||||
-- covers. The first is the cell containing the item start, which is where
|
||||
-- plain "open in editor" used to land.
|
||||
local loIdx = math.floor(reaper.TimeMap2_timeToQN(0, lo) / g + 1e-9)
|
||||
local hiIdx = math.ceil(reaper.TimeMap2_timeToQN(0, hi) / g - 1e-9) - 1
|
||||
if hiIdx < loIdx then hiIdx = loIdx end
|
||||
if idx < loIdx then idx = loIdx elseif idx > hiIdx then idx = hiIdx end
|
||||
|
||||
M.gotoCell(take, idx)
|
||||
return idx
|
||||
end
|
||||
|
||||
------------------------------------------------------------- note queries
|
||||
|
||||
-- A cell counts as occupied by a note if the note overlaps it at all, so
|
||||
|
||||
Reference in New Issue
Block a user