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.

104 lines
2.6KB

  1. /*
  2. Copyright 2016 David Robillard <http://drobilla.net>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. /**
  15. @defgroup util Utilities
  16. @ingroup lv2core
  17. @{
  18. */
  19. #include <string.h>
  20. #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #else
  24. # include <stdbool.h>
  25. #endif
  26. /**
  27. Return the data for a feature in a features array.
  28. If the feature is not found, NULL is returned. Note that this function is
  29. only useful for features with data, and can not detect features that are
  30. present but have NULL data.
  31. */
  32. static inline void*
  33. lv2_features_data(const LV2_Feature*const* features,
  34. const char* const uri)
  35. {
  36. if (features) {
  37. for (const LV2_Feature*const* f = features; *f; ++f) {
  38. if (!strcmp(uri, (*f)->URI)) {
  39. return (*f)->data;
  40. }
  41. }
  42. }
  43. return NULL;
  44. }
  45. /**
  46. Query a features array.
  47. This function allows getting several features in one call, and detect
  48. missing required features, with the same caveat of lv2_features_data().
  49. The arguments should be a series of const char* uri, void** data, bool
  50. required, terminated by a NULL URI. The data pointers MUST be initialized
  51. to NULL. For example:
  52. @code
  53. LV2_URID_Log* log = NULL;
  54. LV2_URID_Map* map = NULL;
  55. const char* missing = lv2_features_query(
  56. features,
  57. LV2_LOG__log, &log, false,
  58. LV2_URID__map, &map, true,
  59. NULL);
  60. @endcode
  61. @return NULL on success, otherwise the URI of this missing feature.
  62. */
  63. static inline const char*
  64. lv2_features_query(const LV2_Feature* const* features, ...)
  65. {
  66. va_list args;
  67. va_start(args, features);
  68. const char* uri = NULL;
  69. while ((uri = va_arg(args, const char*))) {
  70. void** data = va_arg(args, void**);
  71. bool required = va_arg(args, int);
  72. *data = lv2_features_data(features, uri);
  73. if (required && !*data) {
  74. return uri;
  75. }
  76. }
  77. return NULL;
  78. }
  79. #ifdef __cplusplus
  80. } /* extern "C" */
  81. #endif
  82. /**
  83. @}
  84. @}
  85. */