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

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

        return tempoOut
    }

    /// returns an array of (MusicTimeStamp, bpm) tuples
    /// for all tempo events on the tempo track
    open var allTempoEvents: [(MusicTimeStamp, Double)] {
        var tempoTrack: MusicTrack?
        guard let existingSequence = sequence else { return [] }
        MusicSequenceGetTempoTrack(existingSequence, &tempoTrack)
        guard tempoTrack != nil else { return [] }
        
        var tempos = [(MusicTimeStamp, Double)]()
        
        AKMusicTrack.iterateMusicTrack(tempoTrack!) { _, eventTime, eventType, eventData, _, _ in
            if eventType == kMusicEventType_ExtendedTempo {
                if let data = eventData?.assumingMemoryBound(to: ExtendedTempoEvent.self) {
                    let tempoEventPointer: UnsafePointer<ExtendedTempoEvent> = UnsafePointer(data)
                    tempos.append((eventTime, tempoEventPointer.pointee.bpm))
                }
            }
        }
        return tempos
    }

    /// returns the tempo at a given position in beats
    /// - parameter at: Position at which the tempo is desired
    open func getTempo(at position: MusicTimeStamp) -> Double {
        // MIDI file with no tempo events defaults to 120 bpm
        var tempoAtPosition: Double = 120.0
        for event in allTempoEvents {
            if event.0 <= position {
                tempoAtPosition = event.1
            } else {
                break
            }
        }

        return tempoAtPosition
    }
    
    // Remove existing tempo events
    func clearTempoEvents(_ track: MusicTrack) {
        AKMusicTrack.iterateMusicTrack(track) {iterator, _, eventType, eventData, _, hasDeletedEvent in
            hasDeletedEvent = false
            if eventType == kMusicEventType_ExtendedTempo {
                MusicEventIteratorDeleteEvent(iterator)
                hasDeletedEvent = true
            }
        }
    }

    /// Possible values for the time signature lower value
