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.

176 lines
7.3KB

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