/* * Copyright (c) 2006 Dave Dribin * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */#import "DDAudioComponent.h"#import "DDAudioException.h"#define THROW_IF DDThrowAudioIfErr@implementationDDAudioComponent+(NSArray*)componentsMatchingType:(OSType)typesubType:(OSType)subTypemanufacturer:(OSType)manufacturer;{AudioComponentDescriptiondescription;description.componentType=type;description.componentSubType=subType;description.componentManufacturer=manufacturer;description.componentFlags=0;description.componentFlagsMask=0;return[selfcomponentsMatchingDescription:&description];}+(NSArray*)componentsMatchingDescription:(AudioComponentDescription*)description;{UInt32componentCount=AudioComponentCount(description);NSMutableArray*components=[NSMutableArrayarrayWithCapacity:componentCount];AudioComponentcurrent=0;do{NSAutoreleasePool*loopPool=[[NSAutoreleasePoolalloc]init];current=AudioComponentFindNext(current,description);if(current!=0){DDAudioComponent*component=[[DDAudioComponentalloc]initWithComponent:current];[componentsaddObject:component];[componentrelease];}[loopPoolrelease];}while(current!=0);returncomponents;}+(void)printComponents;{OSTypetypes[]={kAudioUnitType_Output,kAudioUnitType_MusicDevice,kAudioUnitType_MusicEffect,kAudioUnitType_FormatConverter,kAudioUnitType_Effect,kAudioUnitType_Mixer,kAudioUnitType_Panner,kAudioUnitType_Generator,kAudioUnitType_OfflineEffect,};for(inti=0;i<(sizeof(types)/sizeof(*types));i++){OSTypetype=types[i];[selfprintComponentsMatchingType:type];}}+(NSString*)stringForOSType:(OSType)type{NSString*string=NSMakeCollectable(UTCreateStringForOSType(type));return[stringautorelease];}+(void)printComponentsMatchingType:(OSType)type;{NSArray*components=[selfcomponentsMatchingType:typesubType:0manufacturer:0];NSEnumerator*e=[componentsobjectEnumerator];DDAudioComponent*component;while(component=[enextObject]){AudioComponentDescriptiondescription=[componentAudioComponentDescription];NSString*type=[selfstringForOSType:description.componentType];NSString*subType=[selfstringForOSType:description.componentSubType];NSString*manufacturer=[selfstringForOSType:description.componentManufacturer];NSLog(@"Compoment %@ %@ %@: %@ by %@",type,subType,manufacturer,[componentname],[componentmanufacturer]);}}-(id)initWithComponent:(AudioComponent)component;{self=[superinit];if(self==nil)returnnil;mComponent=component;mManufacturer=@"";mName=@"";THROW_IF(AudioComponentGetDescription(component,&mDescription));CFStringRefcfFullName=NULL;THROW_IF(AudioComponentCopyName(component,&cfFullName));NSString*fullName=[NSMakeCollectable(cfFullName)autorelease];NSRangecolonRange=[fullNamerangeOfString:@":"];if(colonRange.location!=NSNotFound){mManufacturer=[fullNamesubstringToIndex:colonRange.location];mName=[fullNamesubstringFromIndex:colonRange.location+1];mName=[mNamestringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]];[mManufacturerretain];[mNameretain];}else{mManufacturer=@"";mName=[fullNamecopy];}returnself;}-(void)dealloc{[mManufacturerrelease];[mNamerelease];[superdealloc];}-(AudioComponent)AudioComponent;{returnmComponent;}-(AudioComponentDescription)AudioComponentDescription;{returnmDescription;}-(NSString*)manufacturer;{returnmManufacturer;}-(NSString*)name;{returnmName;}@end