我有一个带有MIDI音符的MusicTrack设置为MusicSequence,用MusicPlayer播放。当我尝试使用;
来调整速度时出现问题MusicTrackNewExtendedTempoEvent(musicTrack,0.0,newBPM);
显然这应该改变正在播放的MusicTrack中的TempoEvent,但事实并非如此。知道为什么会这样吗?
答案 0 :(得分:5)
首先必须从速度轨道中删除所有速度事件。
static void removeTempoEvents(MusicTrack tempoTrack){
MusicEventIterator tempIter;
NewMusicEventIterator(tempoTrack, &tempIter);
Boolean hasEvent;
MusicEventIteratorHasCurrentEvent(tempIter, &hasEvent);
while (hasEvent) {
MusicTimeStamp stamp;
MusicEventType type;
const void *data = NULL;
UInt32 sizeData;
MusicEventIteratorGetEventInfo(tempIter, &stamp, &type, &data, &sizeData);
if (type == kMusicEventType_ExtendedTempo){
MusicEventIteratorDeleteEvent(tempIter);
MusicEventIteratorHasCurrentEvent(tempIter, &hasEvent);
}
else{
MusicEventIteratorNextEvent(tempIter);
MusicEventIteratorHasCurrentEvent(tempIter, &hasEvent);
}
}
DisposeMusicEventIterator(tempIter);
}
static void setTempo(MusicSequence sequence,Float64 tempo){
MusicTrack tempoTrack;
MusicSequenceGetTempoTrack(sequence ,&tempoTrack);
removeTempoEvents(tempoTrack);
MusicTrackNewExtendedTempoEvent(tempoTrack,0, tempo);
}