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.

250 lines
7.0KB

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