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_ARACommon.cpp
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#if (JUCE_PLUGINHOST_ARA && (JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU) && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX))
27
28namespace juce
29{
30
31static void dummyARAInterfaceAssert (ARA::ARAAssertCategory, const void*, const char*)
32{}
33
34static ARA::ARAInterfaceConfiguration createInterfaceConfig (const ARA::ARAFactory* araFactory)
35{
37
38 #if ARA_VALIDATE_API_CALLS
39 assertFunction = &::ARA::ARAInterfaceAssert;
40 static std::once_flag flag;
41 std::call_once (flag, [] { ARA::ARASetExternalAssertReference (&assertFunction); });
42 #endif
43
44 return makeARASizedStruct (&ARA::ARAInterfaceConfiguration::assertFunctionAddress,
45 jmin (araFactory->highestSupportedApiGeneration, (ARA::ARAAPIGeneration) ARA::kARAAPIGeneration_2_X_Draft),
47}
48
49/* If the provided ARAFactory is not yet in use it constructs a new shared_ptr that will call the
50 provided onDelete function inside the custom deleter of this new shared_ptr instance.
51
52 The onDelete function is responsible for releasing the resources that guarantee the validity of
53 the wrapped ARAFactory*.
54
55 If however the ARAFactory is already in use the function will just return a copy of the already
56 existing shared_ptr and call the onDelete function immediately. This is to ensure that the
57 ARAFactory is only uninitialised when no plugin instance can be using it.
58
59 On both platforms the onDelete function is used to release resources that ensure that the module
60 providing the ARAFactory* remains loaded.
61*/
62static std::shared_ptr<const ARA::ARAFactory> getOrCreateARAFactory (const ARA::ARAFactory* ptr,
63 std::function<void()> onDelete)
64{
66
68
69 auto& cachePtr = cache[ptr];
70
71 if (const auto obj = cachePtr.lock())
72 {
73 onDelete();
74 return obj;
75 }
76
77 const auto interfaceConfig = createInterfaceConfig (ptr);
78 ptr->initializeARAWithConfiguration (&interfaceConfig);
79 const auto obj = std::shared_ptr<const ARA::ARAFactory> (ptr, [deleter = std::move (onDelete)] (const ARA::ARAFactory* factory)
80 {
81 factory->uninitializeARA();
82 deleter();
83 });
84 cachePtr = obj;
85 return obj;
86}
87
88}
89
90#endif
T call_once(T... args)
#define JUCE_ASSERT_MESSAGE_THREAD
This macro is used to catch unsafe use of functions which expect to only be called on the message thr...
JUCE Namespace.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
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