From 1339d42c787f07417b9b88c5b3d3925037d0c7e4 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 28 Sep 2017 04:25:50 +0200 Subject: [PATCH] Add DiskIOProc & Latency related Lua bindings & scripts --- libs/ardour/luabindings.cc | 56 +++++++++++++++++++++++++++++++++---- scripts/_dump_latency.lua | 57 ++++++++++++++++++++++++++++++++++---- scripts/s_portengine.lua | 8 ++++-- 3 files changed, 106 insertions(+), 15 deletions(-) diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 58cd71c8a8..a5878a2efd 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -40,6 +40,8 @@ #include "ardour/beats_samples_converter.h" #include "ardour/chan_mapping.h" #include "ardour/dB.h" +#include "ardour/disk_reader.h" +#include "ardour/disk_writer.h" #include "ardour/dsp_filter.h" #include "ardour/file_source.h" #include "ardour/fluid_synth.h" @@ -64,7 +66,9 @@ #include "ardour/runtime_functions.h" #include "ardour/region.h" #include "ardour/region_factory.h" +#include "ardour/return.h" #include "ardour/route_group.h" +#include "ardour/send.h" #include "ardour/session.h" #include "ardour/session_object.h" #include "ardour/sidechain.h" @@ -872,6 +876,10 @@ LuaBindings::common (lua_State* L) .addFunction ("connected_to", (bool (Port::*)(std::string const &)const)&Port::connected_to) .addFunction ("connect", (int (Port::*)(std::string const &))&Port::connect) .addFunction ("disconnect", (int (Port::*)(std::string const &))&Port::disconnect) + .addFunction ("physically_connected", &Port::physically_connected) + .addFunction ("private_latency_range", &Port::private_latency_range) + .addFunction ("public_latency_range", &Port::public_latency_range) + .addRefFunction ("get_connected_latency_range", &Port::get_connected_latency_range) //.addStaticFunction ("port_offset", &Port::port_offset) // static .endClass () @@ -909,6 +917,7 @@ LuaBindings::common (lua_State* L) .addFunction ("port_by_name", &IO::nth) .addFunction ("n_ports", &IO::n_ports) .addFunction ("latency", &IO::latency) + .addFunction ("public_latency", &IO::latency) .endClass () .deriveWSPtrClass ("PannerShell") @@ -1063,6 +1072,7 @@ LuaBindings::common (lua_State* L) .addFunction ("peak_meter", (boost::shared_ptr (Route::*)())&Route::peak_meter) .addFunction ("set_meter_point", &Route::set_meter_point) .addFunction ("signal_latency", &Route::signal_latency) + .addFunction ("playback_latency", &Route::playback_latency) .endClass () .deriveWSPtrClass ("Playlist") @@ -1314,8 +1324,12 @@ LuaBindings::common (lua_State* L) .addCast ("to_ioprocessor") .addCast ("to_unknownprocessor") .addCast ("to_amp") + .addCast ("to_diskioprocessor") + .addCast ("to_diskreader") + .addCast ("to_diskwriter") .addCast ("to_peakmeter") .addCast ("to_monitorprocessor") + .addCast ("to_send") #if 0 // those objects are not yet bound .addCast ("to_capturingprocessor") .addCast ("to_delayline") @@ -1326,8 +1340,22 @@ LuaBindings::common (lua_State* L) .addFunction ("active", &Processor::active) .addFunction ("activate", &Processor::activate) .addFunction ("deactivate", &Processor::deactivate) - .addFunction ("output_streams", &PluginInsert::output_streams) - .addFunction ("input_streams", &PluginInsert::input_streams) + .addFunction ("input_latency", &Processor::input_latency) + .addFunction ("output_latency", &Processor::output_latency) + .addFunction ("capture_offset", &Processor::capture_offset) + .addFunction ("playback_offset", &Processor::playback_offset) + .addFunction ("output_streams", &Processor::output_streams) + .addFunction ("input_streams", &Processor::input_streams) + .addFunction ("signal_latency", &Processor::signal_latency) + .endClass () + + .deriveWSPtrClass ("DiskIOProcessor") + .endClass () + + .deriveWSPtrClass ("DiskReader") + .endClass () + + .deriveWSPtrClass ("DiskWriter") .endClass () .deriveWSPtrClass ("IOProcessor") @@ -1344,6 +1372,20 @@ LuaBindings::common (lua_State* L) .addFunction ("panner_shell", &Route::panner_shell) .endClass () + .deriveWSPtrClass ("Send") + .addFunction ("get_delay_in", &Send::get_delay_in) + .addFunction ("get_delay_out", &Send::get_delay_out) + .endClass () + + .deriveWSPtrClass ("InternalSend") + .endClass () + + .deriveWSPtrClass ("Return") + .endClass () + + .deriveWSPtrClass ("InternalReturn") + .endClass () + .beginNamespace ("Plugin") .beginClass ("IOPortDescription") .addData ("name", &Plugin::IOPortDescription::name) @@ -2007,7 +2049,10 @@ LuaBindings::common (lua_State* L) .addFunction ("set_output_device_name", &AudioBackend::set_output_device_name) .endClass() - .beginClass ("PortEngine") + .beginClass ("LatencyRange") + .addVoidConstructor () + .addData ("min", &LatencyRange::min) + .addData ("max", &LatencyRange::max) .endClass() .beginClass ("PortManager") @@ -2169,9 +2214,8 @@ LuaBindings::common (lua_State* L) .addFunction ("get_block_size", &Session::get_block_size) .addFunction ("worst_output_latency", &Session::worst_output_latency) .addFunction ("worst_input_latency", &Session::worst_input_latency) - .addFunction ("worst_track_latency", &Session::worst_track_latency) - .addFunction ("worst_track_out_latency", &Session::worst_track_out_latency) - .addFunction ("worst_playback_latency", &Session::worst_playback_latency) + .addFunction ("worst_route_latency", &Session::worst_route_latency) + .addFunction ("worst_latency_preroll", &Session::worst_latency_preroll) .addFunction ("cfg", &Session::cfg) .addFunction ("route_groups", &Session::route_groups) .addFunction ("new_route_group", &Session::new_route_group) diff --git a/scripts/_dump_latency.lua b/scripts/_dump_latency.lua index 79b043bfa5..d21af36804 100644 --- a/scripts/_dump_latency.lua +++ b/scripts/_dump_latency.lua @@ -4,14 +4,59 @@ ardour { ["type"] = "Snippet", name = "Dump Latency", } function factory () return function () + local all_procs = true + local show_ports = false + print (" -- Session --") print ("Worst Output Latency: ", Session:worst_output_latency ()) print ("Worst Input Latency: ", Session:worst_input_latency ()) - print ("Worst Track Latency: ", Session:worst_track_latency ()) - print ("Worst Playback Latency:", Session:worst_playback_latency ()) - print (" -- Tracks --") - for t in Session:get_tracks ():iter () do - print (string.format ("%-24s roll-delay: %4d proc: %4d io: %4d", - t:name(), t:initial_delay (), t:signal_latency (), t:output():latency())) + print ("Worst Track Latency: ", Session:worst_route_latency ()) + print ("Worst Latency Preroll: ", Session:worst_latency_preroll ()) + + print (" -- Routes --") + for t in Session:get_routes ():iter () do + print (string.format ("%-30s signal-latency: %4d align: %4d play: %4d || in: %4d out: %4d", + t:name(), + t:signal_latency (), t:playback_latency (false), t:playback_latency (true), + t:input():latency(), t:output():latency())) + local i = 0 + while true do + local proc = t:nth_processor (i) + if proc:isnil () then break end + if all_procs and not proc:to_send():isnil () then + print (string.format (" * %-27s L: %4d in: %4d out: %4d capt: %4d play %4d DLY-SRC: %4d DLY-DST: %4d", + string.sub (proc:name(), 0, 27) , proc:signal_latency(), + proc:input_latency(), proc:output_latency(), + proc:capture_offset(), proc:playback_offset(), + proc:to_send():get_delay_in(), proc:to_send():get_delay_out() + )) + elseif all_procs or not proc:to_diskioprocessor():isnil () then + print (string.format (" * %-27s L: %4d in: %4d out: %4d capt: %4d play %4d", + string.sub (proc:name(), 0, 27) , proc:signal_latency(), + proc:input_latency(), proc:output_latency(), + proc:capture_offset(), proc:playback_offset() + )) + end + i = i + 1 + end + end + + if show_ports then + print (" -- Ports -- (latencies: port, priv, pub)") + local a = Session:engine() + _, t = a:get_ports (ARDOUR.DataType("audio"), ARDOUR.PortList()) + -- table 't' holds argument references. t[2] is the PortList + for p in t[2]:iter() do + local lp = p:get_connected_latency_range (ARDOUR.LatencyRange(), true) + local lc = p:get_connected_latency_range (ARDOUR.LatencyRange(), false) + local ppl = p:private_latency_range (true) + local pcl = p:private_latency_range (false) + local bpl = p:public_latency_range (true) + local bcl = p:public_latency_range (false) + print (string.format ("%-30s play: (%4d, %4d) (%4d, %4d) (%4d, %4d) capt: (%4d, %4d) (%4d, %4d) (%4d, %4d)", + p:name(), + lp[1].min, lp[1].max, ppl.min, ppl.max, bpl.min, bpl.max, + lc[1].min, lc[1].max, pcl.min, pcl.max, bcl.min, bcl.max)) + end end end end diff --git a/scripts/s_portengine.lua b/scripts/s_portengine.lua index 5bbcabdf3f..ebca9ff696 100644 --- a/scripts/s_portengine.lua +++ b/scripts/s_portengine.lua @@ -1,12 +1,14 @@ ardour { ["type"] = "Snippet", name = "portengine" } function factory () return function () - a = Session:engine() + local a = Session:engine() print ("----- Port objects from Ardour's engine ----"); _, t = a:get_ports (ARDOUR.DataType("audio"), ARDOUR.PortList()) -- table 't' holds argument references. t[2] is the PortList for p in t[2]:iter() do - print (p:name()) + local lp = p:get_connected_latency_range (ARDOUR.LatencyRange(), true) + local lc = p:get_connected_latency_range (ARDOUR.LatencyRange(), false) + print (p:name(), " -- Play lat.", lp[1].min, lp[1].max, "Capt lat.", lc[1].min, lc[1].max) end print ("----- Port names queries from the backend ----"); @@ -20,7 +22,7 @@ function factory () return function () _, t = a:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput, C.StringVector()) for n in t[4]:iter() do local printed_name = false; - _, ct = a:get_connections (n, C.StringVector()) + local _, ct = a:get_connections (n, C.StringVector()) for c in ct[2]:iter() do if (not printed_name) then printed_name = true;