1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/*!********************************************************************
Audacity: A Digital Audio Editor
@file AudioUnitEffectsModule.cpp
Dominic Mazzoni
Leland Lucius
Paul Licameli split from AudioUnitEffect.
**********************************************************************/
#if USE_AUDIO_UNITS
#include "AudioUnitEffectsModule.h"
#include "AudioUnitEffectBase.h"
#include "ModuleManager.h"
#include <wx/log.h>
#include <wx/tokenzr.h>
#include "wxArrayStringEx.h"
#include <wx/osx/core/private.h>
static const struct
{
OSType componentManufacturer;
OSType componentType;
OSType componentSubType;
}
BlackList[] =
{
{ 'appl', 'augn', 'afpl' }, // Apple: AUAudioFilePlayer
{ 'appl', 'augn', 'sspl' }, // Apple: AUScheduledSoundPlayer
{ 'appl', 'augn', 'ttsp' }, // Apple: AUSpeechSynthesis
{ 'appl', 'augn', 'nrcv' }, // Apple: AUNetReceive
{ 'appl', 'aumx', '3dmx' }, // Apple: AUMixer3D
{ 'appl', 'aumx', 'mspl' }, // Apple: AUMultiSplitter
{ 'appl', 'aumx', 'mcmx' }, // Apple: AUMultiChannelMixer
{ 'appl', 'aumx', 'mxmx' }, // Apple: AUMatrixMixer
{ 'appl', 'aumx', 'smxr' }, // Apple: AUMixer
{ 'Ignt', 'aufx', 'PTQX' }, // Ignite Amps PTEq-X
};
// ============================================================================
// Module registration entry point
//
// This is the symbol that Audacity looks for when the module is built as a
// dynamic library.
//
// When the module is builtin to Audacity, we use the same function, but it is
// declared static so as not to clash with other builtin modules.
// ============================================================================
DECLARE_PROVIDER_ENTRY(AudacityModule)
{
// Create and register the importer
// Trust the module manager not to leak this
return std::make_unique<AudioUnitEffectsModule>();
}
// ============================================================================
// Register this as a builtin module
// ============================================================================
DECLARE_BUILTIN_PROVIDER(AudioUnitEffectsBuiltin);
///////////////////////////////////////////////////////////////////////////////
//
// AudioUnitEffectsModule
//
///////////////////////////////////////////////////////////////////////////////
namespace
{
wxString FromOSType(OSType type)
{
OSType rev = (type & 0xff000000) >> 24 |
(type & 0x00ff0000) >> 8 |
(type & 0x0000ff00) << 8 |
(type & 0x000000ff) << 24;
return wxString::FromUTF8(reinterpret_cast<char *>(&rev), 4);
}
OSType ToOSType(const wxString & type)
{
wxCharBuffer buf = type.ToUTF8();
OSType rev = ((unsigned char)buf.data()[0]) << 24 |
((unsigned char)buf.data()[1]) << 16 |
((unsigned char)buf.data()[2]) << 8 |
((unsigned char)buf.data()[3]);
return rev;
}
AudioComponent FindAudioUnit(const PluginPath & path,
wxString & name)
{
wxStringTokenizer tokens(path, wxT("/"));
AudioComponentDescription desc;
desc.componentManufacturer = ToOSType(tokens.GetNextToken());
desc.componentType = ToOSType(tokens.GetNextToken());
desc.componentSubType = ToOSType(tokens.GetNextToken());
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
name = tokens.GetNextToken();
return AudioComponentFindNext(NULL, &desc);
}
}
AudioUnitEffectsModule::AudioUnitEffectsModule()
{
}
AudioUnitEffectsModule::~AudioUnitEffectsModule()
{
}
// ============================================================================
// ComponentInterface implementation
// ============================================================================
PluginPath AudioUnitEffectsModule::GetPath() const
{
return {};
}
ComponentInterfaceSymbol AudioUnitEffectsModule::GetSymbol() const
{
/* i18n-hint: Audio Unit is the name of an Apple audio software protocol */
return XO("Audio Unit Effects");
}
VendorSymbol AudioUnitEffectsModule::GetVendor() const
{
return XO("The Audacity Team");
}
wxString AudioUnitEffectsModule::GetVersion() const
{
// This "may" be different if this were to be maintained as a separate DLL
return AUDIOUNITEFFECTS_VERSION;
}
TranslatableString AudioUnitEffectsModule::GetDescription() const
{
return XO("Provides Audio Unit Effects support to Audacity");
}
// ============================================================================
// PluginProvider implementation
// ============================================================================
const FileExtensions &AudioUnitEffectsModule::GetFileExtensions()
{
static FileExtensions result{{ _T("au") }};
return result;
}
bool AudioUnitEffectsModule::Initialize()
{
// Nothing to do here
return true;
}
void AudioUnitEffectsModule::Terminate()
{
// Nothing to do here
return;
}
EffectFamilySymbol AudioUnitEffectsModule::GetOptionalFamilySymbol()
{
#if USE_AUDIO_UNITS
return AUDIOUNITEFFECTS_FAMILY;
#else
return {};
#endif
}
void AudioUnitEffectsModule::AutoRegisterPlugins(PluginManagerInterface &)
{
}
PluginPaths AudioUnitEffectsModule::FindModulePaths(PluginManagerInterface &)
{
PluginPaths effects;
LoadAudioUnitsOfType(kAudioUnitType_Effect, effects);
LoadAudioUnitsOfType(kAudioUnitType_Generator, effects);
LoadAudioUnitsOfType(kAudioUnitType_Mixer, effects);
LoadAudioUnitsOfType(kAudioUnitType_MusicEffect, effects);
LoadAudioUnitsOfType(kAudioUnitType_Panner, effects);
return effects;
}
unsigned AudioUnitEffectsModule::DiscoverPluginsAtPath(
const PluginPath & path, TranslatableString &errMsg,
const RegistrationCallback &callback)
{
errMsg = {};
wxString name;
AudioComponent component = FindAudioUnit(path, name);
if (component == NULL)
{
errMsg = XO("Could not find component");
return 0;
}
AudioUnitEffectBase effect(path, name, component);
if (!effect.InitializePlugin())
{
// TODO: Is it worth it to discriminate all the ways SetHost might
// return false?
errMsg = XO("Could not initialize component");
return 0;
}
if (callback)
{
callback(this, &effect);
}
return 1;
}
std::unique_ptr<ComponentInterface>
AudioUnitEffectsModule::LoadPlugin(const PluginPath & path)
{
// Acquires a resource for the application.
if (wxString name; auto component = FindAudioUnit(path, name)) {
auto result = Factory::Call(path, name, component);
result->InitializePlugin();
return result;
}
return nullptr;
}
bool AudioUnitEffectsModule::CheckPluginExist(const PluginPath& path) const
{
wxString unused;
return FindAudioUnit(path, unused) != nullptr;
}
// ============================================================================
// AudioUnitEffectsModule implementation
// ============================================================================
void AudioUnitEffectsModule::LoadAudioUnitsOfType(OSType inAUType,
PluginPaths & effects)
{
AudioComponentDescription desc;
AudioComponent component;
desc.componentType = inAUType;
desc.componentSubType = 0;
desc.componentManufacturer = 0;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
component = AudioComponentFindNext(NULL, &desc);
while (component != NULL)
{
OSStatus result;
AudioComponentDescription found;
result = AudioComponentGetDescription(component, &found);
if (result == noErr)
{
CFStringRef cfName{};
result = AudioComponentCopyName(component, &cfName);
CF_ptr<CFStringRef> uName{ cfName };
if (result == noErr) {
wxString path;
path.Printf(wxT("%-4.4s/%-4.4s/%-4.4s/%s"),
FromOSType(found.componentManufacturer),
FromOSType(found.componentType),
FromOSType(found.componentSubType),
wxCFStringRef::AsString(cfName));
for (int i = 0; i < WXSIZEOF(BlackList); ++i) {
if (BlackList[i].componentType == found.componentType &&
BlackList[i].componentSubType == found.componentSubType &&
BlackList[i].componentManufacturer ==
found.componentManufacturer) {
wxLogDebug(wxT("Blacklisted AU skipped: %s"), path);
result = !noErr;
break;
}
}
if (result == noErr)
effects.push_back(path);
}
}
component = AudioComponentFindNext(component, &desc);
}
}
#endif
|