From e974a861ead7d729b9eba465fed9350c89cab770 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 1 Oct 2025 22:52:07 +0200 Subject: [PATCH] LV2: add debug option to dump plugin/UI Atom communication --- libs/ardour/ardour/debug.h | 2 ++ libs/ardour/debug.cc | 2 ++ libs/ardour/lv2_plugin.cc | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/libs/ardour/ardour/debug.h b/libs/ardour/ardour/debug.h index c5e71d5c13..8d3e5a7f1c 100644 --- a/libs/ardour/ardour/debug.h +++ b/libs/ardour/ardour/debug.h @@ -61,6 +61,8 @@ namespace PBD { LIBARDOUR_API extern DebugBits IOTaskList; LIBARDOUR_API extern DebugBits LTC; LIBARDOUR_API extern DebugBits LV2; + LIBARDOUR_API extern DebugBits LV2AtomToUI; + LIBARDOUR_API extern DebugBits LV2AtomFromUI; LIBARDOUR_API extern DebugBits LV2Automate; LIBARDOUR_API extern DebugBits LatencyCompensation; LIBARDOUR_API extern DebugBits LatencyDelayLine; diff --git a/libs/ardour/debug.cc b/libs/ardour/debug.cc index b738c3f7b7..99ed4ff45f 100644 --- a/libs/ardour/debug.cc +++ b/libs/ardour/debug.cc @@ -57,6 +57,8 @@ PBD::DebugBits PBD::DEBUG::Graph = PBD::new_debug_bit ("graph"); PBD::DebugBits PBD::DEBUG::IOTaskList = PBD::new_debug_bit ("iotasklist"); PBD::DebugBits PBD::DEBUG::LTC = PBD::new_debug_bit ("ltc"); PBD::DebugBits PBD::DEBUG::LV2 = PBD::new_debug_bit ("lv2"); +PBD::DebugBits PBD::DEBUG::LV2AtomToUI = PBD::new_debug_bit ("lv2atomtoui"); +PBD::DebugBits PBD::DEBUG::LV2AtomFromUI = PBD::new_debug_bit ("lv2atomfromui"); PBD::DebugBits PBD::DEBUG::LV2Automate = PBD::new_debug_bit ("lv2automate"); PBD::DebugBits PBD::DEBUG::LatencyCompensation = PBD::new_debug_bit ("latencycompensation"); PBD::DebugBits PBD::DEBUG::LatencyDelayLine = PBD::new_debug_bit ("latencydelayline"); diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index f488a708a8..94318f490c 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -119,6 +119,10 @@ #include #endif +#ifdef HAVE_SRATOM +#include +#endif + // Compatibility for old LV2 #ifndef LV2_ATOM_CONTENTS_CONST #define LV2_ATOM_CONTENTS_CONST(type, atom) \ @@ -1916,6 +1920,24 @@ LV2Plugin::write_from_ui(uint32_t index, return false; } +#ifdef HAVE_SRATOM + if (DEBUG_ENABLED (DEBUG::LV2AtomFromUI)) { + Sratom* sratom = sratom_new (_uri_map.urid_map()); + const LV2_Atom* atom = (LV2_Atom const*)(body); + char* const str = sratom_to_turtle (sratom, + _uri_map.urid_unmap(), + "ardour:", + NULL, + NULL, + atom->type, + atom->size, + LV2_ATOM_BODY_CONST(atom)); + DEBUG_TRACE (DEBUG::LV2AtomFromUI, string_compose ("Plugin[%1] <- UI: port %2 (%3 bytes)\n%4\n", name(), index, atom->size, str)); + free (str); + sratom_free (sratom); + } +#endif + Glib::Threads::Mutex::Lock lm (_slave_lock, Glib::Threads::TRY_LOCK); if (lm.locked()) { for (auto const& i : _slaves) { @@ -3282,6 +3304,24 @@ LV2Plugin::connect_and_run(BufferSet& bufs, } if (!_to_ui) continue; + +#ifdef HAVE_SRATOM + if (DEBUG_ENABLED (DEBUG::LV2AtomToUI)) { + Sratom* sratom = sratom_new (_uri_map.urid_map()); + LV2_Atom const* atom = (LV2_Atom*)(data - sizeof(LV2_Atom)); + char* const str = sratom_to_turtle (sratom, + _uri_map.urid_unmap(), + "ardour:", + NULL, + NULL, + atom->type, + atom->size, + LV2_ATOM_BODY_CONST(atom)); + DEBUG_TRACE (DEBUG::LV2AtomToUI, string_compose ("Plugin[%1] -> UI: port %2 (%3 bytes)\n%4\n", name(), port_index, atom->size, str)); + free (str); + sratom_free (sratom); + } +#endif write_to_ui(port_index, URIMap::instance().urids.atom_eventTransfer, size + sizeof(LV2_Atom), data - sizeof(LV2_Atom));