Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libjack_metadata.cpp 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  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.
  9. *
  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.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "libjack.hpp"
  18. CARLA_BACKEND_USE_NAMESPACE
  19. // --------------------------------------------------------------------------------------------------------------------
  20. CARLA_EXPORT
  21. const char* JACK_METADATA_PRETTY_NAME;
  22. const char* JACK_METADATA_PRETTY_NAME = "http://jackaudio.org/metadata/pretty-name";
  23. CARLA_EXPORT
  24. const char* JACK_METADATA_HARDWARE;
  25. const char* JACK_METADATA_HARDWARE = "http://jackaudio.org/metadata/hardware";
  26. CARLA_EXPORT
  27. const char* JACK_METADATA_CONNECTED;
  28. const char* JACK_METADATA_CONNECTED = "http://jackaudio.org/metadata/connected";
  29. CARLA_EXPORT
  30. const char* JACK_METADATA_PORT_GROUP;
  31. const char* JACK_METADATA_PORT_GROUP = "http://jackaudio.org/metadata/port-group";
  32. CARLA_EXPORT
  33. const char* JACK_METADATA_ICON_SMALL;
  34. const char* JACK_METADATA_ICON_SMALL = "http://jackaudio.org/metadata/icon-small";
  35. CARLA_EXPORT
  36. const char* JACK_METADATA_ICON_LARGE;
  37. const char* JACK_METADATA_ICON_LARGE = "http://jackaudio.org/metadata/icon-large";
  38. // --------------------------------------------------------------------------------------------------------------------
  39. typedef struct {
  40. jack_uuid_t uuid;
  41. std::string key;
  42. } MetadataKey;
  43. typedef struct {
  44. std::string type;
  45. std::string value;
  46. } MetadataValue;
  47. typedef std::map<MetadataKey, MetadataValue> Metadata;
  48. static Metadata sMetadata;
  49. // --------------------------------------------------------------------------------------------------------------------
  50. CARLA_EXPORT
  51. int jack_set_property(jack_client_t*, jack_uuid_t uuid, const char* key, const char* value, const char* type)
  52. {
  53. CARLA_SAFE_ASSERT_RETURN(uuid != JACK_UUID_EMPTY_INITIALIZER, -1);
  54. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', -1);
  55. CARLA_SAFE_ASSERT_RETURN(value != nullptr && value[0] != '\0', -1);
  56. const MetadataKey mkey = { uuid, key };
  57. const MetadataValue mvalue = { value, type };
  58. // sMetadata[mkey] = mvalue;
  59. return 0;
  60. }
  61. CARLA_EXPORT
  62. int jack_get_property(jack_uuid_t uuid, const char* key, char** value, char** type)
  63. {
  64. CARLA_SAFE_ASSERT_RETURN(uuid != JACK_UUID_EMPTY_INITIALIZER, -1);
  65. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', -1);
  66. // const MetadataKey mkey = { uuid, key };
  67. // const auto mvalueit = sMetadata.find(mkey);
  68. //
  69. // if (mvalueit == sMetadata.end())
  70. // return -1;
  71. //
  72. // const MetadataValue& mvalue = mvalueit->second;
  73. // *value = strdup(mvalue.value.c_str());
  74. //
  75. // if (mvalue.type.size() != 0)
  76. // *type = strdup(mvalue.type.c_str());
  77. // else
  78. // *type = nullptr;
  79. return -1;
  80. (void)value;
  81. (void)type;
  82. }
  83. CARLA_EXPORT
  84. void jack_free_description(jack_description_t*, int)
  85. {
  86. }
  87. CARLA_EXPORT
  88. int jack_get_properties(jack_uuid_t, jack_description_t*)
  89. {
  90. return -1;
  91. }
  92. CARLA_EXPORT
  93. int jack_get_all_properties(jack_description_t**)
  94. {
  95. return -1;
  96. }
  97. CARLA_EXPORT
  98. int jack_remove_property(jack_client_t*, jack_uuid_t uuid, const char* key)
  99. {
  100. // const MetadataKey mkey = { uuid, key };
  101. // sMetadata.erase(mkey);
  102. return -1;
  103. (void)uuid;
  104. (void)key;
  105. }
  106. CARLA_EXPORT
  107. int jack_remove_properties(jack_client_t*, jack_uuid_t uuid)
  108. {
  109. int count = 0;
  110. // for (Metadata::const_iterator cit = sMetadata.begin(), cend = sMetadata.end(); cit != cend; ++cit)
  111. {
  112. // const MetadataKey& mkey = cit->first;
  113. // if (mkey.uuid != uuid)
  114. // continue;
  115. // ++count;
  116. // sMetadata.erase(mkey);
  117. }
  118. return count;
  119. (void)uuid;
  120. }
  121. CARLA_EXPORT
  122. int jack_remove_all_properties(jack_client_t*)
  123. {
  124. // sMetadata = {};
  125. return 0;
  126. }
  127. CARLA_EXPORT
  128. int jack_set_property_change_callback(jack_client_t*, JackPropertyChangeCallback, void*)
  129. {
  130. return -1;
  131. }
  132. // --------------------------------------------------------------------------------------------------------------------
  133. CARLA_EXPORT
  134. jack_uuid_t jack_client_uuid_generate()
  135. {
  136. static uint32_t uuid_cnt = 0;
  137. jack_uuid_t uuid = 0x2; /* JackUUIDClient */;
  138. uuid = (uuid << 32) | ++uuid_cnt;
  139. return uuid;
  140. }
  141. CARLA_EXPORT
  142. jack_uuid_t jack_port_uuid_generate(uint32_t port_id)
  143. {
  144. jack_uuid_t uuid = 0x1; /* JackUUIDPort */
  145. uuid = (uuid << 32) | (port_id + 1);
  146. return uuid;
  147. }
  148. CARLA_EXPORT
  149. uint32_t jack_uuid_to_index(jack_uuid_t u)
  150. {
  151. return static_cast<uint32_t>(u & 0xffff) - 1;
  152. }
  153. CARLA_EXPORT
  154. int jack_uuid_compare(jack_uuid_t a, jack_uuid_t b)
  155. {
  156. if (a == b) {
  157. return 0;
  158. }
  159. if (a < b) {
  160. return -1;
  161. }
  162. return 1;
  163. }
  164. CARLA_EXPORT
  165. void jack_uuid_copy(jack_uuid_t* dst, jack_uuid_t src)
  166. {
  167. *dst = src;
  168. }
  169. CARLA_EXPORT
  170. void jack_uuid_clear(jack_uuid_t* uuid)
  171. {
  172. *uuid = JACK_UUID_EMPTY_INITIALIZER;
  173. }
  174. CARLA_EXPORT
  175. int jack_uuid_parse(const char* b, jack_uuid_t* u)
  176. {
  177. if (std::sscanf(b, P_UINT64, u) != 1)
  178. return -1;
  179. if (*u < (0x1LL << 32)) {
  180. /* has not type bits set - not legal */
  181. return -1;
  182. }
  183. return 0;
  184. }
  185. CARLA_EXPORT
  186. void jack_uuid_unparse(jack_uuid_t u, char buf[JACK_UUID_STRING_SIZE])
  187. {
  188. std::snprintf(buf, JACK_UUID_STRING_SIZE, P_UINT64, u);
  189. }
  190. CARLA_EXPORT
  191. int jack_uuid_empty(jack_uuid_t u)
  192. {
  193. return u == JACK_UUID_EMPTY_INITIALIZER;
  194. }
  195. // --------------------------------------------------------------------------------------------------------------------