Skip to content

Commit

Permalink
AudioUnitBackend: Load music effects too
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Nov 15, 2024
1 parent 028e3ff commit 5d20ec3
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/effects/backends/audiounit/audiounitbackend.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// An effects backend for Audio Unit (AU) plugins. macOS-only.
class AudioUnitBackend : public EffectsBackend {
public:
AudioUnitBackend() : m_componentsById([[NSDictionary alloc] init]) {
AudioUnitBackend() : m_componentsById([[NSMutableDictionary alloc] init]) {
loadAudioUnits();
}

Expand Down Expand Up @@ -59,18 +59,23 @@ bool canInstantiateEffect(const QString& effectId) const override {
}

private:
NSDictionary<NSString*, AVAudioUnitComponent*>* m_componentsById;
NSMutableDictionary<NSString*, AVAudioUnitComponent*>* m_componentsById;
QHash<QString, EffectManifestPointer> m_manifestsById;

void loadAudioUnits() {
qDebug() << "Loading audio units...";

loadAudioUnitsOfType(kAudioUnitType_Effect);
loadAudioUnitsOfType(kAudioUnitType_MusicEffect);
}

void loadAudioUnitsOfType(OSType componentType) {
// See
// https://developer.apple.com/documentation/audiotoolbox/audio_unit_v3_plug-ins/incorporating_audio_effects_and_instruments?language=objc

// Create a query for audio components
AudioComponentDescription description = {
.componentType = kAudioUnitType_Effect,
.componentType = componentType,
.componentSubType = 0,
.componentManufacturer = 0,
.componentFlags = 0,
Expand All @@ -85,10 +90,6 @@ void loadAudioUnits() {
auto components = [manager componentsMatchingDescription:description];

// Assign ids to the components
NSMutableDictionary<NSString*, AVAudioUnitComponent*>* componentsById =
[[NSMutableDictionary alloc] init];
QHash<QString, EffectManifestPointer> manifestsById;

for (AVAudioUnitComponent* component in components) {
qDebug() << "Found audio unit" << [component name];

Expand All @@ -97,13 +98,10 @@ void loadAudioUnits() {
[component manufacturerName],
[component name],
[component versionString]]);
componentsById[effectId.toNSString()] = component;
manifestsById[effectId] = EffectManifestPointer(
m_componentsById[effectId.toNSString()] = component;
m_manifestsById[effectId] = EffectManifestPointer(
new AudioUnitManifest(effectId, component));
}

m_componentsById = componentsById;
m_manifestsById = manifestsById;
}
};

Expand Down

0 comments on commit 5d20ec3

Please sign in to comment.