         }
         if let existingTempoTrack = tempoTrack {
             MusicTrackClear(existingTempoTrack, 0, length.beats)
+            clearTempoEvents(existingTempoTrack)
             MusicTrackNewExtendedTempoEvent(existingTempoTrack, 0, constrainedTempo)
         }
     }

        let timeSignatureMetaEventByte: UInt8 = 0x58
        let metaEventType = kMusicEventType_Meta

        AKMusicTrack.iterateMusicTrack(track) {iterator, _, eventType, eventData, _ in
            guard eventType == metaEventType else { return }

            let data = UnsafePointer<MIDIMetaEvent>(eventData?.assumingMemoryBound(to: MIDIMetaEvent.self))


            if dataMetaEventType == timeSignatureMetaEventByte {
                MusicEventIteratorDeleteEvent(iterator)
                isReadyForNextEvent = false
            }
        }
    }
