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_AudioPluginFormatManager.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
26namespace juce
27{
28
29AudioPluginFormatManager::AudioPluginFormatManager() {}
31
32//==============================================================================
34{
35 #if JUCE_PLUGINHOST_VST && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD || JUCE_IOS)
36 #define HAS_VST 1
37 #else
38 #define HAS_VST 0
39 #endif
40
41 #if JUCE_PLUGINHOST_VST3 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD)
42 #define HAS_VST3 1
43 #else
44 #define HAS_VST3 0
45 #endif
46
47 #if JUCE_PLUGINHOST_AU && (JUCE_MAC || JUCE_IOS)
48 #define HAS_AU 1
49 #else
50 #define HAS_AU 0
51 #endif
52
53 #if JUCE_PLUGINHOST_LADSPA && (JUCE_LINUX || JUCE_BSD)
54 #define HAS_LADSPA 1
55 #else
56 #define HAS_LADSPA 0
57 #endif
58
59 #if JUCE_PLUGINHOST_LV2 && (JUCE_MAC || JUCE_LINUX || JUCE_BSD || JUCE_WINDOWS)
60 #define HAS_LV2 1
61 #else
62 #define HAS_LV2 0
63 #endif
64
65 #if JUCE_DEBUG
66 // you should only call this method once!
67 for (auto* format [[maybe_unused]] : formats)
68 {
69 #if HAS_VST
70 jassert (dynamic_cast<VSTPluginFormat*> (format) == nullptr);
71 #endif
72
73 #if HAS_VST3
74 jassert (dynamic_cast<VST3PluginFormat*> (format) == nullptr);
75 #endif
76
77 #if HAS_AU
78 jassert (dynamic_cast<AudioUnitPluginFormat*> (format) == nullptr);
79 #endif
80
81 #if HAS_LADSPA
82 jassert (dynamic_cast<LADSPAPluginFormat*> (format) == nullptr);
83 #endif
84
85 #if HAS_LV2
86 jassert (dynamic_cast<LV2PluginFormat*> (format) == nullptr);
87 #endif
88 }
89 #endif
90
91 #if HAS_AU
92 formats.add (new AudioUnitPluginFormat());
93 #endif
94
95 #if HAS_VST
96 formats.add (new VSTPluginFormat());
97 #endif
98
99 #if HAS_VST3
100 formats.add (new VST3PluginFormat());
101 #endif
102
103 #if HAS_LADSPA
104 formats.add (new LADSPAPluginFormat());
105 #endif
106
107 #if HAS_LV2
108 formats.add (new LV2PluginFormat());
109 #endif
110}
111
112int AudioPluginFormatManager::getNumFormats() const { return formats.size(); }
113AudioPluginFormat* AudioPluginFormatManager::getFormat (int index) const { return formats[index]; }
114
121
123{
124 formats.add (format);
125}
126
128 double rate, int blockSize,
129 String& errorMessage) const
130{
131 if (auto* format = findFormatForDescription (description, errorMessage))
132 return format->createInstanceFromDescription (description, rate, blockSize, errorMessage);
133
134 return {};
135}
136
139{
140 String errorMessage;
141
142 if (auto* format = findFormatForDescription (description, errorMessage))
143 {
144 format->createARAFactoryAsync (description, callback);
145 }
146 else
147 {
148 errorMessage = NEEDS_TRANS ("Couldn't find format for the provided description");
149 callback ({ {}, std::move (errorMessage) });
150 }
151}
152
156{
157 String error;
158
159 if (auto* format = findFormatForDescription (description, error))
160 return format->createPluginInstanceAsync (description, initialSampleRate, initialBufferSize, std::move (callback));
161
162 struct DeliverError final : public CallbackMessage
163 {
164 DeliverError (AudioPluginFormat::PluginCreationCallback c, const String& e)
165 : call (std::move (c)), error (e)
166 {
167 post();
168 }
169
170 void messageCallback() override { call (nullptr, error); }
171
173 String error;
174 };
175
176 new DeliverError (std::move (callback), error);
177}
178
179AudioPluginFormat* AudioPluginFormatManager::findFormatForDescription (const PluginDescription& description,
180 String& errorMessage) const
181{
182 errorMessage = {};
183
184 for (auto* format : formats)
185 if (format->getName() == description.pluginFormatName
186 && format->fileMightContainThisPluginType (description.fileOrIdentifier))
187 return format;
188
189 errorMessage = NEEDS_TRANS ("No compatible plug-in format exists for this plug-in");
190
191 return {};
192}
193
195{
196 for (auto* format : formats)
197 if (format->getName() == description.pluginFormatName)
198 return format->doesPluginStillExist (description);
199
200 return false;
201}
202
203} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
void addArray(const Type *elementsToAdd, int numElementsToAdd)
Adds elements from an array to the end of this array.
Definition juce_Array.h:583
Array< AudioPluginFormat * > getFormats() const
Returns a list of all the registered formats.
AudioPluginFormat * getFormat(int index) const
Returns one of the available formats.
int getNumFormats() const
Returns the number of types of format that are available.
bool doesPluginStillExist(const PluginDescription &) const
Checks that the file or component for this plugin actually still exists.
void addFormat(AudioPluginFormat *)
Adds a format to the list.
std::unique_ptr< AudioPluginInstance > createPluginInstance(const PluginDescription &description, double initialSampleRate, int initialBufferSize, String &errorMessage) const
Tries to load the type for this description, by trying all the formats that this manager knows about.
void createARAFactoryAsync(const PluginDescription &description, AudioPluginFormat::ARAFactoryCreationCallback callback) const
Tries to create an ::ARAFactoryWrapper for this description.
void createPluginInstanceAsync(const PluginDescription &description, double initialSampleRate, int initialBufferSize, AudioPluginFormat::PluginCreationCallback callback)
Tries to asynchronously load the type for this description, by trying all the formats that this manag...
void addDefaultFormats()
Adds the set of available standard formats, e.g.
The base class for a type of plugin format, such as VST, AudioUnit, LADSPA, etc.
Implements a plugin format manager for AudioUnits.
A message that invokes a callback method when it gets delivered.
Implements a plugin format manager for LADSPA plugins.
Implements a plugin format for LV2 plugins.
A small class to represent some facts about a particular type of plug-in.
String pluginFormatName
The plug-in format, e.g.
The JUCE String class!
Definition juce_String.h:53
Implements a plugin format for VST3s.
Implements a plugin format manager for VSTs.
#define NEEDS_TRANS(stringLiteral)
A dummy version of the TRANS macro, used to indicate a string literal that should be added to the tra...
#define jassert(expression)
Platform-independent assertion macro.
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