prepare fix for copying plugin state
[ardour.git] / libs / ardour / lua_api.cc
index 9c562b0a059c7334f0677dabba6d0788cd9b04af..e24902999d4d0fe0bfb11a3e9968d243ee32a2b5 100644 (file)
@@ -36,6 +36,37 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace std;
 
+int
+ARDOUR::LuaAPI::datatype_ctor_null (lua_State *L)
+{
+       DataType dt (DataType::NIL);
+       luabridge::Stack <DataType>::push (L, dt);
+       return 1;
+}
+
+int
+ARDOUR::LuaAPI::datatype_ctor_audio (lua_State *L)
+{
+       DataType dt (DataType::AUDIO);
+       // NB luabridge will copy construct the object and manage lifetime.
+       luabridge::Stack <DataType>::push (L, dt);
+       return 1;
+}
+
+int
+ARDOUR::LuaAPI::datatype_ctor_midi (lua_State *L)
+{
+       DataType dt (DataType::MIDI);
+       luabridge::Stack <DataType>::push (L, dt);
+       return 1;
+}
+
+boost::shared_ptr<Processor>
+ARDOUR::LuaAPI::nil_processor ()
+{
+       return boost::shared_ptr<Processor> ();
+}
+
 boost::shared_ptr<Processor>
 ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
 {
@@ -45,9 +76,9 @@ ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
 
        LuaScriptInfoPtr spi;
        ARDOUR::LuaScriptList & _scripts (LuaScripting::instance ().scripts (LuaScriptInfo::DSP));
-       for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
-               if (name == (*s)->name) {
-                       spi = *s;
+       for (LuaScriptList::const_iterator i = _scripts.begin(); i != _scripts.end(); ++i) {
+               if (name == (*i)->name) {
+                       spi = *i;
                        break;
                }
        }
@@ -152,6 +183,51 @@ ARDOUR::LuaAPI::set_processor_param (boost::shared_ptr<Processor> proc, uint32_t
        return set_plugin_insert_param (pi, which, val);
 }
 
+int
+ARDOUR::LuaAPI::plugin_automation (lua_State *L)
+{
+       typedef boost::shared_ptr<Processor> T;
+
+       int top = lua_gettop(L);
+       if (top < 2) {
+               return luaL_argerror (L, 1, "invalid number of arguments, :plugin_automation (plugin, parameter_number)");
+       }
+       T* const p = luabridge::Userdata::get<T>(L, 1, false);
+       uint32_t which = luabridge::Stack<uint32_t>::get (L, 2);
+       if (!p) {
+               return luaL_error (L, "Invalid pointer to Ardour:Processor");
+       }
+       boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*p);
+       if (!pi) {
+               return luaL_error (L, "Given Processor is not a Plugin Insert");
+       }
+       boost::shared_ptr<Plugin> plugin = pi->plugin();
+       if (!plugin) {
+               return luaL_error (L, "Given Processor is not a Plugin");
+       }
+
+       bool ok=false;
+       uint32_t controlid = plugin->nth_parameter (which, ok);
+       if (!ok) {
+               return luaL_error (L, "Invalid Parameter");
+       }
+       if (!plugin->parameter_is_input (controlid)) {
+               return luaL_error (L, "Given Parameter is not an input");
+       }
+
+       ParameterDescriptor pd;
+       if (plugin->get_parameter_descriptor (controlid, pd) != 0) {
+               return luaL_error (L, "Cannot describe parameter");
+       }
+
+       boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
+
+       luabridge::Stack<boost::shared_ptr<AutomationList> >::push (L, c->alist());
+       luabridge::Stack<boost::shared_ptr<Evoral::ControlList> >::push (L, c->list());
+       luabridge::Stack<ParameterDescriptor>::push (L, pd);
+       return 3;
+}
+
 int
 ARDOUR::LuaOSC::Address::send (lua_State *L)
 {