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.

279 lines
8.1KB

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