From ad400763c1f4cd10675a9e6bc56d1630d8c6cb5d Mon Sep 17 00:00:00 2001 From: Gubolin Date: Tue, 5 Aug 2014 12:01:41 +0200 Subject: mute Notes immediately --- objects.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 1a42e0f..323ccab 100644 --- a/objects.js +++ b/objects.js @@ -6320,8 +6320,9 @@ Sound.prototype.toDataURL = function () { // Note instance creation -function Note(pitch) { +function Note(pitch, volume) { this.pitch = pitch === 0 ? 0 : pitch || 69; + this.volume = volume; this.setupContext(); this.oscillator = null; } @@ -6356,8 +6357,8 @@ Note.prototype.setupContext = function () { // Note playing -Note.prototype.play = function (volume) { - this.gainNode.gain.value = 0.25 * volume / 100; // reduce volume by 1/4 +Note.prototype.play = function () { + this.gainNode.gain.value = 0.25 * this.volume / 100; // reduce volume by 1/4 this.oscillator = this.audioContext.createOscillator(); if (!this.oscillator.start) { @@ -6374,6 +6375,12 @@ Note.prototype.play = function (volume) { this.oscillator.start(0); }; +Note.prototype.setVolume = function (volume) { + this.stop(); + this.volume = volume; + this.play(); +} + Note.prototype.stop = function () { if (this.oscillator) { this.oscillator.stop(0); -- cgit v1.3.1