2 * Carla JACK API for external applications
3 * Copyright (C) 2016-2022 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "libjack.hpp"
20 CARLA_BACKEND_USE_NAMESPACE
22 // --------------------------------------------------------------------------------------------------------------------
25 const char* JACK_METADATA_PRETTY_NAME
;
26 const char* JACK_METADATA_PRETTY_NAME
= "http://jackaudio.org/metadata/pretty-name";
29 const char* JACK_METADATA_HARDWARE
;
30 const char* JACK_METADATA_HARDWARE
= "http://jackaudio.org/metadata/hardware";
33 const char* JACK_METADATA_CONNECTED
;
34 const char* JACK_METADATA_CONNECTED
= "http://jackaudio.org/metadata/connected";
37 const char* JACK_METADATA_PORT_GROUP
;
38 const char* JACK_METADATA_PORT_GROUP
= "http://jackaudio.org/metadata/port-group";
41 const char* JACK_METADATA_ICON_SMALL
;
42 const char* JACK_METADATA_ICON_SMALL
= "http://jackaudio.org/metadata/icon-small";
45 const char* JACK_METADATA_ICON_LARGE
;
46 const char* JACK_METADATA_ICON_LARGE
= "http://jackaudio.org/metadata/icon-large";
48 // --------------------------------------------------------------------------------------------------------------------
60 typedef std::map
<MetadataKey
, MetadataValue
> Metadata
;
62 static Metadata sMetadata
;
64 // --------------------------------------------------------------------------------------------------------------------
67 int jack_set_property(jack_client_t
*, jack_uuid_t uuid
, const char* key
, const char* value
, const char* type
)
69 CARLA_SAFE_ASSERT_RETURN(uuid
!= JACK_UUID_EMPTY_INITIALIZER
, -1);
70 CARLA_SAFE_ASSERT_RETURN(key
!= nullptr && key
[0] != '\0', -1);
71 CARLA_SAFE_ASSERT_RETURN(value
!= nullptr && value
[0] != '\0', -1);
73 const MetadataKey mkey
= { uuid
, key
};
74 const MetadataValue mvalue
= { value
, type
};
75 // sMetadata[mkey] = mvalue;
81 int jack_get_property(jack_uuid_t uuid
, const char* key
, char** value
, char** type
)
83 CARLA_SAFE_ASSERT_RETURN(uuid
!= JACK_UUID_EMPTY_INITIALIZER
, -1);
84 CARLA_SAFE_ASSERT_RETURN(key
!= nullptr && key
[0] != '\0', -1);
86 // const MetadataKey mkey = { uuid, key };
88 // const auto mvalueit = sMetadata.find(mkey);
90 // if (mvalueit == sMetadata.end())
93 // const MetadataValue& mvalue = mvalueit->second;
95 // *value = strdup(mvalue.value.c_str());
97 // if (mvalue.type.size() != 0)
98 // *type = strdup(mvalue.type.c_str());
109 void jack_free_description(jack_description_t
*, int)
114 int jack_get_properties(jack_uuid_t
, jack_description_t
*)
120 int jack_get_all_properties(jack_description_t
**)
126 int jack_remove_property(jack_client_t
*, jack_uuid_t uuid
, const char* key
)
128 // const MetadataKey mkey = { uuid, key };
130 // sMetadata.erase(mkey);
138 int jack_remove_properties(jack_client_t
*, jack_uuid_t uuid
)
142 // for (Metadata::const_iterator cit = sMetadata.begin(), cend = sMetadata.end(); cit != cend; ++cit)
144 // const MetadataKey& mkey = cit->first;
146 // if (mkey.uuid != uuid)
150 // sMetadata.erase(mkey);
159 int jack_remove_all_properties(jack_client_t
*)
166 int jack_set_property_change_callback(jack_client_t
*, JackPropertyChangeCallback
, void*)
171 // --------------------------------------------------------------------------------------------------------------------
174 jack_uuid_t
jack_client_uuid_generate()
176 static uint32_t uuid_cnt
= 0;
177 jack_uuid_t uuid
= 0x2; /* JackUUIDClient */;
178 uuid
= (uuid
<< 32) | ++uuid_cnt
;
183 jack_uuid_t
jack_port_uuid_generate(uint32_t port_id
)
185 jack_uuid_t uuid
= 0x1; /* JackUUIDPort */
186 uuid
= (uuid
<< 32) | (port_id
+ 1);
191 uint32_t jack_uuid_to_index(jack_uuid_t u
)
193 return static_cast<uint32_t>(u
& 0xffff) - 1;
197 int jack_uuid_compare(jack_uuid_t a
, jack_uuid_t b
)
211 void jack_uuid_copy(jack_uuid_t
* dst
, jack_uuid_t src
)
217 void jack_uuid_clear(jack_uuid_t
* uuid
)
219 *uuid
= JACK_UUID_EMPTY_INITIALIZER
;
223 int jack_uuid_parse(const char* b
, jack_uuid_t
* u
)
225 if (std::sscanf(b
, P_UINT64
, u
) != 1)
228 if (*u
< (0x1LL
<< 32)) {
229 /* has not type bits set - not legal */
237 void jack_uuid_unparse(jack_uuid_t u
, char buf
[JACK_UUID_STRING_SIZE
])
239 std::snprintf(buf
, JACK_UUID_STRING_SIZE
, P_UINT64
, u
);
243 int jack_uuid_empty(jack_uuid_t u
)
245 return u
== JACK_UUID_EMPTY_INITIALIZER
;
248 // --------------------------------------------------------------------------------------------------------------------