mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 07:14:56 +01:00
Allow to un/load Lua Session Scripts in the Script Manager
This commit is contained in:
parent
32fe5a083e
commit
a732c7c9fa
4 changed files with 159 additions and 3 deletions
|
|
@ -116,6 +116,7 @@ ARDOUR_UI::set_session (Session *s)
|
|||
secondary_clock->set_session (s);
|
||||
big_clock->set_session (s);
|
||||
video_timeline->set_session (s);
|
||||
lua_script_window->set_session (s);
|
||||
|
||||
/* sensitize menu bar options that are now valid */
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,13 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "gtkmm2ext/gui_thread.h"
|
||||
#include "gtkmm2ext/utils.h"
|
||||
|
||||
#include "ardour/session.h"
|
||||
|
||||
#include "LuaBridge/LuaBridge.h"
|
||||
|
||||
#include "lua_script_manager.h"
|
||||
#include "script_selector.h"
|
||||
#include "pbd/i18n.h"
|
||||
|
|
@ -34,6 +39,8 @@ LuaScriptManager::LuaScriptManager ()
|
|||
, _a_call_button (_("Call"))
|
||||
, _c_add_button (_("New Hook"))
|
||||
, _c_del_button (_("Remove"))
|
||||
, _s_add_button (_("Load"))
|
||||
, _s_del_button (_("Remove"))
|
||||
{
|
||||
/* action script page */
|
||||
_a_store = ListStore::create (_a_model);
|
||||
|
|
@ -98,21 +105,62 @@ LuaScriptManager::LuaScriptManager ()
|
|||
|
||||
pages.pages ().push_back (Notebook_Helpers::TabElem (*vbox, "Action Hooks"));
|
||||
|
||||
/* session script page */
|
||||
|
||||
_s_store = ListStore::create (_s_model);
|
||||
_s_view.set_model (_s_store);
|
||||
_s_view.append_column (_("Name"), _s_model.name);
|
||||
_s_view.get_column(0)->set_resizable (true);
|
||||
_s_view.get_column(0)->set_expand (true);
|
||||
|
||||
edit_box = manage (new Gtk::HBox);
|
||||
edit_box->set_spacing(3);
|
||||
edit_box->pack_start (_s_add_button, true, true);
|
||||
edit_box->pack_start (_s_del_button, true, true);
|
||||
|
||||
_s_add_button.signal_clicked().connect (sigc::mem_fun(*this, &LuaScriptManager::add_sess_btn_clicked));
|
||||
_s_del_button.signal_clicked().connect (sigc::mem_fun(*this, &LuaScriptManager::del_sess_btn_clicked));
|
||||
_s_view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &LuaScriptManager::session_script_selection_changed));
|
||||
|
||||
vbox = manage (new VBox());
|
||||
vbox->pack_start (_s_view, false, false);
|
||||
vbox->pack_end (*edit_box, false, false);
|
||||
vbox->show_all ();
|
||||
|
||||
pages.pages ().push_back (Notebook_Helpers::TabElem (*vbox, "Session Scripts"));
|
||||
|
||||
/* global layout */
|
||||
|
||||
add (pages);
|
||||
pages.show();
|
||||
|
||||
setup_actions ();
|
||||
setup_callbacks ();
|
||||
setup_session_scripts ();
|
||||
|
||||
action_selection_changed ();
|
||||
callback_selection_changed ();
|
||||
session_script_selection_changed ();
|
||||
}
|
||||
|
||||
void
|
||||
LuaScriptManager::set_session (ARDOUR::Session *s)
|
||||
{
|
||||
ArdourWindow::set_session (s);
|
||||
setup_session_scripts ();
|
||||
if (!_session) {
|
||||
return;
|
||||
}
|
||||
|
||||
_session->LuaScriptsChanged.connect (_session_script_connection, invalidator (*this), boost::bind (&LuaScriptManager::setup_session_scripts, this), gui_context());
|
||||
setup_session_scripts ();
|
||||
}
|
||||
|
||||
void
|
||||
LuaScriptManager::session_going_away ()
|
||||
{
|
||||
ArdourWindow::session_going_away ();
|
||||
_session_script_connection.disconnect ();
|
||||
hide_all();
|
||||
}
|
||||
|
||||
|
|
@ -310,3 +358,61 @@ LuaScriptManager::set_callback_script_name (PBD::ID id, const std::string& name,
|
|||
}
|
||||
callback_selection_changed ();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LuaScriptManager::setup_session_scripts ()
|
||||
{
|
||||
_s_store->clear ();
|
||||
if (!_session) {
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> reg = _session->registered_lua_functions ();
|
||||
for (std::vector<string>::const_iterator i = reg.begin(); i != reg.end(); ++i) {
|
||||
TreeModel::Row r = *_s_store->append ();
|
||||
r[_s_model.name] = *i;
|
||||
}
|
||||
session_script_selection_changed ();
|
||||
}
|
||||
|
||||
void
|
||||
LuaScriptManager::session_script_selection_changed ()
|
||||
{
|
||||
if (!_session) {
|
||||
_s_del_button.set_sensitive (false);
|
||||
_s_add_button.set_sensitive (false);
|
||||
return;
|
||||
}
|
||||
TreeModel::Row row = *(_s_view.get_selection()->get_selected());
|
||||
if (row) {
|
||||
_s_del_button.set_sensitive (true);
|
||||
} else {
|
||||
_s_del_button.set_sensitive (false);
|
||||
}
|
||||
_s_add_button.set_sensitive (true);
|
||||
}
|
||||
|
||||
void
|
||||
LuaScriptManager::add_sess_btn_clicked ()
|
||||
{
|
||||
if (!_session) {
|
||||
return;
|
||||
}
|
||||
LuaInstance *li = LuaInstance::instance();
|
||||
li->interactive_add (LuaScriptInfo::Session, -1);
|
||||
}
|
||||
|
||||
void
|
||||
LuaScriptManager::del_sess_btn_clicked ()
|
||||
{
|
||||
assert (_session);
|
||||
TreeModel::Row row = *(_s_view.get_selection()->get_selected());
|
||||
const std::string& name = row[_s_model.name];
|
||||
try {
|
||||
_session->unregister_lua_function (name);
|
||||
} catch (luabridge::LuaException const& e) {
|
||||
string msg = string_compose (_("Session script '%1' removal failed: %2"), name, e.what ());
|
||||
MessageDialog am (msg);
|
||||
am.run ();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class LuaScriptManager : public ArdourWindow
|
|||
{
|
||||
public:
|
||||
LuaScriptManager ();
|
||||
void set_session (ARDOUR::Session *);
|
||||
|
||||
protected:
|
||||
void session_going_away();
|
||||
|
|
@ -101,6 +102,33 @@ private:
|
|||
|
||||
Gtk::Button _c_add_button;
|
||||
Gtk::Button _c_del_button;
|
||||
|
||||
/* Session scripts */
|
||||
void setup_session_scripts ();
|
||||
void session_script_selection_changed ();
|
||||
|
||||
void add_sess_btn_clicked ();
|
||||
void del_sess_btn_clicked ();
|
||||
|
||||
class LuaSessionScriptModelColumns : public Gtk::TreeModelColumnRecord
|
||||
{
|
||||
public:
|
||||
LuaSessionScriptModelColumns ()
|
||||
{
|
||||
add (name);
|
||||
}
|
||||
|
||||
Gtk::TreeModelColumn<std::string> name;
|
||||
};
|
||||
|
||||
Glib::RefPtr<Gtk::ListStore> _s_store;
|
||||
LuaCallbackScriptModelColumns _s_model;
|
||||
Gtk::TreeView _s_view;
|
||||
|
||||
Gtk::Button _s_add_button;
|
||||
Gtk::Button _s_del_button;
|
||||
|
||||
PBD::ScopedConnection _session_script_connection;
|
||||
};
|
||||
|
||||
#endif /* _gtk2_ardour_lua_script_manager_h_ */
|
||||
|
|
|
|||
|
|
@ -1101,16 +1101,25 @@ bool
|
|||
LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id)
|
||||
{
|
||||
std::string title;
|
||||
std::string param_function = "action_params";
|
||||
std::vector<std::string> reg;
|
||||
|
||||
switch (type) {
|
||||
case LuaScriptInfo::EditorAction:
|
||||
reg = lua_action_names ();
|
||||
title = "Add Lua Action";
|
||||
title = _("Add Lua Action");
|
||||
break;
|
||||
case LuaScriptInfo::EditorHook:
|
||||
reg = lua_slot_names ();
|
||||
title = "Add Lua Callback Hook";
|
||||
title = _("Add Lua Callback Hook");
|
||||
break;
|
||||
case LuaScriptInfo::Session:
|
||||
if (!_session) {
|
||||
return false;
|
||||
}
|
||||
reg = _session->registered_lua_functions ();
|
||||
title = _("Add Lua Session Script");
|
||||
param_function = "sess_params";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
|
@ -1138,7 +1147,7 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id)
|
|||
return false;
|
||||
}
|
||||
|
||||
LuaScriptParamList lsp = LuaScriptParams::script_params (spi, "action_params");
|
||||
LuaScriptParamList lsp = LuaScriptParams::script_params (spi, param_function);
|
||||
|
||||
ScriptParameterDialog spd (_("Set Script Parameters"), spi, reg, lsp);
|
||||
switch (spd.run ()) {
|
||||
|
|
@ -1155,6 +1164,18 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id)
|
|||
case LuaScriptInfo::EditorHook:
|
||||
return register_lua_slot (spd.name(), script, lsp);
|
||||
break;
|
||||
case LuaScriptInfo::Session:
|
||||
try {
|
||||
_session->register_lua_function (spd.name(), script, lsp);
|
||||
} catch (luabridge::LuaException const& e) {
|
||||
string msg = string_compose (_("Session script '%1' instantiation failed: %2"), spd.name(), e.what ());
|
||||
Gtk::MessageDialog am (msg);
|
||||
am.run ();
|
||||
} catch (SessionException e) {
|
||||
string msg = string_compose (_("Loading Session script '%1' failed: %2"), spd.name(), e.what ());
|
||||
Gtk::MessageDialog am (msg);
|
||||
am.run ();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue