improved (as in "correct") deadlock fix for PresentationInfo::Change
[ardour.git] / libs / backends / jack / jack_portengine.cc
index caa962600b764f9686dcfcdc304bcc86d83bab98..a73f4608aa58b7a12dd97baf4f3ab132d849646f 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "ardour/port_manager.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace PBD;
@@ -41,7 +41,7 @@ static uint32_t
 ardour_port_flags_to_jack_flags (PortFlags flags)
 {
        uint32_t jack_flags = 0;
-       
+
        if (flags & IsInput) {
                jack_flags |= JackPortIsInput;
        }
@@ -106,7 +106,16 @@ JACKAudioBackend::when_connected_to_jack ()
 int
 JACKAudioBackend::set_port_name (PortHandle port, const std::string& name)
 {
+#if HAVE_JACK_PORT_RENAME
+       jack_client_t* client = _jack_connection->jack();
+       if (client) {
+               return jack_port_rename (client, (jack_port_t*) port, name.c_str());
+       } else {
+               return -1;
+       }
+#else
        return jack_port_set_name ((jack_port_t*) port, name.c_str());
+#endif
 }
 
 string
@@ -118,7 +127,7 @@ JACKAudioBackend::get_port_name (PortHandle port) const
 int
 JACKAudioBackend::get_port_property (PortHandle port, const std::string& key, std::string& value, std::string& type) const
 {
-#ifndef NO_JACK_METADATA // really everyone ought to have this by now.
+#ifdef HAVE_JACK_METADATA // really everyone ought to have this by now.
        int rv = -1;
        char *cvalue = NULL;
        char *ctype = NULL;
@@ -126,12 +135,31 @@ JACKAudioBackend::get_port_property (PortHandle port, const std::string& key, st
        jack_uuid_t uuid = jack_port_uuid((jack_port_t*) port);
        rv = jack_get_property(uuid, key.c_str(), &cvalue, &ctype);
 
-       if (0 == rv) {
+       if (0 == rv && cvalue) {
                value = cvalue;
-               type = ctype;
-               jack_free(cvalue);
-               jack_free(ctype);
+               if (ctype) {
+                       type = ctype;
+               }
+       } else {
+               rv = -1;
        }
+
+       jack_free(cvalue);
+       jack_free(ctype);
+       return rv;
+#else
+       return -1;
+#endif
+}
+
+int
+JACKAudioBackend::set_port_property (PortHandle port, const std::string& key, const std::string& value, const std::string& type)
+{
+#ifdef HAVE_JACK_METADATA // really everyone ought to have this by now.
+       int rv = -1;
+       jack_client_t* client = _jack_connection->jack();
+       jack_uuid_t uuid = jack_port_uuid((jack_port_t*) port);
+       return jack_set_property(client, uuid, key.c_str(), value.c_str(), type.c_str());
        return rv;
 #else
        return -1;
@@ -233,7 +261,7 @@ JACKAudioBackend::physically_connected (PortHandle p, bool process_callback_safe
        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 {
@@ -306,8 +334,8 @@ JACKAudioBackend::get_ports (const string& port_name_pattern, DataType type, Por
 
        GET_PRIVATE_JACK_POINTER_RET (_priv_jack,0);
 
-       const char** ports =  jack_get_ports (_priv_jack, port_name_pattern.c_str(), 
-                                             ardour_data_type_to_jack_port_type (type), 
+       const char** ports =  jack_get_ports (_priv_jack, port_name_pattern.c_str(),
+                                             ardour_data_type_to_jack_port_type (type),
                                              ardour_port_flags_to_jack_flags (flags));
 
        if (ports == 0) {
@@ -319,7 +347,7 @@ JACKAudioBackend::get_ports (const string& port_name_pattern, DataType type, Por
        }
 
        jack_free (ports);
-       
+
        return s.size();
 }
 
@@ -410,7 +438,7 @@ PortEngine::PortHandle
 JACKAudioBackend::register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags)
 {
        GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
-       return jack_port_register (_priv_jack, shortname.c_str(), 
+       return jack_port_register (_priv_jack, shortname.c_str(),
                                   ardour_data_type_to_jack_port_type (type),
                                   ardour_port_flags_to_jack_flags (flags),
                                   0);
@@ -433,7 +461,7 @@ int
 JACKAudioBackend::connect (const std::string& src, const std::string& dst)
 {
        GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
-       
+
        int r = jack_connect (_priv_jack, src.c_str(), dst.c_str());
        return r;
 }
@@ -496,7 +524,7 @@ void
 JACKAudioBackend::set_latency_range (PortHandle port, bool for_playback, LatencyRange r)
 {
        jack_latency_range_t range;
-       
+
        range.min = r.min;
        range.max = r.max;
 
@@ -508,7 +536,7 @@ JACKAudioBackend::get_latency_range (PortHandle port, bool for_playback)
 {
        jack_latency_range_t range;
        LatencyRange ret;
-       
+
        jack_port_get_latency_range ((jack_port_t*) port, for_playback ? JackPlaybackLatency : JackCaptureLatency, &range);
 
        ret.min = range.min;