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.

231 lines
6.2KB

  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. const String AudioPluginInstance::getParameterText (int parameterIndex)
  53. {
  54. assertOnceOnDeprecatedMethodUse();
  55. if (auto* param = getParameters()[parameterIndex])
  56. return param->getCurrentValueAsText();
  57. return {};
  58. }
  59. String AudioPluginInstance::getParameterText (int parameterIndex, int maximumStringLength)
  60. {
  61. assertOnceOnDeprecatedMethodUse();
  62. if (auto* param = getParameters()[parameterIndex])
  63. return param->getCurrentValueAsText().substring (0, maximumStringLength);
  64. return {};
  65. }
  66. float AudioPluginInstance::getParameterDefaultValue (int parameterIndex)
  67. {
  68. assertOnceOnDeprecatedMethodUse();
  69. if (auto* param = getParameters()[parameterIndex])
  70. return param->getDefaultValue();
  71. return 0.0f;
  72. }
  73. int AudioPluginInstance::getParameterNumSteps (int parameterIndex)
  74. {
  75. assertOnceOnDeprecatedMethodUse();
  76. if (auto* param = getParameters()[parameterIndex])
  77. return param->getNumSteps();
  78. return AudioProcessor::getDefaultNumParameterSteps();
  79. }
  80. bool AudioPluginInstance::isParameterDiscrete (int parameterIndex) const
  81. {
  82. assertOnceOnDeprecatedMethodUse();
  83. if (auto* param = getParameters()[parameterIndex])
  84. return param->isDiscrete();
  85. return false;
  86. }
  87. bool AudioPluginInstance::isParameterAutomatable (int parameterIndex) const
  88. {
  89. assertOnceOnDeprecatedMethodUse();
  90. if (auto* param = getParameters()[parameterIndex])
  91. return param->isAutomatable();
  92. return true;
  93. }
  94. String AudioPluginInstance::getParameterLabel (int parameterIndex) const
  95. {
  96. assertOnceOnDeprecatedMethodUse();
  97. if (auto* param = getParameters()[parameterIndex])
  98. return param->getLabel();
  99. return {};
  100. }
  101. bool AudioPluginInstance::isParameterOrientationInverted (int parameterIndex) const
  102. {
  103. assertOnceOnDeprecatedMethodUse();
  104. if (auto* param = getParameters()[parameterIndex])
  105. return param->isOrientationInverted();
  106. return false;
  107. }
  108. bool AudioPluginInstance::isMetaParameter (int parameterIndex) const
  109. {
  110. assertOnceOnDeprecatedMethodUse();
  111. if (auto* param = getParameters()[parameterIndex])
  112. return param->isMetaParameter();
  113. return false;
  114. }
  115. AudioProcessorParameter::Category AudioPluginInstance::getParameterCategory (int parameterIndex) const
  116. {
  117. assertOnceOnDeprecatedMethodUse();
  118. if (auto* param = getParameters()[parameterIndex])
  119. return param->getCategory();
  120. return AudioProcessorParameter::genericParameter;
  121. }
  122. void AudioPluginInstance::assertOnceOnDeprecatedMethodUse() const noexcept
  123. {
  124. if (! deprecationAssertiontriggered)
  125. {
  126. // If you hit this assertion then you are using at least one of the
  127. // methods marked as deprecated in this class. For now you can simply
  128. // continue past this point and subsequent uses of deprecated methods
  129. // will not trigger additional assertions. However, we will shortly be
  130. // removing these methods so you are strongly advised to look at the
  131. // implementation of the corresponding method in this class and use
  132. // that approach instead.
  133. jassertfalse;
  134. }
  135. deprecationAssertiontriggered = true;
  136. }
  137. bool AudioPluginInstance::deprecationAssertiontriggered = false;
  138. AudioPluginInstance::Parameter::Parameter()
  139. {
  140. onStrings.add (TRANS("on"));
  141. onStrings.add (TRANS("yes"));
  142. onStrings.add (TRANS("true"));
  143. offStrings.add (TRANS("off"));
  144. offStrings.add (TRANS("no"));
  145. offStrings.add (TRANS("false"));
  146. }
  147. AudioPluginInstance::Parameter::~Parameter() {}
  148. String AudioPluginInstance::Parameter::getText (float value, int maximumStringLength) const
  149. {
  150. if (isBoolean())
  151. return value < 0.5f ? TRANS("Off") : TRANS("On");
  152. return String (value).substring (0, maximumStringLength);
  153. }
  154. float AudioPluginInstance::Parameter::getValueForText (const String& text) const
  155. {
  156. auto floatValue = text.retainCharacters ("-0123456789.").getFloatValue();
  157. if (isBoolean())
  158. {
  159. if (onStrings.contains (text, true))
  160. return 1.0f;
  161. if (offStrings.contains (text, true))
  162. return 0.0f;
  163. return floatValue < 0.5f ? 0.0f : 1.0f;
  164. }
  165. return floatValue;
  166. }
  167. } // namespace juce