ARAHostDispatch.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. //------------------------------------------------------------------------------
  2. //! \file ARAHostDispatch.cpp
  3. //! C-to-C++ adapter for implementing ARA hosts
  4. //! Originally written and contributed to the ARA SDK by PreSonus Software Ltd.
  5. //! \project ARA SDK Library
  6. //! \copyright Copyright (c) 2012-2021, Celemony Software GmbH, All Rights Reserved.
  7. //! Developed in cooperation with PreSonus Software Ltd.
  8. //! \license Licensed under the Apache License, Version 2.0 (the "License");
  9. //! you may not use this file except in compliance with the License.
  10. //! You may obtain a copy of the License at
  11. //!
  12. //! http://www.apache.org/licenses/LICENSE-2.0
  13. //!
  14. //! Unless required by applicable law or agreed to in writing, software
  15. //! distributed under the License is distributed on an "AS IS" BASIS,
  16. //! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. //! See the License for the specific language governing permissions and
  18. //! limitations under the License.
  19. //------------------------------------------------------------------------------
  20. #include "ARAHostDispatch.h"
  21. namespace ARA {
  22. namespace Host {
  23. /*******************************************************************************/
  24. // AudioAccessControllerDispatcher
  25. /*******************************************************************************/
  26. namespace AudioAccessControllerDispatcher
  27. {
  28. static ARAAudioReaderHostRef ARA_CALL createAudioReaderForSource (ARAAudioAccessControllerHostRef controllerHostRef,
  29. ARAAudioSourceHostRef audioSourceHostRef, ARABool use64BitSamples) noexcept
  30. {
  31. return fromHostRef (controllerHostRef)->createAudioReaderForSource (audioSourceHostRef, use64BitSamples != kARAFalse);
  32. }
  33. static ARABool ARA_CALL readAudioSamples (ARAAudioAccessControllerHostRef controllerHostRef, ARAAudioReaderHostRef audioReaderHostRef,
  34. ARASamplePosition samplePosition, ARASampleCount samplesPerChannel, void* const buffers[]) noexcept
  35. {
  36. return (fromHostRef (controllerHostRef)->readAudioSamples (audioReaderHostRef, samplePosition, samplesPerChannel, buffers)) ? kARATrue : kARAFalse;
  37. }
  38. static void ARA_CALL destroyAudioReader (ARAAudioAccessControllerHostRef controllerHostRef, ARAAudioReaderHostRef audioReaderHostRef) noexcept
  39. {
  40. fromHostRef (controllerHostRef)->destroyAudioReader (audioReaderHostRef);
  41. }
  42. static const ARAAudioAccessControllerInterface* getInterface () noexcept
  43. {
  44. static const SizedStruct<ARA_STRUCT_MEMBER (ARAAudioAccessControllerInterface, destroyAudioReader)> ifc =
  45. {
  46. AudioAccessControllerDispatcher::createAudioReaderForSource,
  47. AudioAccessControllerDispatcher::readAudioSamples,
  48. AudioAccessControllerDispatcher::destroyAudioReader
  49. };
  50. return &ifc;
  51. }
  52. }
  53. /*******************************************************************************/
  54. // ArchivingControllerDispatcher
  55. /*******************************************************************************/
  56. namespace ArchivingControllerDispatcher
  57. {
  58. static ARASize ARA_CALL getArchiveSize (ARAArchivingControllerHostRef controllerHostRef, ARAArchiveReaderHostRef archiveReaderHostRef) noexcept
  59. {
  60. return fromHostRef (controllerHostRef)->getArchiveSize (archiveReaderHostRef);
  61. }
  62. static ARABool ARA_CALL readBytesFromArchive (ARAArchivingControllerHostRef controllerHostRef, ARAArchiveReaderHostRef archiveReaderHostRef,
  63. ARASize position, ARASize length, ARAByte buffer[]) noexcept
  64. {
  65. return (fromHostRef (controllerHostRef)->readBytesFromArchive (archiveReaderHostRef, position, length, buffer)) ? kARATrue : kARAFalse;
  66. }
  67. static ARABool ARA_CALL writeBytesToArchive (ARAArchivingControllerHostRef controllerHostRef, ARAArchiveWriterHostRef archiveWriterHostRef,
  68. ARASize position, ARASize length, const ARAByte buffer[]) noexcept
  69. {
  70. return (fromHostRef (controllerHostRef)->writeBytesToArchive (archiveWriterHostRef, position, length, buffer)) ? kARATrue : kARAFalse;
  71. }
  72. static void ARA_CALL notifyDocumentArchivingProgress (ARAArchivingControllerHostRef controllerHostRef, float value) noexcept
  73. {
  74. fromHostRef (controllerHostRef)->notifyDocumentArchivingProgress (value);
  75. }
  76. static void ARA_CALL notifyDocumentUnarchivingProgress (ARAArchivingControllerHostRef controllerHostRef, float value) noexcept
  77. {
  78. fromHostRef (controllerHostRef)->notifyDocumentUnarchivingProgress (value);
  79. }
  80. static ARAPersistentID ARA_CALL getDocumentArchiveID (ARAArchivingControllerHostRef controllerHostRef, ARAArchiveReaderHostRef archiveReaderHostRef) noexcept
  81. {
  82. return fromHostRef (controllerHostRef)->getDocumentArchiveID (archiveReaderHostRef);
  83. }
  84. static const ARAArchivingControllerInterface* getInterface () noexcept
  85. {
  86. static const SizedStruct<ARA_STRUCT_MEMBER (ARAArchivingControllerInterface, getDocumentArchiveID)> ifc =
  87. {
  88. ArchivingControllerDispatcher::getArchiveSize,
  89. ArchivingControllerDispatcher::readBytesFromArchive,
  90. ArchivingControllerDispatcher::writeBytesToArchive,
  91. ArchivingControllerDispatcher::notifyDocumentArchivingProgress,
  92. ArchivingControllerDispatcher::notifyDocumentUnarchivingProgress,
  93. ArchivingControllerDispatcher::getDocumentArchiveID
  94. };
  95. return &ifc;
  96. }
  97. }
  98. /*******************************************************************************/
  99. // ContentAccessControllerDispatcher
  100. /*******************************************************************************/
  101. namespace ContentAccessControllerDispatcher
  102. {
  103. static ARABool ARA_CALL isMusicalContextContentAvailable (ARAContentAccessControllerHostRef controllerHostRef, ARAMusicalContextHostRef musicalContextHostRef, ARAContentType type) noexcept
  104. {
  105. return (fromHostRef (controllerHostRef)->isMusicalContextContentAvailable (musicalContextHostRef, type)) ? kARATrue : kARAFalse;
  106. }
  107. static ARAContentGrade ARA_CALL getMusicalContextContentGrade (ARAContentAccessControllerHostRef controllerHostRef, ARAMusicalContextHostRef musicalContextHostRef, ARAContentType type) noexcept
  108. {
  109. return fromHostRef (controllerHostRef)->getMusicalContextContentGrade (musicalContextHostRef, type);
  110. }
  111. static ARAContentReaderHostRef ARA_CALL createMusicalContextContentReader (ARAContentAccessControllerHostRef controllerHostRef,
  112. ARAMusicalContextHostRef musicalContextHostRef, ARAContentType type, const ARAContentTimeRange* range) noexcept
  113. {
  114. return fromHostRef (controllerHostRef)->createMusicalContextContentReader (musicalContextHostRef, type, range);
  115. }
  116. static ARABool ARA_CALL isAudioSourceContentAvailable (ARAContentAccessControllerHostRef controllerHostRef, ARAAudioSourceHostRef audioSourceHostRef, ARAContentType type) noexcept
  117. {
  118. return (fromHostRef (controllerHostRef)->isAudioSourceContentAvailable (audioSourceHostRef, type)) ? kARATrue : kARAFalse;
  119. }
  120. static ARAContentGrade ARA_CALL getAudioSourceContentGrade (ARAContentAccessControllerHostRef controllerHostRef, ARAAudioSourceHostRef audioSourceHostRef, ARAContentType type) noexcept
  121. {
  122. return fromHostRef (controllerHostRef)->getAudioSourceContentGrade (audioSourceHostRef, type);
  123. }
  124. static ARAContentReaderHostRef ARA_CALL createAudioSourceContentReader (ARAContentAccessControllerHostRef controllerHostRef,
  125. ARAAudioSourceHostRef audioSourceHostRef, ARAContentType type, const ARAContentTimeRange* range) noexcept
  126. {
  127. return fromHostRef (controllerHostRef)->createAudioSourceContentReader (audioSourceHostRef, type, range);
  128. }
  129. static ARAInt32 ARA_CALL getContentReaderEventCount (ARAContentAccessControllerHostRef controllerHostRef, ARAContentReaderHostRef contentReaderHostRef) noexcept
  130. {
  131. return fromHostRef (controllerHostRef)->getContentReaderEventCount (contentReaderHostRef);
  132. }
  133. static const void* ARA_CALL getContentReaderDataForEvent (ARAContentAccessControllerHostRef controllerHostRef,
  134. ARAContentReaderHostRef contentReaderHostRef, ARAInt32 eventIndex) noexcept
  135. {
  136. return fromHostRef (controllerHostRef)->getContentReaderDataForEvent (contentReaderHostRef, eventIndex);
  137. }
  138. static void ARA_CALL destroyContentReader (ARAContentAccessControllerHostRef controllerHostRef, ARAContentReaderHostRef contentReaderHostRef) noexcept
  139. {
  140. fromHostRef (controllerHostRef)->destroyContentReader (contentReaderHostRef);
  141. }
  142. static const ARAContentAccessControllerInterface* getInterface () noexcept
  143. {
  144. static const SizedStruct<ARA_STRUCT_MEMBER (ARAContentAccessControllerInterface, destroyContentReader)> ifc =
  145. {
  146. ContentAccessControllerDispatcher::isMusicalContextContentAvailable,
  147. ContentAccessControllerDispatcher::getMusicalContextContentGrade,
  148. ContentAccessControllerDispatcher::createMusicalContextContentReader,
  149. ContentAccessControllerDispatcher::isAudioSourceContentAvailable,
  150. ContentAccessControllerDispatcher::getAudioSourceContentGrade,
  151. ContentAccessControllerDispatcher::createAudioSourceContentReader,
  152. ContentAccessControllerDispatcher::getContentReaderEventCount,
  153. ContentAccessControllerDispatcher::getContentReaderDataForEvent,
  154. ContentAccessControllerDispatcher::destroyContentReader
  155. };
  156. return &ifc;
  157. }
  158. }
  159. /*******************************************************************************/
  160. // ModelUpdateControllerDispatcher
  161. /*******************************************************************************/
  162. namespace ModelUpdateControllerDispatcher
  163. {
  164. static void ARA_CALL notifyAudioSourceAnalysisProgress (ARAModelUpdateControllerHostRef controllerHostRef,
  165. ARAAudioSourceHostRef audioSourceHostRef, ARAAnalysisProgressState state, float value) noexcept
  166. {
  167. fromHostRef (controllerHostRef)->notifyAudioSourceAnalysisProgress (audioSourceHostRef, state, value);
  168. }
  169. static void ARA_CALL notifyAudioSourceContentChanged (ARAModelUpdateControllerHostRef controllerHostRef, ARAAudioSourceHostRef audioSourceHostRef,
  170. const ARAContentTimeRange* range, ARAContentUpdateFlags flags) noexcept
  171. {
  172. fromHostRef (controllerHostRef)->notifyAudioSourceContentChanged (audioSourceHostRef, range, flags);
  173. }
  174. static void ARA_CALL notifyAudioModificationContentChanged (ARAModelUpdateControllerHostRef controllerHostRef, ARAAudioModificationHostRef audioModificationHostRef,
  175. const ARAContentTimeRange* range, ARAContentUpdateFlags flags) noexcept
  176. {
  177. fromHostRef (controllerHostRef)->notifyAudioModificationContentChanged (audioModificationHostRef, range, flags);
  178. }
  179. static void ARA_CALL notifyPlaybackRegionContentChanged (ARAModelUpdateControllerHostRef controllerHostRef, ARAPlaybackRegionHostRef playbackRegionHostRef,
  180. const ARAContentTimeRange* range, ARAContentUpdateFlags flags) noexcept
  181. {
  182. fromHostRef (controllerHostRef)->notifyPlaybackRegionContentChanged (playbackRegionHostRef, range, flags);
  183. }
  184. static const ARAModelUpdateControllerInterface* getInterface () noexcept
  185. {
  186. static const SizedStruct<ARA_STRUCT_MEMBER (ARAModelUpdateControllerInterface, notifyPlaybackRegionContentChanged)> ifc =
  187. {
  188. ModelUpdateControllerDispatcher::notifyAudioSourceAnalysisProgress,
  189. ModelUpdateControllerDispatcher::notifyAudioSourceContentChanged,
  190. ModelUpdateControllerDispatcher::notifyAudioModificationContentChanged,
  191. ModelUpdateControllerDispatcher::notifyPlaybackRegionContentChanged
  192. };
  193. return &ifc;
  194. }
  195. }
  196. /*******************************************************************************/
  197. // PlaybackControllerDispatcher
  198. /*******************************************************************************/
  199. namespace PlaybackControllerDispatcher
  200. {
  201. static void ARA_CALL requestStartPlayback (ARAPlaybackControllerHostRef controllerHostRef) noexcept
  202. {
  203. fromHostRef (controllerHostRef)->requestStartPlayback ();
  204. }
  205. static void ARA_CALL requestStopPlayback (ARAPlaybackControllerHostRef controllerHostRef) noexcept
  206. {
  207. fromHostRef (controllerHostRef)->requestStopPlayback ();
  208. }
  209. static void ARA_CALL requestSetPlaybackPosition (ARAPlaybackControllerHostRef controllerHostRef, ARATimePosition timePosition) noexcept
  210. {
  211. fromHostRef (controllerHostRef)->requestSetPlaybackPosition (timePosition);
  212. }
  213. static void ARA_CALL requestSetCycleRange (ARAPlaybackControllerHostRef controllerHostRef, ARATimePosition startTime, ARATimeDuration duration) noexcept
  214. {
  215. fromHostRef (controllerHostRef)->requestSetCycleRange (startTime, duration);
  216. }
  217. static void ARA_CALL requestEnableCycle (ARAPlaybackControllerHostRef controllerHostRef, ARABool enable) noexcept
  218. {
  219. fromHostRef (controllerHostRef)->requestEnableCycle (enable != kARAFalse);
  220. }
  221. static const ARAPlaybackControllerInterface* getInterface () noexcept
  222. {
  223. static const SizedStruct<ARA_STRUCT_MEMBER (ARAPlaybackControllerInterface, requestEnableCycle)> ifc =
  224. {
  225. PlaybackControllerDispatcher::requestStartPlayback,
  226. PlaybackControllerDispatcher::requestStopPlayback,
  227. PlaybackControllerDispatcher::requestSetPlaybackPosition,
  228. PlaybackControllerDispatcher::requestSetCycleRange,
  229. PlaybackControllerDispatcher::requestEnableCycle
  230. };
  231. return &ifc;
  232. }
  233. }
  234. /*******************************************************************************/
  235. // DocumentControllerHostInstance
  236. /*******************************************************************************/
  237. DocumentControllerHostInstance::DocumentControllerHostInstance (AudioAccessControllerInterface* audioAccessController, ArchivingControllerInterface* archivingController,
  238. ContentAccessControllerInterface* contentAccessController, ModelUpdateControllerInterface* modelUpdateController,
  239. PlaybackControllerInterface* playbackController) noexcept
  240. : BaseType {}
  241. {
  242. setAudioAccessController (audioAccessController);
  243. setArchivingController (archivingController);
  244. if (contentAccessController)
  245. setContentAccessController (contentAccessController);
  246. if (modelUpdateController)
  247. setModelUpdateController (modelUpdateController);
  248. if (playbackController)
  249. setPlaybackController (playbackController);
  250. }
  251. void DocumentControllerHostInstance::setAudioAccessController (AudioAccessControllerInterface* audioAccessController) noexcept
  252. {
  253. audioAccessControllerHostRef = toHostRef (audioAccessController);
  254. audioAccessControllerInterface = AudioAccessControllerDispatcher::getInterface ();
  255. }
  256. void DocumentControllerHostInstance::setArchivingController (ArchivingControllerInterface* archivingController) noexcept
  257. {
  258. archivingControllerHostRef = toHostRef (archivingController);
  259. archivingControllerInterface = ArchivingControllerDispatcher::getInterface ();
  260. }
  261. void DocumentControllerHostInstance::setContentAccessController (ContentAccessControllerInterface* contentAccessController) noexcept
  262. {
  263. contentAccessControllerHostRef = toHostRef (contentAccessController);
  264. contentAccessControllerInterface = (contentAccessController) ? ContentAccessControllerDispatcher::getInterface () : nullptr;
  265. }
  266. void DocumentControllerHostInstance::setModelUpdateController (ModelUpdateControllerInterface* modelUpdateController) noexcept
  267. {
  268. modelUpdateControllerHostRef = toHostRef (modelUpdateController);
  269. modelUpdateControllerInterface = (modelUpdateController) ? ModelUpdateControllerDispatcher::getInterface () : nullptr;
  270. }
  271. void DocumentControllerHostInstance::setPlaybackController (PlaybackControllerInterface* playbackController) noexcept
  272. {
  273. playbackControllerHostRef = toHostRef (playbackController);
  274. playbackControllerInterface = (playbackController) ? PlaybackControllerDispatcher::getInterface () : nullptr;
  275. }
  276. /*******************************************************************************/
  277. // DocumentController
  278. /*******************************************************************************/
  279. void DocumentController::destroyDocumentController () noexcept
  280. {
  281. getInterface ()->destroyDocumentController (getRef ());
  282. }
  283. const ARAFactory* DocumentController::getFactory () noexcept
  284. {
  285. return getInterface ()->getFactory (getRef ());
  286. }
  287. void DocumentController::beginEditing () noexcept
  288. {
  289. getInterface ()->beginEditing (getRef ());
  290. }
  291. void DocumentController::endEditing () noexcept
  292. {
  293. getInterface ()->endEditing (getRef ());
  294. }
  295. void DocumentController::notifyModelUpdates () noexcept
  296. {
  297. getInterface ()->notifyModelUpdates (getRef ());
  298. }
  299. void DocumentController::updateDocumentProperties (const ARADocumentProperties* properties) noexcept
  300. {
  301. getInterface ()->updateDocumentProperties (getRef (), properties);
  302. }
  303. bool DocumentController::beginRestoringDocumentFromArchive (ARAArchiveReaderHostRef archiveReaderHostRef) noexcept
  304. {
  305. // begin-/endRestoringDocumentFromArchive () is deprecated, prefer to use the new partial persistency calls if supported by the plug-in
  306. if (supportsPartialPersistency ())
  307. {
  308. getInterface ()->beginEditing (getRef ());
  309. return true;
  310. }
  311. else
  312. {
  313. return (getInterface ()->beginRestoringDocumentFromArchive (getRef (), archiveReaderHostRef) != kARAFalse);
  314. }
  315. }
  316. bool DocumentController::endRestoringDocumentFromArchive (ARAArchiveReaderHostRef archiveReaderHostRef) noexcept
  317. {
  318. // begin-/endRestoringDocumentFromArchive () is deprecated, prefer to use the new partial persistency calls if supported by the plug-in
  319. if (supportsPartialPersistency ())
  320. {
  321. const auto result { getInterface ()->restoreObjectsFromArchive (getRef (), archiveReaderHostRef, nullptr) };
  322. getInterface ()->endEditing (getRef ());
  323. return (result != kARAFalse);
  324. }
  325. else
  326. {
  327. return (getInterface ()->endRestoringDocumentFromArchive (getRef (), archiveReaderHostRef) != kARAFalse);
  328. }
  329. }
  330. bool DocumentController::storeDocumentToArchive (ARAArchiveWriterHostRef archiveWriterHostRef) noexcept
  331. {
  332. // storeDocumentToArchive () is deprecated, prefer to use the new partial persistency calls if supported by the plug-in
  333. if (supportsPartialPersistency ())
  334. return (getInterface ()->storeObjectsToArchive (getRef (), archiveWriterHostRef, nullptr) != kARAFalse);
  335. else
  336. return (getInterface ()->storeDocumentToArchive (getRef (), archiveWriterHostRef) != kARAFalse);
  337. }
  338. bool DocumentController::supportsPartialPersistency () noexcept
  339. {
  340. return getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, storeObjectsToArchive)> ();
  341. }
  342. bool DocumentController::restoreObjectsFromArchive (ARAArchiveReaderHostRef archiveReaderHostRef, const ARARestoreObjectsFilter* filter) noexcept
  343. {
  344. if (!supportsPartialPersistency ())
  345. return false;
  346. return (getInterface ()->restoreObjectsFromArchive (getRef (), archiveReaderHostRef, filter) != kARAFalse);
  347. }
  348. bool DocumentController::storeObjectsToArchive (ARAArchiveWriterHostRef archiveWriterHostRef, const ARAStoreObjectsFilter* filter) noexcept
  349. {
  350. if (!supportsPartialPersistency ())
  351. return false;
  352. return (getInterface ()->storeObjectsToArchive (getRef (), archiveWriterHostRef, filter) != kARAFalse);
  353. }
  354. bool DocumentController::supportsStoringAudioFileChunks () noexcept
  355. {
  356. if (!getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, storeAudioSourceToAudioFileChunk)> ())
  357. return false;
  358. const SizedStructPtr<ARAFactory> factory { getInterface ()->getFactory (getRef ()) };
  359. if (!factory.implements<ARA_STRUCT_MEMBER (ARAFactory, supportsStoringAudioFileChunks)> ())
  360. return false;
  361. return (factory->supportsStoringAudioFileChunks != kARAFalse);
  362. }
  363. bool DocumentController::storeAudioSourceToAudioFileChunk (ARAArchiveWriterHostRef archiveWriterHostRef, ARAAudioSourceRef audioSourceRef, ARAPersistentID* documentArchiveID, bool* openAutomatically) noexcept
  364. {
  365. if (!supportsStoringAudioFileChunks ())
  366. return false;
  367. ARABool autoOpen { kARAFalse };
  368. const auto result { getInterface ()->storeAudioSourceToAudioFileChunk (getRef (), archiveWriterHostRef, audioSourceRef, documentArchiveID, &autoOpen) };
  369. *openAutomatically = (autoOpen != kARAFalse);
  370. return (result != kARAFalse);
  371. }
  372. ARAMusicalContextRef DocumentController::createMusicalContext (ARAMusicalContextHostRef hostRef, const ARAMusicalContextProperties* properties) noexcept
  373. {
  374. return getInterface ()->createMusicalContext (getRef (), hostRef, properties);
  375. }
  376. void DocumentController::updateMusicalContextProperties (ARAMusicalContextRef musicalContextRef, const ARAMusicalContextProperties* properties) noexcept
  377. {
  378. getInterface ()->updateMusicalContextProperties (getRef (), musicalContextRef, properties);
  379. }
  380. void DocumentController::updateMusicalContextContent (ARAMusicalContextRef musicalContextRef, const ARAContentTimeRange* range, ContentUpdateScopes scopeFlags) noexcept
  381. {
  382. getInterface ()->updateMusicalContextContent (getRef (), musicalContextRef, range, scopeFlags);
  383. }
  384. void DocumentController::destroyMusicalContext (ARAMusicalContextRef musicalContextRef) noexcept
  385. {
  386. getInterface ()->destroyMusicalContext (getRef (), musicalContextRef);
  387. }
  388. ARARegionSequenceRef DocumentController::createRegionSequence (ARARegionSequenceHostRef hostRef, const ARARegionSequenceProperties* properties) noexcept
  389. {
  390. #if ARA_SUPPORT_VERSION_1
  391. if (!getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, destroyRegionSequence)> ())
  392. return nullptr;
  393. #endif
  394. return getInterface ()->createRegionSequence (getRef (), hostRef, properties);
  395. }
  396. void DocumentController::updateRegionSequenceProperties (ARARegionSequenceRef regionSequenceRef, const ARARegionSequenceProperties* properties) noexcept
  397. {
  398. #if ARA_SUPPORT_VERSION_1
  399. if (!getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, destroyRegionSequence)> ())
  400. return;
  401. #endif
  402. return getInterface ()->updateRegionSequenceProperties (getRef (), regionSequenceRef, properties);
  403. }
  404. void DocumentController::destroyRegionSequence (ARARegionSequenceRef regionSequenceRef) noexcept
  405. {
  406. #if ARA_SUPPORT_VERSION_1
  407. if (!getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, destroyRegionSequence)> ())
  408. return;
  409. #endif
  410. return getInterface ()->destroyRegionSequence (getRef (), regionSequenceRef);
  411. }
  412. ARAAudioSourceRef DocumentController::createAudioSource (ARAAudioSourceHostRef hostRef, const ARAAudioSourceProperties* properties) noexcept
  413. {
  414. return getInterface ()->createAudioSource (getRef (), hostRef, properties);
  415. }
  416. void DocumentController::updateAudioSourceProperties (ARAAudioSourceRef audioSourceRef, const ARAAudioSourceProperties* properties) noexcept
  417. {
  418. getInterface ()->updateAudioSourceProperties (getRef (), audioSourceRef, properties);
  419. }
  420. void DocumentController::updateAudioSourceContent (ARAAudioSourceRef audioSourceRef, const ARAContentTimeRange* range, ContentUpdateScopes scopeFlags) noexcept
  421. {
  422. getInterface ()->updateAudioSourceContent (getRef (), audioSourceRef, range, scopeFlags);
  423. }
  424. void DocumentController::enableAudioSourceSamplesAccess (ARAAudioSourceRef audioSourceRef, bool enable) noexcept
  425. {
  426. getInterface ()->enableAudioSourceSamplesAccess (getRef (), audioSourceRef, (enable) ? kARATrue : kARAFalse);
  427. }
  428. void DocumentController::deactivateAudioSourceForUndoHistory (ARAAudioSourceRef audioSourceRef, bool deactivate) noexcept
  429. {
  430. getInterface ()->deactivateAudioSourceForUndoHistory (getRef (), audioSourceRef, (deactivate) ? kARATrue : kARAFalse);
  431. }
  432. void DocumentController::destroyAudioSource (ARAAudioSourceRef audioSourceRef) noexcept
  433. {
  434. getInterface ()->destroyAudioSource (getRef (), audioSourceRef);
  435. }
  436. ARAAudioModificationRef DocumentController::createAudioModification (ARAAudioSourceRef audioSourceRef, ARAAudioModificationHostRef hostRef, const ARAAudioModificationProperties* properties) noexcept
  437. {
  438. return getInterface ()->createAudioModification (getRef (), audioSourceRef, hostRef, properties);
  439. }
  440. ARAAudioModificationRef DocumentController::cloneAudioModification (ARAAudioModificationRef audioModificationRef, ARAAudioModificationHostRef hostRef, const ARAAudioModificationProperties* properties) noexcept
  441. {
  442. return getInterface ()->cloneAudioModification (getRef (), audioModificationRef, hostRef, properties);
  443. }
  444. void DocumentController::updateAudioModificationProperties (ARAAudioModificationRef audioModificationRef, const ARAAudioModificationProperties* properties) noexcept
  445. {
  446. getInterface ()->updateAudioModificationProperties (getRef (), audioModificationRef, properties);
  447. }
  448. void DocumentController::deactivateAudioModificationForUndoHistory (ARAAudioModificationRef audioModificationRef, bool deactivate) noexcept
  449. {
  450. getInterface ()->deactivateAudioModificationForUndoHistory (getRef (), audioModificationRef, (deactivate) ? kARATrue : kARAFalse);
  451. }
  452. void DocumentController::destroyAudioModification (ARAAudioModificationRef audioModificationRef) noexcept
  453. {
  454. getInterface ()->destroyAudioModification (getRef (), audioModificationRef);
  455. }
  456. ARAPlaybackRegionRef DocumentController::createPlaybackRegion (ARAAudioModificationRef audioModificationRef, ARAPlaybackRegionHostRef hostRef, const ARAPlaybackRegionProperties* properties) noexcept
  457. {
  458. return getInterface ()->createPlaybackRegion (getRef (), audioModificationRef, hostRef, properties);
  459. }
  460. void DocumentController::updatePlaybackRegionProperties (ARAPlaybackRegionRef playbackRegionRef, const ARAPlaybackRegionProperties* properties) noexcept
  461. {
  462. getInterface ()->updatePlaybackRegionProperties (getRef (), playbackRegionRef, properties);
  463. }
  464. void DocumentController::getPlaybackRegionHeadAndTailTime (ARAPlaybackRegionRef playbackRegionRef, ARATimeDuration* headTime, ARATimeDuration* tailTime) noexcept
  465. {
  466. #if ARA_SUPPORT_VERSION_1
  467. if (!getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, getPlaybackRegionHeadAndTailTime)> ())
  468. {
  469. *headTime = 0.0;
  470. *tailTime = 0.0;
  471. return;
  472. }
  473. #endif
  474. return getInterface ()->getPlaybackRegionHeadAndTailTime (getRef (), playbackRegionRef, headTime, tailTime);
  475. }
  476. void DocumentController::destroyPlaybackRegion (ARAPlaybackRegionRef playbackRegionRef) noexcept
  477. {
  478. getInterface ()->destroyPlaybackRegion (getRef (), playbackRegionRef);
  479. }
  480. bool DocumentController::isAudioSourceContentAvailable (ARAAudioSourceRef audioSourceRef, ARAContentType type) noexcept
  481. {
  482. return (getInterface ()->isAudioSourceContentAvailable (getRef (), audioSourceRef, type) != kARAFalse);
  483. }
  484. ARAContentGrade DocumentController::getAudioSourceContentGrade (ARAAudioSourceRef audioSourceRef, ARAContentType type) noexcept
  485. {
  486. return getInterface ()->getAudioSourceContentGrade (getRef (), audioSourceRef, type);
  487. }
  488. ARAContentReaderRef DocumentController::createAudioSourceContentReader (ARAAudioSourceRef audioSourceRef, ARAContentType type, const ARAContentTimeRange* range) noexcept
  489. {
  490. return getInterface ()->createAudioSourceContentReader (getRef (), audioSourceRef, type, range);
  491. }
  492. bool DocumentController::isAudioModificationContentAvailable (ARAAudioModificationRef audioModificationRef, ARAContentType type) noexcept
  493. {
  494. return (getInterface ()->isAudioModificationContentAvailable (getRef (), audioModificationRef, type) != kARAFalse);
  495. }
  496. ARAContentGrade DocumentController::getAudioModificationContentGrade (ARAAudioModificationRef audioModificationRef, ARAContentType type) noexcept
  497. {
  498. return getInterface ()->getAudioModificationContentGrade (getRef (), audioModificationRef, type);
  499. }
  500. ARAContentReaderRef DocumentController::createAudioModificationContentReader (ARAAudioModificationRef audioModificationRef, ARAContentType type, const ARAContentTimeRange* range) noexcept
  501. {
  502. return getInterface ()->createAudioModificationContentReader (getRef (), audioModificationRef, type, range);
  503. }
  504. bool DocumentController::isPlaybackRegionContentAvailable (ARAPlaybackRegionRef playbackRegionRef, ARAContentType type) noexcept
  505. {
  506. return (getInterface ()->isPlaybackRegionContentAvailable (getRef (), playbackRegionRef, type) != kARAFalse);
  507. }
  508. ARAContentGrade DocumentController::getPlaybackRegionContentGrade (ARAPlaybackRegionRef playbackRegionRef, ARAContentType type) noexcept
  509. {
  510. return getInterface ()->getPlaybackRegionContentGrade (getRef (), playbackRegionRef, type);
  511. }
  512. ARAContentReaderRef DocumentController::createPlaybackRegionContentReader (ARAPlaybackRegionRef playbackRegionRef, ARAContentType type, const ARAContentTimeRange* range) noexcept
  513. {
  514. return getInterface ()->createPlaybackRegionContentReader (getRef (), playbackRegionRef, type, range);
  515. }
  516. ARAInt32 DocumentController::getContentReaderEventCount (ARAContentReaderRef contentReaderRef) noexcept
  517. {
  518. return getInterface ()->getContentReaderEventCount (getRef (), contentReaderRef);
  519. }
  520. const void* DocumentController::getContentReaderDataForEvent (ARAContentReaderRef contentReaderRef, ARAInt32 eventIndex) noexcept
  521. {
  522. return getInterface ()->getContentReaderDataForEvent (getRef (), contentReaderRef, eventIndex);
  523. }
  524. void DocumentController::destroyContentReader (ARAContentReaderRef contentReaderRef) noexcept
  525. {
  526. getInterface ()->destroyContentReader (getRef (), contentReaderRef);
  527. }
  528. bool DocumentController::isAudioSourceContentAnalysisIncomplete (ARAAudioSourceRef audioSourceRef, ARAContentType type) noexcept
  529. {
  530. return (getInterface ()->isAudioSourceContentAnalysisIncomplete (getRef (), audioSourceRef, type) != kARAFalse);
  531. }
  532. void DocumentController::requestAudioSourceContentAnalysis (ARAAudioSourceRef audioSourceRef, ARASize contentTypesCount, const ARAContentType contentTypes[]) noexcept
  533. {
  534. getInterface ()->requestAudioSourceContentAnalysis (getRef (), audioSourceRef, contentTypesCount, contentTypes);
  535. }
  536. bool DocumentController::supportsProcessingAlgorithms () noexcept
  537. {
  538. return (getProcessingAlgorithmsCount () > 0);
  539. }
  540. ARAInt32 DocumentController::getProcessingAlgorithmsCount () noexcept
  541. {
  542. if (getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, requestProcessingAlgorithmForAudioSource)> ())
  543. return getInterface ()->getProcessingAlgorithmsCount (getRef ());
  544. else
  545. return 0;
  546. }
  547. const ARAProcessingAlgorithmProperties* DocumentController::getProcessingAlgorithmProperties (ARAInt32 algorithmIndex) noexcept
  548. {
  549. return getInterface ()->getProcessingAlgorithmProperties (getRef (), algorithmIndex);
  550. }
  551. ARAInt32 DocumentController::getProcessingAlgorithmForAudioSource (ARAAudioSourceRef audioSourceRef) noexcept
  552. {
  553. return getInterface ()->getProcessingAlgorithmForAudioSource (getRef (), audioSourceRef);
  554. }
  555. void DocumentController::requestProcessingAlgorithmForAudioSource (ARAAudioSourceRef audioSourceRef, ARAInt32 algorithmIndex) noexcept
  556. {
  557. getInterface ()->requestProcessingAlgorithmForAudioSource (getRef (), audioSourceRef, algorithmIndex);
  558. }
  559. bool DocumentController::isLicensedForCapabilities (bool runModalActivationDialogIfNeeded, ARASize contentTypesCount, const ARAContentType contentTypes[], ARAPlaybackTransformationFlags transformationFlags) noexcept
  560. {
  561. if (!getInterface ().implements<ARA_STRUCT_MEMBER (ARADocumentControllerInterface, isLicensedForCapabilities)> ())
  562. return true;
  563. return (getInterface ()->isLicensedForCapabilities (getRef (), (runModalActivationDialogIfNeeded) ? kARATrue : kARAFalse, contentTypesCount, contentTypes, transformationFlags) != kARAFalse);
  564. }
  565. /*******************************************************************************/
  566. // PlaybackRenderer
  567. /*******************************************************************************/
  568. #if ARA_SUPPORT_VERSION_1
  569. bool supportsARA2 (const ARAPlugInExtensionInstance* instance)
  570. {
  571. return SizedStructPtr<ARAPlugInExtensionInstance> (instance).implements<ARA_STRUCT_MEMBER (ARAPlugInExtensionInstance, editorViewInterface)> ();
  572. }
  573. class ARA1PlugInExtension : public InterfaceInstance<ARAPlugInExtensionRef, ARAPlugInExtensionInterface>
  574. {
  575. public:
  576. explicit ARA1PlugInExtension (const ARAPlugInExtensionInstance* instance) noexcept
  577. : BaseType { instance->plugInExtensionRef, instance->plugInExtensionInterface }
  578. {}
  579. };
  580. // this is not really a host ref but rather a dummy plug-in ref created by the host,
  581. // but since this macro only deals with proper casting this difference does not matter.
  582. ARA_MAP_HOST_REF (ARA1PlugInExtension, ARAPlaybackRendererRef)
  583. // playback renderer for ARA 1 is forwarding to plug-in extension
  584. namespace ARA1PlaybackRendererAdapterDispatcher
  585. {
  586. static void ARA_CALL addPlaybackRegion (ARAPlaybackRendererRef playbackRendererRef, ARAPlaybackRegionRef playbackRegionRef)
  587. {
  588. auto plugInExtension { fromHostRef (playbackRendererRef) };
  589. fromHostRef (playbackRendererRef)->getInterface ()->setPlaybackRegion (plugInExtension->getRef (), playbackRegionRef);
  590. }
  591. static void ARA_CALL removePlaybackRegion (ARAPlaybackRendererRef playbackRendererRef, ARAPlaybackRegionRef playbackRegionRef)
  592. {
  593. auto plugInExtension { fromHostRef (playbackRendererRef) };
  594. plugInExtension->getInterface ()->removePlaybackRegion (plugInExtension->getRef (), playbackRegionRef);
  595. }
  596. static const ARAPlaybackRendererInterface* getInterface () noexcept
  597. {
  598. static const SizedStruct<ARA_STRUCT_MEMBER (ARAPlaybackRendererInterface, removePlaybackRegion)> ifc =
  599. {
  600. ARA1PlaybackRendererAdapterDispatcher::addPlaybackRegion,
  601. ARA1PlaybackRendererAdapterDispatcher::removePlaybackRegion
  602. };
  603. return &ifc;
  604. }
  605. }
  606. PlaybackRenderer::PlaybackRenderer (const ARAPlugInExtensionInstance* instance)
  607. : BaseType { supportsARA2 (instance) ? instance->playbackRendererRef : toHostRef (new ARA1PlugInExtension (instance)),
  608. supportsARA2 (instance) ? instance->playbackRendererInterface : ARA1PlaybackRendererAdapterDispatcher::getInterface () }
  609. {}
  610. PlaybackRenderer::~PlaybackRenderer ()
  611. {
  612. // ARA 2 plug-ins will provide their own distinct interface pointers, so this test
  613. // basically equals a dynamic_cast<ARA1PlugInExtension> (PlaybackRenderer.getRef ())
  614. if (getInterface () == ARA1PlaybackRendererAdapterDispatcher::getInterface ())
  615. delete reinterpret_cast<ARA1PlugInExtension*> (getRef ());
  616. }
  617. #endif // ARA_SUPPORT_VERSION_1
  618. void PlaybackRenderer::addPlaybackRegion (ARAPlaybackRegionRef playbackRegionRef) noexcept
  619. {
  620. getInterface ()->addPlaybackRegion (getRef (), playbackRegionRef);
  621. }
  622. void PlaybackRenderer::removePlaybackRegion (ARAPlaybackRegionRef playbackRegionRef) noexcept
  623. {
  624. getInterface ()->removePlaybackRegion (getRef (), playbackRegionRef);
  625. }
  626. //************************************************************************************************
  627. // EditorRenderer
  628. //************************************************************************************************
  629. #if ARA_SUPPORT_VERSION_1
  630. // editor renderer for ARA 1 is empty stub
  631. namespace ARA1EditorRendererAdapterDispatcher
  632. {
  633. static void ARA_CALL addPlaybackRegion (ARAEditorRendererRef /*editorRendererRef*/, ARAPlaybackRegionRef /*playbackRegionRef*/)
  634. {}
  635. static void ARA_CALL removePlaybackRegion (ARAEditorRendererRef /*editorRendererRef*/, ARAPlaybackRegionRef /*playbackRegionRef*/)
  636. {}
  637. static void ARA_CALL addRegionSequence (ARAEditorRendererRef /*editorRendererRef*/, ARARegionSequenceRef /*regionSequenceRef*/)
  638. {}
  639. static void ARA_CALL removeRegionSequence (ARAEditorRendererRef /*editorRendererRef*/, ARARegionSequenceRef /*regionSequenceRef*/)
  640. {}
  641. static const ARAEditorRendererInterface* getInterface () noexcept
  642. {
  643. static const SizedStruct<ARA_STRUCT_MEMBER (ARAEditorRendererInterface, removeRegionSequence)> ifc =
  644. {
  645. ARA1EditorRendererAdapterDispatcher::addPlaybackRegion,
  646. ARA1EditorRendererAdapterDispatcher::removePlaybackRegion,
  647. ARA1EditorRendererAdapterDispatcher::addRegionSequence,
  648. ARA1EditorRendererAdapterDispatcher::removeRegionSequence
  649. };
  650. return &ifc;
  651. }
  652. }
  653. EditorRenderer::EditorRenderer (const ARAPlugInExtensionInstance* instance) noexcept
  654. : BaseType { supportsARA2 (instance) ? instance->editorRendererRef : nullptr,
  655. supportsARA2 (instance) ? instance->editorRendererInterface : ARA1EditorRendererAdapterDispatcher::getInterface () }
  656. {}
  657. #endif // ARA_SUPPORT_VERSION_1
  658. void EditorRenderer::addPlaybackRegion (ARAPlaybackRegionRef playbackRegionRef) noexcept
  659. {
  660. getInterface ()->addPlaybackRegion (getRef (), playbackRegionRef);
  661. }
  662. void EditorRenderer::removePlaybackRegion (ARAPlaybackRegionRef playbackRegionRef) noexcept
  663. {
  664. getInterface ()->removePlaybackRegion (getRef (), playbackRegionRef);
  665. }
  666. void EditorRenderer::addRegionSequence (ARARegionSequenceRef regionSequenceRef) noexcept
  667. {
  668. getInterface ()->addRegionSequence (getRef (), regionSequenceRef);
  669. }
  670. void EditorRenderer::removeRegionSequence (ARARegionSequenceRef regionSequenceRef) noexcept
  671. {
  672. getInterface ()->removeRegionSequence (getRef (), regionSequenceRef);
  673. }
  674. //************************************************************************************************
  675. // EditorView
  676. //************************************************************************************************
  677. #if ARA_SUPPORT_VERSION_1
  678. // editor view for ARA 1 is empty stub
  679. namespace ARA1EditorViewAdapterDispatcher
  680. {
  681. static void ARA_CALL notifySelection (ARAEditorViewRef /*editorViewRef*/, const ARAViewSelection* /*selection*/)
  682. {}
  683. static void ARA_CALL notifyHideRegionSequences (ARAEditorViewRef /*editorViewRef*/, ARASize /*regionSequenceRefsCount*/, const ARARegionSequenceRef /*regionSequenceRefs*/[])
  684. {}
  685. static const ARAEditorViewInterface* getInterface () noexcept
  686. {
  687. static const SizedStruct<ARA_STRUCT_MEMBER (ARAEditorViewInterface, notifyHideRegionSequences)> ifc =
  688. {
  689. ARA1EditorViewAdapterDispatcher::notifySelection,
  690. ARA1EditorViewAdapterDispatcher::notifyHideRegionSequences
  691. };
  692. return &ifc;
  693. }
  694. }
  695. EditorView::EditorView (const ARAPlugInExtensionInstance* instance) noexcept
  696. : BaseType { supportsARA2 (instance) ? instance->editorViewRef : nullptr,
  697. supportsARA2 (instance) ? instance->editorViewInterface : ARA1EditorViewAdapterDispatcher::getInterface () }
  698. {}
  699. #endif // ARA_SUPPORT_VERSION_1
  700. void EditorView::notifySelection (const ARAViewSelection* selection) noexcept
  701. {
  702. getInterface ()->notifySelection (getRef (), selection);
  703. }
  704. void EditorView::notifyHideRegionSequences (ARASize regionSequenceRefsCount, const ARARegionSequenceRef regionSequenceRefs[]) noexcept
  705. {
  706. getInterface ()->notifyHideRegionSequences (getRef (), regionSequenceRefsCount, regionSequenceRefs);
  707. }
  708. } // namespace Host
  709. } // namespace ARA