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