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.

252 lines
7.1KB

  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. void* AudioPluginInstance::getPlatformSpecificData() { return nullptr; }
  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() {}
  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. } // namespace juce