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.

138 lines
4.9KB

  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_const {
  40. // Either data32 or data64 pointer will be set.
  41. const float* const* data32;
  42. const double* const* data64;
  43. uint32_t channel_count;
  44. uint32_t latency; // latency from/to the audio interface
  45. uint64_t constant_mask;
  46. } clap_audio_buffer_const_t;
  47. }
  48. // --------------------------------------------------------------------------------------------------------------------
  49. CARLA_BACKEND_START_NAMESPACE
  50. // --------------------------------------------------------------------------------------------------------------------
  51. static inline
  52. PluginCategory getPluginCategoryFromClapFeatures(const char* const* const features) noexcept
  53. {
  54. // 1st pass for main categories
  55. for (uint32_t i=0; features[i] != nullptr; ++i)
  56. {
  57. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_INSTRUMENT) == 0)
  58. return PLUGIN_CATEGORY_SYNTH;
  59. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_NOTE_EFFECT) == 0)
  60. return PLUGIN_CATEGORY_UTILITY;
  61. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_ANALYZER) == 0)
  62. return PLUGIN_CATEGORY_UTILITY;
  63. }
  64. // 2nd pass for FX sub categories
  65. /*
  66. #define CLAP_PLUGIN_FEATURE_DEESSER "de-esser"
  67. #define CLAP_PLUGIN_FEATURE_PHASE_VOCODER "phase-vocoder"
  68. #define CLAP_PLUGIN_FEATURE_GRANULAR "granular"
  69. #define CLAP_PLUGIN_FEATURE_FREQUENCY_SHIFTER "frequency-shifter"
  70. #define CLAP_PLUGIN_FEATURE_PITCH_SHIFTER "pitch-shifter"
  71. #define CLAP_PLUGIN_FEATURE_TREMOLO "tremolo"
  72. #define CLAP_PLUGIN_FEATURE_GLITCH "glitch"
  73. */
  74. for (uint32_t i=0; features[i] != nullptr; ++i)
  75. {
  76. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_DELAY) == 0 ||
  77. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_REVERB) == 0)
  78. {
  79. return PLUGIN_CATEGORY_DELAY;
  80. }
  81. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_EQUALIZER) == 0)
  82. {
  83. return PLUGIN_CATEGORY_EQ;
  84. }
  85. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_FILTER) == 0)
  86. {
  87. return PLUGIN_CATEGORY_FILTER;
  88. }
  89. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_DISTORTION) == 0)
  90. {
  91. return PLUGIN_CATEGORY_DISTORTION;
  92. }
  93. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_COMPRESSOR) == 0 ||
  94. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_LIMITER) == 0 ||
  95. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_MASTERING) == 0 ||
  96. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_MIXING) == 0 ||
  97. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_TRANSIENT_SHAPER) == 0)
  98. {
  99. return PLUGIN_CATEGORY_DYNAMICS;
  100. }
  101. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_CHORUS) == 0 ||
  102. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_FLANGER) == 0 ||
  103. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_PHASER) == 0
  104. )
  105. {
  106. return PLUGIN_CATEGORY_MODULATOR;
  107. }
  108. if (std::strcmp(features[i], CLAP_PLUGIN_FEATURE_PITCH_CORRECTION) == 0 ||
  109. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_RESTORATION) == 0 ||
  110. std::strcmp(features[i], CLAP_PLUGIN_FEATURE_UTILITY) == 0
  111. )
  112. {
  113. return PLUGIN_CATEGORY_UTILITY;
  114. }
  115. }
  116. return PLUGIN_CATEGORY_OTHER;
  117. }
  118. // --------------------------------------------------------------------------------------------------------------------
  119. CARLA_BACKEND_END_NAMESPACE
  120. #endif // CARLA_CLAP_UTILS_HPP_INCLUDED