Add some more Lua script examples

This commit is contained in:
Robin Gareus 2017-08-09 15:04:42 +02:00
parent e983e08f1d
commit 8fbc2c6484
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,32 @@
ardour {
["type"] = "EditorHook",
name = "Load Session Hook Example",
author = "Ardour Lua Task Force",
description = "Display some dialogs during session load and execute actions",
}
-- subscribe to signals
-- http://manual.ardour.org/lua-scripting/class_reference/#LuaSignal.LuaSignal
function signals ()
s = LuaSignal.Set()
s:add ({[LuaSignal.SetSession] = true})
return s
end
-- create callback functions
function factory () return function (signal, ...)
assert (signal == LuaSignal.SetSession)
local md = LuaDialog.Message ("Set Session", "Loading Session:" .. Session:name(), LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close)
md:run()
local dialog_options = {
{ type = "checkbox", key = "tempo", default = true, title = "Show Tempo Ruler" },
{ type = "checkbox", key = "meter", default = true, title = "Show Meter Ruler" },
}
local dlg = LuaDialog.Dialog ("Tweak Rulers", dialog_options)
local rv = dlg:run()
if (rv) then
Editor:set_toggleaction ("Rulers", "toggle-tempo-ruler", rv['tempo'])
Editor:set_toggleaction ("Rulers", "toggle-meter-ruler", rv['meter'])
end
end end

20
scripts/_system_exec.lua Normal file
View File

@ -0,0 +1,20 @@
ardour { ["type"] = "EditorAction", name = "System Exec" }
function factory () return function ()
-- ** EXAMPLES TO RUN EXTERNAL APPLICATIONS ** --
-- run a command in a shell and wait for it to complete.
--
-- Details: basically just system(3), except on Unix like systems with
-- memory-locking, this call is special-cased to use vfork and close
-- file-descriptors. On other systems it defaults to Lua's os-library
-- built-in os.execute system() call.
os.execute ("date > /tmp/testdate")
-- os.forkexec() works as fire-and-forget. execv(3) style
--
-- Details: It calls vfork() and exec() under the hood, passing each
-- argument separately to exec (and needs a full-path to the binary).
os.forkexec ("/usr/bin/xterm")
os.forkexec ("/bin/sh", "-c", "import --frame \"/tmp/scr_$(date).png\"")
end end

View File

@ -0,0 +1,40 @@
--
-- Session Template setup-hook
--
-- If a script named 'template.lua' exists in a session-template folder
-- the `template_load` function of the script is called after
-- creating the session from the template.
--
-- (e.g. ~/.config/ardour5/templates/Template-Name/template.lua
--
function template_load ()
local e = Session:engine()
-- from the engine's POV readable/capture ports are "outputs"
local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
-- table 't' holds argument references. t[4] is the C.StringVector (return value)
local tracks = t[4]:size();
local dialog_options = {
{ type = "heading", title = "Customize Session: " .. Session:name () },
{ type = "number", key = "tracks", title = "Create Tracks", min = 0, max = 128, step = 1, digits = 0, default = tracks },
{ type = "checkbox", key = "recarm", default = false, title = "Record Arm Tracks" },
}
local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
local rv = dlg:run()
if (not rv or rv['tracks'] == 0) then
return
end
-- create tracks
local tl = Session:new_audio_track (1, 2, nil, rv['tracks'], "", ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
-- and optionally record-arm them
if rv['recarm'] then
for track in tl:iter() do
track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
end
end
Session:save_state("");
end