我已经在MusicSequence中设置了带有MIDI Notes的MusicTrack,可以通过MusicPlayer进行播放。当我尝试通过使用来调整速度时,问题就来了。

MusicTrackNewExtendedTempoEvent(musicTrack,0.0,newBPM);

显然,这应该更改正在播放的MusicTrack中的TempoEvent,但不会更改。知道为什么会这样吗?

最佳答案

您首先必须从速度轨道中删除所有速度事件。

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);
}

10-07 16:50