From f27e53f48543f364bd37764018b4710b465f0369 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 11 Aug 2017 14:29:08 +0200 Subject: Add support for scripted meta-templates. --- gtk2_ardour/ardour_ui.cc | 53 ++++++++++++++++++++++++++++--------------- gtk2_ardour/ardour_ui.h | 2 ++ gtk2_ardour/session_dialog.cc | 11 +++++++++ gtk2_ardour/session_dialog.h | 2 ++ 4 files changed, 50 insertions(+), 18 deletions(-) (limited to 'gtk2_ardour') 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 (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 (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 () { 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 name; Gtk::TreeModelColumn path; + Gtk::TreeModelColumn desc; }; SessionTemplateColumns session_template_columns; -- cgit v1.2.3