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.

293 lines
8.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. {
  157. onStrings.add (TRANS("on"));
  158. onStrings.add (TRANS("yes"));
  159. onStrings.add (TRANS("true"));
  160. offStrings.add (TRANS("off"));
  161. offStrings.add (TRANS("no"));
  162. offStrings.add (TRANS("false"));
  163. }
  164. AudioPluginInstance::Parameter::~Parameter() = default;
  165. String AudioPluginInstance::Parameter::getText (float value, int maximumStringLength) const
  166. {
  167. if (isBoolean())
  168. return value < 0.5f ? TRANS("Off") : TRANS("On");
  169. return String (value).substring (0, maximumStringLength);
  170. }
  171. float AudioPluginInstance::Parameter::getValueForText (const String& text) const
  172. {
  173. auto floatValue = text.retainCharacters ("-0123456789.").getFloatValue();
  174. if (isBoolean())
  175. {
  176. if (onStrings.contains (text, true))
  177. return 1.0f;
  178. if (offStrings.contains (text, true))
  179. return 0.0f;
  180. return floatValue < 0.5f ? 0.0f : 1.0f;
  181. }
  182. return floatValue;
  183. }
  184. void AudioPluginInstance::addHostedParameter (std::unique_ptr<HostedParameter> param)
  185. {
  186. addParameter (param.release());
  187. }
  188. void AudioPluginInstance::addHostedParameterGroup (std::unique_ptr<AudioProcessorParameterGroup> group)
  189. {
  190. #if JUCE_DEBUG
  191. // All parameters *must* be HostedParameters, otherwise getHostedParameter will return
  192. // garbage and your host will crash and burn
  193. for (auto* param : group->getParameters (true))
  194. {
  195. jassert (dynamic_cast<HostedParameter*> (param) != nullptr);
  196. }
  197. #endif
  198. addParameterGroup (std::move (group));
  199. }
  200. void AudioPluginInstance::setHostedParameterTree (AudioProcessorParameterGroup group)
  201. {
  202. #if JUCE_DEBUG
  203. // All parameters *must* be HostedParameters, otherwise getHostedParameter will return
  204. // garbage and your host will crash and burn
  205. for (auto* param : group.getParameters (true))
  206. {
  207. jassert (dynamic_cast<HostedParameter*> (param) != nullptr);
  208. }
  209. #endif
  210. setParameterTree (std::move (group));
  211. }
  212. AudioPluginInstance::HostedParameter* AudioPluginInstance::getHostedParameter (int index) const
  213. {
  214. // It's important that all AudioPluginInstance implementations
  215. // only ever own HostedParameters!
  216. return static_cast<HostedParameter*> (getParameters()[index]);
  217. }
  218. } // namespace juce