Skip to content

Commit

Permalink
overdue fixes
Browse files Browse the repository at this point in the history
-Fixed first note not playing (mudcube#165)
-Fixed issue where progress bar would skip silent lead-in
  • Loading branch information
silverhawk184 committed Jan 1, 2018
1 parent a8a8425 commit c28d720
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions js/midi/player.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
----------------------------------------------------------
MIDI.Player : 0.3.1 : 2015-03-26
MIDI.Player : 0.3.2 : 2017-12-31
----------------------------------------------------------
https://github.com/mudcube/MIDI.js
----------------------------------------------------------
Expand All @@ -19,6 +19,9 @@ midi.playing = false;
midi.timeWarp = 1;
midi.startDelay = 0;
midi.BPM = 120;
midi.playingStartTime = 0;
midi.ctxStartTime = 0;
midi.lastCallbackTime = 0;

midi.start =
midi.resume = function(onsuccess) {
Expand Down Expand Up @@ -82,22 +85,23 @@ midi.setAnimation = function(callback) {
currentTime = midi.currentTime;
}
///
var endTime = midi.endTime;
var percent = currentTime / endTime;
var total = currentTime / 1000;
var minutes = total / 60;
var seconds = total - (minutes * 60);
var t1 = minutes * 60 + seconds;
var t2 = (endTime / 1000);
///
if (t2 - t1 < -1.0) {
return;
} else {
callback({
now: t1,
end: t2,
events: noteRegistrar
});
if(currentTime == 0 && midi.playing) currentTime = ((Date.now() - midi.ctxStartTime * 10) - midi.playingStartTime) / 100 * MIDI.Player.BPM;
if(midi.lastCallbackTime!=currentTime){
var endTime = midi.endTime;
//var percent = currentTime / endTime;
var t1 = currentTime / 1000;
var t2 = endTime / 1000;
///
if (t2 - t1 < -1.0) {
return;
} else {
callback({
now: t1,
end: t2,
events: noteRegistrar
});
}
midi.lastCallbackTime = currentTime;
}
};
///
Expand Down Expand Up @@ -285,13 +289,16 @@ var startAudio = function(currentTime, fromCache, onsuccess) {
ctx.currentTime = (now - __now) / 1000;
}
///
startTime = ctx.currentTime;
midi.ctxStartTime = startTime = ctx.currentTime;
midi.playingStartTime = Date.now() - midi.ctxStartTime*10 ;
///
for (var n = 0; n < length && messages < 100; n++) {
var obj = data[n];
if ((queuedTime += obj[1]) <= currentTime) {
offset = queuedTime;
continue;

if (obj[0].event.type !== 'channel')
continue;
}
///
currentTime = queuedTime - offset;
Expand Down

0 comments on commit c28d720

Please sign in to comment.