expose Undo Commands to Lua
authorRobin Gareus <robin@gareus.org>
Sat, 9 Apr 2016 23:45:41 +0000 (01:45 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 9 Apr 2016 23:45:41 +0000 (01:45 +0200)
Some trickery is needed here to manage object lifetimes and
multiple inheritance.

libs/ardour/ardour/session.h
libs/ardour/luabindings.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index 4efe41f9cc0114876575178cfa94182dfbee0ed5..c25d80ccf51b6e17850f852419504702a3fef2a7 100644 (file)
@@ -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;
index 7e1379912fa9bc180942130ceaf9b8986ac53c25..9130af69d5535abe38876e2e81bb72ff75d48d40 100644 (file)
     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
index edae568645e8e92634b445eb054a7567b76952e7..b4128411801395bf4d27ceebc603d9a0c64f6b41 100644 (file)
@@ -5898,6 +5898,7 @@ Session::write_one_track (Track& track, framepos_t start, framepos_t end,
        }
 
        unblock_processing ();
+       itt.done = true;
 
        return result;
 }
index 6344a953e5d09ba991ebf1b24bbdee0cabb45cdf..41fb75ccc92eb513ae610d02dfdad1c3258f810c 100644 (file)
@@ -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)
 {