From 77bb262c26eb3679af1a2c0309e54def7f8380b6 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 7 Mar 2023 15:28:59 +0100 Subject: [PATCH] Add API to check for internal port connections --- libs/ardour/ardour/port.h | 11 ++++++++++- libs/ardour/audio_port.cc | 1 + libs/ardour/midi_port.cc | 3 ++- libs/ardour/port.cc | 12 ++++++++++++ libs/ardour/port_manager.cc | 6 ++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index d8b2af26b2..07fbe9f16e 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -119,7 +119,7 @@ public: virtual DataType type () const = 0; virtual void cycle_start (pframes_t); - virtual void cycle_end (pframes_t) = 0; + virtual void cycle_end (pframes_t); virtual void cycle_split () = 0; virtual void reinit (bool) {} virtual Buffer& get_buffer (pframes_t nframes) = 0; @@ -129,11 +129,18 @@ public: virtual void set_buffer_size (pframes_t) {} bool physically_connected () const; + bool in_cycle () const { return _in_cycle; } + uint32_t externally_connected () const { return _externally_connected; } + uint32_t internally_connected () const { return _internally_connected; } void increment_external_connections() { _externally_connected++; } void decrement_external_connections() { if (_externally_connected) _externally_connected--; } + void increment_internal_connections() { _internally_connected++; } + void decrement_internal_connections() { if (_internally_connected) _internally_connected--; } + + PBD::Signal1 MonitorInputChanged; PBD::Signal3,boost::shared_ptr, bool > ConnectedOrDisconnected; @@ -190,7 +197,9 @@ private: std::string _name; ///< port short name PortFlags _flags; ///< flags bool _last_monitor; + bool _in_cycle; uint32_t _externally_connected; + uint32_t _internally_connected; /** ports that we are connected to, kept so that we can reconnect to the backend when required diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 1e6671ebb4..4cee8150da 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -89,6 +89,7 @@ AudioPort::cycle_start (pframes_t nframes) void AudioPort::cycle_end (pframes_t nframes) { + Port::cycle_end (nframes); if (sends_output() && !_buffer->written() && _port_handle) { if (!_buffer->data (0)) { get_audio_buffer (nframes); diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index 76f3e15f7b..5fcb6f8d92 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -225,8 +225,9 @@ MidiPort::read_and_parse_entire_midi_buffer_with_no_speed_adjustment (pframes_t } void -MidiPort::cycle_end (pframes_t /*nframes*/) +MidiPort::cycle_end (pframes_t nframes) { + Port::cycle_end (nframes); _data_fetched_for_cycle = false; } diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc index fae4cf8ad1..492a3ea3a1 100644 --- a/libs/ardour/port.cc +++ b/libs/ardour/port.cc @@ -64,7 +64,9 @@ Port::Port (std::string const & n, DataType t, PortFlags f) : _name (n) , _flags (f) , _last_monitor (false) + , _in_cycle (false) , _externally_connected (0) + , _internally_connected (0) { _private_playback_latency.min = 0; _private_playback_latency.max = 0; @@ -374,8 +376,18 @@ Port::reset () void Port::cycle_start (pframes_t) { + assert (!_in_cycle); + _in_cycle = true; } +void +Port::cycle_end (pframes_t) +{ + assert (_in_cycle); + _in_cycle = false; +} + + void Port::set_public_latency_range (LatencyRange const& range, bool playback) const { diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index cb0a011eee..dc48f0d781 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -946,12 +946,18 @@ PortManager::connect_callback (const string& a, const string& b, bool conn) port_a->increment_external_connections (); } else if (port_b && !port_a) { port_b->increment_external_connections (); + } else if (port_a && port_b) { + port_a->increment_internal_connections (); + port_a->increment_internal_connections (); } } else { if (port_a && !port_b) { port_a->decrement_external_connections (); } else if (port_b && !port_a) { port_b->decrement_external_connections (); + } else if (port_a && port_b) { + port_a->decrement_internal_connections (); + port_a->decrement_internal_connections (); } }