【问题标题】:How to change MIDI TEMPO on the fly? [CoreMIDI] iOS如何即时更改 MIDI TEMPO? [CoreMIDI] iOS
【发布时间】:2015-06-04 16:50:07
【问题描述】:

我在 MusicSequence 中设置了带有 MIDI 音符的 MusicTrack,它正在使用 MusicPlayer 播放。当我尝试通过使用来调整速度时,问题就来了;

MusicTrackNewExtendedTempoEvent(musicTrack, 0.0, newBPM);

显然这应该改变正在播放的 MusicTrack 中的 TempoEvent,但它没有。知道为什么会发生这种情况吗?

【问题讨论】:

    标签: ios objective-c midi coremidi


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多