Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The track |toBytes| function was not having into account the end-of-t…
…rack bytes
  • Loading branch information
sergi committed Nov 4, 2010
1 parent d5cdfa3 commit 3472e0b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions midi.js
Expand Up @@ -313,10 +313,15 @@ MidiTrack.prototype = {
metaEvents.forEach(addEventBytes);
midiEvents.forEach(addEventBytes);

return MidiTrack.TRACK_START.concat(
str2Bytes(trackLength.toString(16), 4),
eventBytes,
MidiTrack.TRACK_END);
// Add the end-of-track bytes to the sum of bytes for the track, since
// they are counted (unlike the start-of-track ones).
trackLength += endBytes.length;

// Makes sure that track length will fill up 4 bytes with 0s in case
// the length is less than that (the usual case).
var lengthBytes = str2Bytes(trackLength.toString(16), 4),

return startBytes.concat(lengthBytes, eventBytes, endBytes);
}
};

Expand Down

0 comments on commit 3472e0b

Please sign in to comment.