Skip to content

Commit

Permalink
added a way to read a signed int to correctly read the key signature …
Browse files Browse the repository at this point in the history
…meta event
  • Loading branch information
luckyllama committed Jan 2, 2013
1 parent ee4a320 commit 18da67a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion midifile.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function MidiFile(data) {
case 0x59:
event.subtype = 'keySignature';
if (length != 2) throw "Expected length for keySignature event is 2, got " + length;
event.key = stream.readInt8();
event.key = stream.readInt8(true);
event.scale = stream.readInt8();
return event;
case 0x7f:
Expand Down
3 changes: 2 additions & 1 deletion stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ function Stream(str) {
}

/* read an 8-bit integer */
function readInt8() {
function readInt8(signed) {
var result = str.charCodeAt(position);
if (signed && result > 127) result -= 256;
position += 1;
return result;
}
Expand Down

0 comments on commit 18da67a

Please sign in to comment.