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

            print("could not start avSeq")
        }
    }
    public func stop(){
//        MusicPlayerStop(musicPlayer)
        avSeq.stop()
    }
    public func rewind(){
//        MusicPlayerSetTime(musicPlayer, 0)
        avSeq.currentPositionInBeats = 0
    }
    
    public func setGlobalMidiOutput(midiEndpoint:MIDIEndpointRef){
//        for trackInd in tracks{
//            MusicTrackSetDestMIDIEndpoint(trackInd.internalMusicTrack, midiEndpoint)
//        }

 */
public class AKSequencer {
    
    /// Music sequence
    public var sequence:MusicSequence = nil
    
    /// Pointer to Music Sequence
    public var sequencePointer:UnsafeMutablePointer<MusicSequence>
    
    /// AVAudioSequencer
    public var avSeq = AVAudioSequencer()
    
    /// Array of AudioKit Music Tracks
    public var tracks:[AKMusicTrack] = []
    
    /// Array of AVMusicTracks
    public var rawTracks:[AVMusicTrack] {
        return avSeq.tracks
    }
    
    /// Musci Player
    var musicPlayer:MusicPlayer = nil
    
    /// Loop control
    public var loopEnabled:Bool = false
    
    /// Sequencer Initialization
    public init() {
        NewMusicSequence(&sequence)
        sequencePointer = UnsafeMutablePointer<MusicSequence>(sequence)
