Re: AudioFile.h and FSRef??
Re: AudioFile.h and FSRef??
- Subject: Re: AudioFile.h and FSRef??
- From: Pete Yandell <email@hidden>
- Date: Thu, 19 Sep 2002 23:34:53 +1000
I made myself a little extension to NSString to make this easy.
NSStringFSSpec.h:
#import <AppKit/AppKit.h>
@interface NSString(Carbon_Additions)
- (bool)makeFSSpec:(FSSpec*)specPtr;
@end
NSStringFSSpec.m:
#import "NSStringFSSpec.h"
@implementation NSString(Carbon_Additions)
- (bool)makeFSSpec:(FSSpec*)specPtr
{
OSStatus status;
FSRef fsref;
status = FSPathMakeRef ([self fileSystemRepresentation], &fsref,
NULL);
if (status != noErr) return false;
status = FSGetCatalogInfo (&fsref, kFSCatInfoNone, NULL, NULL,
specPtr, NULL);
if (status != noErr) return false;
return true;
}
@end
Then you can just import NSStringFSSpec.h and use [string
makeFSSpec:&myFSSpec]...hides the carbon side of things from you pretty
nicely.
It should be easy to add an initWithFSSpec: method to do the conversion
the other way. I'll leave that as an exercise for the reader. :)
On Thursday, September 19, 2002, at 02:24 PM, Kurt Revis wrote:
>
On Wednesday, September 18, 2002, at 04:06 PM,
>
email@hidden wrote:
>
>
> I was looking at the AudioFile.h routines and wondered why FSRef
>
> types are being used. I am confused as to why it appears that Carbon
>
> is *required* for this particular OS X development, especially since
>
> it was announced to be an easy porting solution. In addition, it
>
> seems quite a small thing to have added support for Cocoa or UNIX
>
> types in these calls.
>
>
I agree with you that it would be nicer if something nicer like a
>
CFURL were used instead. I filed a bug on this a while ago, but it was
>
marked "not to be fixed" (or something equivalent). I can deal with
>
it as it is, but I wouldn't mind knowing the rationale.
>
>
In any case, it really won't hurt to link against Carbon, since if
>
you're using Cocoa you're effectively dragging in a bunch of Carbon
>
anyway.
>
>
Here are functions to convert UNIX paths (in CFStrings) to and from
>
FSRefs. If you have a path in an NSString, you can just cast the
>
(NSString *) to a CFStringRef (look up "toll-free bridging" for more
>
details). If you have a CFURL or NSURL, it should be pretty obvious
>
what to do.
>
>
(credit: these are slightly modified versions of functions in BDAlias:
>
http://bdistributed.com/Projects/BDAlias/)
>
>
#include <Carbon/Carbon.h>
>
#include <CoreFoundation/CoreFoundation.h>
>
>
OSStatus PathToFSRef(CFStringRef inPath, FSRef *outRef)
>
{
>
CFURLRef tempURL = NULL;
>
Boolean gotRef = false;
>
>
tempURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
>
inPath, kCFURLPOSIXPathStyle, false);
>
>
if (tempURL == NULL)
>
return fnfErr;
>
>
gotRef = CFURLGetFSRef(tempURL, outRef);
>
>
CFRelease(tempURL);
>
>
if (!gotRef)
>
return fnfErr;
>
>
return noErr;
>
}
>
>
CFStringRef FSRefToPathCopy(const FSRef *inRef)
>
{
>
CFURLRef tempURL = NULL;
>
CFStringRef result = NULL;
>
>
if (inRef != NULL) {
>
tempURL = CFURLCreateFromFSRef(kCFAllocatorDefault, inRef);
>
if (tempURL) {
>
result = CFURLCopyFileSystemPath(tempURL,
>
kCFURLPOSIXPathStyle);
>
CFRelease(tempURL);
>
}
>
}
>
>
return result;
>
}
>
>
>
> I've been staying away from Carbon on purpose so unless there's some
>
> workaround I think I'll wait until I can use them with Cocoa or UNIX!
>
>
I wouldn't hold your breath. This is really not such a big problem.
>
>
--
>
Kurt Revis
>
email@hidden
>
_______________________________________________
>
coreaudio-api mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
Do not post admin requests to the list. They will be ignored.
>
>
Pete Yandell
http://pete.yandell.com/
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.