From af6f8abdc79d4238b5a9364dc37c32a4ec87cb4c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 1 May 2022 15:57:03 +0200 Subject: [PATCH] Prepare IOPlug processing as GraphNode --- libs/ardour/ardour/graph.h | 3 +++ libs/ardour/ardour/io_plug.h | 10 +++++++++- libs/ardour/ardour/session.h | 1 + libs/ardour/graph.cc | 28 ++++++++++++++++++++++++++++ libs/ardour/io_plug.cc | 19 +++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/graph.h b/libs/ardour/ardour/graph.h index d7798f4cd7..7517f898ee 100644 --- a/libs/ardour/ardour/graph.h +++ b/libs/ardour/ardour/graph.h @@ -44,6 +44,7 @@ namespace ARDOUR class GraphNode; class Graph; +class IOPlug; class Route; class Session; class GraphEdges; @@ -74,6 +75,7 @@ public: /* public API for use by session-process */ int process_routes (boost::shared_ptr chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler); int routes_no_roll (boost::shared_ptr chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool non_rt_pending); + int process_io_plugs (boost::shared_ptr chain, pframes_t nframes, samplepos_t start_sample); bool in_process_thread () const; uint32_t n_threads () const; @@ -84,6 +86,7 @@ public: /* called by virtual GraphNode::process() */ void process_one_route (Route* route); + void process_one_ioplug (IOPlug*); protected: virtual void session_going_away (); diff --git a/libs/ardour/ardour/io_plug.h b/libs/ardour/ardour/io_plug.h index 0c06e56162..d6aaf627fe 100644 --- a/libs/ardour/ardour/io_plug.h +++ b/libs/ardour/ardour/io_plug.h @@ -28,6 +28,7 @@ #include "ardour/automation_control.h" #include "ardour/buffer_set.h" #include "ardour/latent.h" +#include "ardour/graphnode.h" #include "ardour/plugin.h" #include "ardour/session_object.h" #include "ardour/plug_insert_base.h" @@ -41,7 +42,7 @@ namespace ARDOUR { class IO; class ReadOnlyControl; -class LIBARDOUR_API IOPlug : public SessionObject, public PlugInsertBase, public Latent +class LIBARDOUR_API IOPlug : public SessionObject, public PlugInsertBase, public Latent, public GraphNode { public: IOPlug (Session&, boost::shared_ptr = boost::shared_ptr(), bool pre = true); @@ -92,6 +93,13 @@ public: /* ControlSet */ boost::shared_ptr control_factory (const Evoral::Parameter& id); + /* GraphNode */ + std::string graph_node_name () const { + return name (); + } + bool direct_feeds_according_to_reality (boost::shared_ptr, bool* via_send_only = 0); + void process (); + protected: std::string describe_parameter (Evoral::Parameter); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 56975ac1c8..005353cd5b 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -2275,6 +2275,7 @@ private: */ GraphEdges _current_route_graph; + friend class IOPlug; boost::shared_ptr _process_graph; boost::shared_ptr _graph_chain; diff --git a/libs/ardour/graph.cc b/libs/ardour/graph.cc index b4f4614946..fb9175a925 100644 --- a/libs/ardour/graph.cc +++ b/libs/ardour/graph.cc @@ -33,6 +33,7 @@ #include "ardour/audioengine.h" #include "ardour/debug.h" #include "ardour/graph.h" +#include "ardour/io_plug.h" #include "ardour/process_thread.h" #include "ardour/route.h" #include "ardour/session.h" @@ -477,6 +478,27 @@ Graph::routes_no_roll (boost::shared_ptr chain, pframes_t nframes, s return _process_retval; } +int +Graph::process_io_plugs (boost::shared_ptr chain, pframes_t nframes, samplepos_t start_sample) +{ + DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("IOPlug graph execution at %1 for %2\n", start_sample, nframes)); + + if (g_atomic_int_get (&_terminate)) { + return 0; + } + + _graph_chain = chain.get (); + _process_nframes = nframes; + _process_start_sample = start_sample; + + DEBUG_TRACE (DEBUG::ProcessThreads, "wake graph for IOPlug processing\n"); + _callback_start_sem.signal (); + _callback_done_sem.wait (); + DEBUG_TRACE (DEBUG::ProcessThreads, "graph execution complete\n"); + + return _process_retval; +} + void Graph::process_one_route (Route* route) { @@ -502,6 +524,12 @@ Graph::process_one_route (Route* route) } } +void +Graph::process_one_ioplug (IOPlug* ioplug) +{ + ioplug->run (_process_start_sample, _process_nframes); +} + bool Graph::in_process_thread () const { diff --git a/libs/ardour/io_plug.cc b/libs/ardour/io_plug.cc index 4fb4589fa6..ab345da8cb 100644 --- a/libs/ardour/io_plug.cc +++ b/libs/ardour/io_plug.cc @@ -25,6 +25,7 @@ #include "ardour/audio_buffer.h" #include "ardour/audio_port.h" #include "ardour/event_type_map.h" +#include "ardour/graph.h" #include "ardour/io.h" #include "ardour/io_plug.h" #include "ardour/lv2_plugin.h" @@ -40,6 +41,7 @@ using namespace std; IOPlug::IOPlug (Session& s, boost::shared_ptr p, bool pre) : SessionObject (s, "") + , GraphNode (s._process_graph) , _plugin (p) , _pre (pre) , _plugin_signal_latency (0) @@ -382,6 +384,12 @@ IOPlug::ensure_io () return true; } +void +IOPlug::process () +{ + _graph->process_one_ioplug (this); +} + void IOPlug::run (samplepos_t start, pframes_t n_samples) { @@ -509,6 +517,17 @@ IOPlug::describe_parameter (Evoral::Parameter param) return EventTypeMap::instance ().to_symbol (param); } +bool +IOPlug::direct_feeds_according_to_reality (boost::shared_ptr node, bool* via_send_only) +{ + boost::shared_ptr other (boost::dynamic_pointer_cast (node)); + assert (other && other->_pre == _pre); + if (via_send_only) { + *via_send_only = false; + } + return other->input()->connected_to (_output); +} + /* ****************************************************************************/ IOPlug::PluginControl::PluginControl (IOPlug* p,