Skip to content

Commit

Permalink
The options parameter is now left unaltered (followup to PR #56)
Browse files Browse the repository at this point in the history
  • Loading branch information
djipco committed Jan 27, 2019
1 parent 0ffd968 commit 941b41f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/webmidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,8 @@
*/
Output.prototype.playNote = function(note, channel, options) {

var nVelocity = 64;
var time,
nVelocity = 64;

options = options || {};

Expand All @@ -2877,14 +2878,16 @@

}

time = this._parseTimeParameter(options.time);

// Send note on messages
this._convertNoteToArray(note).forEach(function(item) {

wm.toMIDIChannels(channel).forEach(function(ch) {
this.send(
(wm.MIDI_CHANNEL_MESSAGES.noteon << 4) + (ch - 1),
[item, Math.round(nVelocity)],
this._parseTimeParameter(options.time)
time
);
}.bind(this));

Expand Down Expand Up @@ -2919,7 +2922,7 @@
this.send(
(wm.MIDI_CHANNEL_MESSAGES.noteoff << 4) + (ch - 1),
[item, Math.round(nRelease)],
(options.time || wm.time) + options.duration
(time || wm.time) + options.duration
);
}.bind(this));

Expand Down Expand Up @@ -4106,14 +4109,13 @@
*/
Output.prototype._parseTimeParameter = function(time) {

var parsed, value;
var value,
parsed = parseFloat(time);

if (typeof time === 'string' && time.substring(0, 1) === "+") {
parsed = parseFloat(time);
if (parsed && parsed > 0) { value = wm.time + parsed; }
if (parsed && parsed > 0) value = wm.time + parsed;
} else {
parsed = parseFloat(time);
if (parsed > wm.time) { value = parsed; }
if (parsed > wm.time) value = parsed;
}

return value;
Expand Down

0 comments on commit 941b41f

Please sign in to comment.