• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AudioFile.h and FSRef??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AudioFile.h and FSRef??


  • Subject: Re: AudioFile.h and FSRef??
  • From: Kurt Revis <email@hidden>
  • Date: Wed, 18 Sep 2002 21:24:41 -0700

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.

  • Follow-Ups:
    • Re: AudioFile.h and FSRef??
      • From: Pete Yandell <email@hidden>
  • Prev by Date: Re: Calculating size for MIDIPacketListAdd
  • Next by Date: Re: Calculating size for MIDIPacketListAdd
  • Previous by thread: Re: AudioFile.h and FSRef??
  • Next by thread: Re: AudioFile.h and FSRef??
  • Index(es):
    • Date
    • Thread