summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-08-11 14:29:08 +0200
committerRobin Gareus <robin@gareus.org>2017-08-11 15:24:05 +0200
commitf27e53f48543f364bd37764018b4710b465f0369 (patch)
tree2156debc0aa59480d0693fa21cdc43c42fdf9754
parent62ce5465cadaa6cf7e315cb1dc2e61444bc19e01 (diff)
Add support for scripted meta-templates.
-rw-r--r--gtk2_ardour/ardour_ui.cc53
-rw-r--r--gtk2_ardour/ardour_ui.h2
-rw-r--r--gtk2_ardour/session_dialog.cc11
-rw-r--r--gtk2_ardour/session_dialog.h2
-rw-r--r--scripts/_template_example.lua25
5 files changed, 69 insertions, 24 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc
index f09e2a41ab..0748d418c2 100644
--- a/gtk2_ardour/ardour_ui.cc
+++ b/gtk2_ardour/ardour_ui.cc
@@ -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);
}
@@ -3939,6 +3928,34 @@ ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name,
}
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 ()
{
MessageDialog dialog(_("<b>Just ask and wait for an answer.\nIt may take from minutes to hours.</b>"), true);
diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h
index 42a4f20c79..e85135bf40 100644
--- a/gtk2_ardour/ardour_ui.h
+++ b/gtk2_ardour/ardour_ui.h
@@ -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 ();
diff --git a/gtk2_ardour/session_dialog.cc b/gtk2_ardour/session_dialog.cc
index 9594c14ff9..08f7b15c16 100644
--- a/gtk2_ardour/session_dialog.cc
+++ b/gtk2_ardour/session_dialog.cc
@@ -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()) {
diff --git a/gtk2_ardour/session_dialog.h b/gtk2_ardour/session_dialog.h
index d27666e62b..5f4062fc1b 100644
--- a/gtk2_ardour/session_dialog.h
+++ b/gtk2_ardour/session_dialog.h
@@ -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;
diff --git a/scripts/_template_example.lua b/scripts/_template_example.lua
index e219cb209e..bf895dccf2 100644
--- a/scripts/_template_example.lua
+++ b/scripts/_template_example.lua
@@ -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" },
}