diff options
author | Robin Gareus <robin@gareus.org> | 2016-02-23 15:41:21 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-02-23 15:41:21 +0100 |
commit | f4553880f6a68b7cd8cb4cc5dcfc24612b00fc54 (patch) | |
tree | 002485e6de77e5944cbd8b34dea6d37bbf5ef13b /libs/ardour/session_state.cc | |
parent | 51385ced3c5564bb9155c9072321740b8eaac928 (diff) |
Implement Lua session-scripts
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r-- | libs/ardour/session_state.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index fcd16788d8..e252563dcd 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -122,6 +122,8 @@ #include "control_protocol/control_protocol.h" +#include "LuaBridge/LuaBridge.h" + #include "i18n.h" #include <locale.h> @@ -1249,6 +1251,26 @@ Session::state (bool full_state) node->add_child_copy (*_extra_xml); } + { + Glib::Threads::Mutex::Lock lm (lua_lock); + std::string saved; + { + luabridge::LuaRef savedstate ((*_lua_save)()); + saved = savedstate.cast<std::string>(); + } + lua.collect_garbage (); + lm.release (); + + gchar* b64 = g_base64_encode ((const guchar*)saved.c_str (), saved.size ()); + std::string b64s (b64); + g_free (b64); + + XMLNode* script_node = new XMLNode (X_("Script")); + script_node->add_property (X_("lua"), LUA_VERSION); + script_node->add_content (b64s); + node->add_child_nocopy (*script_node); + } + return *node; } @@ -1459,6 +1481,21 @@ Session::set_state (const XMLNode& node, int version) ControlProtocolManager::instance().set_state (*child, version); } + if ((child = find_named_node (node, "Script"))) { + for (XMLNodeList::const_iterator n = child->children ().begin (); n != child->children ().end (); ++n) { + if (!(*n)->is_content ()) { continue; } + gsize size; + guchar* buf = g_base64_decode ((*n)->content ().c_str (), &size); + try { + Glib::Threads::Mutex::Lock lm (lua_lock); + (*_lua_load)(std::string ((const char*)buf, size)); + } catch (luabridge::LuaException const& e) { + cerr << "LuaException:" << e.what () << endl; + } + g_free (buf); + } + } + update_route_record_state (); /* here beginneth the second phase ... */ |