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.

166 lines
5.5KB

  1. /*
  2. * Carla CLAP utils
  3. * Copyright (C) 2022 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. #ifndef CARLA_CLAP_UTILS_HPP_INCLUDED
  18. #define CARLA_CLAP_UTILS_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #include "CarlaUtils.hpp"
  21. #include "clap/entry.h"
  22. #include "clap/plugin-factory.h"
  23. #include "clap/plugin-features.h"
  24. #include "clap/ext/audio-ports.h"
  25. #include "clap/ext/note-ports.h"
  26. #include "clap/ext/gui.h"
  27. #include "clap/ext/params.h"
  28. #include "clap/ext/state.h"
  29. #include "clap/ext/timer-support.h"
  30. #if defined(CARLA_OS_WIN)
  31. # define CLAP_WINDOW_API_NATIVE CLAP_WINDOW_API_WIN32
  32. #elif defined(CARLA_OS_MAC)
  33. # define CLAP_WINDOW_API_NATIVE CLAP_WINDOW_API_COCOA
  34. #elif defined(HAVE_X11)
  35. # define CLAP_WINDOW_API_NATIVE CLAP_WINDOW_API_X11
  36. #endif
  37. // --------------------------------------------------------------------------------------------------------------------
  38. extern "C" {
  39. typedef struct clap_audio_buffer_with_offset {
  40. float **data32;
  41. double **data64;
  42. uint32_t channel_count;
  43. uint32_t latency;
  44. uint64_t constant_mask;
  45. uint16_t offset;
  46. bool isMain;
  47. } clap_audio_buffer_with_offset_t;
  48. typedef struct clap_audio_buffer_const_with_offset {
  49. // Either data32 or data64 pointer will be set.
  50. const float* const* data32;
  51. const double* const* data64;
  52. uint32_t channel_count;
  53. uint32_t latency;
  54. uint64_t constant_mask;
  55. uint16_t offset;
  56. bool isMain;
  57. } clap_audio_buffer_const_with_offset_t;
  58. }
  59. // --------------------------------------------------------------------------------------------------------------------
  60. CARLA_BACKEND_START_NAMESPACE
  61. // --------------------------------------------------------------------------------------------------------------------
  62. static inline
  63. PluginCategory getPluginCategoryFromClapFeatures(const char* const* const features) noexcept
  64. {
  65. // 1st pass for main categories
  66. for (uint32_t i=0; features[i] != nullptr; ++i)
  67. {
  68. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_INSTRUMENT) == 0)
  69. return PLUGIN_CATEGORY_SYNTH;
  70. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_NOTE_EFFECT) == 0)
  71. return PLUGIN_CATEGORY_UTILITY;
  72. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_ANALYZER) == 0)
  73. return PLUGIN_CATEGORY_UTILITY;
  74. }
  75. // 2nd pass for FX sub categories
  76. /*
  77. #define CLAP_PLUGIN_FEATURE_DEESSER "de-esser"
  78. #define CLAP_PLUGIN_FEATURE_PHASE_VOCODER "phase-vocoder"
  79. #define CLAP_PLUGIN_FEATURE_GRANULAR "granular"
  80. #define CLAP_PLUGIN_FEATURE_FREQUENCY_SHIFTER "frequency-shifter"
  81. #define CLAP_PLUGIN_FEATURE_PITCH_SHIFTER "pitch-shifter"
  82. #define CLAP_PLUGIN_FEATURE_TREMOLO "tremolo"
  83. #define CLAP_PLUGIN_FEATURE_GLITCH "glitch"
  84. */
  85. for (uint32_t i=0; features[i] != nullptr; ++i)
  86. {
  87. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_DELAY) == 0 ||
  88. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_REVERB) == 0)
  89. {
  90. return PLUGIN_CATEGORY_DELAY;
  91. }
  92. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_EQUALIZER) == 0)
  93. {
  94. return PLUGIN_CATEGORY_EQ;
  95. }
  96. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_FILTER) == 0)
  97. {
  98. return PLUGIN_CATEGORY_FILTER;
  99. }
  100. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_DISTORTION) == 0)
  101. {
  102. return PLUGIN_CATEGORY_DISTORTION;
  103. }
  104. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_COMPRESSOR) == 0 ||
  105. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_LIMITER) == 0 ||
  106. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_MASTERING) == 0 ||
  107. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_MIXING) == 0 ||
  108. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_TRANSIENT_SHAPER) == 0)
  109. {
  110. return PLUGIN_CATEGORY_DYNAMICS;
  111. }
  112. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_CHORUS) == 0 ||
  113. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_FLANGER) == 0 ||
  114. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_PHASER) == 0
  115. )
  116. {
  117. return PLUGIN_CATEGORY_MODULATOR;
  118. }
  119. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_PITCH_CORRECTION) == 0 ||
  120. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_RESTORATION) == 0 ||
  121. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_UTILITY) == 0
  122. )
  123. {
  124. return PLUGIN_CATEGORY_UTILITY;
  125. }
  126. }
  127. return PLUGIN_CATEGORY_OTHER;
  128. }
  129. static inline
  130. bool clapFeaturesContainInstrument(const char* const* const features) noexcept
  131. {
  132. if (features == nullptr)
  133. return false;
  134. // 1st pass for main categories
  135. for (uint32_t i=0; features[i] != nullptr; ++i)
  136. {
  137. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_INSTRUMENT) == 0)
  138. return true;
  139. }
  140. return false;
  141. }
  142. // --------------------------------------------------------------------------------------------------------------------
  143. CARLA_BACKEND_END_NAMESPACE
  144. #endif // CARLA_CLAP_UTILS_HPP_INCLUDED