The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

286 lines
8.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. PluginDescription AudioPluginInstance::getPluginDescription() const
  21. {
  22. PluginDescription desc;
  23. fillInPluginDescription (desc);
  24. return desc;
  25. }
  26. void* AudioPluginInstance::getPlatformSpecificData() { return nullptr; }
  27. void AudioPluginInstance::getExtensions (ExtensionsVisitor& visitor) const { visitor.visitUnknown ({}); }
  28. String AudioPluginInstance::getParameterID (int parameterIndex)
  29. {
  30. assertOnceOnDeprecatedMethodUse();
  31. // Currently there is no corresponding method available in the
  32. // AudioProcessorParameter class, and the previous behaviour of JUCE's
  33. // plug-in hosting code simply returns a string version of the index; to
  34. // maintain backwards compatibility you should perform the operation below
  35. // this comment. However the caveat is that for plug-ins which change their
  36. // number of parameters dynamically at runtime you cannot rely upon the
  37. // returned parameter ID mapping to the correct parameter. A comprehensive
  38. // solution to this problem requires some additional work in JUCE's hosting
  39. // code.
  40. return String (parameterIndex);
  41. }
  42. float AudioPluginInstance::getParameter (int parameterIndex)
  43. {
  44. assertOnceOnDeprecatedMethodUse();
  45. if (auto* param = getParameters()[parameterIndex])
  46. return param->getValue();
  47. return 0.0f;
  48. }
  49. void AudioPluginInstance::setParameter (int parameterIndex, float newValue)
  50. {
  51. assertOnceOnDeprecatedMethodUse();
  52. if (auto* param = getParameters()[parameterIndex])
  53. param->setValue (newValue);
  54. }
  55. const String AudioPluginInstance::getParameterName (int parameterIndex)
  56. {
  57. assertOnceOnDeprecatedMethodUse();
  58. if (auto* param = getParameters()[parameterIndex])
  59. return param->getName (1024);
  60. return {};
  61. }
  62. String AudioPluginInstance::getParameterName (int parameterIndex, int maximumStringLength)
  63. {
  64. assertOnceOnDeprecatedMethodUse();
  65. if (auto* param = getParameters()[parameterIndex])
  66. return param->getName (maximumStringLength);
  67. return {};
  68. }
  69. const String AudioPluginInstance::getParameterText (int parameterIndex)
  70. {
  71. assertOnceOnDeprecatedMethodUse();
  72. if (auto* param = getParameters()[parameterIndex])
  73. return param->getCurrentValueAsText();
  74. return {};
  75. }
  76. String AudioPluginInstance::getParameterText (int parameterIndex, int maximumStringLength)
  77. {
  78. assertOnceOnDeprecatedMethodUse();
  79. if (auto* param = getParameters()[parameterIndex])
  80. return param->getCurrentValueAsText().substring (0, maximumStringLength);
  81. return {};
  82. }
  83. float AudioPluginInstance::getParameterDefaultValue (int parameterIndex)
  84. {
  85. assertOnceOnDeprecatedMethodUse();
  86. if (auto* param = getParameters()[parameterIndex])
  87. return param->getDefaultValue();
  88. return 0.0f;
  89. }
  90. int AudioPluginInstance::getParameterNumSteps (int parameterIndex)
  91. {
  92. assertOnceOnDeprecatedMethodUse();
  93. if (auto* param = getParameters()[parameterIndex])
  94. return param->getNumSteps();
  95. return AudioProcessor::getDefaultNumParameterSteps();
  96. }
  97. bool AudioPluginInstance::isParameterDiscrete (int parameterIndex) const
  98. {
  99. assertOnceOnDeprecatedMethodUse();
  100. if (auto* param = getParameters()[parameterIndex])
  101. return param->isDiscrete();
  102. return false;
  103. }
  104. bool AudioPluginInstance::isParameterAutomatable (int parameterIndex) const
  105. {
  106. assertOnceOnDeprecatedMethodUse();
  107. if (auto* param = getParameters()[parameterIndex])
  108. return param->isAutomatable();
  109. return true;
  110. }
  111. String AudioPluginInstance::getParameterLabel (int parameterIndex) const
  112. {
  113. assertOnceOnDeprecatedMethodUse();
  114. if (auto* param = getParameters()[parameterIndex])
  115. return param->getLabel();
  116. return {};
  117. }
  118. bool AudioPluginInstance::isParameterOrientationInverted (int parameterIndex) const
  119. {
  120. assertOnceOnDeprecatedMethodUse();
  121. if (auto* param = getParameters()[parameterIndex])
  122. return param->isOrientationInverted();
  123. return false;
  124. }
  125. bool AudioPluginInstance::isMetaParameter (int parameterIndex) const
  126. {
  127. assertOnceOnDeprecatedMethodUse();
  128. if (auto* param = getParameters()[parameterIndex])
  129. return param->isMetaParameter();
  130. return false;
  131. }
  132. AudioProcessorParameter::Category AudioPluginInstance::getParameterCategory (int parameterIndex) const
  133. {
  134. assertOnceOnDeprecatedMethodUse();
  135. if (auto* param = getParameters()[parameterIndex])
  136. return param->getCategory();
  137. return AudioProcessorParameter::genericParameter;
  138. }
  139. void AudioPluginInstance::assertOnceOnDeprecatedMethodUse() const noexcept
  140. {
  141. if (! deprecationAssertiontriggered)
  142. {
  143. // If you hit this assertion then you are using at least one of the
  144. // methods marked as deprecated in this class. For now you can simply
  145. // continue past this point and subsequent uses of deprecated methods
  146. // will not trigger additional assertions. However, we will shortly be
  147. // removing these methods so you are strongly advised to look at the
  148. // implementation of the corresponding method in this class and use
  149. // that approach instead.
  150. jassertfalse;
  151. }
  152. deprecationAssertiontriggered = true;
  153. }
  154. bool AudioPluginInstance::deprecationAssertiontriggered = false;
  155. AudioPluginInstance::Parameter::Parameter()
  156. : onStrings { TRANS ("on"), TRANS ("yes"), TRANS ("true") },
  157. offStrings { TRANS ("off"), TRANS ("no"), TRANS ("false") }
  158. {
  159. }
  160. String AudioPluginInstance::Parameter::getText (float value, int maximumStringLength) const
  161. {
  162. if (isBoolean())
  163. return value < 0.5f ? TRANS("Off") : TRANS("On");
  164. return String (value).substring (0, maximumStringLength);
  165. }
  166. float AudioPluginInstance::Parameter::getValueForText (const String& text) const
  167. {
  168. auto floatValue = text.retainCharacters ("-0123456789.").getFloatValue();
  169. if (isBoolean())
  170. {
  171. if (onStrings.contains (text, true))
  172. return 1.0f;
  173. if (offStrings.contains (text, true))
  174. return 0.0f;
  175. return floatValue < 0.5f ? 0.0f : 1.0f;
  176. }
  177. return floatValue;
  178. }
  179. void AudioPluginInstance::addHostedParameter (std::unique_ptr<HostedParameter> param)
  180. {
  181. addParameter (param.release());
  182. }
  183. void AudioPluginInstance::addHostedParameterGroup (std::unique_ptr<AudioProcessorParameterGroup> group)
  184. {
  185. #if JUCE_DEBUG
  186. // All parameters *must* be HostedParameters, otherwise getHostedParameter will return
  187. // garbage and your host will crash and burn
  188. for (auto* param : group->getParameters (true))
  189. {
  190. jassert (dynamic_cast<HostedParameter*> (param) != nullptr);
  191. }
  192. #endif
  193. addParameterGroup (std::move (group));
  194. }
  195. void AudioPluginInstance::setHostedParameterTree (AudioProcessorParameterGroup group)
  196. {
  197. #if JUCE_DEBUG
  198. // All parameters *must* be HostedParameters, otherwise getHostedParameter will return
  199. // garbage and your host will crash and burn
  200. for (auto* param : group.getParameters (true))
  201. {
  202. jassert (dynamic_cast<HostedParameter*> (param) != nullptr);
  203. }
  204. #endif
  205. setParameterTree (std::move (group));
  206. }
  207. AudioPluginInstance::HostedParameter* AudioPluginInstance::getHostedParameter (int index) const
  208. {
  209. // It's important that all AudioPluginInstance implementations
  210. // only ever own HostedParameters!
  211. return static_cast<HostedParameter*> (getParameters()[index]);
  212. }
  213. } // namespace juce