abudaan / heartbeat

a javascript MIDI/Audio sequencer for your browser
http://abudaan.github.io/heartbeat/
121 stars 20 forks source link

Errors with recordedEvents/Notes objects around 6395 and 6406 in keyEditor Snapshots #4

Closed TimVen closed 9 years ago

TimVen commented 10 years ago

In function KeyEditor.prototype.getSnapshot 'recordedEventsSong' and 'recordedNotesSong' are sometimes undefined throwing an error. This happens when loading new songs and removing old ones

for a quick fix i've added an 'if' block around the objects so they are not called

recordedEventsSong = this.song.recordedEvents;
        **if(recordedEventsSong){**
            length = recordedEventsSong.length;
            for(i = 0; i < length; i++){
                tmp = recordedEventsSong[i];
                if(this.recordedEventsObj[tmp.id] === undefined){
                    tmp.bbox = this.getEventRect(tmp);
                    recordedEvents.push(tmp);
                    this.recordedEventsObj[tmp.id] = tmp;
                }
            }
        }

recordedNotesSong = this.song.recordedNotes;
        **if(recordedNotesSong){**
            length = recordedNotesSong.length;
            for(i = 0; i < length; i++){
                tmp = recordedNotesSong[i];
                if(this.recordedNotesObj[tmp.id] === undefined){
                    this.recordedNotesObj[tmp.id] = tmp;
                    tmp.bbox = this.getNoteRect(tmp);
                    recordedNotes.push(tmp);
                    //console.log('recordedNotes', tmp);
                }else if(tmp.endless === true){
                    tmp.bbox = this.getNoteRect(tmp);
                    recordingNotes.push(tmp);
                    //console.log('endless1', tmp);
                }else if(tmp.endless === false){
                    tmp.bbox = this.getNoteRect(tmp);
                    recordingNotes.push(tmp);
                    //console.log('endless2', tmp);
                    tmp.endless = undefined;
                }
                //console.log(tmp.bbox.width);
            }
        }