LMMS
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)) || 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
37
38//==============================================================================
39namespace juce
40{
59class ARAEditGuard
60{
61public:
62 explicit ARAEditGuard (ARA::Host::DocumentController& dcIn);
63 ~ARAEditGuard();
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//==============================================================================
111template <typename Base, typename PtrIn>
112class ManagedARAHandle
113{
114public:
115 using Ptr = PtrIn;
116
118 ManagedARAHandle (ARA::Host::DocumentController& dc, Ptr ptr) noexcept
119 : handle (ptr, Deleter { dc }) {}
120
122 auto& getDocumentController() const { return handle.get_deleter().documentController; }
123
125 Ptr getPluginRef() const { return handle.get(); }
126
127private:
128 struct Deleter
129 {
130 void operator() (Ptr ptr) const noexcept
131 {
132 const ARAEditGuard guard (documentController);
133 Base::destroy (documentController, ptr);
134 }
135
136 ARA::Host::DocumentController& documentController;
137 };
138
139 std::unique_ptr<std::remove_pointer_t<Ptr>, Deleter> handle;
140};
141
142//==============================================================================
159class AudioSource : public ManagedARAHandle<AudioSource, ARA::ARAAudioSourceRef>
160{
161public:
168 static constexpr auto getEmptyProperties() { return makeARASizedStruct (&ARA::ARAAudioSourceProperties::merits64BitSamples); }
169
181 AudioSource (ARA::ARAAudioSourceHostRef hostRef,
182 ARA::Host::DocumentController& dc,
183 const ARA::ARAAudioSourceProperties& props);
184
186 ~AudioSource() = default;
187
195 void update (const ARA::ARAAudioSourceProperties& props);
196
201 void enableAudioSourceSamplesAccess (bool);
202
208 static void destroy (ARA::Host::DocumentController&, Ptr);
209};
210
227class AudioModification : public ManagedARAHandle<AudioModification, ARA::ARAAudioModificationRef>
228{
229public:
236 static constexpr auto getEmptyProperties()
237 {
238 return makeARASizedStruct (&ARA::ARAAudioModificationProperties::persistentID);
239 }
240
252 AudioModification (ARA::ARAAudioModificationHostRef hostRef,
253 ARA::Host::DocumentController& dc,
254 AudioSource& s,
255 const ARA::ARAAudioModificationProperties& props);
256
264 void update (const ARA::ARAAudioModificationProperties& props);
265
267 auto& getAudioSource() const { return source; }
268
274 static void destroy (ARA::Host::DocumentController&, Ptr);
275
276private:
277 AudioSource& source;
278};
279
283struct DeletionListener
284{
286 virtual ~DeletionListener() = default;
287
289 virtual void removeListener (DeletionListener& other) noexcept = 0;
290};
291
308struct PlaybackRegion
309{
310public:
317 static constexpr auto getEmptyProperties()
318 {
319 return makeARASizedStruct (&ARA::ARAPlaybackRegionProperties::color);
320 }
321
322 PlaybackRegion (ARA::ARAPlaybackRegionHostRef hostRef,
323 ARA::Host::DocumentController& dc,
324 AudioModification& m,
325 const ARA::ARAPlaybackRegionProperties& props);
326
327 ~PlaybackRegion();
328
336 void update (const ARA::ARAPlaybackRegionProperties& props);
337
345 void addListener (DeletionListener& x);
346
348 auto& getAudioModification() const;
349
351 ARA::ARAPlaybackRegionRef getPluginRef() const noexcept;
352 DeletionListener& getDeletionListener() const noexcept;
353
354private:
355 class Impl;
356
357 std::unique_ptr<Impl> impl;
358};
359
376class MusicalContext : public ManagedARAHandle<MusicalContext, ARA::ARAMusicalContextRef>
377{
378public:
385 static constexpr auto getEmptyProperties()
386 {
387 return makeARASizedStruct (&ARA::ARAMusicalContextProperties::color);
388 }
389
401 MusicalContext (ARA::ARAMusicalContextHostRef hostRef,
402 ARA::Host::DocumentController& dc,
403 const ARA::ARAMusicalContextProperties& props);
404
412 void update (const ARA::ARAMusicalContextProperties& props);
413
419 static void destroy (ARA::Host::DocumentController&, Ptr);
420};
421
438class RegionSequence : public ManagedARAHandle<RegionSequence, ARA::ARARegionSequenceRef>
439{
440public:
447 static constexpr auto getEmptyProperties()
448 {
449 return makeARASizedStruct (&ARA::ARARegionSequenceProperties::color);
450 }
451
463 RegionSequence (ARA::ARARegionSequenceHostRef hostRef,
464 ARA::Host::DocumentController& dc,
465 const ARA::ARARegionSequenceProperties& props);
466
474 void update (const ARA::ARARegionSequenceProperties& props);
475
481 static void destroy (ARA::Host::DocumentController&, Ptr);
482};
483
484//==============================================================================
533template <typename RendererRef, typename Interface>
534class PlaybackRegionRegistry
535{
536public:
537 PlaybackRegionRegistry() = default;
538
539 PlaybackRegionRegistry (RendererRef rendererRefIn, const Interface* interfaceIn)
540 : registry (std::make_unique<Registry> (rendererRefIn, interfaceIn))
541 {
542 }
543
549 void add (PlaybackRegion& region) { registry->add (region); }
550
556 void remove (PlaybackRegion& region) { registry->remove (region); }
557
559 bool isValid() { return registry->isValid(); }
560
561private:
562 class Registry : private DeletionListener
563 {
564 public:
565 Registry (RendererRef rendererRefIn, const Interface* interfaceIn)
566 : rendererRef (rendererRefIn), rendererInterface (interfaceIn)
567 {
568 }
569
570 Registry (const Registry&) = delete;
571 Registry (Registry&&) noexcept = delete;
572
573 Registry& operator= (const Registry&) = delete;
574 Registry& operator= (Registry&&) noexcept = delete;
575
576 ~Registry() override
577 {
578 for (const auto& region : regions)
579 doRemoveListener (*region.first);
580 }
581
582 bool isValid() { return rendererRef != nullptr && rendererInterface != nullptr; }
583
584 void add (PlaybackRegion& region)
585 {
586 if (isValid())
587 rendererInterface->addPlaybackRegion (rendererRef, region.getPluginRef());
588
589 regions.emplace (&region.getDeletionListener(), region.getPluginRef());
590 region.addListener (*this);
591 }
592
593 void remove (PlaybackRegion& region)
594 {
595 doRemoveListener (region.getDeletionListener());
596 }
597
598 private:
599 void doRemoveListener (DeletionListener& listener) noexcept
600 {
601 listener.removeListener (*this);
602 removeListener (listener);
603 }
604
605 void removeListener (DeletionListener& listener) noexcept override
606 {
607 const auto it = regions.find (&listener);
608
609 if (it == regions.end())
610 {
612 return;
613 }
614
615 if (isValid())
616 rendererInterface->removePlaybackRegion (rendererRef, it->second);
617
618 regions.erase (it);
619 }
620
621 RendererRef rendererRef = nullptr;
622 const Interface* rendererInterface = nullptr;
623 std::map<DeletionListener*, ARA::ARAPlaybackRegionRef> regions;
624 };
625
626 std::unique_ptr<Registry> registry;
627};
628
629//==============================================================================
638using PlaybackRendererInterface = PlaybackRegionRegistry<ARA::ARAPlaybackRendererRef, ARA::ARAPlaybackRendererInterface>;
639
640//==============================================================================
649using EditorRendererInterface = PlaybackRegionRegistry<ARA::ARAEditorRendererRef, ARA::ARAEditorRendererInterface>;
650
651//==============================================================================
657class PlugInExtensionInstance final
658{
659public:
664 PlugInExtensionInstance() = default;
665
671 explicit PlugInExtensionInstance (const ARA::ARAPlugInExtensionInstance* instanceIn)
672 : instance (instanceIn)
673 {
674 }
675
683 PlaybackRendererInterface getPlaybackRendererInterface() const;
684
692 EditorRendererInterface getEditorRendererInterface() const;
693
697 bool isValid() const noexcept { return instance != nullptr; }
698
699private:
700 const ARA::ARAPlugInExtensionInstance* instance = nullptr;
701};
702
703} // namespace ARAHostModel
704
705//==============================================================================
714class ARAHostDocumentController final
715{
716public:
721 static std::unique_ptr<ARAHostDocumentController>
722 create (ARAFactoryWrapper factory,
723 const String& documentName,
724 std::unique_ptr<ARA::Host::AudioAccessControllerInterface> audioAccessController,
725 std::unique_ptr<ARA::Host::ArchivingControllerInterface> archivingController,
726 std::unique_ptr<ARA::Host::ContentAccessControllerInterface> contentAccessController = nullptr,
727 std::unique_ptr<ARA::Host::ModelUpdateControllerInterface> modelUpdateController = nullptr,
728 std::unique_ptr<ARA::Host::PlaybackControllerInterface> playbackController = nullptr);
729
730 ~ARAHostDocumentController();
731
733 ARA::Host::DocumentController& getDocumentController() const;
734
743 ARAHostModel::PlugInExtensionInstance bindDocumentToPluginInstance (AudioPluginInstance& instance,
744 ARA::ARAPlugInInstanceRoleFlags knownRoles,
745 ARA::ARAPlugInInstanceRoleFlags assignedRoles);
746
747private:
748 class Impl;
749 std::unique_ptr<Impl> impl;
750
751 explicit ARAHostDocumentController (std::unique_ptr<Impl>&& implIn);
752};
753
763void createARAFactoryAsync (AudioPluginInstance& instance, std::function<void (ARAFactoryWrapper)> cb);
764
765} // namespace juce
766
767//==============================================================================
768#undef ARA_REF
769#undef ARA_HOST_REF
770
771#endif
#define noexcept
Definition DistrhoDefines.h:72
#define final
Definition DistrhoDefines.h:74
unsigned * m
Definition inflate.c:1559
unsigned s
Definition inflate.c:1555
unsigned x[BMAX+1]
Definition inflate.c:1586
static PuglViewHint int value
Definition pugl.h:1708
#define JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE(...)
Definition juce_CompilerWarnings.h:181
#define JUCE_END_IGNORE_WARNINGS_GCC_LIKE
Definition juce_CompilerWarnings.h:182
#define jassertfalse
#define A(x)
Definition lice_arc.cpp:13
Definition carla_juce.cpp:31
constexpr Obj makeARASizedStruct(Member Obj::*member, Ts &&... ts)
Definition juce_ARACommon.h:79
void add(SampleFrame *dst, const SampleFrame *src, int frames)
Add samples from src to dst.
Definition MixHelpers.cpp:135
@ B
Definition Note.h:59
#define const
Definition zconf.h:137