Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Always add delay to currentTime. #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions js/midi/plugin.webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@
}

/// convert relative delay to absolute delay
if (delay < ctx.currentTime) {
delay += ctx.currentTime;
}
delay += ctx.currentTime;

/// create audio buffer
if (useStreamingBuffer) {
Expand Down Expand Up @@ -128,9 +126,7 @@
var bufferId = instrument + '' + noteId;
var buffer = audioBuffers[bufferId];
if (buffer) {
if (delay < ctx.currentTime) {
delay += ctx.currentTime;
}
delay += ctx.currentTime;
///
var source = sources[channelId + '' + noteId];
if (source) {
Expand Down Expand Up @@ -185,9 +181,7 @@
midi.stopAllNotes = function() {
for (var sid in sources) {
var delay = 0;
if (delay < ctx.currentTime) {
delay += ctx.currentTime;
}
delay += ctx.currentTime;
var source = sources[sid];
source.gain.linearRampToValueAtTime(1, delay);
source.gain.linearRampToValueAtTime(0, delay + 0.3);
Expand Down Expand Up @@ -323,4 +317,4 @@
return new (window.AudioContext || window.webkitAudioContext)();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge this bugfix into mainstream. I was trying to play Javascript generated melodies with MIDI.js and it took me 1 hour just to find this bug, which prevents MIDI.js to work correctly, so this bug-report must be accepted.

};
})();
})(MIDI);
})(MIDI);