         MusicTrackGetSequence(internalMusicTrack, seqPtr)
         MusicSequenceNewTrack(tmpSeq, &tmpTrack)
         MusicTrackSetProperty(tmpTrack, kSequenceTrackProperty_TrackLength, &len, size)
-        MusicTrackCopyInsert(internalMusicTrack, 0, len, tmpTrack, 0)
-        self.clear()
-        MusicTrackSetProperty(internalMusicTrack, kSequenceTrackProperty_TrackLength, &len, size)
-        MusicTrackCopyInsert(tmpTrack, 0, len, internalMusicTrack, 0)
-        MusicSequenceDisposeTrack(tmpSeq, tmpTrack)
-
-        DisposeMusicSequence(tmpSeq)
-
-        //now to clean up any notes that are too long
-        var iterator: MusicEventIterator = nil
-        NewMusicEventIterator(internalMusicTrack, &iterator)
-        var eventTime = MusicTimeStamp(0)
-        var eventType = MusicEventType()
-        var eventData: UnsafePointer<Void> = nil
-        var eventDataSize: UInt32 = 0
-        var hasNextEvent: DarwinBoolean = false
-
-        MusicEventIteratorHasCurrentEvent(iterator, &hasNextEvent)
-
-        while(hasNextEvent) {
-            MusicEventIteratorGetEventInfo(iterator, &eventTime, &eventType, &eventData, &eventDataSize)
-
-            if eventType == kMusicEventType_MIDINoteMessage {
-                let data = UnsafePointer<MIDINoteMessage>(eventData)
-                let channel = data.memory.channel
-                let note = data.memory.note
-                let velocity = data.memory.velocity
-                let dur = data.memory.duration
-
-                if eventTime + dur > duration.beats {
-                    var newNote = MIDINoteMessage(channel: channel, note: note, velocity: velocity, releaseVelocity: 0, duration: Float32(duration.beats - eventTime))
-                    MusicEventIteratorSetEventInfo(iterator, eventType, &newNote)
+        
+        if !isEmpty {
+            MusicTrackCopyInsert(internalMusicTrack, 0, len, tmpTrack, 0)
+            clear()
+            MusicTrackSetProperty(internalMusicTrack, kSequenceTrackProperty_TrackLength, &len, size)
+            MusicTrackCopyInsert(tmpTrack, 0, len, internalMusicTrack, 0)
+            MusicSequenceDisposeTrack(tmpSeq, tmpTrack)
+            
+            DisposeMusicSequence(tmpSeq)
+            
+            //now to clean up any notes that are too long
+            var iterator: MusicEventIterator = nil
+            NewMusicEventIterator(internalMusicTrack, &iterator)
+            var eventTime = MusicTimeStamp(0)
+            var eventType = MusicEventType()
+            var eventData: UnsafePointer<Void> = nil
+            var eventDataSize: UInt32 = 0
+            var hasNextEvent: DarwinBoolean = false
+            
+            MusicEventIteratorHasCurrentEvent(iterator, &hasNextEvent)
+            
+            while(hasNextEvent) {
+                MusicEventIteratorGetEventInfo(iterator, &eventTime, &eventType, &eventData, &eventDataSize)
+                
+                if eventType == kMusicEventType_MIDINoteMessage {
+                    let data = UnsafePointer<MIDINoteMessage>(eventData)
+                    let channel = data.memory.channel
+                    let note = data.memory.note
+                    let velocity = data.memory.velocity
+                    let dur = data.memory.duration
+                    
+                    if eventTime + dur > duration.beats {
+                        var newNote = MIDINoteMessage(channel: channel, note: note, velocity: velocity, releaseVelocity: 0, duration: Float32(duration.beats - eventTime))
+                        MusicEventIteratorSetEventInfo(iterator, eventType, &newNote)
+                    }
                 }
+                
+                MusicEventIteratorNextEvent(iterator)
+                MusicEventIteratorHasCurrentEvent(iterator, &hasNextEvent)
             }
-
-            MusicEventIteratorNextEvent(iterator)
-            MusicEventIteratorHasCurrentEvent(iterator, &hasNextEvent)
-        }
-        DisposeMusicEventIterator(iterator)
+            DisposeMusicEventIterator(iterator)
+        }
     }
 
     /// A less destructive and simpler way to set the length


    /// Clear all events from the track
    public func clear() {
        if !isEmpty {
            MusicTrackClear(internalMusicTrack, 0, length)
        }
        clearMetaEvents()
    }
    
    func clearMetaEvents(){

        var eventData: UnsafePointer<Void> = nil
        var eventDataSize: UInt32 = 0
        var hasNextEvent: DarwinBoolean = false
        MusicEventIteratorHasCurrentEvent(iterator, &hasNextEvent)
        while(hasNextEvent) {
            MusicEventIteratorGetEventInfo(iterator, &eventTime, &eventType, &eventData, &eventDataSize)
            
            outBool = false
            //print("time is \(eventTime) - type is \(eventType)")
            //print("data is \(eventData)")
            MusicEventIteratorNextEvent(iterator)
            MusicEventIteratorHasCurrentEvent(iterator, &hasNextEvent)
        }
