2
我目前正在开发一个需要基于用户输入创建MusicSequence的应用程序,而且我目前在MusicSequenceFileCreate()上得到-1错误。 -1在MusicSequence引用中没有列为错误 - 我是否使用错误的格式打印OSStatus?使用MusicSequenceFileCreate()将音乐序列保存到.mid文件
任何帮助,非常感谢!我一直无法在网上找到很多关于将MusicSequence保存到.mid文件的参考信息...
我在最后得到错误。
OSStatus status = 0;
MusicSequence newSeq;
status = NewMusicSequence(&newSeq);
if(status){
printf("Error new sequence: %ld\n", status);
status = 0;
} else {
MusicSequenceSetSequenceType(newSeq, kMusicSequenceType_Seconds);
}
MusicTrack tempoTrack;
status = MusicSequenceGetTempoTrack(newSeq, &tempoTrack);
if(status){
printf("Error getting tempo track: %ld\n", status);
status = 0;
}
status = MusicTrackNewExtendedTempoEvent(tempoTrack, 0, 120);
if(status){
printf("Error adding tempo to track: %ld\n", status);
status = 0;
}
MusicTrack thisTrack;
status = MusicSequenceNewTrack(newSeq, &thisTrack);
if(status){
printf("Error adding main track: %ld\n", status);
status = 0;
}
for(int i = 0; i<convertThis.melodyPoints.count; i++) {
MIDINoteMessage thisMessage;
thisMessage.note = thisNote.midiNoteNumber;
thisMessage.duration = thisNote.duration;
thisMessage.velocity = 120;
thisMessage.releaseVelocity = 0;
thisMessage.channel = 1;
status = MusicTrackNewMIDINoteEvent(thisTrack, thisNoteBegin, &thisMessage);
if(status){
printf("Error adding midi note: %ld\n", status);
status = 0;
}
}
NSURL *thisurl = [NSURL URLWithString:[@"~/Documents" stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mid", convertThis.title]]];
status = MusicSequenceFileCreate(newSeq, (__bridge CFURLRef) thisurl, kMusicSequenceFile_MIDIType, kMusicSequenceFileFlags_EraseFile, 0);
if(status != noErr){
printf("Error on create: %ld\n", status);
status = 0;
}
当心,ARC用户。您可能只想__bridge(CFURLRef)投下,但那是错误的。 CFURLRef行可能会导致崩溃,因为xcode决定不再需要NSURL,因为它实际上并不存储在NSURL *中,所以ios会让它被破坏。您需要将NSURL *赋予其自己声明的对象,或使用不同的桥接方法。 – 2013-07-30 18:14:13
patchdiaz,这真的很有帮助,但是我得到-10846的最终状态错误值。任何想法可能是错的? – 2013-07-30 18:15:02
似乎错误是kAudioToolboxErr_InvalidSequenceType我相信这可能是MusicSequence的问题?您始终可以使用CAShow打印序列并查看是否一切正常。 – fdiaz 2013-08-06 17:22:53