Add play-from-start-of-bar

Alt+Space plays from the downbeat of the bar the cursor is in. Auditioning a
cell says what a note is; playing from the bar line says whether it is in the
right place, which is the question that matters at 16ths and 32nds and cannot
be answered from a note in isolation.

REAPER can almost do this by chaining a go-to-measure action with play, but
that leaves the edit cursor at the bar line -- and the edit cursor is the grid
cursor, so you would lose your editing position every time you listened. Here
the cursor is moved just long enough to start playback and then restored with
seekplay=false so the restore cannot drag playback with it.

Works regardless of grid mode, being a listening aid rather than an edit.
This commit is contained in:
2026-08-14 19:57:55 +02:00
parent 51dff21e85
commit 8fd1b4755f
4 changed files with 68 additions and 2 deletions
+35
View File
@@ -352,6 +352,41 @@ function M.toggleCell(take, pitch)
return result, detail
end
------------------------------------------------------------------ playback
-- Start of the bar containing time t, plus the 1-based bar number.
function M.barStart(t)
local _, measures = reaper.TimeMap2_timeToBeats(0, t)
return reaper.TimeMap2_beatsToTime(0, 0, measures), measures + 1
end
--[[
Play from the top of the bar the cursor is in, without losing your place.
The edit cursor doubles as the grid cursor, so it is moved to the bar line
only long enough to start playback and then put straight back. Restoring it
passes seekplay=false so the restore cannot drag playback along with it.
Playing from the bar line rather than the cursor is what makes fine
subdivisions checkable: you hear the note in relation to the downbeat,
which is the thing you are actually trying to judge.
]]
function M.playFromBar()
local here = reaper.GetCursorPosition()
local barPos, barNum = M.barStart(here)
reaper.PreventUIRefresh(1)
reaper.SetEditCurPos(barPos, false, true)
-- GetPlayState bit 0 is "playing"; avoid bitwise ops for portability.
if (reaper.GetPlayState() % 2) == 0 then
reaper.CSurf_OnPlay()
end
reaper.SetEditCurPos(here, false, false)
reaper.PreventUIRefresh(-1)
return barNum
end
---------------------------------------------------------------- time shift
--[[