+int CAAudioUnit::GetChannelInfo (AUChannelInfo** chaninfo, UInt32& cnt)
+{
+ // this is the default assumption of an audio effect unit
+ Boolean* isWritable = 0;
+ UInt32 dataSize = 0;
+ // lets see if the unit has any channel restrictions
+ OSStatus result = AudioUnitGetPropertyInfo (AU(),
+ kAudioUnitProperty_SupportedNumChannels,
+ kAudioUnitScope_Global, 0,
+ &dataSize, isWritable); //don't care if this is writable
+
+ // if this property is NOT implemented an FX unit
+ // is expected to deal with same channel valance in and out
+
+ if (result)
+ {
+ if (Comp().Desc().IsEffect())
+ {
+ return 1;
+ }
+ else if (Comp().Desc().IsGenerator() || Comp().Desc().IsMusicDevice()) {
+ // directly query Bus Formats
+ // Note that that these may refer to different subBusses
+ // (eg. Kick, Snare,.. on a Drummachine)
+ // eventually the Bus-Name for each configuration should be exposed
+ // for the User to select..
+
+ UInt32 elCountIn, elCountOut;
+
+ if (GetElementCount (kAudioUnitScope_Input, elCountIn)) return -1;
+ if (GetElementCount (kAudioUnitScope_Output, elCountOut)) return -1;
+
+ cnt = std::max(elCountIn, elCountOut);
+
+ *chaninfo = (AUChannelInfo*) malloc (sizeof (AUChannelInfo) * cnt);
+
+ for (unsigned int i = 0; i < elCountIn; ++i) {
+ UInt32 numChans;
+ if (NumberChannels (kAudioUnitScope_Input, i, numChans)) return -1;
+ (*chaninfo)[i].inChannels = numChans;
+ }
+ for (unsigned int i = elCountIn; i < cnt; ++i) {
+ (*chaninfo)[i].inChannels = 0;
+ }
+
+ for (unsigned int i = 0; i < elCountOut; ++i) {
+ UInt32 numChans;
+ if (NumberChannels (kAudioUnitScope_Output, i, numChans)) return -1;
+ (*chaninfo)[i].outChannels = numChans;
+ }
+ for (unsigned int i = elCountOut; i < cnt; ++i) {
+ (*chaninfo)[i].outChannels = 0;
+ }
+ return 0;
+ }
+ else
+ {
+ // the au should either really tell us about this
+ // or we will assume the worst
+ return -1;
+ }
+ }
+
+ *chaninfo = (AUChannelInfo*) malloc (dataSize);
+ cnt = dataSize / sizeof (AUChannelInfo);
+
+ result = GetProperty (kAudioUnitProperty_SupportedNumChannels,
+ kAudioUnitScope_Global, 0,
+ *chaninfo, &dataSize);
+
+ if (result) { return -1; }
+ return 0;
+}
+
+