Allow Lua DSP processors to report latency
authorRobin Gareus <robin@gareus.org>
Fri, 19 Oct 2018 16:10:19 +0000 (18:10 +0200)
committerRobin Gareus <robin@gareus.org>
Fri, 19 Oct 2018 22:24:38 +0000 (00:24 +0200)
libs/ardour/ardour/luaproc.h
libs/ardour/luaproc.cc

index 8ac27095abf8bbad7c8e1edba3d2e57635b07377..45b730ff73a438f2a1dafcf5631b6c25affde313 100644 (file)
@@ -85,7 +85,7 @@ public:
        void cleanup () { }
 
        int set_block_size (pframes_t /*nframes*/) { return 0; }
-       samplecnt_t  signal_latency() const { return 0; }
+       samplecnt_t signal_latency() const { return _signal_latency; }
 
        int connect_and_run (BufferSet& bufs,
                        samplepos_t start, samplepos_t end, double speed,
@@ -148,6 +148,7 @@ private:
 #endif
        LuaState lua;
        luabridge::LuaRef * _lua_dsp;
+       luabridge::LuaRef * _lua_latency;
        std::string _script;
        std::string _origin;
        std::string _docs;
@@ -176,6 +177,8 @@ private:
        std::map<int, std::string> _param_doc;
        uint32_t _designated_bypass_port;
 
+       samplecnt_t _signal_latency;
+
        float* _control_data;
        float* _shadow_data;
 
@@ -192,6 +195,7 @@ private:
        bool _has_midi_input;
        bool _has_midi_output;
 
+
 #ifdef WITH_LUAPROC_STATS
        int64_t _stats_avg[2];
        int64_t _stats_max[2];
index 4e2b32c83840a87876d2415bbe43859220e1e2d0..ec13efb1bf1888a27123aa5a3afdf5535ac177d5 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