nfroidure / midifile

A MIDI file parser/writer using ArrayBuffers
http://karaoke.insertafter.com
MIT License
199 stars 30 forks source link

variable declared twice #6

Closed yukulele closed 8 years ago

yukulele commented 8 years ago

variable format declared twice on https://github.com/nfroidure/MIDIFile/blob/master/src/MIDIFileHeader.js#L52-L53

nfroidure commented 8 years ago

@yukulele thanks for reviewing but why not simply make a PR ?

yukulele commented 8 years ago

I'm not sure between

MIDIFileHeader.prototype.setFormat=function(format) {
    if(0!==format&&1!==format&&2!==format) {
        throw new Error('Invalid MIDI format given ('+format+'),'
            +' format can be 0, 1 or 2 only.');
    }
    return format;
};

and

MIDIFileHeader.prototype.setFormat=function(format) {
    if(format == null)
        format=this.datas.getUint16(8);
    if(0!==format&&1!==format&&2!==format) {
        throw new Error('Invalid MIDI format given ('+format+'),'
            +' format can be 0, 1 or 2 only.');
    }
    return format;
};
nfroidure commented 8 years ago

Looks like there is a mistake in the original code since its purpose is to set the format and not to read it:

MIDIFileHeader.prototype.setFormat=function(format) {
    if(0!==format&&1!==format&&2!==format) {
        throw new Error('Invalid MIDI format given ('+format+'),'
            +' format can be 0, 1 or 2 only.');
    }
    this.datas.setUint16(8, format);
};

Feel free to PR this, otherwise i'll try to find some time to do this.

yukulele commented 8 years ago

done