some love for session-scripts.
authorRobin Gareus <robin@gareus.org>
Sat, 14 May 2016 21:59:32 +0000 (23:59 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 14 May 2016 21:59:32 +0000 (23:59 +0200)
scripts/session_test.lua
scripts/stop_at_marker.lua [new file with mode: 0644]

index dbe4390b5e5b0990d220d48fcef0864a47c9b279..49f05c329b62d1db1a9d2f413a1e6a5ca984f70a 100644 (file)
@@ -1,15 +1,14 @@
 ardour {
        ["type"]    = "session",
-       name        = "Example",
+       name        = "Good Night",
        license     = "MIT",
        author      = "Robin Gareus",
        email       = "robin@gareus.org",
        site        = "http://gareus.org",
        description = [[
-       An Example Ardour Session Process Plugin.
-       Install a 'hook' that is called on every process cycle
-       (before doing any processing).
-       This example stops the transport after rolling for a specific time.]]
+       Example Ardour Session Script.
+       Session scripts are called at the beginning of every process-callback (before doing any audio processing).
+       This example stops the transport after rolling for a configurable time which can be set when instantiating the script.]]
 }
 
 function sess_params ()
diff --git a/scripts/stop_at_marker.lua b/scripts/stop_at_marker.lua
new file mode 100644 (file)
index 0000000..140fb7a
--- /dev/null
@@ -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