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.

996 lines
58KB

  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. namespace juce
  19. {
  20. class SimpleTimer final : private Timer
  21. {
  22. public:
  23. SimpleTimer (int frequencyHz, std::function<void()> callbackIn)
  24. : callback (std::move (callbackIn))
  25. {
  26. jassert (callback);
  27. startTimerHz (frequencyHz);
  28. }
  29. ~SimpleTimer() override
  30. {
  31. stopTimer();
  32. }
  33. private:
  34. void timerCallback() override
  35. {
  36. callback();
  37. }
  38. std::function<void()> callback;
  39. };
  40. class ARADocumentControllerSpecialisation::ARADocumentControllerImpl : public ARADocumentController
  41. {
  42. public:
  43. ARADocumentControllerImpl (const ARA::PlugIn::PlugInEntry* entry,
  44. const ARA::ARADocumentControllerHostInstance* instance,
  45. ARADocumentControllerSpecialisation* spec)
  46. : ARADocumentController (entry, instance), specialisation (spec)
  47. {
  48. }
  49. template <typename PlaybackRenderer_t = ARAPlaybackRenderer>
  50. std::vector<PlaybackRenderer_t*> const& getPlaybackRenderers() const noexcept
  51. {
  52. return ARA::PlugIn::DocumentController::getPlaybackRenderers<PlaybackRenderer_t>();
  53. }
  54. template <typename EditorRenderer_t = ARAEditorRenderer>
  55. std::vector<EditorRenderer_t*> const& getEditorRenderers() const noexcept
  56. {
  57. return ARA::PlugIn::DocumentController::getEditorRenderers<EditorRenderer_t>();
  58. }
  59. template <typename EditorView_t = ARAEditorView>
  60. std::vector<EditorView_t*> const& getEditorViews() const noexcept
  61. {
  62. return ARA::PlugIn::DocumentController::getEditorViews<EditorView_t>();
  63. }
  64. auto getSpecialisation() { return specialisation; }
  65. protected:
  66. //==============================================================================
  67. bool doRestoreObjectsFromStream (ARAInputStream& input, const ARARestoreObjectsFilter* filter) noexcept
  68. {
  69. return specialisation->doRestoreObjectsFromStream (input, filter);
  70. }
  71. bool doStoreObjectsToStream (ARAOutputStream& output, const ARAStoreObjectsFilter* filter) noexcept
  72. {
  73. return specialisation->doStoreObjectsToStream (output, filter);
  74. }
  75. //==============================================================================
  76. // Model object creation
  77. ARA::PlugIn::Document* doCreateDocument () noexcept override;
  78. ARA::PlugIn::MusicalContext* doCreateMusicalContext (ARA::PlugIn::Document* document, ARA::ARAMusicalContextHostRef hostRef) noexcept override;
  79. ARA::PlugIn::RegionSequence* doCreateRegionSequence (ARA::PlugIn::Document* document, ARA::ARARegionSequenceHostRef hostRef) noexcept override;
  80. ARA::PlugIn::AudioSource* doCreateAudioSource (ARA::PlugIn::Document* document, ARA::ARAAudioSourceHostRef hostRef) noexcept override;
  81. ARA::PlugIn::AudioModification* doCreateAudioModification (ARA::PlugIn::AudioSource* audioSource, ARA::ARAAudioModificationHostRef hostRef, const ARA::PlugIn::AudioModification* optionalModificationToClone) noexcept override;
  82. ARA::PlugIn::PlaybackRegion* doCreatePlaybackRegion (ARA::PlugIn::AudioModification* modification, ARA::ARAPlaybackRegionHostRef hostRef) noexcept override;
  83. //==============================================================================
  84. // Plugin role implementation
  85. friend class ARAPlaybackRegionReader;
  86. ARA::PlugIn::PlaybackRenderer* doCreatePlaybackRenderer() noexcept override;
  87. ARA::PlugIn::EditorRenderer* doCreateEditorRenderer() noexcept override;
  88. ARA::PlugIn::EditorView* doCreateEditorView() noexcept override;
  89. //==============================================================================
  90. // ARAAudioSource content access
  91. bool doIsAudioSourceContentAvailable (const ARA::PlugIn::AudioSource* audioSource,
  92. ARA::ARAContentType type) noexcept override;
  93. ARA::ARAContentGrade doGetAudioSourceContentGrade (const ARA::PlugIn::AudioSource* audioSource,
  94. ARA::ARAContentType type) noexcept override;
  95. ARA::PlugIn::ContentReader* doCreateAudioSourceContentReader (ARA::PlugIn::AudioSource* audioSource,
  96. ARA::ARAContentType type,
  97. const ARA::ARAContentTimeRange* range) noexcept override;
  98. //==============================================================================
  99. // ARAAudioModification content access
  100. bool doIsAudioModificationContentAvailable (const ARA::PlugIn::AudioModification* audioModification,
  101. ARA::ARAContentType type) noexcept override;
  102. ARA::ARAContentGrade doGetAudioModificationContentGrade (const ARA::PlugIn::AudioModification* audioModification,
  103. ARA::ARAContentType type) noexcept override;
  104. ARA::PlugIn::ContentReader* doCreateAudioModificationContentReader (ARA::PlugIn::AudioModification* audioModification,
  105. ARA::ARAContentType type,
  106. const ARA::ARAContentTimeRange* range) noexcept override;
  107. //==============================================================================
  108. // ARAPlaybackRegion content access
  109. bool doIsPlaybackRegionContentAvailable (const ARA::PlugIn::PlaybackRegion* playbackRegion,
  110. ARA::ARAContentType type) noexcept override;
  111. ARA::ARAContentGrade doGetPlaybackRegionContentGrade (const ARA::PlugIn::PlaybackRegion* playbackRegion,
  112. ARA::ARAContentType type) noexcept override;
  113. ARA::PlugIn::ContentReader* doCreatePlaybackRegionContentReader (ARA::PlugIn::PlaybackRegion* playbackRegion,
  114. ARA::ARAContentType type,
  115. const ARA::ARAContentTimeRange* range) noexcept override;
  116. void doGetPlaybackRegionHeadAndTailTime (const ARA::PlugIn::PlaybackRegion* playbackRegion,
  117. ARA::ARATimeDuration* headTime,
  118. ARA::ARATimeDuration* tailTime) noexcept override;
  119. //==============================================================================
  120. // ARAAudioSource analysis
  121. bool doIsAudioSourceContentAnalysisIncomplete (const ARA::PlugIn::AudioSource* audioSource,
  122. ARA::ARAContentType type) noexcept override;
  123. void doRequestAudioSourceContentAnalysis (ARA::PlugIn::AudioSource* audioSource,
  124. std::vector<ARA::ARAContentType> const& contentTypes) noexcept override;
  125. //==============================================================================
  126. // Analysis Algorithm selection
  127. ARA::ARAInt32 doGetProcessingAlgorithmsCount() noexcept override;
  128. const ARA::ARAProcessingAlgorithmProperties* doGetProcessingAlgorithmProperties (ARA::ARAInt32 algorithmIndex) noexcept override;
  129. ARA::ARAInt32 doGetProcessingAlgorithmForAudioSource (const ARA::PlugIn::AudioSource* audioSource) noexcept override;
  130. void doRequestProcessingAlgorithmForAudioSource (ARA::PlugIn::AudioSource* audioSource,
  131. ARA::ARAInt32 algorithmIndex) noexcept override;
  132. #ifndef DOXYGEN
  133. //==============================================================================
  134. bool doRestoreObjectsFromArchive (ARA::PlugIn::HostArchiveReader* archiveReader, const ARA::PlugIn::RestoreObjectsFilter* filter) noexcept override;
  135. bool doStoreObjectsToArchive (ARA::PlugIn::HostArchiveWriter* archiveWriter, const ARA::PlugIn::StoreObjectsFilter* filter) noexcept override;
  136. //==============================================================================
  137. // Document notifications
  138. void willBeginEditing() noexcept override;
  139. void didEndEditing() noexcept override;
  140. void willNotifyModelUpdates() noexcept override;
  141. void didNotifyModelUpdates() noexcept override;
  142. void willUpdateDocumentProperties (ARA::PlugIn::Document* document, ARADocument::PropertiesPtr newProperties) noexcept override;
  143. void didUpdateDocumentProperties (ARA::PlugIn::Document* document) noexcept override;
  144. void didAddMusicalContextToDocument (ARA::PlugIn::Document* document, ARA::PlugIn::MusicalContext* musicalContext) noexcept override;
  145. void willRemoveMusicalContextFromDocument (ARA::PlugIn::Document* document, ARA::PlugIn::MusicalContext* musicalContext) noexcept override;
  146. void didReorderMusicalContextsInDocument (ARA::PlugIn::Document* document) noexcept override;
  147. void didAddRegionSequenceToDocument (ARA::PlugIn::Document* document, ARA::PlugIn::RegionSequence* regionSequence) noexcept override;
  148. void willRemoveRegionSequenceFromDocument (ARA::PlugIn::Document* document, ARA::PlugIn::RegionSequence* regionSequence) noexcept override;
  149. void didReorderRegionSequencesInDocument (ARA::PlugIn::Document* document) noexcept override;
  150. void didAddAudioSourceToDocument (ARA::PlugIn::Document* document, ARA::PlugIn::AudioSource* audioSource) noexcept override;
  151. void willRemoveAudioSourceFromDocument (ARA::PlugIn::Document* document, ARA::PlugIn::AudioSource* audioSource) noexcept override;
  152. void willDestroyDocument (ARA::PlugIn::Document* document) noexcept override;
  153. //==============================================================================
  154. // MusicalContext notifications
  155. void willUpdateMusicalContextProperties (ARA::PlugIn::MusicalContext* musicalContext, ARAMusicalContext::PropertiesPtr newProperties) noexcept override;
  156. void didUpdateMusicalContextProperties (ARA::PlugIn::MusicalContext* musicalContext) noexcept override;
  157. void doUpdateMusicalContextContent (ARA::PlugIn::MusicalContext* musicalContext, const ARA::ARAContentTimeRange* range, ARA::ContentUpdateScopes flags) noexcept override;
  158. void didAddRegionSequenceToMusicalContext (ARA::PlugIn::MusicalContext* musicalContext, ARA::PlugIn::RegionSequence* regionSequence) noexcept override;
  159. void willRemoveRegionSequenceFromMusicalContext (ARA::PlugIn::MusicalContext* musicalContext, ARA::PlugIn::RegionSequence* regionSequence) noexcept override;
  160. void didReorderRegionSequencesInMusicalContext (ARA::PlugIn::MusicalContext* musicalContext) noexcept override;
  161. void willDestroyMusicalContext (ARA::PlugIn::MusicalContext* musicalContext) noexcept override;
  162. //==============================================================================
  163. // RegionSequence notifications, typically not overridden further
  164. void willUpdateRegionSequenceProperties (ARA::PlugIn::RegionSequence* regionSequence, ARARegionSequence::PropertiesPtr newProperties) noexcept override;
  165. void didUpdateRegionSequenceProperties (ARA::PlugIn::RegionSequence* regionSequence) noexcept override;
  166. void didAddPlaybackRegionToRegionSequence (ARA::PlugIn::RegionSequence* regionSequence, ARA::PlugIn::PlaybackRegion* playbackRegion) noexcept override;
  167. void willRemovePlaybackRegionFromRegionSequence (ARA::PlugIn::RegionSequence* regionSequence, ARA::PlugIn::PlaybackRegion* playbackRegion) noexcept override;
  168. void willDestroyRegionSequence (ARA::PlugIn::RegionSequence* regionSequence) noexcept override;
  169. //==============================================================================
  170. // AudioSource notifications
  171. void willUpdateAudioSourceProperties (ARA::PlugIn::AudioSource* audioSource, ARAAudioSource::PropertiesPtr newProperties) noexcept override;
  172. void didUpdateAudioSourceProperties (ARA::PlugIn::AudioSource* audioSource) noexcept override;
  173. void doUpdateAudioSourceContent (ARA::PlugIn::AudioSource* audioSource, const ARA::ARAContentTimeRange* range, ARA::ContentUpdateScopes flags) noexcept override;
  174. void willEnableAudioSourceSamplesAccess (ARA::PlugIn::AudioSource* audioSource, bool enable) noexcept override;
  175. void didEnableAudioSourceSamplesAccess (ARA::PlugIn::AudioSource* audioSource, bool enable) noexcept override;
  176. void didAddAudioModificationToAudioSource (ARA::PlugIn::AudioSource* audioSource, ARA::PlugIn::AudioModification* audioModification) noexcept override;
  177. void willRemoveAudioModificationFromAudioSource (ARA::PlugIn::AudioSource* audioSource, ARA::PlugIn::AudioModification* audioModification) noexcept override;
  178. void willDeactivateAudioSourceForUndoHistory (ARA::PlugIn::AudioSource* audioSource, bool deactivate) noexcept override;
  179. void didDeactivateAudioSourceForUndoHistory (ARA::PlugIn::AudioSource* audioSource, bool deactivate) noexcept override;
  180. void willDestroyAudioSource (ARA::PlugIn::AudioSource* audioSource) noexcept override;
  181. //==============================================================================
  182. // AudioModification notifications
  183. void willUpdateAudioModificationProperties (ARA::PlugIn::AudioModification* audioModification, ARAAudioModification::PropertiesPtr newProperties) noexcept override;
  184. void didUpdateAudioModificationProperties (ARA::PlugIn::AudioModification* audioModification) noexcept override;
  185. void didAddPlaybackRegionToAudioModification (ARA::PlugIn::AudioModification* audioModification, ARA::PlugIn::PlaybackRegion* playbackRegion) noexcept override;
  186. void willRemovePlaybackRegionFromAudioModification (ARA::PlugIn::AudioModification* audioModification, ARA::PlugIn::PlaybackRegion* playbackRegion) noexcept override;
  187. void willDeactivateAudioModificationForUndoHistory (ARA::PlugIn::AudioModification* audioModification, bool deactivate) noexcept override;
  188. void didDeactivateAudioModificationForUndoHistory (ARA::PlugIn::AudioModification* audioModification, bool deactivate) noexcept override;
  189. void willDestroyAudioModification (ARA::PlugIn::AudioModification* audioModification) noexcept override;
  190. //==============================================================================
  191. // PlaybackRegion notifications
  192. void willUpdatePlaybackRegionProperties (ARA::PlugIn::PlaybackRegion* playbackRegion, ARAPlaybackRegion::PropertiesPtr newProperties) noexcept override;
  193. void didUpdatePlaybackRegionProperties (ARA::PlugIn::PlaybackRegion* playbackRegion) noexcept override;
  194. void willDestroyPlaybackRegion (ARA::PlugIn::PlaybackRegion* playbackRegion) noexcept override;
  195. public:
  196. //==============================================================================
  197. /** @internal */
  198. void internalNotifyAudioSourceAnalysisProgressStarted (ARAAudioSource* audioSource) override;
  199. /** @internal */
  200. void internalNotifyAudioSourceAnalysisProgressUpdated (ARAAudioSource* audioSource, float progress) override;
  201. /** @internal */
  202. void internalNotifyAudioSourceAnalysisProgressCompleted (ARAAudioSource* audioSource) override;
  203. /** @internal */
  204. void internalDidUpdateAudioSourceAnalysisProgress (ARAAudioSource* audioSource,
  205. ARAAudioSource::ARAAnalysisProgressState state,
  206. float progress) override;
  207. //==============================================================================
  208. /** @internal */
  209. void internalNotifyAudioSourceContentChanged (ARAAudioSource* audioSource,
  210. ARAContentUpdateScopes scopeFlags,
  211. bool notifyARAHost) override;
  212. /** @internal */
  213. void internalNotifyAudioModificationContentChanged (ARAAudioModification* audioModification,
  214. ARAContentUpdateScopes scopeFlags,
  215. bool notifyARAHost) override;
  216. /** @internal */
  217. void internalNotifyPlaybackRegionContentChanged (ARAPlaybackRegion* playbackRegion,
  218. ARAContentUpdateScopes scopeFlags,
  219. bool notifyARAHost) override;
  220. #endif
  221. private:
  222. //==============================================================================
  223. ARADocumentControllerSpecialisation* specialisation;
  224. std::atomic<bool> internalAnalysisProgressIsSynced { true };
  225. ScopedJuceInitialiser_GUI libraryInitialiser;
  226. int activeAudioSourcesCount = 0;
  227. std::optional<SimpleTimer> analysisTimer;
  228. void analysisTimerCallback();
  229. //==============================================================================
  230. template <typename ModelObject, typename Function, typename... Ts>
  231. void notifyListeners (Function ModelObject::Listener::* function, ModelObject* modelObject, Ts... ts)
  232. {
  233. (specialisation->*function) (modelObject, ts...);
  234. modelObject->notifyListeners ([&] (auto& l)
  235. {
  236. try
  237. {
  238. (l.*function) (modelObject, ts...);
  239. }
  240. catch (...)
  241. {
  242. }
  243. });
  244. }
  245. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ARADocumentControllerImpl)
  246. };
  247. ARA::PlugIn::DocumentController* ARADocumentControllerSpecialisation::getDocumentController() noexcept
  248. {
  249. return documentController.get();
  250. }
  251. //==============================================================================
  252. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalNotifyAudioSourceAnalysisProgressStarted (ARAAudioSource* audioSource)
  253. {
  254. if (audioSource->internalAnalysisProgressTracker.updateProgress (ARA::kARAAnalysisProgressStarted, 0.0f))
  255. internalAnalysisProgressIsSynced.store (false, std::memory_order_release);
  256. DocumentController::notifyAudioSourceAnalysisProgressStarted (audioSource);
  257. }
  258. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalNotifyAudioSourceAnalysisProgressUpdated (ARAAudioSource* audioSource,
  259. float progress)
  260. {
  261. if (audioSource->internalAnalysisProgressTracker.updateProgress (ARA::kARAAnalysisProgressUpdated, progress))
  262. internalAnalysisProgressIsSynced.store (false, std::memory_order_release);
  263. DocumentController::notifyAudioSourceAnalysisProgressUpdated (audioSource, progress);
  264. }
  265. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalNotifyAudioSourceAnalysisProgressCompleted (ARAAudioSource* audioSource)
  266. {
  267. if (audioSource->internalAnalysisProgressTracker.updateProgress (ARA::kARAAnalysisProgressCompleted, 1.0f))
  268. internalAnalysisProgressIsSynced.store (false, std::memory_order_release);
  269. DocumentController::notifyAudioSourceAnalysisProgressCompleted (audioSource);
  270. }
  271. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalDidUpdateAudioSourceAnalysisProgress (ARAAudioSource* audioSource,
  272. ARAAudioSource::ARAAnalysisProgressState state,
  273. float progress)
  274. {
  275. specialisation->didUpdateAudioSourceAnalysisProgress (audioSource, state, progress);
  276. }
  277. //==============================================================================
  278. ARADocumentControllerSpecialisation* ARADocumentControllerSpecialisation::getSpecialisedDocumentControllerImpl (ARA::PlugIn::DocumentController* dc)
  279. {
  280. return static_cast<ARADocumentControllerImpl*> (dc)->getSpecialisation();
  281. }
  282. ARADocument* ARADocumentControllerSpecialisation::getDocumentImpl()
  283. {
  284. return documentController->getDocument();
  285. }
  286. //==============================================================================
  287. // some helper macros to ease repeated declaration & implementation of notification functions below:
  288. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wgnu-zero-variadic-macro-arguments")
  289. // no notification arguments
  290. #define OVERRIDE_TO_NOTIFY_1(function, ModelObjectType, modelObject) \
  291. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::function (ARA::PlugIn::ModelObjectType* modelObject) noexcept \
  292. { \
  293. notifyListeners (&ARA##ModelObjectType::Listener::function, static_cast<ARA##ModelObjectType*> (modelObject)); \
  294. }
  295. // single notification argument, model object version
  296. #define OVERRIDE_TO_NOTIFY_2(function, ModelObjectType, modelObject, ArgumentType, argument) \
  297. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::function (ARA::PlugIn::ModelObjectType* modelObject, ARA::PlugIn::ArgumentType argument) noexcept \
  298. { \
  299. notifyListeners (&ARA##ModelObjectType::Listener::function, static_cast<ARA##ModelObjectType*> (modelObject), static_cast<ARA##ArgumentType> (argument)); \
  300. }
  301. // single notification argument, non-model object version
  302. #define OVERRIDE_TO_NOTIFY_3(function, ModelObjectType, modelObject, ArgumentType, argument) \
  303. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::function (ARA::PlugIn::ModelObjectType* modelObject, ArgumentType argument) noexcept \
  304. { \
  305. notifyListeners (&ARA##ModelObjectType::Listener::function, static_cast<ARA##ModelObjectType*> (modelObject), argument); \
  306. }
  307. //==============================================================================
  308. ARA::PlugIn::Document* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateDocument() noexcept
  309. {
  310. auto* document = specialisation->doCreateDocument();
  311. // Your Document subclass must inherit from juce::ARADocument
  312. jassert (dynamic_cast<ARADocument*> (document));
  313. return document;
  314. }
  315. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::willBeginEditing() noexcept
  316. {
  317. notifyListeners (&ARADocument::Listener::willBeginEditing, static_cast<ARADocument*> (getDocument()));
  318. }
  319. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::didEndEditing() noexcept
  320. {
  321. notifyListeners (&ARADocument::Listener::didEndEditing, static_cast<ARADocument*> (getDocument()));
  322. if (activeAudioSourcesCount == 0)
  323. analysisTimer.reset();
  324. else if (! analysisTimer.has_value() && (activeAudioSourcesCount > 0))
  325. analysisTimer.emplace (20, [this] { analysisTimerCallback(); });
  326. }
  327. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::willNotifyModelUpdates() noexcept
  328. {
  329. notifyListeners (&ARADocument::Listener::willNotifyModelUpdates, static_cast<ARADocument*> (getDocument()));
  330. }
  331. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::didNotifyModelUpdates() noexcept
  332. {
  333. notifyListeners (&ARADocument::Listener::didNotifyModelUpdates, static_cast<ARADocument*> (getDocument()));
  334. }
  335. //==============================================================================
  336. bool ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doRestoreObjectsFromArchive (ARA::PlugIn::HostArchiveReader* archiveReader,
  337. const ARA::PlugIn::RestoreObjectsFilter* filter) noexcept
  338. {
  339. ARAInputStream reader (archiveReader);
  340. return doRestoreObjectsFromStream (reader, filter);
  341. }
  342. bool ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doStoreObjectsToArchive (ARA::PlugIn::HostArchiveWriter* archiveWriter,
  343. const ARA::PlugIn::StoreObjectsFilter* filter) noexcept
  344. {
  345. ARAOutputStream writer (archiveWriter);
  346. return doStoreObjectsToStream (writer, filter);
  347. }
  348. //==============================================================================
  349. OVERRIDE_TO_NOTIFY_3 (willUpdateDocumentProperties, Document, document, ARADocument::PropertiesPtr, newProperties)
  350. OVERRIDE_TO_NOTIFY_1 (didUpdateDocumentProperties, Document, document)
  351. OVERRIDE_TO_NOTIFY_2 (didAddMusicalContextToDocument, Document, document, MusicalContext*, musicalContext)
  352. OVERRIDE_TO_NOTIFY_2 (willRemoveMusicalContextFromDocument, Document, document, MusicalContext*, musicalContext)
  353. OVERRIDE_TO_NOTIFY_1 (didReorderMusicalContextsInDocument, Document, document)
  354. OVERRIDE_TO_NOTIFY_2 (didAddRegionSequenceToDocument, Document, document, RegionSequence*, regionSequence)
  355. OVERRIDE_TO_NOTIFY_2 (willRemoveRegionSequenceFromDocument, Document, document, RegionSequence*, regionSequence)
  356. OVERRIDE_TO_NOTIFY_1 (didReorderRegionSequencesInDocument, Document, document)
  357. OVERRIDE_TO_NOTIFY_2 (didAddAudioSourceToDocument, Document, document, AudioSource*, audioSource)
  358. OVERRIDE_TO_NOTIFY_2 (willRemoveAudioSourceFromDocument, Document, document, AudioSource*, audioSource)
  359. OVERRIDE_TO_NOTIFY_1 (willDestroyDocument, Document, document)
  360. //==============================================================================
  361. ARA::PlugIn::MusicalContext* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateMusicalContext (ARA::PlugIn::Document* document,
  362. ARA::ARAMusicalContextHostRef hostRef) noexcept
  363. {
  364. return specialisation->doCreateMusicalContext (static_cast<ARADocument*> (document), hostRef);
  365. }
  366. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doUpdateMusicalContextContent (ARA::PlugIn::MusicalContext* musicalContext,
  367. const ARA::ARAContentTimeRange*,
  368. ARA::ContentUpdateScopes flags) noexcept
  369. {
  370. notifyListeners (&ARAMusicalContext::Listener::doUpdateMusicalContextContent,
  371. static_cast<ARAMusicalContext*> (musicalContext),
  372. flags);
  373. }
  374. OVERRIDE_TO_NOTIFY_3 (willUpdateMusicalContextProperties, MusicalContext, musicalContext, ARAMusicalContext::PropertiesPtr, newProperties)
  375. OVERRIDE_TO_NOTIFY_1 (didUpdateMusicalContextProperties, MusicalContext, musicalContext)
  376. OVERRIDE_TO_NOTIFY_2 (didAddRegionSequenceToMusicalContext, MusicalContext, musicalContext, RegionSequence*, regionSequence)
  377. OVERRIDE_TO_NOTIFY_2 (willRemoveRegionSequenceFromMusicalContext, MusicalContext, musicalContext, RegionSequence*, regionSequence)
  378. OVERRIDE_TO_NOTIFY_1 (didReorderRegionSequencesInMusicalContext, MusicalContext, musicalContext)
  379. OVERRIDE_TO_NOTIFY_1 (willDestroyMusicalContext, MusicalContext, musicalContext)
  380. //==============================================================================
  381. ARA::PlugIn::RegionSequence* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateRegionSequence (ARA::PlugIn::Document* document, ARA::ARARegionSequenceHostRef hostRef) noexcept
  382. {
  383. return specialisation->doCreateRegionSequence (static_cast<ARADocument*> (document), hostRef);
  384. }
  385. OVERRIDE_TO_NOTIFY_3 (willUpdateRegionSequenceProperties, RegionSequence, regionSequence, ARARegionSequence::PropertiesPtr, newProperties)
  386. OVERRIDE_TO_NOTIFY_1 (didUpdateRegionSequenceProperties, RegionSequence, regionSequence)
  387. OVERRIDE_TO_NOTIFY_2 (didAddPlaybackRegionToRegionSequence, RegionSequence, regionSequence, PlaybackRegion*, playbackRegion)
  388. OVERRIDE_TO_NOTIFY_2 (willRemovePlaybackRegionFromRegionSequence, RegionSequence, regionSequence, PlaybackRegion*, playbackRegion)
  389. OVERRIDE_TO_NOTIFY_1 (willDestroyRegionSequence, RegionSequence, regionSequence)
  390. //==============================================================================
  391. ARA::PlugIn::AudioSource* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateAudioSource (ARA::PlugIn::Document* document, ARA::ARAAudioSourceHostRef hostRef) noexcept
  392. {
  393. ++activeAudioSourcesCount;
  394. return specialisation->doCreateAudioSource (static_cast<ARADocument*> (document), hostRef);
  395. }
  396. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doUpdateAudioSourceContent (ARA::PlugIn::AudioSource* audioSource,
  397. const ARA::ARAContentTimeRange*,
  398. ARA::ContentUpdateScopes flags) noexcept
  399. {
  400. notifyListeners (&ARAAudioSource::Listener::doUpdateAudioSourceContent, static_cast<ARAAudioSource*> (audioSource), flags);
  401. }
  402. OVERRIDE_TO_NOTIFY_3 (willUpdateAudioSourceProperties, AudioSource, audioSource, ARAAudioSource::PropertiesPtr, newProperties)
  403. OVERRIDE_TO_NOTIFY_1 (didUpdateAudioSourceProperties, AudioSource, audioSource)
  404. OVERRIDE_TO_NOTIFY_3 (willEnableAudioSourceSamplesAccess, AudioSource, audioSource, bool, enable)
  405. OVERRIDE_TO_NOTIFY_3 (didEnableAudioSourceSamplesAccess, AudioSource, audioSource, bool, enable)
  406. OVERRIDE_TO_NOTIFY_2 (didAddAudioModificationToAudioSource, AudioSource, audioSource, AudioModification*, audioModification)
  407. OVERRIDE_TO_NOTIFY_2 (willRemoveAudioModificationFromAudioSource, AudioSource, audioSource, AudioModification*, audioModification)
  408. OVERRIDE_TO_NOTIFY_3 (willDeactivateAudioSourceForUndoHistory, AudioSource, audioSource, bool, deactivate)
  409. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::didDeactivateAudioSourceForUndoHistory (ARA::PlugIn::AudioSource* audioSource,
  410. bool deactivate) noexcept
  411. {
  412. activeAudioSourcesCount += (deactivate ? -1 : 1);
  413. notifyListeners (&ARAAudioSource::Listener::didDeactivateAudioSourceForUndoHistory,
  414. static_cast<ARAAudioSource*> (audioSource),
  415. deactivate);
  416. }
  417. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::willDestroyAudioSource (ARA::PlugIn::AudioSource* audioSource) noexcept
  418. {
  419. if (! audioSource->isDeactivatedForUndoHistory())
  420. --activeAudioSourcesCount;
  421. notifyListeners (&ARAAudioSource::Listener::willDestroyAudioSource, static_cast<ARAAudioSource*> (audioSource));
  422. }
  423. //==============================================================================
  424. ARA::PlugIn::AudioModification* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateAudioModification (ARA::PlugIn::AudioSource* audioSource,
  425. ARA::ARAAudioModificationHostRef hostRef,
  426. const ARA::PlugIn::AudioModification* optionalModificationToClone) noexcept
  427. {
  428. return specialisation->doCreateAudioModification (static_cast<ARAAudioSource*> (audioSource),
  429. hostRef,
  430. static_cast<const ARAAudioModification*> (optionalModificationToClone));
  431. }
  432. OVERRIDE_TO_NOTIFY_3 (willUpdateAudioModificationProperties, AudioModification, audioModification, ARAAudioModification::PropertiesPtr, newProperties)
  433. OVERRIDE_TO_NOTIFY_1 (didUpdateAudioModificationProperties, AudioModification, audioModification)
  434. OVERRIDE_TO_NOTIFY_2 (didAddPlaybackRegionToAudioModification, AudioModification, audioModification, PlaybackRegion*, playbackRegion)
  435. OVERRIDE_TO_NOTIFY_2 (willRemovePlaybackRegionFromAudioModification, AudioModification, audioModification, PlaybackRegion*, playbackRegion)
  436. OVERRIDE_TO_NOTIFY_3 (willDeactivateAudioModificationForUndoHistory, AudioModification, audioModification, bool, deactivate)
  437. OVERRIDE_TO_NOTIFY_3 (didDeactivateAudioModificationForUndoHistory, AudioModification, audioModification, bool, deactivate)
  438. OVERRIDE_TO_NOTIFY_1 (willDestroyAudioModification, AudioModification, audioModification)
  439. //==============================================================================
  440. ARA::PlugIn::PlaybackRegion* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreatePlaybackRegion (ARA::PlugIn::AudioModification* modification,
  441. ARA::ARAPlaybackRegionHostRef hostRef) noexcept
  442. {
  443. return specialisation->doCreatePlaybackRegion (static_cast<ARAAudioModification*> (modification), hostRef);
  444. }
  445. OVERRIDE_TO_NOTIFY_3 (willUpdatePlaybackRegionProperties, PlaybackRegion, playbackRegion, ARAPlaybackRegion::PropertiesPtr, newProperties)
  446. OVERRIDE_TO_NOTIFY_1 (didUpdatePlaybackRegionProperties, PlaybackRegion, playbackRegion)
  447. OVERRIDE_TO_NOTIFY_1 (willDestroyPlaybackRegion, PlaybackRegion, playbackRegion)
  448. //==============================================================================
  449. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalNotifyAudioSourceContentChanged (ARAAudioSource* audioSource,
  450. ARAContentUpdateScopes scopeFlags,
  451. bool notifyARAHost)
  452. {
  453. if (notifyARAHost)
  454. DocumentController::notifyAudioSourceContentChanged (audioSource, scopeFlags);
  455. notifyListeners (&ARAAudioSource::Listener::doUpdateAudioSourceContent, audioSource, scopeFlags);
  456. }
  457. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalNotifyAudioModificationContentChanged (ARAAudioModification* audioModification,
  458. ARAContentUpdateScopes scopeFlags,
  459. bool notifyARAHost)
  460. {
  461. if (notifyARAHost)
  462. DocumentController::notifyAudioModificationContentChanged (audioModification, scopeFlags);
  463. notifyListeners (&ARAAudioModification::Listener::didUpdateAudioModificationContent, audioModification, scopeFlags);
  464. }
  465. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::internalNotifyPlaybackRegionContentChanged (ARAPlaybackRegion* playbackRegion,
  466. ARAContentUpdateScopes scopeFlags,
  467. bool notifyARAHost)
  468. {
  469. if (notifyARAHost)
  470. DocumentController::notifyPlaybackRegionContentChanged (playbackRegion, scopeFlags);
  471. notifyListeners (&ARAPlaybackRegion::Listener::didUpdatePlaybackRegionContent, playbackRegion, scopeFlags);
  472. }
  473. //==============================================================================
  474. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  475. #undef OVERRIDE_TO_NOTIFY_1
  476. #undef OVERRIDE_TO_NOTIFY_2
  477. #undef OVERRIDE_TO_NOTIFY_3
  478. //==============================================================================
  479. ARADocument* ARADocumentControllerSpecialisation::doCreateDocument()
  480. {
  481. return new ARADocument (static_cast<ARADocumentControllerImpl*> (getDocumentController()));
  482. }
  483. ARAMusicalContext* ARADocumentControllerSpecialisation::doCreateMusicalContext (ARADocument* document,
  484. ARA::ARAMusicalContextHostRef hostRef)
  485. {
  486. return new ARAMusicalContext (static_cast<ARADocument*> (document), hostRef);
  487. }
  488. ARARegionSequence* ARADocumentControllerSpecialisation::doCreateRegionSequence (ARADocument* document,
  489. ARA::ARARegionSequenceHostRef hostRef)
  490. {
  491. return new ARARegionSequence (static_cast<ARADocument*> (document), hostRef);
  492. }
  493. ARAAudioSource* ARADocumentControllerSpecialisation::doCreateAudioSource (ARADocument* document,
  494. ARA::ARAAudioSourceHostRef hostRef)
  495. {
  496. return new ARAAudioSource (static_cast<ARADocument*> (document), hostRef);
  497. }
  498. ARAAudioModification* ARADocumentControllerSpecialisation::doCreateAudioModification (
  499. ARAAudioSource* audioSource,
  500. ARA::ARAAudioModificationHostRef hostRef,
  501. const ARAAudioModification* optionalModificationToClone)
  502. {
  503. return new ARAAudioModification (static_cast<ARAAudioSource*> (audioSource),
  504. hostRef,
  505. static_cast<const ARAAudioModification*> (optionalModificationToClone));
  506. }
  507. ARAPlaybackRegion*
  508. ARADocumentControllerSpecialisation::doCreatePlaybackRegion (ARAAudioModification* modification,
  509. ARA::ARAPlaybackRegionHostRef hostRef)
  510. {
  511. return new ARAPlaybackRegion (static_cast<ARAAudioModification*> (modification), hostRef);
  512. }
  513. //==============================================================================
  514. ARA::PlugIn::PlaybackRenderer* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreatePlaybackRenderer() noexcept
  515. {
  516. return specialisation->doCreatePlaybackRenderer();
  517. }
  518. ARA::PlugIn::EditorRenderer* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateEditorRenderer() noexcept
  519. {
  520. return specialisation->doCreateEditorRenderer();
  521. }
  522. ARA::PlugIn::EditorView* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateEditorView() noexcept
  523. {
  524. return specialisation->doCreateEditorView();
  525. }
  526. bool ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doIsAudioSourceContentAvailable (const ARA::PlugIn::AudioSource* audioSource,
  527. ARA::ARAContentType type) noexcept
  528. {
  529. return specialisation->doIsAudioSourceContentAvailable (audioSource, type);
  530. }
  531. ARA::ARAContentGrade ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetAudioSourceContentGrade (const ARA::PlugIn::AudioSource* audioSource,
  532. ARA::ARAContentType type) noexcept
  533. {
  534. return specialisation->doGetAudioSourceContentGrade (audioSource, type);
  535. }
  536. ARA::PlugIn::ContentReader* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateAudioSourceContentReader (ARA::PlugIn::AudioSource* audioSource,
  537. ARA::ARAContentType type,
  538. const ARA::ARAContentTimeRange* range) noexcept
  539. {
  540. return specialisation->doCreateAudioSourceContentReader (audioSource, type, range);
  541. }
  542. bool ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doIsAudioModificationContentAvailable (const ARA::PlugIn::AudioModification* audioModification,
  543. ARA::ARAContentType type) noexcept
  544. {
  545. return specialisation->doIsAudioModificationContentAvailable (audioModification, type);
  546. }
  547. ARA::ARAContentGrade ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetAudioModificationContentGrade (const ARA::PlugIn::AudioModification* audioModification,
  548. ARA::ARAContentType type) noexcept
  549. {
  550. return specialisation->doGetAudioModificationContentGrade (audioModification, type);
  551. }
  552. ARA::PlugIn::ContentReader* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreateAudioModificationContentReader (ARA::PlugIn::AudioModification* audioModification,
  553. ARA::ARAContentType type,
  554. const ARA::ARAContentTimeRange* range) noexcept
  555. {
  556. return specialisation->doCreateAudioModificationContentReader (audioModification, type, range);
  557. }
  558. bool ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doIsPlaybackRegionContentAvailable (const ARA::PlugIn::PlaybackRegion* playbackRegion,
  559. ARA::ARAContentType type) noexcept
  560. {
  561. return specialisation->doIsPlaybackRegionContentAvailable (playbackRegion, type);
  562. }
  563. ARA::ARAContentGrade
  564. ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetPlaybackRegionContentGrade (const ARA::PlugIn::PlaybackRegion* playbackRegion,
  565. ARA::ARAContentType type) noexcept
  566. {
  567. return specialisation->doGetPlaybackRegionContentGrade (playbackRegion, type);
  568. }
  569. ARA::PlugIn::ContentReader* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doCreatePlaybackRegionContentReader (ARA::PlugIn::PlaybackRegion* playbackRegion,
  570. ARA::ARAContentType type,
  571. const ARA::ARAContentTimeRange* range) noexcept
  572. {
  573. return specialisation->doCreatePlaybackRegionContentReader (playbackRegion, type, range);
  574. }
  575. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetPlaybackRegionHeadAndTailTime (const ARA::PlugIn::PlaybackRegion* playbackRegion,
  576. ARA::ARATimeDuration* headTime,
  577. ARA::ARATimeDuration* tailTime) noexcept
  578. {
  579. specialisation->doGetPlaybackRegionHeadAndTailTime (playbackRegion, headTime, tailTime);
  580. }
  581. bool ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doIsAudioSourceContentAnalysisIncomplete (const ARA::PlugIn::AudioSource* audioSource,
  582. ARA::ARAContentType type) noexcept
  583. {
  584. return specialisation->doIsAudioSourceContentAnalysisIncomplete (audioSource, type);
  585. }
  586. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doRequestAudioSourceContentAnalysis (ARA::PlugIn::AudioSource* audioSource,
  587. std::vector<ARA::ARAContentType> const& contentTypes) noexcept
  588. {
  589. specialisation->doRequestAudioSourceContentAnalysis (audioSource, contentTypes);
  590. }
  591. ARA::ARAInt32 ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetProcessingAlgorithmsCount() noexcept
  592. {
  593. return specialisation->doGetProcessingAlgorithmsCount();
  594. }
  595. const ARA::ARAProcessingAlgorithmProperties* ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetProcessingAlgorithmProperties (ARA::ARAInt32 algorithmIndex) noexcept
  596. {
  597. return specialisation->doGetProcessingAlgorithmProperties (algorithmIndex);
  598. }
  599. ARA::ARAInt32 ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doGetProcessingAlgorithmForAudioSource (const ARA::PlugIn::AudioSource* audioSource) noexcept
  600. {
  601. return specialisation->doGetProcessingAlgorithmForAudioSource (audioSource);
  602. }
  603. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::doRequestProcessingAlgorithmForAudioSource (ARA::PlugIn::AudioSource* audioSource,
  604. ARA::ARAInt32 algorithmIndex) noexcept
  605. {
  606. return specialisation->doRequestProcessingAlgorithmForAudioSource (audioSource, algorithmIndex);
  607. }
  608. //==============================================================================
  609. // Helper code for ARADocumentControllerSpecialisation::ARADocumentControllerImpl::timerCallback() to
  610. // rewire the host-related ARA SDK's progress tracker to our internal update mechanism.
  611. namespace ModelUpdateControllerProgressAdapter
  612. {
  613. using namespace ARA;
  614. static void ARA_CALL notifyAudioSourceAnalysisProgress (ARAModelUpdateControllerHostRef /*controllerHostRef*/,
  615. ARAAudioSourceHostRef audioSourceHostRef, ARAAnalysisProgressState state, float value) noexcept
  616. {
  617. auto audioSource = reinterpret_cast<ARAAudioSource*> (audioSourceHostRef);
  618. audioSource->getDocumentController<ARADocumentController>()->internalDidUpdateAudioSourceAnalysisProgress (audioSource, state, value);
  619. audioSource->notifyListeners ([&] (ARAAudioSource::Listener& l) { l.didUpdateAudioSourceAnalysisProgress (audioSource, state, value); });
  620. }
  621. static void ARA_CALL notifyAudioSourceContentChanged (ARAModelUpdateControllerHostRef, ARAAudioSourceHostRef,
  622. const ARAContentTimeRange*, ARAContentUpdateFlags) noexcept
  623. {
  624. jassertfalse; // not to be called - this adapter only forwards analysis progress
  625. }
  626. static void ARA_CALL notifyAudioModificationContentChanged (ARAModelUpdateControllerHostRef, ARAAudioModificationHostRef,
  627. const ARAContentTimeRange*, ARAContentUpdateFlags) noexcept
  628. {
  629. jassertfalse; // not to be called - this adapter only forwards analysis progress
  630. }
  631. static void ARA_CALL notifyPlaybackRegionContentChanged (ARAModelUpdateControllerHostRef, ARAPlaybackRegionHostRef,
  632. const ARAContentTimeRange*, ARAContentUpdateFlags) noexcept
  633. {
  634. jassertfalse; // not to be called - this adapter only forwards analysis progress
  635. }
  636. static ARA::PlugIn::HostModelUpdateController* get()
  637. {
  638. static const auto modelUpdateControllerInterface = makeARASizedStruct (&ARA::ARAModelUpdateControllerInterface::notifyPlaybackRegionContentChanged,
  639. ModelUpdateControllerProgressAdapter::notifyAudioSourceAnalysisProgress,
  640. ModelUpdateControllerProgressAdapter::notifyAudioSourceContentChanged,
  641. ModelUpdateControllerProgressAdapter::notifyAudioModificationContentChanged,
  642. ModelUpdateControllerProgressAdapter::notifyPlaybackRegionContentChanged);
  643. static const auto instance = makeARASizedStruct (&ARA::ARADocumentControllerHostInstance::playbackControllerInterface,
  644. nullptr,
  645. nullptr,
  646. nullptr,
  647. nullptr,
  648. nullptr,
  649. nullptr,
  650. nullptr,
  651. &modelUpdateControllerInterface,
  652. nullptr,
  653. nullptr);
  654. static auto progressAdapter = ARA::PlugIn::HostModelUpdateController { &instance };
  655. return &progressAdapter;
  656. }
  657. }
  658. void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::analysisTimerCallback()
  659. {
  660. if (! internalAnalysisProgressIsSynced.exchange (true, std::memory_order_release))
  661. for (auto& audioSource : getDocument()->getAudioSources())
  662. audioSource->internalAnalysisProgressTracker.notifyProgress (ModelUpdateControllerProgressAdapter::get(),
  663. reinterpret_cast<ARA::ARAAudioSourceHostRef> (audioSource));
  664. }
  665. //==============================================================================
  666. ARAInputStream::ARAInputStream (ARA::PlugIn::HostArchiveReader* reader)
  667. : archiveReader (reader),
  668. size ((int64) reader->getArchiveSize())
  669. {}
  670. int ARAInputStream::read (void* destBuffer, int maxBytesToRead)
  671. {
  672. const auto bytesToRead = std::min ((int64) maxBytesToRead, size - position);
  673. if (bytesToRead > 0 && ! archiveReader->readBytesFromArchive ((ARA::ARASize) position, (ARA::ARASize) bytesToRead,
  674. static_cast<ARA::ARAByte*> (destBuffer)))
  675. {
  676. failure = true;
  677. return 0;
  678. }
  679. position += bytesToRead;
  680. return (int) bytesToRead;
  681. }
  682. bool ARAInputStream::setPosition (int64 newPosition)
  683. {
  684. position = jlimit ((int64) 0, size, newPosition);
  685. return true;
  686. }
  687. bool ARAInputStream::isExhausted()
  688. {
  689. return position >= size;
  690. }
  691. ARAOutputStream::ARAOutputStream (ARA::PlugIn::HostArchiveWriter* writer)
  692. : archiveWriter (writer)
  693. {}
  694. bool ARAOutputStream::write (const void* dataToWrite, size_t numberOfBytes)
  695. {
  696. if (! archiveWriter->writeBytesToArchive ((ARA::ARASize) position, numberOfBytes, (const ARA::ARAByte*) dataToWrite))
  697. return false;
  698. position += (int64) numberOfBytes;
  699. return true;
  700. }
  701. bool ARAOutputStream::setPosition (int64 newPosition)
  702. {
  703. position = newPosition;
  704. return true;
  705. }
  706. //==============================================================================
  707. ARADocumentControllerSpecialisation::ARADocumentControllerSpecialisation (
  708. const ARA::PlugIn::PlugInEntry* entry,
  709. const ARA::ARADocumentControllerHostInstance* instance)
  710. : documentController (std::make_unique<ARADocumentControllerImpl> (entry, instance, this))
  711. {
  712. }
  713. ARADocumentControllerSpecialisation::~ARADocumentControllerSpecialisation() = default;
  714. ARAPlaybackRenderer* ARADocumentControllerSpecialisation::doCreatePlaybackRenderer()
  715. {
  716. return new ARAPlaybackRenderer (getDocumentController());
  717. }
  718. ARAEditorRenderer* ARADocumentControllerSpecialisation::doCreateEditorRenderer()
  719. {
  720. return new ARAEditorRenderer (getDocumentController());
  721. }
  722. ARAEditorView* ARADocumentControllerSpecialisation::doCreateEditorView()
  723. {
  724. return new ARAEditorView (getDocumentController());
  725. }
  726. bool ARADocumentControllerSpecialisation::doIsAudioSourceContentAvailable ([[maybe_unused]] const ARA::PlugIn::AudioSource* audioSource,
  727. [[maybe_unused]] ARA::ARAContentType type)
  728. {
  729. return false;
  730. }
  731. ARA::ARAContentGrade ARADocumentControllerSpecialisation::doGetAudioSourceContentGrade ([[maybe_unused]] const ARA::PlugIn::AudioSource* audioSource,
  732. [[maybe_unused]] ARA::ARAContentType type)
  733. {
  734. // Overriding doIsAudioSourceContentAvailable() requires overriding
  735. // doGetAudioSourceContentGrade() accordingly!
  736. jassertfalse;
  737. return ARA::kARAContentGradeInitial;
  738. }
  739. ARA::PlugIn::ContentReader* ARADocumentControllerSpecialisation::doCreateAudioSourceContentReader ([[maybe_unused]] ARA::PlugIn::AudioSource* audioSource,
  740. [[maybe_unused]] ARA::ARAContentType type,
  741. [[maybe_unused]] const ARA::ARAContentTimeRange* range)
  742. {
  743. // Overriding doIsAudioSourceContentAvailable() requires overriding
  744. // doCreateAudioSourceContentReader() accordingly!
  745. jassertfalse;
  746. return nullptr;
  747. }
  748. bool ARADocumentControllerSpecialisation::doIsAudioModificationContentAvailable ([[maybe_unused]] const ARA::PlugIn::AudioModification* audioModification,
  749. [[maybe_unused]] ARA::ARAContentType type)
  750. {
  751. return false;
  752. }
  753. ARA::ARAContentGrade ARADocumentControllerSpecialisation::doGetAudioModificationContentGrade ([[maybe_unused]] const ARA::PlugIn::AudioModification* audioModification,
  754. [[maybe_unused]] ARA::ARAContentType type)
  755. {
  756. // Overriding doIsAudioModificationContentAvailable() requires overriding
  757. // doGetAudioModificationContentGrade() accordingly!
  758. jassertfalse;
  759. return ARA::kARAContentGradeInitial;
  760. }
  761. ARA::PlugIn::ContentReader* ARADocumentControllerSpecialisation::doCreateAudioModificationContentReader ([[maybe_unused]] ARA::PlugIn::AudioModification* audioModification,
  762. [[maybe_unused]] ARA::ARAContentType type,
  763. [[maybe_unused]] const ARA::ARAContentTimeRange* range)
  764. {
  765. // Overriding doIsAudioModificationContentAvailable() requires overriding
  766. // doCreateAudioModificationContentReader() accordingly!
  767. jassertfalse;
  768. return nullptr;
  769. }
  770. bool ARADocumentControllerSpecialisation::doIsPlaybackRegionContentAvailable ([[maybe_unused]] const ARA::PlugIn::PlaybackRegion* playbackRegion,
  771. [[maybe_unused]] ARA::ARAContentType type)
  772. {
  773. return false;
  774. }
  775. ARA::ARAContentGrade ARADocumentControllerSpecialisation::doGetPlaybackRegionContentGrade ([[maybe_unused]] const ARA::PlugIn::PlaybackRegion* playbackRegion,
  776. [[maybe_unused]] ARA::ARAContentType type)
  777. {
  778. // Overriding doIsPlaybackRegionContentAvailable() requires overriding
  779. // doGetPlaybackRegionContentGrade() accordingly!
  780. jassertfalse;
  781. return ARA::kARAContentGradeInitial;
  782. }
  783. ARA::PlugIn::ContentReader* ARADocumentControllerSpecialisation::doCreatePlaybackRegionContentReader ([[maybe_unused]] ARA::PlugIn::PlaybackRegion* playbackRegion,
  784. [[maybe_unused]] ARA::ARAContentType type,
  785. [[maybe_unused]] const ARA::ARAContentTimeRange* range)
  786. {
  787. // Overriding doIsPlaybackRegionContentAvailable() requires overriding
  788. // doCreatePlaybackRegionContentReader() accordingly!
  789. jassertfalse;
  790. return nullptr;
  791. }
  792. void ARADocumentControllerSpecialisation::doGetPlaybackRegionHeadAndTailTime ([[maybe_unused]] const ARA::PlugIn::PlaybackRegion* playbackRegion,
  793. ARA::ARATimeDuration* headTime,
  794. ARA::ARATimeDuration* tailTime)
  795. {
  796. *headTime = 0.0;
  797. *tailTime = 0.0;
  798. }
  799. bool ARADocumentControllerSpecialisation::doIsAudioSourceContentAnalysisIncomplete ([[maybe_unused]] const ARA::PlugIn::AudioSource* audioSource,
  800. [[maybe_unused]] ARA::ARAContentType type)
  801. {
  802. return false;
  803. }
  804. void ARADocumentControllerSpecialisation::doRequestAudioSourceContentAnalysis ([[maybe_unused]] ARA::PlugIn::AudioSource* audioSource,
  805. [[maybe_unused]] std::vector<ARA::ARAContentType> const& contentTypes)
  806. {
  807. }
  808. ARA::ARAInt32 ARADocumentControllerSpecialisation::doGetProcessingAlgorithmsCount() { return 0; }
  809. const ARA::ARAProcessingAlgorithmProperties*
  810. ARADocumentControllerSpecialisation::doGetProcessingAlgorithmProperties ([[maybe_unused]] ARA::ARAInt32 algorithmIndex)
  811. {
  812. return nullptr;
  813. }
  814. ARA::ARAInt32 ARADocumentControllerSpecialisation::doGetProcessingAlgorithmForAudioSource ([[maybe_unused]] const ARA::PlugIn::AudioSource* audioSource)
  815. {
  816. // doGetProcessingAlgorithmForAudioSource() must be implemented if the supported
  817. // algorithm count is greater than zero.
  818. if (getDocumentController()->getProcessingAlgorithmsCount() > 0)
  819. jassertfalse;
  820. return 0;
  821. }
  822. void ARADocumentControllerSpecialisation::doRequestProcessingAlgorithmForAudioSource ([[maybe_unused]] ARA::PlugIn::AudioSource* audioSource,
  823. [[maybe_unused]] ARA::ARAInt32 algorithmIndex)
  824. {
  825. // doRequestProcessingAlgorithmForAudioSource() must be implemented if the supported
  826. // algorithm count is greater than zero.
  827. jassert (getDocumentController()->getProcessingAlgorithmsCount() <= 0);
  828. }
  829. } // namespace juce