             print("could not start avSeq")
         }
     }
-    public func stop(){
+    
+    /// Stop the sequence
+    public func stop() {
 //        MusicPlayerStop(musicPlayer)
         avSeq.stop()
     }
-    public func rewind(){
+    
+    /// Rewind the sequence
+    public func rewind() {
 //        MusicPlayerSetTime(musicPlayer, 0)
         avSeq.currentPositionInBeats = 0
     }
     
-    public func setGlobalMidiOutput(midiEndpoint:MIDIEndpointRef){
+    /// Set the midi output for all tracks
+    public func setGlobalMidiOutput(midiEndpoint: MIDIEndpointRef) {
 //        for trackInd in tracks{
 //            MusicTrackSetDestMIDIEndpoint(trackInd.internalMusicTrack, midiEndpoint)
 //        }

        return Double(length)
    }
    
    public func play(){
//        MusicPlayerStart(musicPlayer)
        do{
            try avSeq.start()

        MusicPlayerSetSequence(musicPlayer, sequence)
    }
    
    /// Initialize the sequence with a MIDI file
    public convenience init(filename: String) {
        self.init()
        loadMidiFile(filename)
    }
    
    /// Initialize the sequence with a midi file and audioengine
    public convenience init(filename: String, engine: AVAudioEngine) {
        self.init()
        avSeq = AVAudioSequencer(audioEngine: engine)
        loadMidiFile(filename)
    }
    
    /// Set loop functionality of entire sequence
    public func loopToggle(){
        (loopEnabled ? loopOff() : loopOn())
    }
    
    /// Enable looping for all tracks
    public func loopOn() {
        setLoopInfo(length, numberOfLoops: 0)
        for track in avSeq.tracks{
            track.loopingEnabled = true
            track.loopRange = AVMakeBeatRange(0, self.length)
        }
        loopEnabled = true
    }
    
    /// Disable looping for all tracks
    public func loopOff() {
        setLoopInfo(0, numberOfLoops: 0)
        for track in avSeq.tracks{
            track.loopingEnabled = false
        }
        loopEnabled = false
    }
    
    ///  Set looping duration and count for all tracks
    public func setLoopInfo(duration: Double, numberOfLoops: Int) {
        let size:UInt32 = 0
        let len = MusicTimeStamp(duration)
        var loopInfo = MusicTrackLoopInfo(loopDuration: len, numberOfLoops: Int32(numberOfLoops))
        for( var i = 0; i < self.numberOfTracks; ++i){
            var musicTrack = MusicTrack()
            MusicSequenceGetIndTrack(sequence, UInt32(i), &musicTrack)
            MusicTrackSetProperty(musicTrack, kSequenceTrackProperty_LoopInfo, &loopInfo, size)
        }
    }
    /// Set length of all tracks
    public func setLength(length: Double) {
        let size:UInt32 = 0
        var len = MusicTimeStamp(length)
        for( var i = 0; i < self.numberOfTracks; ++i){
            var musicTrack = MusicTrack()
            MusicSequenceGetIndTrack(sequence, UInt32(i), &musicTrack)
            MusicTrackSetProperty(musicTrack, kSequenceTrackProperty_TrackLength, &len, size)
