Add & implement PortEngine::externally_connected() API
[ardour.git] / libs / backends / jack / jack_portengine.cc
index dfa2bdad113313a27bd5ad3f5b9ff79583f52d73..70dded77c46f07a5487347c47127bf8303b760c3 100644 (file)
@@ -275,6 +275,7 @@ JACKAudioBackend::physically_connected (PortHandle p, bool process_callback_safe
                        jack_port_t* other = jack_port_by_name (_priv_jack, ports[i]);
 
                        if (other && (jack_port_flags (other) & JackPortIsPhysical)) {
+                               jack_free (ports);
                                return true;
                        }
                }
@@ -284,6 +285,39 @@ JACKAudioBackend::physically_connected (PortHandle p, bool process_callback_safe
        return false;
 }
 
+bool
+JACKAudioBackend::externally_connected (PortHandle p, bool process_callback_safe)
+{
+       GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
+       jack_port_t* port = (jack_port_t*) p;
+
+       const char** ports;
+
+       if (process_callback_safe) {
+               ports = jack_port_get_connections ((jack_port_t*)port);
+       } else {
+               GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
+               ports = jack_port_get_all_connections (_priv_jack, (jack_port_t*)port);
+       }
+
+       if (ports) {
+               for (int i = 0; ports[i]; ++i) {
+                       jack_port_t* other = jack_port_by_name (_priv_jack, ports[i]);
+
+                       if (other && (jack_port_flags (other) & JackPortIsPhysical)) {
+                               jack_free (ports);
+                               return true;
+                       }
+                       if (other && !jack_port_is_mine (_priv_jack, other)) {
+                               jack_free (ports);
+                               return true;
+                       }
+               }
+               jack_free (ports);
+       }
+       return false;
+}
+
 int
 JACKAudioBackend::get_connections (PortHandle port, vector<string>& s, bool process_callback_safe)
 {