if(($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']){ ?> } else { ?> } ?>
This is an old revision of the document!
Lua is a lightweight programming language which lends itself nicely to embedded into other applications.
In Ardour's case Lua is available:
small, lean, rt-safe, easily bindable.
DSP-plugins have additional list of automatable parameters.
An minimal example script looks like:
ardour { ["type"] = "EditorAction", name = "Rewind", } function factory (params) return function () Session:goto_start() end end
Lua has direct access to Ardour internals: C++ classes, methods, data and functions. So writing elaborate scripts requires some knowledge about Ardour's internal interfaces. However the vast majority of simple actions can be done nearly self-contained in Lua.
To access methods or data of specific instances, use a colon ”:”, e.g. Lua Session:get_tracks()
is equivalent to C++ _session→get_tracks()
.
Static variables, static functions, enums or C++ singletons directly access the Object. e.g. Lua: ARDOUR.AudioEngine.create()
calls C++ ARDOUR::AudioEngine::create()
or Lua: Editing.ImportDistinctFiles
refers to the C++ enum Editing::ImportDistinctFiles
.
The common part for all scripts is the “Descriptor”. It's a Lua table with the following keys (the keys are case-sensitive)
Session scripts have access to the current session via the global variable Session
.
Editor Actions and Hooks both have access to the Session and Editor via the global variables Session
and Editor
respectively.
DSP scripts are the odd one out. An approach not unlike other audio-plugin standard API is used for the script. DSP scripts directly provide functions:
dsp_ioconfig()
[required], returns a table of possible I/O port configurationsdsp (bufs, in_map, out_map, n_samples, offset)
[required], process the given buffersdsp_init(sample_rate)
[optional], called when the script is instantiateddsp_params()
[optional], returns a table of automatable parameters
The script has access to the current session via the global variable Session
, control-port data is currently mapped to the global variable CtrlPorts
(only valid during dsp()
).
The audio-port to buffer-mapping is currently passed to every call to dsp()
, via the local in_map, out_map variables, however Ardour's ChanCount
is mapped to the global Lua variables InputConfig
and OutputConfig
.
print (Session:route_by_remote_id(1):name()) a = Session:route_by_remote_id(1); print (a:name()); print(Session:get_tracks():size()) for i, v in ipairs(Session:unknown_processors():table()) do print(v) end for i, v in ipairs(Session:get_tracks():table()) do print(v:name()) end for t in Session:get_tracks():iter() do print(t:name()) end for r in Session:get_routes():iter() do print(r:name()) end Session:tempo_map():add_tempo(ARDOUR.Tempo(100,4), ARDOUR.BBT_TIME(4,1,0)) Editor:set_zoom_focus(Editing.ZoomFocusRight) print(Editing.ZoomFocusRight); Editor:set_zoom_focus(1) files = ARDOUR.StringVector(); files:push_back("/home/rgareus/data/coding/ltc-tools/smpte.wav") pos = -1 Editor:do_import(files, Editing.ImportDistinctFiles, Editing.ImportAsTrack, ARDOUR.SrcQuality.SrcBest, pos, ARDOUR.PluginInfo()) #or in one line: Editor:do_import(ARDOUR.StringVector():add({"/path/to/file.wav"}), Editing.ImportDistinctFiles, Editing.ImportAsTrack, ARDOUR.SrcQuality.SrcBest, -1, ARDOUR.PluginInfo()) # called when a new session is loaded: function new_session (name) print("NEW SESSION:", name) end
There's a standalone tool luasession' which allows to access an Ardour session directly from the commandline.
Interaction is limited by the fact that most actions are provided by the Ardour Editor/GUI.
The tool provides only two special functions
load_session and
close_session''.
A = ARDOUR.AudioEngine.create() for i,_ in A:available_backends():iter() do print (i.name) end backend = A:set_backend("ALSA", "", "") print (A:current_backend_name()) for i,_ in backend:enumerate_devices():iter() do print (i.name) end backend:set_input_device_name("HDA Intel PCH") backend:set_output_device_name("HDA Intel PCH") print (backend:buffer_size()) print (A:get_last_backend_error()) s = load_session ("/home/rgareus/Documents/ArdourSessions/lua2/", "lua2") s:request_transport_speed (1.0) print (s:transport_rolling()) s:goto_start() unload_session()