13
0

Add API to check for internal port connections

This commit is contained in:
Robin Gareus 2023-03-07 15:28:59 +01:00
parent 7a18ef6ceb
commit 77bb262c26
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 31 additions and 2 deletions

View File

@ -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<void,bool> MonitorInputChanged;
PBD::Signal3<void,boost::shared_ptr<Port>,boost::shared_ptr<Port>, 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

View File

@ -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);

View File

@ -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;
}

View File

@ -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
{

View File

@ -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 ();
}
}