summaryrefslogtreecommitdiff
path: root/scripts/stop_at_marker.lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-05-14 23:59:32 +0200
committerRobin Gareus <robin@gareus.org>2016-05-14 23:59:32 +0200
commitc560ca67bdfe926f2f84e2b5eb48d52957827d5d (patch)
tree8a5bf6acbfe1c8e338c26b1beda5dc7e30000943 /scripts/stop_at_marker.lua
parentfe74c587f3054180d8c1243c50d97411450e009e (diff)
some love for session-scripts.
Diffstat (limited to 'scripts/stop_at_marker.lua')
-rw-r--r--scripts/stop_at_marker.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/stop_at_marker.lua b/scripts/stop_at_marker.lua
new file mode 100644
index 0000000000..140fb7a98d
--- /dev/null
+++ b/scripts/stop_at_marker.lua
@@ -0,0 +1,42 @@
+ardour {
+ ["type"] = "session",
+ name = "Stop at Marker",
+ license = "MIT",
+ author = "Robin Gareus",
+ email = "robin@gareus.org",
+ site = "http://gareus.org",
+ description = [[An example session script which stops the transport on every location marker when rolling forward.]]
+}
+
+function factory ()
+ return function (n_samples)
+ if (not Session:transport_rolling ()) then
+ -- not rolling, nothing to do.
+ return
+ end
+
+ local pos = Session:transport_frame () -- current playhead position
+ 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 )
+ local m = loc:first_mark_after (pos, false)
+
+ if (m == -1) then
+ -- no marker was found
+ return
+ end
+
+ -- since ardour may split the process cycle for events,
+ -- n_samples may be smaller.
+ local blk = Session:get_block_size ()
+
+ -- transport stop can only happen on a process-cycle boundary.
+ -- This callback happens from within the process callback,
+ -- so we need to queue it ahead of time.
+ if (pos + n_samples + blk >= m and pos + n_samples < m) then
+ Session:request_transport_speed (0.0, true)
+ end
+ end
+end