2016-05-14 17:59:32 -04:00
|
|
|
ardour {
|
|
|
|
["type"] = "session",
|
|
|
|
name = "Stop at Marker",
|
|
|
|
license = "MIT",
|
2020-09-30 16:06:35 -04:00
|
|
|
author = "Ardour Team",
|
2020-04-23 23:47:02 -04:00
|
|
|
description = [[Stop the transport on every location marker when rolling forward.]]
|
2016-05-14 17:59:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function factory ()
|
|
|
|
return function (n_samples)
|
|
|
|
if (not Session:transport_rolling ()) then
|
|
|
|
-- not rolling, nothing to do.
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-09-26 23:03:10 -04:00
|
|
|
local pos = Session:transport_sample () -- current playhead position
|
2016-05-14 17:59:32 -04:00
|
|
|
local loc = Session:locations () -- all marker locations
|
|
|
|
|
|
|
|
-- find first marker after the current playhead position, ignore loop + punch ranges
|
|
|
|
-- (this only works when rolling forward, to extend this example see
|
|
|
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Locations )
|
2020-01-30 19:45:24 -05:00
|
|
|
--
|
2016-05-14 17:59:32 -04:00
|
|
|
local m = loc:first_mark_after (pos, false)
|
|
|
|
|
|
|
|
if (m == -1) then
|
|
|
|
-- no marker was found
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-01-30 20:11:04 -05:00
|
|
|
-- due to `first_mark_after(pos)` "m" is always > "pos":
|
2020-01-30 19:45:24 -05:00
|
|
|
-- assert(pos < m)
|
2020-01-30 20:11:04 -05:00
|
|
|
--
|
|
|
|
-- This callback happens from within the process callback:
|
|
|
|
--
|
|
|
|
-- this cycle's end = next cycle start = pos + n_samples.
|
|
|
|
--
|
|
|
|
-- Note that if "m" is exactly at cycle's end, that marker
|
|
|
|
-- will be at "pos" in the next cycle. Since we ask for
|
|
|
|
-- "first_mark_after pos", the marker would not be found.
|
|
|
|
--
|
|
|
|
-- So even though "pos + n_samples" is barely reached,
|
|
|
|
-- we need to stop at "m" in the cycle that crosses or ends at "m".
|
2020-01-30 19:45:24 -05:00
|
|
|
if (pos + n_samples >= m) then
|
2020-01-30 20:11:04 -05:00
|
|
|
-- asking to locate to "m" ensures that playback continues at "m"
|
|
|
|
-- and the same marker will not be taken into account.
|
2020-01-30 19:45:24 -05:00
|
|
|
Session:request_locate (m, ARDOUR.LocateTransportDisposition.MustStop, ARDOUR.TransportRequestSource.TRS_Engine)
|
2016-05-14 17:59:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|