3

Apple の Load Preset Demo サンプル コードに含まれる他の多くの機能に加えて、CFURLCreateDataAndPropertiesFromResource の呼び出しは非推奨になりました。しかし、私はそれに代わるものを見つけることができません - オプションをクリックしてもリファレンスを見ても、それがもはや行われたことではないことを教えてくれます。

CFDataRef propertyResourceData = 0;
Boolean status;
SInt32 errorCode = 0;
OSStatus result = noErr;

// Read from the URL and convert into a CFData chunk
status = CFURLCreateDataAndPropertiesFromResource (
                                                   kCFAllocatorDefault,
                                                   (__bridge CFURLRef) presetURL,
                                                   &propertyResourceData,
                                                   NULL,
                                                   NULL,
                                                   &errorCode
                                                   );


NSAssert (status == YES && propertyResourceData != 0, @"Unable to create data and properties from a preset. Error code: %d '%.4s'", (int) errorCode, (const char *)&errorCode);

// Convert the data object into a property list
CFPropertyListRef presetPropertyList = 0;
CFPropertyListFormat dataFormat = 0;
CFErrorRef errorRef = 0;
presetPropertyList = CFPropertyListCreateWithData (
                                                   kCFAllocatorDefault,
                                                   propertyResourceData,
                                                   kCFPropertyListImmutable,
                                                   &dataFormat,
                                                   &errorRef
                                                   );

// Set the class info property for the Sampler unit using the property list as the value.
if (presetPropertyList != 0) {

    result = AudioUnitSetProperty(
                                  self.samplerUnit,
                                  kAudioUnitProperty_ClassInfo,
                                  kAudioUnitScope_Global,
                                  0,
                                  &presetPropertyList,
                                  sizeof(CFPropertyListRef)
                                  );

    CFRelease(presetPropertyList);
}

if (errorRef) CFRelease(errorRef);
CFRelease (propertyResourceData);

return result;
4

3 に答える 3

5

プロパティの場合: CFURLCopyResourcePropertiesForKeys example property: kCFURLFileSizeKeyand kCFURLContentModificationDateKey、または Foundation-style with [NSURL resourceValuesForKeys:error:].

データの場合: +[NSData dataWithContentsOfURL:options:error:] .

それらは代替品として文書化されていません、AFAIK。これらの新しい代替 API のほとんどは、数年前から存在しています。

編集

編集で投稿したこの例では、プログラムはプロパティを要求しないため、必要なのは URL のデータだけですpresetURL

これは次の方法で実現できます。

NSURL * presetURL = ...;
// do review these options for your needs. you can make great
// optimizations if you use memory mapping or avoid unnecessary caching.
const NSDataReadingOptions DataReadingOptions = 0;
NSError * outError = nil;
NSData * data = [NSData dataWithContentsOfURL:presetURL
                                      options:DataReadingOptions
                                        error:&outError];

const bool status = nil != data; // << your `status` variable

if (!status) {
 // oops - an error was encountered getting the data see `outError`
}
else {
 // use the data
}
于 2013-09-26T21:29:01.900 に答える
0

以下を使用するだけで、さらに多くのコードを削除できることがわかりました。

OSStatus result = noErr;
NSData* data = [NSData dataWithContentsOfURL:presetURL];
id propertyList = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:NULL error:NULL];

// Set the class info property for the Sampler unit using the property list as the value.
if (propertyList) {
    result = AudioUnitSetProperty(
                                  self.samplerUnit,
                                  kAudioUnitProperty_ClassInfo,
                                  kAudioUnitScope_Global,
                                  0,
                                  (__bridge CFPropertyListRef)propertyList,
                                  sizeof(CFPropertyListRef)
                                  );
}

return result;
于 2014-11-11T16:51:14.760 に答える
-1

私はこのコードを使用してしまいまし

- (OSStatus) loadSynthFromPresetURL: (NSURL *) presetURL {

OSStatus result = noErr;

AUSamplerInstrumentData auPreset = {0};

auPreset.fileURL = (__bridge CFURLRef) presetURL;
auPreset.instrumentType = kInstrumentType_AUPreset;

result = AudioUnitSetProperty(self.samplerUnit,
                              kAUSamplerProperty_LoadInstrument,
                              kAudioUnitScope_Global,
                              0,
                              &auPreset,
                              sizeof(auPreset));

return result;
于 2015-04-24T11:32:57.600 に答える