I need to delete all tempo events from an AKSequencer instance but I can't find a way to do it.
I tried to use the clearRange() method as shown below but I'm not sure it is the right way because it won't work:
var sequencer = AKSequencer()
// successfully adding a few tempo events with addTempoEventAt(tempo bpm: Double, position: AKDuration)
...
// trying to remove them
let sequenceLength = sequencer.length
sequencer.clearRange(start: AKDuration(beats: 0.0), duration: sequenceLength)
Is there something I am missing?
Unfortunately
clearRange()removes note events and meta events but, as you observed, it does not remove tempo events (the next version of the docs will make this explicit - thank you for catching this).AKSequencerhas a privateclearTempoEventsmethod called internally by thesetTempo()method, so you can usesetTempo()to clear all the existing tempo events. Of course, after removing the existing tempo events, this will also add a new tempo event at the start of the sequence with the tempo you include as an argument.So it won't exactly give you a sequence with no tempo events - but a sequence needs a tempo and with no tempo events it will default to 120 - so forcing you to be explicit about the starting tempo isn't such a bad thing. Anyway, unless you really need for there to be absolutely no tempo events,
setTempo()should do the trick for clearing all existing tempo events in the sequence.