summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-04-10 01:45:41 +0200
committerRobin Gareus <robin@gareus.org>2016-04-10 01:45:41 +0200
commit0e70b779b4dc812faefa8ab4708fc1249bd89b0d (patch)
tree5d12d3195b0b11cfcd24314de7e64f1e636bdd7d
parentfa7b15babfdb73db0aeb94a158c0c90a5e36a12c (diff)
expose Undo Commands to Lua
Some trickery is needed here to manage object lifetimes and multiple inheritance.
-rw-r--r--libs/ardour/ardour/session.h2
-rw-r--r--libs/ardour/luabindings.cc46
-rw-r--r--libs/ardour/session.cc1
-rw-r--r--libs/ardour/session_state.cc9
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<PBD::StatefulDestructible>);
+
/** @return The list of operations that are currently in progress */
std::list<GQuark> 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 <glibmm.h>
+
#include "timecode/bbt_time.h"
+#include "pbd/stateful_diff_command.h"
#include "evoral/Control.hpp"
#include "evoral/ControlList.hpp"
#include "evoral/Range.hpp"
@@ -107,18 +110,39 @@ LuaBindings::common (lua_State* L)
.beginClass <PBD::Stateful> ("Stateful")
.addFunction ("properties", &PBD::Stateful::properties)
- .endClass ()
-
- .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
+ .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
.endClass ()
.beginWSPtrClass <PBD::Stateful> ("StatefulPtr")
.addFunction ("properties", &PBD::Stateful::properties)
+ .addFunction ("clear_changes", &PBD::Stateful::clear_changes)
+ .endClass ()
+
+ .deriveClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructible")
.endClass ()
.deriveWSPtrClass <PBD::StatefulDestructible, PBD::Stateful> ("StatefulDestructiblePtr")
.endClass ()
+ .deriveClass <Command, PBD::StatefulDestructible> ("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 <PBD::StatefulDiffCommand, Command> ("StatefulDiffCommand")
+ .addFunction ("undo", &PBD::StatefulDiffCommand::undo)
+ .addFunction ("empty", &PBD::StatefulDiffCommand::empty)
+ .endClass ()
+
.deriveWSPtrClass <PBD::Controllable, PBD::StatefulDestructible> ("Controllable")
.addFunction ("get_value", &PBD::Controllable::get_value)
.endClass ()
@@ -260,6 +284,10 @@ LuaBindings::common (lua_State* L)
.endClass ()
.deriveWSPtrClass <SessionObject, PBD::StatefulDestructible> ("SessionObject")
+ /* multiple inheritance is not covered by luabridge,
+ * we need explicit casts :( */
+ .addCast<PBD::Stateful> ("to_stateful")
+ .addCast<PBD::StatefulDestructible> ("to_statefuldestructible")
.addFunction ("name", &SessionObject::name)
.endClass ()
@@ -426,11 +454,8 @@ LuaBindings::common (lua_State* L)
.addData ("logarithmic", &ParameterDescriptor::logarithmic)
.endClass ()
- .deriveWSPtrClass <Processor, SessionObject> ("Processor")
- // TODO mult. inheritance
- .endClass ()
-
.deriveWSPtrClass <Processor, Automatable> ("Processor")
+ .addCast<SessionObject> ("to_sessionobject")
.addCast<PluginInsert> ("to_insert")
.addCast<SideChain> ("to_sidechain")
.addCast<IOProcessor> ("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> ("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<PBD::StatefulDestructible> sfd)
+{
+ PBD::StatefulDiffCommand* cmd = new PBD::StatefulDiffCommand (sfd);
+ add_command (cmd);
+ return cmd;
+}
+
void
Session::begin_reversible_command (const string& name)
{