'Note's positions are shifted after AppleSequencer.genData()

I have issue with notes position after "regenerating" midi via AppleSequencer.

New midi (regenerated), which were created from original midi, have different "notes" position. Please have a look at this code:

let keysToExport: AppleSequencer = ... // AppleSequencer
let generatedMIDI = AppleSequencer(fromData: keysToExport.genData()!)
print(keysToExport.tracks[0].getMIDINoteData().suffix(10).map { $0.position.beats })
print(generatedMIDI.tracks[0].getMIDINoteData().suffix(10).map { $0.position.beats })

Output:

[668.0008163265306, 669.0, 669.0000907029479, 669.0004081632653, 670.0, 670.0000907029479, 670.0002721088435, 671.0001814058957, 671.002902494331, 671.0151927437641]
[667.7395629882812, 668.7395629882812, 668.7395629882812, 668.7395629882812, 669.7395629882812, 669.7395629882812, 669.7395629882812, 670.7374877929688, 670.7395629882812, 670.7520751953125]

It's clear that the difference isn't just "floating-point error" -- the notes are really shifted.

I'll be glad if someone provide me the solution of my problem. I know, that this isn't AudioKit's problem because AppleSequencer is just a wrapper of MusicSequence, but maybe someone faced this problem and have a solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source