                 if status != OSStatus(noErr) {
                     print("Error setting loopinfo on track \(status)")
                 }
-            }
-            
-            var trackLength: MusicTimeStamp = 0
-            var trackLengthSize: UInt32 = 0
-            
-            MusicSequenceGetIndTrack(sequence, i, &musicTrack)
-            MusicTrackGetProperty(musicTrack!, kSequenceTrackProperty_TrackLength, &trackLength, &trackLengthSize)
-            
-            if sequenceLength < trackLength {
-                sequenceLength = trackLength
             }
         }
         

    
    weak public var delegate: MIDIMessageListener?
    
    
    public var currentPositionInSeconds: TimeInterval {
        get {

        
        var musicTrack: MusicTrack? = nil
        var sequenceLength: MusicTimeStamp = 0
        var trackCount: UInt32 = 0
        MusicSequenceGetTrackCount(sequence, &trackCount)
        for i in 0 ..< trackCount {
            var trackLength: MusicTimeStamp = 0
            var trackLengthSize: UInt32 = 0
            
            MusicSequenceGetIndTrack(sequence, i, &musicTrack)
            MusicTrackGetProperty(musicTrack!, kSequenceTrackProperty_TrackLength, &trackLength, &trackLengthSize)
            
            if sequenceLength < trackLength {
                sequenceLength = trackLength
            }
            
            if enableLooping {
                var loopInfo = MusicTrackLoopInfo(loopDuration: 1, numberOfLoops: 0)
