我正在尝试从简单的MusicSequence
生成MIDI文件。这是我的代码:
MusicSequence mySequence;
MusicTrack myTrack;
NewMusicSequence(&mySequence);
MusicSequenceNewTrack(mySequence, &myTrack);
MIDINoteMessage noteMessage;
MusicTimeStamp timestamp = 0;
noteMessage.channel = 0;
noteMessage.note = 60;
noteMessage.velocity = 90;
noteMessage.releaseVelocity = 0;
noteMessage.duration = 4;
if (MusicTrackNewMIDINoteEvent(myTrack, timestamp, ¬eMessage) != noErr) NSLog(@"ERROR creating the note");
else NSLog(@"Note added");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *midiPath = [documentsDirectory
stringByAppendingPathComponent:@"testfile.mid"];
CFURLRef midiURL = (__bridge CFURLRef)([[NSURL alloc] initFileURLWithPath:midiPath]);
OSStatus status = 0;
status = MusicSequenceFileCreate(mySequence, midiURL, kMusicSequenceFile_MIDIType, kMusicSequenceFileFlags_EraseFile, 0);
if(status != noErr){
printf("Error on create: %d\n", (int)status);
status = 0;
}
我的代码在MusicSequenceFileCreate
处失败。
这是我得到的错误:
线程1:EXC_BAD_ACCESS(代码= EXC_I386_GPFLT)
我该如何克服?
答案 0 :(得分:0)
这似乎是MIDI URL定义的错误。我将该行更改为此,现在可以使用。
CFURLRef midiURL = (__bridge CFURLRef)([NSURL fileURLWithPath:midiPath]);