0

I am loading a midi file in AKAppleSequencer which has a tempo of 80 BPM.

I checked the sequencer.length.seconds property and it shows the length of the file in seconds. In my case the file is 33 seconds long and the length.seconds property shows the same.

I have a timer that fires every 0.1 seconds and checks the sequencer.currentPosition.seconds property when the file is played

I noticed something strange, the sequencer.currentPosition.seconds property increments faster than actual clock seconds. Why is this happening?

When I timed it with a stopwatch, my midi file which is supposed to play 33 seconds finishes in 24 seconds (approximately).

On my sequencer, I don't have any tempo, rate set on the sequencer.

When I set the tempo to 60 BPM using sequencer.setTempo(60), the sequencer.currentPosition.seconds property updates every seconds at the right speed. This creates another problem, now the length.seconds property shows 41 (increased value) instead of original 33 which is expected on changing tempo.

I haven't tried this but if I set the tempo to greater than 80, I think the file playback will be even faster.

Anjali Shah
  • 720
  • 7
  • 21
Sarang Borude
  • 329
  • 1
  • 12
  • "If I set the tempo to greater than 80, I think the file playback will be even faster" - This is literally the definition 'increasing the tempo'. I think you might be confused about what you're measuring. Try using AKAppleSequencer.allTempoEvents to confirm that the tempo events are as expected in your MIDI file. It sounds like your file is actually playing back at 120bpm. A ~33s seq at 80bpm will be ~41s at 60bpm and ~22s at 120bpm – c_booth Mar 06 '20 at 12:15
  • I don't think you get, I understand setting the tempo faster will shorten the midi file length. but for some reason when I check the currentPositions property it appears to go faster than a second. Say for example if the file's new duration after changing the tempo is 21 seconds, it will finish in like 14. I will post a gif today if it helps explain the issue better. – Sarang Borude Mar 06 '20 at 17:32
  • The issue is that a playback second as observed in a recurring timer on sequencer.currentPosition.seconds feels faster if the tempo is higher than 60 BPM – Sarang Borude Mar 06 '20 at 17:38
  • Fair enough. Is the currentPosition (in beats not in seconds) accurate? When you set the tempo to 60bpm, 80bpm etc, does it play at 60bpm, 80bpm etc? Does this behaviour hold for other MIDI files or just this one file? Does the behaviour hold for sequences you constructed programmatically? Again, try checking AKAppleSequencer.allTempoEvents. A cluster of tempo events might account for this behaviour. – c_booth Mar 06 '20 at 18:47
  • Thanks, your advice pointed me to something interesting. Seems like a bug in AKDuration. I calculated current position manually calculatedCurrentPositionInSeconds = (sequencer.currentPosition.beats/sequencer.tempo) * 60 I printed out Print(calculatedCurrentPosition, sequencer.currentPosition.seconds) Here is the output of the last 3 lines 54.75047402399985, 63.875578231292515 54.85050193999985, 63.992290249433104 54.95022631499986, 64.10863945578231 ideally they should be the same. right? – Sarang Borude Mar 06 '20 at 23:01

0 Answers0