Add play-current-bar-only
Ctrl+Alt+Space plays the cursor's bar and stops at the next bar line, so the same bar can be fired repeatedly while nudging a note without reaching for stop. Alt+Space keeps its play-onwards behaviour. The stop is performed by the preview daemon rather than the action script: a script that stayed alive waiting for the bar to end would bring back REAPER's "already running" prompt on the next press, which is the problem the daemon exists to avoid. Stopping transport can move the edit cursor depending on preferences, and the edit cursor is the grid cursor, so the daemon restores it. A short arming window covers the gap between requesting playback and the transport reporting as playing, so the pending stop is not cancelled instantly.
This commit is contained in:
+19
-5
@@ -354,10 +354,12 @@ end
|
||||
|
||||
------------------------------------------------------------------ playback
|
||||
|
||||
-- Start of the bar containing time t, plus the 1-based bar number.
|
||||
function M.barStart(t)
|
||||
-- Start and end of the bar containing time t, plus the 1-based bar number.
|
||||
function M.barBounds(t)
|
||||
local _, measures = reaper.TimeMap2_timeToBeats(0, t)
|
||||
return reaper.TimeMap2_beatsToTime(0, 0, measures), measures + 1
|
||||
return reaper.TimeMap2_beatsToTime(0, 0, measures),
|
||||
reaper.TimeMap2_beatsToTime(0, 0, measures + 1),
|
||||
measures + 1
|
||||
end
|
||||
|
||||
--[[
|
||||
@@ -371,9 +373,9 @@ end
|
||||
subdivisions checkable: you hear the note in relation to the downbeat,
|
||||
which is the thing you are actually trying to judge.
|
||||
]]
|
||||
function M.playFromBar()
|
||||
function M.playFromBar(stopAtBarEnd)
|
||||
local here = reaper.GetCursorPosition()
|
||||
local barPos, barNum = M.barStart(here)
|
||||
local barPos, barEnd, barNum = M.barBounds(here)
|
||||
|
||||
reaper.PreventUIRefresh(1)
|
||||
reaper.SetEditCurPos(barPos, false, true)
|
||||
@@ -384,6 +386,18 @@ function M.playFromBar()
|
||||
reaper.SetEditCurPos(here, false, false)
|
||||
reaper.PreventUIRefresh(-1)
|
||||
|
||||
if stopAtBarEnd then
|
||||
-- The daemon watches for this and stops transport, because an action
|
||||
-- script must never stay alive to wait for it.
|
||||
M.setTemp("stopat", barEnd)
|
||||
-- Grace period: play state takes a moment to report as playing, and
|
||||
-- without this the daemon would see "not playing" and cancel instantly.
|
||||
M.setTemp("stoparm", reaper.time_precise() + 0.5)
|
||||
M.ensureDaemon()
|
||||
else
|
||||
M.setTemp("stopat", "")
|
||||
end
|
||||
|
||||
return barNum
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user