Add support for scripted meta-templates.
This commit is contained in:
parent
62ce5465ca
commit
f27e53f485
@ -3612,7 +3612,12 @@ ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, stri
|
||||
_session_is_new = true;
|
||||
}
|
||||
|
||||
if (likely_new && template_name.empty()) {
|
||||
if (!template_name.empty() && template_name.substr (0, 11) == "urn:ardour:") {
|
||||
|
||||
ret = build_session_from_dialog (session_dialog, session_path, session_name);
|
||||
meta_session_setup (template_name.substr (11));
|
||||
|
||||
} else if (likely_new && template_name.empty()) {
|
||||
|
||||
ret = build_session_from_dialog (session_dialog, session_path, session_name);
|
||||
|
||||
@ -3828,23 +3833,7 @@ ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name,
|
||||
if (!mix_template.empty ()) {
|
||||
/* if mix_template is given, assume this is a new session */
|
||||
string metascript = Glib::build_filename (mix_template, "template.lua");
|
||||
if (Glib::file_test (metascript, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
|
||||
LuaState lua;
|
||||
lua_State* L = lua.getState();
|
||||
lua.Print.connect (&LuaInstance::_lua_print);
|
||||
LuaInstance::register_classes (L);
|
||||
LuaBindings::set_session (L, _session);
|
||||
luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
|
||||
lua_setglobal (L, "Editor");
|
||||
lua.sandbox (true);
|
||||
lua.do_file (metascript);
|
||||
try {
|
||||
luabridge::LuaRef fn = luabridge::getGlobal (L, "template_load");
|
||||
if (fn.isFunction()) {
|
||||
fn ();
|
||||
}
|
||||
} catch (luabridge::LuaException const& e) { }
|
||||
}
|
||||
meta_session_setup (metascript);
|
||||
}
|
||||
|
||||
|
||||
@ -3938,6 +3927,34 @@ ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ARDOUR_UI::meta_session_setup (const std::string& script_path)
|
||||
{
|
||||
if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LuaState lua;
|
||||
lua.Print.connect (&LuaInstance::_lua_print);
|
||||
lua.sandbox (true);
|
||||
|
||||
lua_State* L = lua.getState();
|
||||
LuaInstance::register_classes (L);
|
||||
LuaBindings::set_session (L, _session);
|
||||
luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
|
||||
lua_setglobal (L, "Editor");
|
||||
|
||||
lua.do_command ("function ardour () end");
|
||||
lua.do_file (script_path);
|
||||
|
||||
try {
|
||||
luabridge::LuaRef fn = luabridge::getGlobal (L, "session_setup");
|
||||
if (fn.isFunction()) {
|
||||
fn ();
|
||||
}
|
||||
} catch (luabridge::LuaException const& e) { }
|
||||
}
|
||||
|
||||
void
|
||||
ARDOUR_UI::launch_chat ()
|
||||
{
|
||||
|
@ -656,6 +656,8 @@ private:
|
||||
void save_template ();
|
||||
void manage_templates ();
|
||||
|
||||
void meta_session_setup (const std::string& script_path);
|
||||
|
||||
void edit_metadata ();
|
||||
void import_metadata ();
|
||||
|
||||
|
@ -48,6 +48,7 @@
|
||||
|
||||
#include "ardour/audioengine.h"
|
||||
#include "ardour/filesystem_paths.h"
|
||||
#include "ardour/luascripting.h"
|
||||
#include "ardour/recent_sessions.h"
|
||||
#include "ardour/session.h"
|
||||
#include "ardour/session_state_utils.h"
|
||||
@ -516,6 +517,16 @@ SessionDialog::populate_session_templates ()
|
||||
|
||||
row[session_template_columns.name] = (*x).name;
|
||||
row[session_template_columns.path] = (*x).path;
|
||||
row[session_template_columns.desc] = (*x).description;
|
||||
}
|
||||
|
||||
LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionSetup));
|
||||
for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) {
|
||||
TreeModel::Row row;
|
||||
row = *(template_model->append ());
|
||||
row[session_template_columns.name] = "Meta: " + (*s)->name;
|
||||
row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
|
||||
row[session_template_columns.desc] = "urn:ardour:" + (*s)->description;
|
||||
}
|
||||
|
||||
if (!templates.empty()) {
|
||||
|
@ -165,10 +165,12 @@ private:
|
||||
SessionTemplateColumns () {
|
||||
add (name);
|
||||
add (path);
|
||||
add (desc);
|
||||
}
|
||||
|
||||
Gtk::TreeModelColumn<std::string> name;
|
||||
Gtk::TreeModelColumn<std::string> path;
|
||||
Gtk::TreeModelColumn<std::string> desc;
|
||||
};
|
||||
|
||||
SessionTemplateColumns session_template_columns;
|
||||
|
@ -1,14 +1,27 @@
|
||||
--
|
||||
-- Session Template setup-hook
|
||||
ardour {
|
||||
["type"] = "SessionSetup",
|
||||
name = "Recording Session",
|
||||
description = [[Add as many mono tracks to the new session as there are physical audio inputs and optionally record-arm them.]]
|
||||
}
|
||||
|
||||
---- For use with templates: 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
|
||||
-- the `session_setup` function of the script is called after
|
||||
-- creating the session from the template.
|
||||
--
|
||||
-- (e.g. ~/.config/ardour5/templates/Template-Name/template.lua
|
||||
-- (e.g. ~/.config/ardour5/templates/Template-Name/template.lua)
|
||||
--
|
||||
--
|
||||
---- For use as meta-session
|
||||
--
|
||||
-- Every Lua script in the script-folder of type "SessionSetup"
|
||||
-- is listed as implicit template in the new-session dialog.
|
||||
-- The scripts 'session_setup' function is called once after
|
||||
-- creating a new, empty session.
|
||||
--
|
||||
|
||||
function template_load ()
|
||||
function session_setup ()
|
||||
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())
|
||||
@ -17,7 +30,7 @@ function template_load ()
|
||||
|
||||
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 = "number", key = "tracks", title = "Create Tracks", min = 1, max = 128, step = 1, digits = 0, default = tracks },
|
||||
{ type = "checkbox", key = "recarm", default = false, title = "Record Arm Tracks" },
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user