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.

255 lines
11KB

  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. /** Frees render resources allocated in prepareToPlay(). */
  49. virtual void releaseResources() {}
  50. /** Resets the internal state variables of the renderer. */
  51. virtual void reset() {}
  52. /** Renders the output into the given buffer. Returns true if rendering executed without error,
  53. false otherwise.
  54. @param buffer The output buffer for the rendering. ARAPlaybackRenderers will
  55. replace the sample data, while ARAEditorRenderer will add to it.
  56. @param realtime Indicates whether the call is executed under real time constraints.
  57. The value of this parameter may change from one call to the next,
  58. and if the value is yes, the rendering may fail if the required
  59. samples cannot be obtained in time.
  60. @param positionInfo Current song position, playback state and playback loop location.
  61. There should be no need to access the bpm, timeSig and ppqPosition
  62. members in any ARA renderer since ARA provides that information with
  63. random access in its model graph.
  64. Returns false if non-ARA fallback rendering is required and true otherwise.
  65. */
  66. virtual bool processBlock (AudioBuffer<float>& buffer,
  67. AudioProcessor::Realtime realtime,
  68. const AudioPlayHead::PositionInfo& positionInfo) noexcept = 0;
  69. /** Renders the output into the given buffer. Returns true if rendering executed without error,
  70. false otherwise.
  71. @param buffer The output buffer for the rendering. ARAPlaybackRenderers will
  72. replace the sample data, while ARAEditorRenderer will add to it.
  73. @param realtime Indicates whether the call is executed under real time constraints.
  74. The value of this parameter may change from one call to the next,
  75. and if the value is yes, the rendering may fail if the required
  76. samples cannot be obtained in time.
  77. @param positionInfo Current song position, playback state and playback loop location.
  78. There should be no need to access the bpm, timeSig and ppqPosition
  79. members in any ARA renderer since ARA provides that information with
  80. random access in its model graph.
  81. Returns false if non-ARA fallback rendering is required and true otherwise.
  82. */
  83. virtual bool processBlock (AudioBuffer<double>& buffer,
  84. AudioProcessor::Realtime realtime,
  85. const AudioPlayHead::PositionInfo& positionInfo) noexcept;
  86. };
  87. //==============================================================================
  88. /** Base class for a renderer fulfilling the ARAPlaybackRenderer role as described in the ARA SDK.
  89. Instances of this class are constructed by the DocumentController. If you are subclassing
  90. ARAPlaybackRenderer, make sure to call the base class implementation of any overridden function,
  91. except for processBlock.
  92. @tags{ARA}
  93. */
  94. class JUCE_API ARAPlaybackRenderer : public ARA::PlugIn::PlaybackRenderer,
  95. public ARARenderer
  96. {
  97. public:
  98. using ARA::PlugIn::PlaybackRenderer::PlaybackRenderer;
  99. bool processBlock (AudioBuffer<float>& buffer,
  100. AudioProcessor::Realtime realtime,
  101. const AudioPlayHead::PositionInfo& positionInfo) noexcept override;
  102. using ARARenderer::processBlock;
  103. // Shadowing templated getters to default to JUCE versions of the returned classes
  104. /** Returns the PlaybackRegions
  105. *
  106. * @tparam PlaybackRegion_t
  107. * @return
  108. */
  109. template <typename PlaybackRegion_t = ARAPlaybackRegion>
  110. std::vector<PlaybackRegion_t*> const& getPlaybackRegions() const noexcept
  111. {
  112. return ARA::PlugIn::PlaybackRenderer::getPlaybackRegions<PlaybackRegion_t>();
  113. }
  114. #if ARA_VALIDATE_API_CALLS
  115. void addPlaybackRegion (ARA::ARAPlaybackRegionRef playbackRegionRef) noexcept override;
  116. void removePlaybackRegion (ARA::ARAPlaybackRegionRef playbackRegionRef) noexcept override;
  117. AudioProcessorARAExtension* araExtension {};
  118. #endif
  119. private:
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARAPlaybackRenderer)
  121. };
  122. //==============================================================================
  123. /** Base class for a renderer fulfilling the ARAEditorRenderer role as described in the ARA SDK.
  124. Instances of this class are constructed by the DocumentController. If you are subclassing
  125. ARAEditorRenderer, make sure to call the base class implementation of any overridden function,
  126. except for processBlock.
  127. @tags{ARA}
  128. */
  129. class JUCE_API ARAEditorRenderer : public ARA::PlugIn::EditorRenderer,
  130. public ARARenderer
  131. {
  132. public:
  133. using ARA::PlugIn::EditorRenderer::EditorRenderer;
  134. // Shadowing templated getters to default to JUCE versions of the returned classes
  135. template <typename PlaybackRegion_t = ARAPlaybackRegion>
  136. std::vector<PlaybackRegion_t*> const& getPlaybackRegions() const noexcept
  137. {
  138. return ARA::PlugIn::EditorRenderer::getPlaybackRegions<PlaybackRegion_t>();
  139. }
  140. template <typename RegionSequence_t = ARARegionSequence>
  141. std::vector<RegionSequence_t*> const& getRegionSequences() const noexcept
  142. {
  143. return ARA::PlugIn::EditorRenderer::getRegionSequences<RegionSequence_t>();
  144. }
  145. // By default, editor renderers will just let the signal pass through unaltered.
  146. // If you're overriding this to implement actual audio preview, remember to check
  147. // isNonRealtime of the process context - typically preview is limited to realtime.
  148. bool processBlock (AudioBuffer<float>& buffer,
  149. AudioProcessor::Realtime isNonRealtime,
  150. const AudioPlayHead::PositionInfo& positionInfo) noexcept override;
  151. using ARARenderer::processBlock;
  152. private:
  153. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARAEditorRenderer)
  154. };
  155. //==============================================================================
  156. /** Base class for fulfilling the ARAEditorView role as described in the ARA SDK.
  157. Instances of this class are constructed by the DocumentController. If you are subclassing
  158. ARAEditorView, make sure to call the base class implementation of overridden functions.
  159. @tags{ARA}
  160. */
  161. class JUCE_API ARAEditorView : public ARA::PlugIn::EditorView
  162. {
  163. public:
  164. using ARA::PlugIn::EditorView::EditorView;
  165. // Shadowing templated getters to default to JUCE versions of the returned classes
  166. template <typename RegionSequence_t = ARARegionSequence>
  167. const std::vector<RegionSequence_t*>& getHiddenRegionSequences() const noexcept
  168. {
  169. return ARA::PlugIn::EditorView::getHiddenRegionSequences<RegionSequence_t>();
  170. }
  171. // Base class implementation must be called if overridden
  172. void doNotifySelection (const ARA::PlugIn::ViewSelection* currentSelection) noexcept override;
  173. // Base class implementation must be called if overridden
  174. void doNotifyHideRegionSequences (const std::vector<ARA::PlugIn::RegionSequence*>& regionSequences) noexcept override;
  175. /** A base class for listeners that want to know about changes to an ARAEditorView object.
  176. Use ARAEditorView::addListener() to register your listener with an ARAEditorView.
  177. */
  178. class JUCE_API Listener
  179. {
  180. public:
  181. /** Destructor. */
  182. virtual ~Listener() = default;
  183. /** Called when the editor view's selection changes.
  184. @param viewSelection The current selection state
  185. */
  186. virtual void onNewSelection (const ARAViewSelection& viewSelection);
  187. /** Called when region sequences are flagged as hidden in the host UI.
  188. @param regionSequences A vector containing all hidden region sequences.
  189. */
  190. virtual void onHideRegionSequences (const std::vector<ARARegionSequence*>& regionSequences);
  191. };
  192. /** \copydoc ARAListenableModelClass::addListener */
  193. void addListener (Listener* l);
  194. /** \copydoc ARAListenableModelClass::removeListener */
  195. void removeListener (Listener* l);
  196. private:
  197. ListenerList<Listener> listeners;
  198. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARAEditorView)
  199. };
  200. }