From e312817b6f3d95e928dfde119934e7657092e7cc Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 1 Oct 2024 08:07:58 +0200 Subject: [PATCH] A few more tweaks for AU hosting, WIP Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginAU.cpp | 73 ++++++++++++++++++---- source/discovery/carla-discovery.cpp | 81 ++++++++++++++++++++----- source/utils/CarlaStateUtils.cpp | 5 +- 3 files changed, 132 insertions(+), 27 deletions(-) diff --git a/source/backend/plugin/CarlaPluginAU.cpp b/source/backend/plugin/CarlaPluginAU.cpp index 675b8ae5ce..8660883bc4 100644 --- a/source/backend/plugin/CarlaPluginAU.cpp +++ b/source/backend/plugin/CarlaPluginAU.cpp @@ -260,11 +260,8 @@ class CarlaPluginAU : public CarlaPlugin, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global, 0, &outDataSize, &outWritable) == noErr - /* && outDataSize != 0 - && outDataSize % sizeof(AUChannelInfo) == 0 - */ - ) + && outDataSize % sizeof(AUChannelInfo) == 0) { const uint32_t numChannels = outDataSize / sizeof(AUChannelInfo); AUChannelInfo* const channelInfo = new AUChannelInfo[numChannels]; @@ -279,12 +276,17 @@ class CarlaPluginAU : public CarlaPlugin, { AUChannelInfo* highestInfo = &channelInfo[0]; - carla_stdout("getProperty returns {%u,%u}... config", + carla_stdout("kAudioUnitProperty_SupportedNumChannels returns {%d,%d}... config", channelInfo[0].inChannels, channelInfo[0].outChannels); - for (uint32_t i=1; i highestInfo->inChannels && channelInfo[i].outChannels > highestInfo->outChannels) { @@ -292,20 +294,69 @@ class CarlaPluginAU : public CarlaPlugin, } } - audioIns = highestInfo->inChannels; - audioOuts = highestInfo->outChannels; + audioIns = std::min(64, highestInfo->inChannels); + audioOuts = std::min(64, highestInfo->outChannels); } else { - carla_stdout("getProperty failed"); + carla_stdout("kAudioUnitProperty_SupportedNumChannels failed"); } delete[] channelInfo; } else { - carla_stdout("kAudioUnitProperty_SupportedNumChannels returns no configs, assume stereo"); - audioIns = audioOuts = 2; + outDataSize = 0; + if (fFunctions.getPropertyInfo(fInterface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Input, + 0, &outDataSize, &outWritable) == noErr + && outDataSize == sizeof(UInt32)) + { + UInt32 count = 0; + if (fFunctions.getProperty(fInterface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Input, + 0, &count, &outDataSize) == noErr + && outDataSize == sizeof(UInt32) && count != 0) + { + AudioStreamBasicDescription desc; + std::memset(&desc, 0, sizeof(desc)); + outDataSize = sizeof(AudioStreamBasicDescription); + + if (fFunctions.getProperty(fInterface, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, &desc, &outDataSize) == noErr) + audioIns = std::min(64, desc.mChannelsPerFrame); + } + } + + outDataSize = 0; + if (fFunctions.getPropertyInfo(fInterface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Output, + 0, &outDataSize, &outWritable) == noErr + && outDataSize == sizeof(UInt32)) + { + UInt32 count = 0; + if (fFunctions.getProperty(fInterface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Output, + 0, &count, &outDataSize) == noErr + && outDataSize == sizeof(UInt32) && count != 0) + { + AudioStreamBasicDescription desc; + std::memset(&desc, 0, sizeof(desc)); + outDataSize = sizeof(AudioStreamBasicDescription); + + if (fFunctions.getProperty(fInterface, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Output, + 0, &desc, &outDataSize) == noErr) + audioOuts = std::min(64, desc.mChannelsPerFrame); + } + } } if (audioIns > 0) diff --git a/source/discovery/carla-discovery.cpp b/source/discovery/carla-discovery.cpp index 5ab21dd35b..440064ccff 100644 --- a/source/discovery/carla-discovery.cpp +++ b/source/discovery/carla-discovery.cpp @@ -2182,8 +2182,13 @@ static bool do_au_check(const char* const filename, const bool doInit) { AUChannelInfo* highestInfo = &channelInfo[0]; - for (uint32_t i=1; i highestInfo->inChannels && channelInfo[i].outChannels > highestInfo->outChannels) { @@ -2191,12 +2196,70 @@ static bool do_au_check(const char* const filename, const bool doInit) } } - audioIns = highestInfo->inChannels; - audioOuts = highestInfo->outChannels; + audioIns = std::min(64, highestInfo->inChannels); + audioOuts = std::min(64, highestInfo->outChannels); } delete[] channelInfo; } + else + { + // unsupported for now + interface->Close(interface); + continue; + + outDataSize = 0; + if (auGetPropertyInfo(interface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Input, + 0, &outDataSize, &outWritable) == noErr + && outDataSize == sizeof(UInt32)) + { + UInt32 count = 0; + if (auGetProperty(interface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Input, + 0, &count, &outDataSize) == noErr + && outDataSize == sizeof(UInt32) && count != 0) + { + AudioStreamBasicDescription desc; + std::memset(&desc, 0, sizeof(desc)); + outDataSize = sizeof(AudioStreamBasicDescription); + + if (auGetProperty(interface, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, &desc, &outDataSize) == noErr) + audioIns = std::min(64, desc.mChannelsPerFrame); + } + } + + outDataSize = 0; + if (auGetPropertyInfo(interface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Output, + 0, &outDataSize, &outWritable) == noErr + && outDataSize == sizeof(UInt32)) + { + UInt32 count = 0; + if (auGetProperty(interface, + kAudioUnitProperty_ElementCount, + kAudioUnitScope_Output, + 0, &count, &outDataSize) == noErr + && outDataSize == sizeof(UInt32) && count != 0) + { + AudioStreamBasicDescription desc; + std::memset(&desc, 0, sizeof(desc)); + outDataSize = sizeof(AudioStreamBasicDescription); + + if (auGetProperty(interface, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Output, + 0, &desc, &outDataSize) == noErr) + audioOuts = std::min(64, desc.mChannelsPerFrame); + } + } + } // parameter count outDataSize = 0; @@ -2292,17 +2355,7 @@ static bool do_au_check(const char* const filename, const bool doInit) if (doInit) { - // test valid scopes - outDataSize = 0; - if (auGetPropertyInfo(interface, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &outDataSize, &outWritable) == noErr && outDataSize == sizeof(UInt32)) - { - UInt32 count = 0; - if (auGetProperty(interface, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &count, &outDataSize) == noErr && outDataSize == sizeof(UInt32) && count != 0) - { - } - } - - // TODO + // TODO tests } const CFIndex componentNameLen = CFStringGetLength(componentName); diff --git a/source/utils/CarlaStateUtils.cpp b/source/utils/CarlaStateUtils.cpp index 419991ae0c..8a87da8532 100644 --- a/source/utils/CarlaStateUtils.cpp +++ b/source/utils/CarlaStateUtils.cpp @@ -1,6 +1,6 @@ /* * Carla State utils - * Copyright (C) 2012-2023 Filipe Coelho + * Copyright (C) 2012-2024 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -310,7 +310,7 @@ bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement) name = xmlSafeStringCharDup(text, false); else if (tag == "Label" || tag == "URI" || tag == "Identifier" || tag == "Setup") label = xmlSafeStringCharDup(text, false); - else if (tag == "Binary" || tag == "Filename") + else if (tag == "Binary" || tag == "Bundle" || tag == "Filename") binary = xmlSafeStringCharDup(text, false); else if (tag == "UniqueID") uniqueId = text.getLargeIntValue(); @@ -594,6 +594,7 @@ void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const infoXml << " \n"; break; case PLUGIN_AU: + infoXml << " " << xmlSafeString(binary, true) << "\n"; infoXml << " " << xmlSafeString(label, true) << "\n"; break; case PLUGIN_CLAP: