Add option to limit automatable control parmaters
[ardour.git] / libs / ardour / luaproc.cc
index 4e2b32c83840a87876d2415bbe43859220e1e2d0..bf93e1df676adfe690d31b3590a2b6e1679c1579 100644 (file)
@@ -54,10 +54,12 @@ LuaProc::LuaProc (AudioEngine& engine,
        , lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
 #endif
        , _lua_dsp (0)
+       , _lua_latency (0)
        , _script (script)
        , _lua_does_channelmapping (false)
        , _lua_has_inline_display (false)
        , _designated_bypass_port (UINT32_MAX)
+       , _signal_latency (0)
        , _control_data (0)
        , _shadow_data (0)
        , _configured (false)
@@ -85,11 +87,13 @@ LuaProc::LuaProc (const LuaProc &other)
        , lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
 #endif
        , _lua_dsp (0)
+       , _lua_latency (0)
        , _script (other.script ())
        , _origin (other._origin)
        , _lua_does_channelmapping (false)
        , _lua_has_inline_display (false)
        , _designated_bypass_port (UINT32_MAX)
+       , _signal_latency (0)
        , _control_data (0)
        , _shadow_data (0)
        , _configured (false)
@@ -125,6 +129,7 @@ LuaProc::~LuaProc () {
 #endif
        lua.do_command ("collectgarbage();");
        delete (_lua_dsp);
+       delete (_lua_latency);
        delete [] _control_data;
        delete [] _shadow_data;
 }
@@ -236,6 +241,11 @@ LuaProc::load_script ()
                assert (0);
        }
 
+       luabridge::LuaRef lua_dsp_latency = luabridge::getGlobal (L, "dsp_latency");
+       if (lua_dsp_latency.type () == LUA_TFUNCTION) {
+               _lua_latency = new luabridge::LuaRef (lua_dsp_latency);
+       }
+
        // initialize the DSP if needed
        luabridge::LuaRef lua_dsp_init = luabridge::getGlobal (L, "dsp_init");
        if (lua_dsp_init.type () == LUA_TFUNCTION) {
@@ -735,6 +745,11 @@ LuaProc::connect_and_run (BufferSet& bufs,
                                }
                        }
                }
+
+               if (_lua_latency) {
+                       _signal_latency = (*_lua_latency)();
+               }
+
        } catch (luabridge::LuaException const& e) {
                PBD::error << "LuaException: " << e.what () << "\n";
 #ifndef NDEBUG
@@ -1243,7 +1258,7 @@ LuaPluginInfo::load (Session& session)
 
        try {
                script = Glib::file_get_contents (path);
-       } catch (Glib::FileError err) {
+       } catch (Glib::FileError const& err) {
                return PluginPtr ();
        }