From 5c85695362d4ffe0eaa4728b06b3ed9a3bafde4e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 17 May 2022 02:25:23 +0200 Subject: [PATCH] Add Input Port meters for I/O Pre-Plugin outputs --- libs/ardour/ardour/io_plug.h | 10 ++++++ libs/ardour/io_plug.cc | 64 +++++++++++++++++++++++++++++++++- libs/ardour/session_process.cc | 1 + 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/io_plug.h b/libs/ardour/ardour/io_plug.h index d6aaf627fe..6f90e0ad4d 100644 --- a/libs/ardour/ardour/io_plug.h +++ b/libs/ardour/ardour/io_plug.h @@ -30,6 +30,7 @@ #include "ardour/latent.h" #include "ardour/graphnode.h" #include "ardour/plugin.h" +#include "ardour/port_manager.h" #include "ardour/session_object.h" #include "ardour/plug_insert_base.h" @@ -68,6 +69,11 @@ public: Gtkmm2ext::WindowProxy* window_proxy () const { return _window_proxy; } void set_window_proxy (Gtkmm2ext::WindowProxy* wp) { _window_proxy = wp; } + PortManager::AudioInputPorts audio_input_ports () const { return _audio_input_ports; } + PortManager::MIDIInputPorts midi_input_ports () const { return _midi_input_ports; } + + void reset_input_meters (); + /* Latent */ samplecnt_t signal_latency () const; @@ -157,10 +163,14 @@ private: boost::shared_ptr _input; boost::shared_ptr _output; + PortManager::AudioInputPorts _audio_input_ports; + PortManager::MIDIInputPorts _midi_input_ports; + Gtkmm2ext::WindowProxy* _window_proxy; PBD::TimingStats _timing_stats; GATOMIC_QUAL gint _stat_reset; + GATOMIC_QUAL gint _reset_meters; }; } diff --git a/libs/ardour/io_plug.cc b/libs/ardour/io_plug.cc index ab345da8cb..731e2323c7 100644 --- a/libs/ardour/io_plug.cc +++ b/libs/ardour/io_plug.cc @@ -22,6 +22,7 @@ #include "temporal/tempo.h" +#include "ardour/audioengine.h" #include "ardour/audio_buffer.h" #include "ardour/audio_port.h" #include "ardour/event_type_map.h" @@ -48,6 +49,7 @@ IOPlug::IOPlug (Session& s, boost::shared_ptr p, bool pre) , _window_proxy (0) { g_atomic_int_set (&_stat_reset, 0); + g_atomic_int_set (&_reset_meters, 0); if (_plugin) { setup (); @@ -67,7 +69,7 @@ IOPlug::~IOPlug () std::string IOPlug::io_name (std::string const& n) const { - return (string_compose ("%1/%2/%3", _("IO"), _pre ? _("Pre"): _("Post"), n.empty () ? name() : n)); + return (string_compose ("%1/%2/%3", _("IO"), _pre ? _("Pre"): _("Post"), n.empty () ? name () : n)); } std::string @@ -381,6 +383,38 @@ IOPlug::ensure_io () } _bufs.ensure_buffers (ChanCount::max (_n_in, _n_out), _session.get_block_size ()); + + for (uint32_t i = 0; i < _n_in.n_audio (); ++i) { + const auto& pd (_plugin->describe_io_port (DataType::AUDIO, true, i)); + std::string const pn = string_compose ("%1 %2 - %3", _("IO"), name (), pd.name); + _input->audio (i)->set_pretty_name (pn); + } + for (uint32_t i = 0; i < _n_in.n_midi (); ++i) { + const auto& pd (_plugin->describe_io_port (DataType::MIDI, true, i)); + std::string const pn = string_compose ("%1 %2 - %3", _("IO"), name (), pd.name); + _input->midi (i)->set_pretty_name (pn); + } + for (uint32_t i = 0; i < _n_out.n_audio (); ++i) { + const auto& pd (_plugin->describe_io_port (DataType::AUDIO, false, i)); + std::string const pn = string_compose ("%1 %2 - %3", _("IO"), name (), pd.name); + _output->audio (i)->set_pretty_name (pn); + } + for (uint32_t i = 0; i < _n_out.n_midi (); ++i) { + const auto& pd (_plugin->describe_io_port (DataType::MIDI, false, i)); + std::string const pn = string_compose ("%1 %2 - %3", _("IO"), name (), pd.name); + _output->midi (i)->set_pretty_name (pn); + } + + if (_pre) { + for (uint32_t i = 0; i < _n_out.n_audio (); ++i) { + std::string const& n = AudioEngine::instance ()->make_port_name_non_relative (_output->audio (i)->name ()); + _audio_input_ports.insert (make_pair (n, PortManager::AudioInputPort (24288))); // 2^19 ~ 1MB / port + } + for (uint32_t i = 0; i < _n_out.n_midi (); ++i) { + std::string const& n = AudioEngine::instance ()->make_port_name_non_relative (_output->midi (i)->name ()); + _midi_input_ports.insert (make_pair (n, PortManager::MIDIInputPort (32))); + } + } return true; } @@ -431,6 +465,28 @@ IOPlug::run (samplepos_t start, pframes_t n_samples) } PortSet& ports (_output->ports()); + if (_pre) { + const bool reset = g_atomic_int_compare_and_exchange (&_reset_meters, 1, 0); + samplecnt_t const rate = _session.nominal_sample_rate (); + + auto a = _audio_input_ports.begin (); + auto m = _midi_input_ports.begin (); + for (auto p = _bufs.audio_begin (); p != _bufs.audio_end (); ++p, ++a) { + AudioBuffer const& ab (*p); + PortManager::AudioInputPort& ai (a->second); + ai.apply_falloff (n_samples, rate, reset); + ai.process (ab.data (), n_samples, reset); + } + for (auto p = _bufs.midi_begin (); p != _bufs.midi_end (); ++p, ++m) { + PortManager::MIDIInputPort& mi (m->second); + MidiBuffer const& mb (*p); + mi.apply_falloff (n_samples, rate, reset); + for (MidiBuffer::const_iterator i = mb.begin (); i != mb.end (); ++i) { + Evoral::Event ev (*i, false); + mi.process_event (ev.buffer (), ev.size ()); + } + } + } for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) { i->flush_buffers (n_samples); } @@ -444,6 +500,12 @@ IOPlug::run (samplepos_t start, pframes_t n_samples) _timing_stats.update (); } +void +IOPlug::reset_input_meters () +{ + g_atomic_int_set (&_reset_meters, 1); +} + bool IOPlug::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& avg, double& dev) const { diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index a0bafbea0f..e989671b0b 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -112,6 +112,7 @@ Session::process (pframes_t nframes) boost::shared_ptr io_graph_chain = _io_graph_chain[0]; if (io_graph_chain) { + PortManager::falloff_cache_calc (nframes, _nominal_sample_rate); _process_graph->process_io_plugs (io_graph_chain, nframes, 0); io_graph_chain.reset (); /* drop reference */ }