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.

272 lines
12KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. #pragma once
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /** Base class for a renderer fulfilling either the ARAPlaybackRenderer or the ARAEditorRenderer role.
  23. Instances of either subclass are constructed by the DocumentController.
  24. @tags{ARA}
  25. */
  26. class JUCE_API ARARenderer
  27. {
  28. public:
  29. enum class AlwaysNonRealtime { no, yes };
  30. virtual ~ARARenderer() = default;
  31. /** Initialises the renderer for playback.
  32. @param sampleRate The sample rate that will be used for the data that is sent
  33. to the renderer
  34. @param maximumSamplesPerBlock The maximum number of samples that will be in the blocks
  35. sent to process() method
  36. @param numChannels The number of channels that the process() method will be
  37. expected to handle
  38. @param precision This should be the same as the result of getProcessingPrecision()
  39. for the enclosing AudioProcessor
  40. @param alwaysNonRealtime yes if this renderer is never used in realtime (e.g. if
  41. providing data for views only)
  42. */
  43. virtual void prepareToPlay (double sampleRate,
  44. int maximumSamplesPerBlock,
  45. int numChannels,
  46. AudioProcessor::ProcessingPrecision precision,
  47. AlwaysNonRealtime alwaysNonRealtime = AlwaysNonRealtime::no)
  48. {
  49. ignoreUnused (sampleRate, maximumSamplesPerBlock, numChannels, precision, alwaysNonRealtime);
  50. }
  51. /** Frees render resources allocated in prepareToPlay(). */
  52. virtual void releaseResources() {}
  53. /** Resets the internal state variables of the renderer. */
  54. virtual void reset() {}
  55. /** Renders the output into the given buffer. Returns true if rendering executed without error,
  56. false otherwise.
  57. @param buffer The output buffer for the rendering. ARAPlaybackRenderers will
  58. replace the sample data, while ARAEditorRenderer will add to it.
  59. @param realtime Indicates whether the call is executed under real time constraints.
  60. The value of this parameter may change from one call to the next,
  61. and if the value is yes, the rendering may fail if the required
  62. samples cannot be obtained in time.
  63. @param positionInfo Current song position, playback state and playback loop location.
  64. There should be no need to access the bpm, timeSig and ppqPosition
  65. members in any ARA renderer since ARA provides that information with
  66. random access in its model graph.
  67. Returns false if non-ARA fallback rendering is required and true otherwise.
  68. */
  69. virtual bool processBlock (AudioBuffer<float>& buffer,
  70. AudioProcessor::Realtime realtime,
  71. const AudioPlayHead::PositionInfo& positionInfo) noexcept = 0;
  72. /** Renders the output into the given buffer. Returns true if rendering executed without error,
  73. false otherwise.
  74. @param buffer The output buffer for the rendering. ARAPlaybackRenderers will
  75. replace the sample data, while ARAEditorRenderer will add to it.
  76. @param realtime Indicates whether the call is executed under real time constraints.
  77. The value of this parameter may change from one call to the next,
  78. and if the value is yes, the rendering may fail if the required
  79. samples cannot be obtained in time.
  80. @param positionInfo Current song position, playback state and playback loop location.
  81. There should be no need to access the bpm, timeSig and ppqPosition
  82. members in any ARA renderer since ARA provides that information with
  83. random access in its model graph.
  84. Returns false if non-ARA fallback rendering is required and true otherwise.
  85. */
  86. virtual bool processBlock (AudioBuffer<double>& buffer,
  87. AudioProcessor::Realtime realtime,
  88. const AudioPlayHead::PositionInfo& positionInfo) noexcept;
  89. };
  90. //==============================================================================
  91. /** Base class for a renderer fulfilling the ARAPlaybackRenderer role as described in the ARA SDK.
  92. Instances of this class are constructed by the DocumentController. If you are subclassing
  93. ARAPlaybackRenderer, make sure to call the base class implementation of any overridden function,
  94. except for processBlock.
  95. @tags{ARA}
  96. */
  97. class JUCE_API ARAPlaybackRenderer : public ARA::PlugIn::PlaybackRenderer,
  98. public ARARenderer
  99. {
  100. public:
  101. using ARA::PlugIn::PlaybackRenderer::PlaybackRenderer;
  102. bool processBlock (AudioBuffer<float>& buffer,
  103. AudioProcessor::Realtime realtime,
  104. const AudioPlayHead::PositionInfo& positionInfo) noexcept override
  105. {
  106. ignoreUnused (buffer, realtime, positionInfo);
  107. return false;
  108. }
  109. // Shadowing templated getters to default to JUCE versions of the returned classes
  110. /** Returns the PlaybackRegions
  111. *
  112. * @tparam PlaybackRegion_t
  113. * @return
  114. */
  115. template <typename PlaybackRegion_t = ARAPlaybackRegion>
  116. std::vector<PlaybackRegion_t*> const& getPlaybackRegions() const noexcept
  117. {
  118. return ARA::PlugIn::PlaybackRenderer::getPlaybackRegions<PlaybackRegion_t>();
  119. }
  120. #if ARA_VALIDATE_API_CALLS
  121. void addPlaybackRegion (ARA::ARAPlaybackRegionRef playbackRegionRef) noexcept override;
  122. void removePlaybackRegion (ARA::ARAPlaybackRegionRef playbackRegionRef) noexcept override;
  123. AudioProcessorARAExtension* araExtension {};
  124. #endif
  125. private:
  126. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARAPlaybackRenderer)
  127. };
  128. //==============================================================================
  129. /** Base class for a renderer fulfilling the ARAEditorRenderer role as described in the ARA SDK.
  130. Instances of this class are constructed by the DocumentController. If you are subclassing
  131. ARAEditorRenderer, make sure to call the base class implementation of any overridden function,
  132. except for processBlock.
  133. @tags{ARA}
  134. */
  135. class JUCE_API ARAEditorRenderer : public ARA::PlugIn::EditorRenderer,
  136. public ARARenderer
  137. {
  138. public:
  139. using ARA::PlugIn::EditorRenderer::EditorRenderer;
  140. // Shadowing templated getters to default to JUCE versions of the returned classes
  141. template <typename PlaybackRegion_t = ARAPlaybackRegion>
  142. std::vector<PlaybackRegion_t*> const& getPlaybackRegions() const noexcept
  143. {
  144. return ARA::PlugIn::EditorRenderer::getPlaybackRegions<PlaybackRegion_t>();
  145. }
  146. template <typename RegionSequence_t = ARARegionSequence>
  147. std::vector<RegionSequence_t*> const& getRegionSequences() const noexcept
  148. {
  149. return ARA::PlugIn::EditorRenderer::getRegionSequences<RegionSequence_t>();
  150. }
  151. // By default, editor renderers will just let the signal pass through unaltered.
  152. // If you're overriding this to implement actual audio preview, remember to check
  153. // isNonRealtime of the process context - typically preview is limited to realtime.
  154. bool processBlock (AudioBuffer<float>& buffer,
  155. AudioProcessor::Realtime isNonRealtime,
  156. const AudioPlayHead::PositionInfo& positionInfo) noexcept override
  157. {
  158. ignoreUnused (buffer, isNonRealtime, positionInfo);
  159. return true;
  160. }
  161. private:
  162. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARAEditorRenderer)
  163. };
  164. //==============================================================================
  165. /** Base class for a renderer fulfilling the ARAEditorView role as described in the ARA SDK.
  166. Instances of this class are constructed by the DocumentController. If you are subclassing
  167. ARAEditorView, make sure to call the base class implementation of overridden functions.
  168. @tags{ARA}
  169. */
  170. class JUCE_API ARAEditorView : public ARA::PlugIn::EditorView
  171. {
  172. public:
  173. using ARA::PlugIn::EditorView::EditorView;
  174. // Shadowing templated getters to default to JUCE versions of the returned classes
  175. template <typename RegionSequence_t = ARARegionSequence>
  176. std::vector<RegionSequence_t*> const& getHiddenRegionSequences() const noexcept
  177. {
  178. return ARA::PlugIn::EditorView::getHiddenRegionSequences<RegionSequence_t>();
  179. }
  180. // Base class implementation must be called if overridden
  181. void doNotifySelection (const ARA::PlugIn::ViewSelection* currentSelection) noexcept override;
  182. // Base class implementation must be called if overridden
  183. void doNotifyHideRegionSequences (std::vector<ARA::PlugIn::RegionSequence*> const& regionSequences) noexcept override;
  184. /** A base class for listeners that want to know about changes to an ARAEditorView object.
  185. Use ARAEditorView::addListener() to register your listener with an ARAEditorView.
  186. */
  187. class JUCE_API Listener
  188. {
  189. public:
  190. /** Destructor. */
  191. virtual ~Listener() = default;
  192. ARA_DISABLE_UNREFERENCED_PARAMETER_WARNING_BEGIN
  193. /** Called when the editor view's selection changes.
  194. @param viewSelection The current selection state
  195. */
  196. virtual void onNewSelection (const ARA::PlugIn::ViewSelection& viewSelection)
  197. {
  198. ignoreUnused (viewSelection);
  199. }
  200. /** Called when region sequences are flagged as hidden in the host UI.
  201. @param regionSequences A vector containing all hidden region sequences.
  202. */
  203. virtual void onHideRegionSequences (std::vector<ARARegionSequence*> const& regionSequences)
  204. {
  205. ignoreUnused (regionSequences);
  206. }
  207. ARA_DISABLE_UNREFERENCED_PARAMETER_WARNING_END
  208. };
  209. /** \copydoc ARAListenableModelClass::addListener */
  210. void addListener (Listener* l);
  211. /** \copydoc ARAListenableModelClass::removeListener */
  212. void removeListener (Listener* l);
  213. private:
  214. ListenerList<Listener> listeners;
  215. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARAEditorView)
  216. };
  217. }