Use a C++ bool constant
[ardour.git] / scripts / stop_at_marker.lua
1 ardour {
2         ["type"]    = "session",
3         name        = "Stop at Marker",
4         license     = "MIT",
5         author      = "Ardour Lua Task Force",
6         description = [[An example session script which stops the transport on every location marker when rolling forward.]]
7 }
8
9 function factory ()
10         return function (n_samples)
11                 if (not Session:transport_rolling ()) then
12                         -- not rolling, nothing to do.
13                         return
14                 end
15
16                 local pos = Session:transport_frame () -- current playhead position
17                 local loc = Session:locations () -- all marker locations
18
19                 -- find first marker after the current playhead position, ignore loop + punch ranges
20                 -- (this only works when rolling forward, to extend this example see
21                 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Locations )
22                 local m = loc:first_mark_after (pos, false)
23
24                 if (m == -1) then
25                         -- no marker was found
26                         return
27                 end
28
29                 -- since ardour may split the process cycle for events,
30                 -- n_samples may be smaller.
31                 local blk = Session:get_block_size ()
32
33                 -- transport stop can only happen on a process-cycle boundary.
34                 -- This callback happens from within the process callback,
35                 -- so we need to queue it ahead of time.
36                 if (pos + n_samples + blk >= m and pos + n_samples < m) then
37                         Session:request_transport_speed (0.0, true)
38                 end
39         end
40 end