A few more tweaks for AU hosting, WIP
[carla.git] / source / libjack / libjack_metadata.cpp
blob33e507ac18360d0e7aa1682bc1c71ebd5b08084d
1 /*
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 // --------------------------------------------------------------------------------------------------------------------
24 CARLA_PLUGIN_EXPORT
25 const char* JACK_METADATA_PRETTY_NAME;
26 const char* JACK_METADATA_PRETTY_NAME = "http://jackaudio.org/metadata/pretty-name";
28 CARLA_PLUGIN_EXPORT
29 const char* JACK_METADATA_HARDWARE;
30 const char* JACK_METADATA_HARDWARE = "http://jackaudio.org/metadata/hardware";
32 CARLA_PLUGIN_EXPORT
33 const char* JACK_METADATA_CONNECTED;
34 const char* JACK_METADATA_CONNECTED = "http://jackaudio.org/metadata/connected";
36 CARLA_PLUGIN_EXPORT
37 const char* JACK_METADATA_PORT_GROUP;
38 const char* JACK_METADATA_PORT_GROUP = "http://jackaudio.org/metadata/port-group";
40 CARLA_PLUGIN_EXPORT
41 const char* JACK_METADATA_ICON_SMALL;
42 const char* JACK_METADATA_ICON_SMALL = "http://jackaudio.org/metadata/icon-small";
44 CARLA_PLUGIN_EXPORT
45 const char* JACK_METADATA_ICON_LARGE;
46 const char* JACK_METADATA_ICON_LARGE = "http://jackaudio.org/metadata/icon-large";
48 // --------------------------------------------------------------------------------------------------------------------
50 typedef struct {
51 jack_uuid_t uuid;
52 std::string key;
53 } MetadataKey;
55 typedef struct {
56 std::string type;
57 std::string value;
58 } MetadataValue;
60 typedef std::map<MetadataKey, MetadataValue> Metadata;
62 static Metadata sMetadata;
64 // --------------------------------------------------------------------------------------------------------------------
66 CARLA_PLUGIN_EXPORT
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;
77 return 0;
80 CARLA_PLUGIN_EXPORT
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())
91 // return -1;
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());
99 // else
100 // *type = nullptr;
102 return -1;
104 (void)value;
105 (void)type;
108 CARLA_PLUGIN_EXPORT
109 void jack_free_description(jack_description_t*, int)
113 CARLA_PLUGIN_EXPORT
114 int jack_get_properties(jack_uuid_t, jack_description_t*)
116 return -1;
119 CARLA_PLUGIN_EXPORT
120 int jack_get_all_properties(jack_description_t**)
122 return -1;
125 CARLA_PLUGIN_EXPORT
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);
131 return -1;
133 (void)uuid;
134 (void)key;
137 CARLA_PLUGIN_EXPORT
138 int jack_remove_properties(jack_client_t*, jack_uuid_t uuid)
140 int count = 0;
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)
147 // continue;
149 // ++count;
150 // sMetadata.erase(mkey);
153 return count;
155 (void)uuid;
158 CARLA_PLUGIN_EXPORT
159 int jack_remove_all_properties(jack_client_t*)
161 // sMetadata = {};
162 return 0;
165 CARLA_PLUGIN_EXPORT
166 int jack_set_property_change_callback(jack_client_t*, JackPropertyChangeCallback, void*)
168 return -1;
171 // --------------------------------------------------------------------------------------------------------------------
173 CARLA_PLUGIN_EXPORT
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;
179 return uuid;
182 CARLA_PLUGIN_EXPORT
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);
187 return uuid;
190 CARLA_PLUGIN_EXPORT
191 uint32_t jack_uuid_to_index(jack_uuid_t u)
193 return static_cast<uint32_t>(u & 0xffff) - 1;
196 CARLA_PLUGIN_EXPORT
197 int jack_uuid_compare(jack_uuid_t a, jack_uuid_t b)
199 if (a == b) {
200 return 0;
203 if (a < b) {
204 return -1;
207 return 1;
210 CARLA_PLUGIN_EXPORT
211 void jack_uuid_copy(jack_uuid_t* dst, jack_uuid_t src)
213 *dst = src;
216 CARLA_PLUGIN_EXPORT
217 void jack_uuid_clear(jack_uuid_t* uuid)
219 *uuid = JACK_UUID_EMPTY_INITIALIZER;
222 CARLA_PLUGIN_EXPORT
223 int jack_uuid_parse(const char* b, jack_uuid_t* u)
225 if (std::sscanf(b, P_UINT64, u) != 1)
226 return -1;
228 if (*u < (0x1LL << 32)) {
229 /* has not type bits set - not legal */
230 return -1;
233 return 0;
236 CARLA_PLUGIN_EXPORT
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);
242 CARLA_PLUGIN_EXPORT
243 int jack_uuid_empty(jack_uuid_t u)
245 return u == JACK_UUID_EMPTY_INITIALIZER;
248 // --------------------------------------------------------------------------------------------------------------------