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.

241 lines
6.4KB

  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. return String (parameterIndex);
  31. }
  32. float AudioPluginInstance::getParameter (int parameterIndex)
  33. {
  34. assertOnceOnDeprecatedMethodUse();
  35. if (auto* param = getParameters()[parameterIndex])
  36. return param->getValue();
  37. return 0.0f;
  38. }
  39. void AudioPluginInstance::setParameter (int parameterIndex, float newValue)
  40. {
  41. assertOnceOnDeprecatedMethodUse();
  42. if (auto* param = getParameters()[parameterIndex])
  43. return param->setValue (newValue);
  44. }
  45. const String AudioPluginInstance::getParameterName (int parameterIndex)
  46. {
  47. assertOnceOnDeprecatedMethodUse();
  48. if (auto* param = getParameters()[parameterIndex])
  49. return param->getName (1024);
  50. return {};
  51. }
  52. String AudioPluginInstance::getParameterName (int parameterIndex, int maximumStringLength)
  53. {
  54. assertOnceOnDeprecatedMethodUse();
  55. if (auto* param = getParameters()[parameterIndex])
  56. return param->getName (maximumStringLength);
  57. return {};
  58. }
  59. const String AudioPluginInstance::getParameterText (int parameterIndex)
  60. {
  61. assertOnceOnDeprecatedMethodUse();
  62. if (auto* param = getParameters()[parameterIndex])
  63. return param->getCurrentValueAsText();
  64. return {};
  65. }
  66. String AudioPluginInstance::getParameterText (int parameterIndex, int maximumStringLength)
  67. {
  68. assertOnceOnDeprecatedMethodUse();
  69. if (auto* param = getParameters()[parameterIndex])
  70. return param->getCurrentValueAsText().substring (0, maximumStringLength);
  71. return {};
  72. }
  73. float AudioPluginInstance::getParameterDefaultValue (int parameterIndex)
  74. {
  75. assertOnceOnDeprecatedMethodUse();
  76. if (auto* param = getParameters()[parameterIndex])
  77. return param->getDefaultValue();
  78. return 0.0f;
  79. }
  80. int AudioPluginInstance::getParameterNumSteps (int parameterIndex)
  81. {
  82. assertOnceOnDeprecatedMethodUse();
  83. if (auto* param = getParameters()[parameterIndex])
  84. return param->getNumSteps();
  85. return AudioProcessor::getDefaultNumParameterSteps();
  86. }
  87. bool AudioPluginInstance::isParameterDiscrete (int parameterIndex) const
  88. {
  89. assertOnceOnDeprecatedMethodUse();
  90. if (auto* param = getParameters()[parameterIndex])
  91. return param->isDiscrete();
  92. return false;
  93. }
  94. bool AudioPluginInstance::isParameterAutomatable (int parameterIndex) const
  95. {
  96. assertOnceOnDeprecatedMethodUse();
  97. if (auto* param = getParameters()[parameterIndex])
  98. return param->isAutomatable();
  99. return true;
  100. }
  101. String AudioPluginInstance::getParameterLabel (int parameterIndex) const
  102. {
  103. assertOnceOnDeprecatedMethodUse();
  104. if (auto* param = getParameters()[parameterIndex])
  105. return param->getLabel();
  106. return {};
  107. }
  108. bool AudioPluginInstance::isParameterOrientationInverted (int parameterIndex) const
  109. {
  110. assertOnceOnDeprecatedMethodUse();
  111. if (auto* param = getParameters()[parameterIndex])
  112. return param->isOrientationInverted();
  113. return false;
  114. }
  115. bool AudioPluginInstance::isMetaParameter (int parameterIndex) const
  116. {
  117. assertOnceOnDeprecatedMethodUse();
  118. if (auto* param = getParameters()[parameterIndex])
  119. return param->isMetaParameter();
  120. return false;
  121. }
  122. AudioProcessorParameter::Category AudioPluginInstance::getParameterCategory (int parameterIndex) const
  123. {
  124. assertOnceOnDeprecatedMethodUse();
  125. if (auto* param = getParameters()[parameterIndex])
  126. return param->getCategory();
  127. return AudioProcessorParameter::genericParameter;
  128. }
  129. void AudioPluginInstance::assertOnceOnDeprecatedMethodUse() const noexcept
  130. {
  131. if (! deprecationAssertiontriggered)
  132. {
  133. // If you hit this assertion then you are using at least one of the
  134. // methods marked as deprecated in this class. For now you can simply
  135. // continue past this point and subsequent uses of deprecated methods
  136. // will not trigger additional assertions. However, we will shortly be
  137. // removing these methods so you are strongly advised to look at the
  138. // implementation of the corresponding method in this class and use
  139. // that approach instead.
  140. jassertfalse;
  141. }
  142. deprecationAssertiontriggered = true;
  143. }
  144. bool AudioPluginInstance::deprecationAssertiontriggered = false;
  145. AudioPluginInstance::Parameter::Parameter()
  146. {
  147. onStrings.add (TRANS("on"));
  148. onStrings.add (TRANS("yes"));
  149. onStrings.add (TRANS("true"));
  150. offStrings.add (TRANS("off"));
  151. offStrings.add (TRANS("no"));
  152. offStrings.add (TRANS("false"));
  153. }
  154. AudioPluginInstance::Parameter::~Parameter() {}
  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. } // namespace juce