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.

167 lines
4.6KB

  1. // SPDX-FileCopyrightText: 2021 Jean Pierre Cimalando
  2. // SPDX-FileCopyrightText: 2011-2025 Filipe Coelho <falktx@falktx.com>
  3. // SPDX-License-Identifier: GPL-2.0-or-later
  4. #ifndef CARLA_JSFX_UTILS_HPP_INCLUDED
  5. #define CARLA_JSFX_UTILS_HPP_INCLUDED
  6. #include "CarlaBackend.h"
  7. #include "extra/String.hpp"
  8. #include "water/files/File.h"
  9. #ifdef YSFX_API
  10. # error YSFX_API is not private
  11. #endif
  12. #include "ysfx/include/ysfx.h"
  13. CARLA_BACKEND_START_NAMESPACE
  14. // --------------------------------------------------------------------------------------------------------------------
  15. struct CarlaJsfxLogging
  16. {
  17. static void logAll(intptr_t, const ysfx_log_level level, const char* const message)
  18. {
  19. switch (level)
  20. {
  21. case ysfx_log_info:
  22. carla_stdout("%s: %s", ysfx_log_level_string(level), message);
  23. break;
  24. case ysfx_log_warning:
  25. carla_stderr("%s: %s", ysfx_log_level_string(level), message);
  26. break;
  27. case ysfx_log_error:
  28. carla_stderr2("%s: %s", ysfx_log_level_string(level), message);
  29. break;
  30. }
  31. };
  32. static void logErrorsOnly(intptr_t, const ysfx_log_level level, const char* const message)
  33. {
  34. switch (level)
  35. {
  36. case ysfx_log_info:
  37. break;
  38. case ysfx_log_warning:
  39. carla_stderr("%s: %s", ysfx_log_level_string(level), message);
  40. break;
  41. case ysfx_log_error:
  42. carla_stderr2("%s: %s", ysfx_log_level_string(level), message);
  43. break;
  44. }
  45. };
  46. };
  47. // --------------------------------------------------------------------------------------------------------------------
  48. struct CarlaJsfxCategories
  49. {
  50. static PluginCategory getFromEffect(ysfx_t* const effect)
  51. {
  52. PluginCategory category = PLUGIN_CATEGORY_OTHER;
  53. if (const uint32_t tagCount = ysfx_get_tags(effect, nullptr, 0))
  54. {
  55. std::vector<const char*> tags;
  56. tags.resize(tagCount);
  57. ysfx_get_tags(effect, tags.data(), tagCount);
  58. for (uint32_t i=0; i<tagCount && category == PLUGIN_CATEGORY_OTHER; ++i)
  59. {
  60. PluginCategory current = getFromTag(tags[i]);
  61. if (current != PLUGIN_CATEGORY_NONE)
  62. category = current;
  63. }
  64. }
  65. return category;
  66. }
  67. static PluginCategory getFromTag(const char* const tag)
  68. {
  69. if (carla_strcasecmp(tag, "synthesis") == 0)
  70. return PLUGIN_CATEGORY_SYNTH;
  71. if (carla_strcasecmp(tag, "delay") == 0)
  72. return PLUGIN_CATEGORY_DELAY;
  73. if (carla_strcasecmp(tag, "equalizer") == 0)
  74. return PLUGIN_CATEGORY_EQ;
  75. if (carla_strcasecmp(tag, "filter") == 0)
  76. return PLUGIN_CATEGORY_FILTER;
  77. if (carla_strcasecmp(tag, "distortion") == 0)
  78. return PLUGIN_CATEGORY_DISTORTION;
  79. if (carla_strcasecmp(tag, "dynamics") == 0)
  80. return PLUGIN_CATEGORY_DYNAMICS;
  81. if (carla_strcasecmp(tag, "modulation") == 0)
  82. return PLUGIN_CATEGORY_MODULATOR;
  83. if (carla_strcasecmp(tag, "utility") == 0)
  84. return PLUGIN_CATEGORY_UTILITY;
  85. return PLUGIN_CATEGORY_NONE;
  86. }
  87. };
  88. // --------------------------------------------------------------------------------------------------------------------
  89. class CarlaJsfxUnit
  90. {
  91. static String createFileId(const water::File& rootPath, const water::File& filePath)
  92. {
  93. String fileId(filePath.getRelativePathFrom(rootPath).toRawUTF8());
  94. #ifdef CARLA_OS_WIN
  95. fileId.replace('\\', '/');
  96. #endif
  97. return fileId;
  98. }
  99. public:
  100. CarlaJsfxUnit() noexcept
  101. : fFileId(),
  102. fFilePath(),
  103. fRootPath() {}
  104. CarlaJsfxUnit(const water::File& rootPath, const water::File& filePath)
  105. : fFileId(createFileId(rootPath, filePath)),
  106. fFilePath(rootPath.getChildFile(fFileId).getFullPathName().toRawUTF8()),
  107. fRootPath(rootPath.getFullPathName().toRawUTF8()) {}
  108. explicit operator bool() const noexcept
  109. {
  110. return fFileId.isNotEmpty();
  111. }
  112. const String& getFileId() const noexcept
  113. {
  114. return fFileId;
  115. }
  116. const String& getFilePath() const noexcept
  117. {
  118. return fFilePath;
  119. }
  120. const String& getRootPath() const noexcept
  121. {
  122. return fRootPath;
  123. }
  124. private:
  125. String fFileId;
  126. String fFilePath;
  127. String fRootPath;
  128. };
  129. // --------------------------------------------------------------------------------------------------------------------
  130. CARLA_BACKEND_END_NAMESPACE
  131. #endif // CARLA_JSFX_UTILS_HPP_INCLUDED