JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ARAHosting.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26#pragma once
27
28#if (JUCE_PLUGINHOST_ARA && (JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU) && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX)) || DOXYGEN
29
30// Include ARA SDK headers
31JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wgnu-zero-variadic-macro-arguments")
32
33#include <ARA_API/ARAInterface.h>
34#include <ARA_Library/Dispatch/ARAHostDispatch.h>
35
36JUCE_END_IGNORE_WARNINGS_GCC_LIKE
37
38//==============================================================================
39namespace juce
40{
60{
61public:
62 explicit ARAEditGuard (ARA::Host::DocumentController& dcIn);
64
65private:
66 ARA::Host::DocumentController& dc;
67};
68
69namespace ARAHostModel
70{
71
72//==============================================================================
87template <typename A, typename B>
88struct ConversionFunctions
89{
90 static_assert (sizeof (A) <= sizeof (B),
91 "It is only possible to convert between types of the same size");
92
93 static B toHostRef (A value)
94 {
95 return readUnaligned<B> (&value);
96 }
97
98 static A fromHostRef (B value)
99 {
100 return readUnaligned<A> (&value);
101 }
102};
103
104//==============================================================================
113template <typename Base, typename PtrIn>
114class ManagedARAHandle
115{
116public:
117 using Ptr = PtrIn;
118
120 ManagedARAHandle (ARA::Host::DocumentController& dc, Ptr ptr) noexcept
121 : handle (ptr, Deleter { dc }) {}
122
124 auto& getDocumentController() const { return handle.get_deleter().documentController; }
125
127 Ptr getPluginRef() const { return handle.get(); }
128
129private:
130 struct Deleter
131 {
132 void operator() (Ptr ptr) const noexcept
133 {
134 const ARAEditGuard guard (documentController);
135 Base::destroy (documentController, ptr);
136 }
137
138 ARA::Host::DocumentController& documentController;
139 };
140
142};
143
144//==============================================================================
161class AudioSource : public ManagedARAHandle<AudioSource, ARA::ARAAudioSourceRef>
162{
163public:
170 static constexpr auto getEmptyProperties() { return makeARASizedStruct (&ARA::ARAAudioSourceProperties::merits64BitSamples); }
171
183 AudioSource (ARA::ARAAudioSourceHostRef hostRef,
184 ARA::Host::DocumentController& dc,
185 const ARA::ARAAudioSourceProperties& props);
186
188 ~AudioSource() = default;
189
197 void update (const ARA::ARAAudioSourceProperties& props);
198
203 void enableAudioSourceSamplesAccess (bool);
204
210 static void destroy (ARA::Host::DocumentController&, Ptr);
211};
212
229class AudioModification : public ManagedARAHandle<AudioModification, ARA::ARAAudioModificationRef>
230{
231public:
238 static constexpr auto getEmptyProperties()
239 {
240 return makeARASizedStruct (&ARA::ARAAudioModificationProperties::persistentID);
241 }
242
254 AudioModification (ARA::ARAAudioModificationHostRef hostRef,
255 ARA::Host::DocumentController& dc,
256 AudioSource& s,
257 const ARA::ARAAudioModificationProperties& props);
258
266 void update (const ARA::ARAAudioModificationProperties& props);
267
269 auto& getAudioSource() const { return source; }
270
276 static void destroy (ARA::Host::DocumentController&, Ptr);
277
278private:
279 AudioSource& source;
280};
281
287struct DeletionListener
288{
290 virtual ~DeletionListener() = default;
291
293 virtual void removeListener (DeletionListener& other) noexcept = 0;
294};
295
312struct PlaybackRegion
313{
314public:
321 static constexpr auto getEmptyProperties()
322 {
323 return makeARASizedStruct (&ARA::ARAPlaybackRegionProperties::color);
324 }
325
326 PlaybackRegion (ARA::ARAPlaybackRegionHostRef hostRef,
327 ARA::Host::DocumentController& dc,
328 AudioModification& m,
329 const ARA::ARAPlaybackRegionProperties& props);
330
331 ~PlaybackRegion();
332
340 void update (const ARA::ARAPlaybackRegionProperties& props);
341
349 void addListener (DeletionListener& x);
350
352 auto& getAudioModification() const;
353
355 ARA::ARAPlaybackRegionRef getPluginRef() const noexcept;
356 DeletionListener& getDeletionListener() const noexcept;
357
358private:
359 class Impl;
360
361 std::unique_ptr<Impl> impl;
362};
363
380class MusicalContext : public ManagedARAHandle<MusicalContext, ARA::ARAMusicalContextRef>
381{
382public:
389 static constexpr auto getEmptyProperties()
390 {
391 return makeARASizedStruct (&ARA::ARAMusicalContextProperties::color);
392 }
393
405 MusicalContext (ARA::ARAMusicalContextHostRef hostRef,
406 ARA::Host::DocumentController& dc,
407 const ARA::ARAMusicalContextProperties& props);
408
416 void update (const ARA::ARAMusicalContextProperties& props);
417
423 static void destroy (ARA::Host::DocumentController&, Ptr);
424};
425
442class RegionSequence : public ManagedARAHandle<RegionSequence, ARA::ARARegionSequenceRef>
443{
444public:
451 static constexpr auto getEmptyProperties()
452 {
453 return makeARASizedStruct (&ARA::ARARegionSequenceProperties::color);
454 }
455
467 RegionSequence (ARA::ARARegionSequenceHostRef hostRef,
468 ARA::Host::DocumentController& dc,
469 const ARA::ARARegionSequenceProperties& props);
470
478 void update (const ARA::ARARegionSequenceProperties& props);
479
485 static void destroy (ARA::Host::DocumentController&, Ptr);
486};
487
488//==============================================================================
537template <typename RendererRef, typename Interface>
538class PlaybackRegionRegistry
539{
540public:
541 PlaybackRegionRegistry() = default;
542
543 PlaybackRegionRegistry (RendererRef rendererRefIn, const Interface* interfaceIn)
544 : registry (std::make_unique<Registry> (rendererRefIn, interfaceIn))
545 {
546 }
547
553 void add (PlaybackRegion& region) { registry->add (region); }
554
560 void remove (PlaybackRegion& region) { registry->remove (region); }
561
563 bool isValid() { return registry->isValid(); }
564
565private:
566 class Registry : private DeletionListener
567 {
568 public:
569 Registry (RendererRef rendererRefIn, const Interface* interfaceIn)
570 : rendererRef (rendererRefIn), rendererInterface (interfaceIn)
571 {
572 }
573
574 Registry (const Registry&) = delete;
575 Registry (Registry&&) noexcept = delete;
576
577 Registry& operator= (const Registry&) = delete;
578 Registry& operator= (Registry&&) noexcept = delete;
579
580 ~Registry() override
581 {
582 for (const auto& region : regions)
583 doRemoveListener (*region.first);
584 }
585
586 bool isValid() { return rendererRef != nullptr && rendererInterface != nullptr; }
587
588 void add (PlaybackRegion& region)
589 {
590 if (isValid())
591 rendererInterface->addPlaybackRegion (rendererRef, region.getPluginRef());
592
593 regions.emplace (&region.getDeletionListener(), region.getPluginRef());
594 region.addListener (*this);
595 }
596
597 void remove (PlaybackRegion& region)
598 {
599 doRemoveListener (region.getDeletionListener());
600 }
601
602 private:
603 void doRemoveListener (DeletionListener& listener) noexcept
604 {
605 listener.removeListener (*this);
606 removeListener (listener);
607 }
608
609 void removeListener (DeletionListener& listener) noexcept override
610 {
611 const auto it = regions.find (&listener);
612
613 if (it == regions.end())
614 {
616 return;
617 }
618
619 if (isValid())
620 rendererInterface->removePlaybackRegion (rendererRef, it->second);
621
622 regions.erase (it);
623 }
624
625 RendererRef rendererRef = nullptr;
626 const Interface* rendererInterface = nullptr;
628 };
629
631};
632
633//==============================================================================
643
644//==============================================================================
654
655//==============================================================================
663class PlugInExtensionInstance final
664{
665public:
670 PlugInExtensionInstance() = default;
671
677 explicit PlugInExtensionInstance (const ARA::ARAPlugInExtensionInstance* instanceIn)
678 : instance (instanceIn)
679 {
680 }
681
689 PlaybackRendererInterface getPlaybackRendererInterface() const;
690
698 EditorRendererInterface getEditorRendererInterface() const;
699
703 bool isValid() const noexcept { return instance != nullptr; }
704
705private:
706 const ARA::ARAPlugInExtensionInstance* instance = nullptr;
707};
708
709} // namespace ARAHostModel
710
711//==============================================================================
721{
722public:
729 const String& documentName,
732 std::unique_ptr<ARA::Host::ContentAccessControllerInterface> contentAccessController = nullptr,
735
737
739 ARA::Host::DocumentController& getDocumentController() const;
740
749 ARAHostModel::PlugInExtensionInstance bindDocumentToPluginInstance (AudioPluginInstance& instance,
750 ARA::ARAPlugInInstanceRoleFlags knownRoles,
751 ARA::ARAPlugInInstanceRoleFlags assignedRoles);
752
753private:
754 class Impl;
756
758};
759
770
771} // namespace juce
772
773//==============================================================================
774#undef ARA_REF
775#undef ARA_HOST_REF
776
777#endif
Reference counting helper class to ensure that the DocumentController is in editable state.
Encapsulates an ARAFactory pointer and makes sure that it remains in a valid state for the lifetime o...
Wrapper class for ARA::Host::DocumentController.
ARA::Host::DocumentController & getDocumentController() const
Returns the underlying ARA::Host::DocumentController reference.
static std::unique_ptr< ARAHostDocumentController > create(ARAFactoryWrapper factory, const String &documentName, std::unique_ptr< ARA::Host::AudioAccessControllerInterface > audioAccessController, std::unique_ptr< ARA::Host::ArchivingControllerInterface > archivingController, std::unique_ptr< ARA::Host::ContentAccessControllerInterface > contentAccessController=nullptr, std::unique_ptr< ARA::Host::ModelUpdateControllerInterface > modelUpdateController=nullptr, std::unique_ptr< ARA::Host::PlaybackControllerInterface > playbackController=nullptr)
Factory function.
ARAHostModel::PlugInExtensionInstance bindDocumentToPluginInstance(AudioPluginInstance &instance, ARA::ARAPlugInInstanceRoleFlags knownRoles, ARA::ARAPlugInInstanceRoleFlags assignedRoles)
Binds the ARAHostDocumentController and its enclosed document to a plugin instance.
Base class for an active instance of a plugin.
The JUCE String class!
Definition juce_String.h:53
T destroy(T... args)
#define jassertfalse
This will always cause an assertion failure.
T make_unique(T... args)
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
void createARAFactoryAsync(AudioPluginInstance &instance, std::function< void(ARAFactoryWrapper)> cb)
Calls the provided callback with an ARAFactoryWrapper object obtained from the provided AudioPluginIn...
remove