From 0e70b779b4dc812faefa8ab4708fc1249bd89b0d Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 10 Apr 2016 01:45:41 +0200 Subject: [PATCH] expose Undo Commands to Lua Some trickery is needed here to manage object lifetimes and multiple inheritance. --- libs/ardour/ardour/session.h | 2 ++ libs/ardour/luabindings.cc | 46 +++++++++++++++++++++++++++++------- libs/ardour/session.cc | 1 + libs/ardour/session_state.cc | 9 +++++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 4efe41f9cc..c25d80ccf5 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -862,6 +862,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop void add_command (Command *const cmd); + PBD::StatefulDiffCommand* add_stateful_diff_command (boost::shared_ptr); + /** @return The list of operations that are currently in progress */ std::list const & current_operations () { return _current_trans_quarks; diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 7e1379912f..9130af69d5 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -16,7 +16,10 @@ 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include + #include "timecode/bbt_time.h" +#include "pbd/stateful_diff_command.h" #include "evoral/Control.hpp" #include "evoral/ControlList.hpp" #include "evoral/Range.hpp" @@ -107,16 +110,37 @@ LuaBindings::common (lua_State* L) .beginClass ("Stateful") .addFunction ("properties", &PBD::Stateful::properties) + .addFunction ("clear_changes", &PBD::Stateful::clear_changes) + .endClass () + + .beginWSPtrClass ("StatefulPtr") + .addFunction ("properties", &PBD::Stateful::properties) + .addFunction ("clear_changes", &PBD::Stateful::clear_changes) .endClass () .deriveClass ("StatefulDestructible") .endClass () - .beginWSPtrClass ("StatefulPtr") - .addFunction ("properties", &PBD::Stateful::properties) + .deriveWSPtrClass ("StatefulDestructiblePtr") .endClass () - .deriveWSPtrClass ("StatefulDestructiblePtr") + .deriveClass ("Command") + .addFunction ("set_name", &Command::set_name) + .addFunction ("name", &Command::name) + .endClass () + + /* UndoTransaction::add_command() subscribes to DropReferences() + * and deletes the object. + * + * This object cannot be constructed by lua because lua would manage lifetime + * and delete the object leading to a double free. + * + * use Session::add_stateful_diff_command() + * and Session::abort_reversible_command() + */ + .deriveClass ("StatefulDiffCommand") + .addFunction ("undo", &PBD::StatefulDiffCommand::undo) + .addFunction ("empty", &PBD::StatefulDiffCommand::empty) .endClass () .deriveWSPtrClass ("Controllable") @@ -260,6 +284,10 @@ LuaBindings::common (lua_State* L) .endClass () .deriveWSPtrClass ("SessionObject") + /* multiple inheritance is not covered by luabridge, + * we need explicit casts :( */ + .addCast ("to_stateful") + .addCast ("to_statefuldestructible") .addFunction ("name", &SessionObject::name) .endClass () @@ -426,11 +454,8 @@ LuaBindings::common (lua_State* L) .addData ("logarithmic", &ParameterDescriptor::logarithmic) .endClass () - .deriveWSPtrClass ("Processor") - // TODO mult. inheritance - .endClass () - .deriveWSPtrClass ("Processor") + .addCast ("to_sessionobject") .addCast ("to_insert") .addCast ("to_sidechain") .addCast ("to_ioprocessor") @@ -589,7 +614,7 @@ LuaBindings::common (lua_State* L) .addStaticCFunction ("null", &LuaAPI::datatype_ctor_null) // "nil" is a lua reseved word .addStaticCFunction ("audio", &LuaAPI::datatype_ctor_audio) .addStaticCFunction ("midi", &LuaAPI::datatype_ctor_midi) - .addFunction ("to_string", &DataType::to_string) + .addFunction ("to_string", &DataType::to_string) // TODO Lua __tostring // TODO add uint32_t cast, add operator== != .endClass() @@ -731,6 +756,10 @@ LuaBindings::common (lua_State* L) .addFunction ("snap_name", &Session::snap_name) .addFunction ("tempo_map", (TempoMap& (Session::*)())&Session::tempo_map) .addFunction ("locations", &Session::locations) + .addFunction ("begin_reversible_command", (void (Session::*)(const std::string&))&Session::begin_reversible_command) + .addFunction ("commit_reversible_command", &Session::commit_reversible_command) + .addFunction ("abort_reversible_command", &Session::abort_reversible_command) + .addFunction ("add_stateful_diff_command", &Session::add_stateful_diff_command) .endClass () .beginClass ("RegionFactory") @@ -755,6 +784,7 @@ LuaBindings::common (lua_State* L) .addFunction ("new_plugin", ARDOUR::LuaAPI::new_plugin) .addFunction ("set_processor_param", ARDOUR::LuaAPI::set_processor_param) .addFunction ("set_plugin_insert_param", ARDOUR::LuaAPI::set_plugin_insert_param) + .addFunction ("usleep", Glib::usleep) .endNamespace () .endNamespace ();// END ARDOUR diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index edae568645..b412841180 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -5898,6 +5898,7 @@ Session::write_one_track (Track& track, framepos_t start, framepos_t end, } unblock_processing (); + itt.done = true; return result; } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 6344a953e5..41fb75ccc9 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2614,6 +2614,15 @@ Session::add_command (Command* const cmd) cmd->name ())); _current_trans->add_command (cmd); } + +PBD::StatefulDiffCommand* +Session::add_stateful_diff_command (boost::shared_ptr sfd) +{ + PBD::StatefulDiffCommand* cmd = new PBD::StatefulDiffCommand (sfd); + add_command (cmd); + return cmd; +} + void Session::begin_reversible_command (const string& name) {