Open page200 opened 2 months ago
Thanks for discovering this! Yeah, the original formula is really bad style. That is not a notation humans should have to parse.
With event.time, it could be confused with wall clock time of the event happening or being scheduled for. How about position, trackPosition or something like that?
Thanks for helping here, feel free to PR a fix, I'll merge asap.
The following code resets
playTime
to0
when the Format isn't2
. https://github.com/nfroidure/midifile/blob/11fd971355e3faa6a912b8546cd0baafba2b1899/src/MIDIFile.js#L90-L91(
That's good, becauseall tracks should play simultaneously if the Format isn't2
. Edit: The simultaneity of tracks isn't handled by resettingplayTime
to0
(and this code isn't reached by Format 1 anyway, although it might get reached by corrupt Format 0 files that have several tracks in spite of Format 0). The simultaneity of tracks is handled by thesmallestDelta
loop below.)However, the code comment says the opposite: "reset playtime if format is 2".
That comment should be changed, I guess.Edit: I don't know whether the users of Format 2 want to restart theplayTime
for each track. The comment implies that they do, and in that case the code should be changed to match the comment, although maybe the users have gotten used to the current code behavior. The current code probably has no effect, it setsplayTime
to0
only when it's already0
, if I'm not mistaken.To make the code clearer in that regard, it should be replaced by something like
(
What seems a bigger problem is thatthat code is currently inside aif (1 !== format || 1 === this.tracks.length)
condition,so it would not execute when it is most important: when Format is 1 and there are multiple tracks. Maybe the current version hasn't been tested on such files, or am I missing something?Edit: Format 1 with multiple tracks is handled by thesmallestDelta
loop.)While we're at it, can we rename
playTime
(andevent.playTime
) to something liketime
(andevent.time
)? "Play" is an appropriate word for Note On events, but most other events don't "play" in the normal sense. It's even confusing for Note Off events, because "playTime
" seems like the duration for which the note has been playing.Edit: TL;DR: The plan was probably to reset
playTime
to0
at the start of each track of Format 2 files. I haven't checked whether that's common. In any case, this didn't happen due to a bug, and maybe the users have gotten used to that.