diff options
author | Robin Gareus <robin@gareus.org> | 2017-08-18 20:41:35 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-08-18 20:42:55 +0200 |
commit | e0a83a758e458b56d55a0e0beceb90129fc02354 (patch) | |
tree | 71a03d4965f2d2d2a13b47c457a093d876dedd1b /gtk2_ardour | |
parent | e951e6878097b2d4073cf815e8d9693cafaa5884 (diff) |
Redesign Session+Route Template Meta Script API
Remove special-cased script types. Allow Action-Scripts to be re-used
for session-setup or route-templates.
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/add_route_dialog.cc | 126 | ||||
-rw-r--r-- | gtk2_ardour/add_route_dialog.h | 1 | ||||
-rw-r--r-- | gtk2_ardour/ardour_ui.cc | 100 | ||||
-rw-r--r-- | gtk2_ardour/ardour_ui.h | 5 | ||||
-rw-r--r-- | gtk2_ardour/session_dialog.cc | 20 |
5 files changed, 220 insertions, 32 deletions
diff --git a/gtk2_ardour/add_route_dialog.cc b/gtk2_ardour/add_route_dialog.cc index 4bfaedd4e3..b743fbb15b 100644 --- a/gtk2_ardour/add_route_dialog.cc +++ b/gtk2_ardour/add_route_dialog.cc @@ -41,9 +41,13 @@ #include "ardour/session.h" #include "ardour/vca.h" -#include "utils.h" +#include "LuaBridge/LuaBridge.h" + #include "add_route_dialog.h" +#include "ardour_ui.h" #include "route_group_dialog.h" +#include "utils.h" + #include "pbd/i18n.h" using namespace Gtk; @@ -139,6 +143,7 @@ AddRouteDialog::AddRouteDialog () /* template_desc is the textview that displays the currently selected template's description */ trk_template_desc.set_editable (false); + trk_template_desc.set_can_focus (false); trk_template_desc.set_wrap_mode (Gtk::WRAP_WORD); trk_template_desc.set_size_request(400,200); trk_template_desc.set_name (X_("TextOnBackground")); @@ -288,25 +293,94 @@ AddRouteDialog::trk_template_row_selected () trk_template_desc.get_buffer ()->set_text (d); const string n = (*iter)[track_template_columns.name]; - if ( n != _("Manual Configuration") ) { - /* template or meta-template */ - const string p = (*iter)[track_template_columns.path]; - bool meta_template = p.substr (0, 11) == "urn:ardour:"; + const string p = (*iter)[track_template_columns.path]; + + if ( n != _("Manual Configuration") && p.substr (0, 11) == "urn:ardour:") { + /* lua script - meta-template */ + const std::map<std::string, std::string> rs (ARDOUR_UI::instance()->route_setup_info (p.substr (11))); + + trk_template_desc.set_sensitive (true); + + manual_label.set_sensitive (false); + add_label.set_sensitive (false); + type_label.set_sensitive (false); + + name_label.set_sensitive (rs.find ("name") != rs.end()); + group_label.set_sensitive (rs.find ("group") != rs.end()); + strict_io_label.set_sensitive (rs.find ("strict_io") != rs.end()); + configuration_label.set_sensitive (rs.find ("channels") != rs.end ()); + mode_label.set_sensitive (rs.find ("track_mode") != rs.end ()); + instrument_label.set_sensitive (rs.find ("instrument") != rs.end ()); + strict_io_label.set_sensitive (rs.find ("strict_io") != rs.end()); + + track_bus_combo.set_sensitive (false); + routes_spinner.set_sensitive (rs.find ("how_many") != rs.end ()); + name_template_entry.set_sensitive (rs.find ("name") != rs.end ()); + route_group_combo.set_sensitive (rs.find ("group") != rs.end()); + channel_combo.set_sensitive (rs.find ("channels") != rs.end ()); + mode_combo.set_sensitive (rs.find ("track_mode") != rs.end ()); + instrument_combo.set_sensitive (rs.find ("instrument") != rs.end ()); + strict_io_combo.set_sensitive (rs.find ("strict_io") != rs.end()); + + std::map<string,string>::const_iterator it; + + if ((it = rs.find ("name")) != rs.end()) { + name_template_entry.set_text (it->second); + } + + if ((it = rs.find ("how_many")) != rs.end()) { + routes_adjustment.set_value (atoi (it->second.c_str())); + } + + if ((it = rs.find ("track_mode")) != rs.end()) { + switch ((ARDOUR::TrackMode) atoi (it->second.c_str())) { + case ARDOUR::Normal: + mode_combo.set_active_text (_("Normal")); + break; + case ARDOUR::NonLayered: + mode_combo.set_active_text (_("Nn Layered")); + break; + case ARDOUR::Destructive: + mode_combo.set_active_text (_("Tape")); + break; + } + } + if ((it = rs.find ("strict_io")) != rs.end()) { + if (it->second == X_("true")) { + strict_io_combo.set_active (1); + } else if (it->second == X_("false")) { + strict_io_combo.set_active (0); + } + } + + if ((it = rs.find ("channels")) != rs.end()) { + uint32_t channels = atoi (it->second.c_str()); + for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) { + if ((*i).channels == channels) { + channel_combo.set_active_text ((*i).name); + break; + } + } + } + + } else if ( n != _("Manual Configuration")) { + /* user-template */ trk_template_desc.set_sensitive (true); manual_label.set_sensitive (false); add_label.set_sensitive (false); type_label.set_sensitive (false); - name_label.set_sensitive (!meta_template); + name_label.set_sensitive (true); group_label.set_sensitive (false); strict_io_label.set_sensitive (false); configuration_label.set_sensitive (false); mode_label.set_sensitive (false); + instrument_label.set_sensitive (false); - routes_spinner.set_sensitive (!meta_template); + routes_spinner.set_sensitive (true); track_bus_combo.set_sensitive (false); - name_template_entry.set_sensitive (!meta_template); + name_template_entry.set_sensitive (true); channel_combo.set_sensitive (false); mode_combo.set_sensitive (false); instrument_combo.set_sensitive (false); @@ -314,7 +388,7 @@ AddRouteDialog::trk_template_row_selected () route_group_combo.set_sensitive (false); } else { - + /* all manual mode */ trk_template_desc.set_sensitive (false); manual_label.set_sensitive (true); @@ -564,21 +638,26 @@ AddRouteDialog::mode () return ARDOUR::Normal; } +uint32_t +AddRouteDialog::channel_count () +{ + string str = channel_combo.get_active_text(); + for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) { + if (str == (*i).name) { + return (*i).channels; + } + } + return 0; +} + ChanCount AddRouteDialog::channels () { ChanCount ret; - string str; switch (type_wanted()) { case AudioTrack: case AudioBus: - str = channel_combo.get_active_text(); - for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) { - if (str == (*i).name) { - ret.set (DataType::AUDIO, (*i).channels); - break; - } - } + ret.set (DataType::MIDI, channel_count ()); ret.set (DataType::MIDI, 0); break; @@ -589,13 +668,7 @@ AddRouteDialog::channels () break; case MixedTrack: - str = channel_combo.get_active_text(); - for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) { - if (str == (*i).name) { - ret.set (DataType::AUDIO, (*i).channels); - break; - } - } + ret.set (DataType::MIDI, channel_count ()); ret.set (DataType::MIDI, 1); break; default: @@ -676,8 +749,11 @@ AddRouteDialog::refill_channel_setups () trk_template_model->clear(); /* Add any Lua scripts (factory templates) found in the scripts folder */ - LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::TrackSetup)); + LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction)); for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) { + if (!((*s)->subtype & LuaScriptInfo::RouteSetup)) { + continue; + } TreeModel::Row row; if ( (*s)->name == "Add tracks") { //somewhat-special, most-used template row = *(trk_template_model->prepend ()); diff --git a/gtk2_ardour/add_route_dialog.h b/gtk2_ardour/add_route_dialog.h index 920113f275..c49e1a1692 100644 --- a/gtk2_ardour/add_route_dialog.h +++ b/gtk2_ardour/add_route_dialog.h @@ -71,6 +71,7 @@ public: TypeWanted type_wanted() const; ARDOUR::ChanCount channels (); + uint32_t channel_count (); int count (); std::string name_template () const; diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 95a97d2829..d3b07badb9 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -3885,6 +3885,100 @@ static void _lua_print (std::string s) { PBD::info << "LuaInstance: " << s << endmsg; } +std::map<std::string, std::string> +ARDOUR_UI::route_setup_info (const std::string& script_path) +{ + std::map<std::string, std::string> rv; + + if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) { + return rv; + } + + LuaState lua; + lua.Print.connect (&_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, "route_setup"); + if (!fn.isFunction ()) { + return rv; + } + luabridge::LuaRef rs = fn (); + if (!rs.isTable ()) { + return rv; + } + for (luabridge::Iterator i(rs); !i.isNil (); ++i) { + if (!i.key().isString()) { + continue; + } + std::string key = i.key().tostring(); + if (i.value().isString() || i.value().isNumber() || i.value().isBoolean()) { + rv[key] = i.value().tostring(); + } + } + } catch (luabridge::LuaException const& e) { + cerr << "LuaException:" << e.what () << endl; + return rv; + } + return rv; +} + +void +ARDOUR_UI::meta_route_setup (const std::string& script_path) +{ + if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) { + return; + } + assert (add_route_dialog); + + int count; + if ((count = add_route_dialog->count()) <= 0) { + return; + } + + LuaState lua; + lua.Print.connect (&_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); + + luabridge::LuaRef args (luabridge::newTable (L)); + + args["name"] = add_route_dialog->name_template (); + args["insert_at"] = translate_order (add_route_dialog->insert_at()); + args["group"] = add_route_dialog->route_group (); + args["strict_io"] = add_route_dialog->use_strict_io (); + args["instrument"] = add_route_dialog->requested_instrument (); + args["track_mode"] = add_route_dialog->mode (); + args["channels"] = add_route_dialog->channel_count (); + args["how_many"] = count; + + try { + luabridge::LuaRef fn = luabridge::getGlobal (L, "factory"); + if (fn.isFunction()) { + fn (args)(); + } + } catch (luabridge::LuaException const& e) { + cerr << "LuaException:" << e.what () << endl; + } +} + void ARDOUR_UI::meta_session_setup (const std::string& script_path) { @@ -3906,9 +4000,9 @@ ARDOUR_UI::meta_session_setup (const std::string& script_path) lua.do_file (script_path); try { - luabridge::LuaRef fn = luabridge::getGlobal (L, "session_setup"); + luabridge::LuaRef fn = luabridge::getGlobal (L, "factory"); if (fn.isFunction()) { - fn (); + fn ()(); } } catch (luabridge::LuaException const& e) { cerr << "LuaException:" << e.what () << endl; @@ -4379,7 +4473,7 @@ ARDOUR_UI::add_route_dialog_response (int r) std::string template_path = add_route_dialog->get_template_path(); if (!template_path.empty() && template_path.substr (0, 11) == "urn:ardour:") { - meta_session_setup (template_path.substr (11)); + meta_route_setup (template_path.substr (11)); return; } diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index ae1cd9c132..de1b598b3c 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -67,6 +67,8 @@ #include "ardour/session_handle.h" #include "ardour/system_exec.h" +#include "LuaBridge/LuaBridge.h" + #include "video_timeline.h" #include "widgets/ardour_button.h" @@ -347,6 +349,8 @@ public: ARDOUR::PresentationInfo::order_t translate_order (RouteDialogs::InsertAt); + std::map<std::string, std::string> route_setup_info (const std::string& script_path); + protected: friend class PublicEditor; @@ -624,6 +628,7 @@ private: void manage_templates (); void meta_session_setup (const std::string& script_path); + void meta_route_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 2337d985c3..a41078c49a 100644 --- a/gtk2_ardour/session_dialog.cc +++ b/gtk2_ardour/session_dialog.cc @@ -237,7 +237,7 @@ SessionDialog::meta_master_bus_profile (std::string script_path) const } LuaScriptInfo::ScriptType type = LuaScriptInfo::str2type (nfo["type"].cast<std::string>()); - if (type != LuaScriptInfo::SessionSetup) { + if (type != LuaScriptInfo::SessionInit) { return UINT32_MAX; } @@ -562,10 +562,22 @@ SessionDialog::populate_session_templates () template_model->clear (); //Add any Lua scripts (factory templates) found in the scripts folder - LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionSetup)); + LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit)); for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) { - TreeModel::Row row; - row = *(template_model->append ()); + TreeModel::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.description] = (*s)->description; + row[session_template_columns.created_with_short] = _("{Factory Template}"); + row[session_template_columns.created_with_long] = _("{Factory Template}"); + } + + LuaScriptList& as (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction)); + for (LuaScriptList::const_iterator s = as.begin(); s != as.end(); ++s) { + if (!((*s)->subtype & LuaScriptInfo::SessionSetup)) { + continue; + } + TreeModel::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.description] = (*s)->description; |