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.

184 lines
7.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. // MSVC does not like it if you override a deprecated method even if you
  21. // keep the deprecation attribute. Other compilers are more forgiving.
  22. JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
  23. //==============================================================================
  24. /**
  25. Base class for an active instance of a plugin.
  26. This derives from the AudioProcessor class, and adds some extra functionality
  27. that helps when wrapping dynamically loaded plugins.
  28. This class is not needed when writing plugins, and you should never need to derive
  29. your own sub-classes from it. The plugin hosting classes use it internally and will
  30. return AudioPluginInstance objects which wrap external plugins.
  31. @see AudioProcessor, AudioPluginFormat
  32. @tags{Audio}
  33. */
  34. class JUCE_API AudioPluginInstance : public AudioProcessor
  35. {
  36. public:
  37. //==============================================================================
  38. /** Destructor.
  39. Make sure that you delete any UI components that belong to this plugin before
  40. deleting the plugin.
  41. */
  42. ~AudioPluginInstance() override = default;
  43. //==============================================================================
  44. /** Fills-in the appropriate parts of this plugin description object. */
  45. virtual void fillInPluginDescription (PluginDescription&) const = 0;
  46. /** Returns a PluginDescription for this plugin.
  47. This is just a convenience method to avoid calling fillInPluginDescription.
  48. */
  49. PluginDescription getPluginDescription() const;
  50. /** Allows retrieval of information related to the inner workings of a particular plugin format,
  51. such as the AEffect* of a VST, or the handle of an AudioUnit.
  52. To use this, create a new class derived from ExtensionsVisitor, and override
  53. each of the visit member functions. If this AudioPluginInstance wraps a VST3 plugin
  54. the visitVST3() member will be called, while if the AudioPluginInstance wraps an
  55. unknown format the visitUnknown() member will be called. The argument of the visit function
  56. can be queried to extract information related to the AudioPluginInstance's implementation.
  57. */
  58. virtual void getExtensions (ExtensionsVisitor&) const;
  59. using HostedParameter = HostedAudioProcessorParameter;
  60. /** Adds a parameter to this instance.
  61. @see AudioProcessor::addParameter()
  62. */
  63. void addHostedParameter (std::unique_ptr<HostedParameter>);
  64. /** Adds multiple parameters to this instance.
  65. In debug mode, this will also check that all added parameters derive from
  66. HostedParameter.
  67. @see AudioProcessor::addParameterGroup()
  68. */
  69. void addHostedParameterGroup (std::unique_ptr<AudioProcessorParameterGroup>);
  70. /** Adds multiple parameters to this instance.
  71. In debug mode, this will also check that all added parameters derive from
  72. HostedParameter.
  73. @see AudioProcessor::setParameterTree()
  74. */
  75. void setHostedParameterTree (AudioProcessorParameterGroup);
  76. /** Gets the parameter at a particular index.
  77. If you want to find lots of parameters by their IDs, you should probably build and
  78. use a map<String, HostedParameter*> by looping through all parameters.
  79. */
  80. HostedParameter* getHostedParameter (int index) const;
  81. #ifndef DOXYGEN
  82. /** Use the new typesafe visitor-based interface rather than this function.
  83. Returns a pointer to some kind of platform-specific data about the plugin.
  84. E.g. For a VST, this value can be cast to an AEffect*. For an AudioUnit, it can be
  85. cast to an AudioUnit handle.
  86. */
  87. [[deprecated ("Use the new typesafe visitor-based interface rather than this function.")]]
  88. virtual void* getPlatformSpecificData();
  89. // Rather than using these methods you should call the corresponding methods
  90. // on the AudioProcessorParameter objects returned from getParameters().
  91. // See the implementations of the methods below for some examples of how to
  92. // do this.
  93. //
  94. // In addition to being marked as deprecated these methods will assert on
  95. // the first call.
  96. [[deprecated]] String getParameterID (int index) override;
  97. [[deprecated]] float getParameter (int parameterIndex) override;
  98. [[deprecated]] void setParameter (int parameterIndex, float newValue) override;
  99. [[deprecated]] const String getParameterName (int parameterIndex) override;
  100. [[deprecated]] String getParameterName (int parameterIndex, int maximumStringLength) override;
  101. [[deprecated]] const String getParameterText (int parameterIndex) override;
  102. [[deprecated]] String getParameterText (int parameterIndex, int maximumStringLength) override;
  103. [[deprecated]] int getParameterNumSteps (int parameterIndex) override;
  104. [[deprecated]] bool isParameterDiscrete (int parameterIndex) const override;
  105. [[deprecated]] bool isParameterAutomatable (int parameterIndex) const override;
  106. [[deprecated]] float getParameterDefaultValue (int parameterIndex) override;
  107. [[deprecated]] String getParameterLabel (int parameterIndex) const override;
  108. [[deprecated]] bool isParameterOrientationInverted (int parameterIndex) const override;
  109. [[deprecated]] bool isMetaParameter (int parameterIndex) const override;
  110. [[deprecated]] AudioProcessorParameter::Category getParameterCategory (int parameterIndex) const override;
  111. #endif
  112. protected:
  113. //==============================================================================
  114. /** Structure used to describe plugin parameters */
  115. struct Parameter : public HostedParameter
  116. {
  117. public:
  118. Parameter();
  119. ~Parameter() override;
  120. String getText (float value, int maximumStringLength) const override;
  121. float getValueForText (const String& text) const override;
  122. private:
  123. StringArray onStrings, offStrings;
  124. };
  125. AudioPluginInstance() = default;
  126. AudioPluginInstance (const BusesProperties& ioLayouts) : AudioProcessor (ioLayouts) {}
  127. template <size_t numLayouts>
  128. AudioPluginInstance (const short channelLayoutList[numLayouts][2]) : AudioProcessor (channelLayoutList) {}
  129. private:
  130. // It's not safe to add a plain AudioProcessorParameter to an AudioPluginInstance.
  131. // Instead, all parameters must be HostedParameters.
  132. using AudioProcessor::addParameter;
  133. using AudioProcessor::addParameterGroup;
  134. using AudioProcessor::setParameterTree;
  135. void assertOnceOnDeprecatedMethodUse() const noexcept;
  136. static bool deprecationAssertiontriggered;
  137. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioPluginInstance)
  138. };
  139. JUCE_END_IGNORE_WARNINGS_MSVC
  140. } // namespace juce