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.

244 lines
6.8KB

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