From 90e62b4313f300de1da3013a558d51f7d4c883a6 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Mon, 4 Aug 2014 11:10:21 +0200 Subject: allow changing the volume of notes --- threads.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 3324ac6..56ff45a 100644 --- a/threads.js +++ b/threads.js @@ -2716,10 +2716,11 @@ Process.prototype.doPlayNote = function (pitch, beats) { Process.prototype.doPlayNoteForSecs = function (pitch, secs) { // interpolated + var volume = this.homeContext.receiver.volume; if (!this.context.startTime) { this.context.startTime = Date.now(); this.context.activeNote = new Note(pitch); - this.context.activeNote.play(); + this.context.activeNote.play(volume); } if ((Date.now() - this.context.startTime) >= (secs * 1000)) { if (this.context.activeNote) { -- cgit v1.3.1 From 5a485b466779e26259323173f453275bece79713 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Mon, 4 Aug 2014 12:17:32 +0200 Subject: mute notes --- threads.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 56ff45a..5347110 100644 --- a/threads.js +++ b/threads.js @@ -2717,6 +2717,12 @@ Process.prototype.doPlayNote = function (pitch, beats) { Process.prototype.doPlayNoteForSecs = function (pitch, secs) { // interpolated var volume = this.homeContext.receiver.volume; + var muted = this.homeContext.receiver.parentThatIsA(StageMorph).muted; + + if (muted === true) { + volume = 0; + } + if (!this.context.startTime) { this.context.startTime = Date.now(); this.context.activeNote = new Note(pitch); -- cgit v1.3.1 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 ++++++++++--- threads.js | 15 +++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'threads.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); diff --git a/threads.js b/threads.js index 5347110..354d002 100644 --- a/threads.js +++ b/threads.js @@ -2716,8 +2716,9 @@ Process.prototype.doPlayNote = function (pitch, beats) { Process.prototype.doPlayNoteForSecs = function (pitch, secs) { // interpolated - var volume = this.homeContext.receiver.volume; - var muted = this.homeContext.receiver.parentThatIsA(StageMorph).muted; + var receiver = this.homeContext.receiver; + var volume = receiver.volume; + var muted = receiver.parentThatIsA(StageMorph).muted; if (muted === true) { volume = 0; @@ -2725,16 +2726,22 @@ Process.prototype.doPlayNoteForSecs = function (pitch, secs) { if (!this.context.startTime) { this.context.startTime = Date.now(); - this.context.activeNote = new Note(pitch); - this.context.activeNote.play(volume); + this.context.activeNote = new Note(pitch, volume); + this.context.activeNote.play(); } + if ((Date.now() - this.context.startTime) >= (secs * 1000)) { if (this.context.activeNote) { this.context.activeNote.stop(); this.context.activeNote = null; } return null; + } else if (this.context.activeNote) { + if (this.context.activeNote.volume !== volume) { + this.context.activeNote.setVolume(volume); + } } + this.pushContext('doYield'); this.pushContext(); }; -- cgit v1.3.1 From e2191d8f6ea72077ec5595dc6570a9804b8cbd89 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Tue, 5 Aug 2014 12:10:20 +0200 Subject: fix another sound pause bug --- threads.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 354d002..7e87614 100644 --- a/threads.js +++ b/threads.js @@ -418,11 +418,17 @@ Process.prototype.pause = function () { if (this.context && this.context.startTime) { this.pauseOffset = Date.now() - this.context.startTime; } + if (this.context.activeNote) { + this.context.activeNote.stop(); + } }; Process.prototype.resume = function () { this.isPaused = false; this.pauseOffset = null; + if (this.context.activeNote) { + this.context.activeNote.play(); + } }; Process.prototype.pauseStep = function () { -- cgit v1.3.1 From fc36ac7fea89447682868dc40cc9a818afc51c5c Mon Sep 17 00:00:00 2001 From: Gubolin Date: Wed, 6 Aug 2014 12:24:45 +0200 Subject: fix another strange Note bug --- objects.js | 2 +- threads.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'threads.js') diff --git a/objects.js b/objects.js index e4d0928..8923384 100644 --- a/objects.js +++ b/objects.js @@ -4811,7 +4811,7 @@ StageMorph.prototype.fireGreenFlagEvent = function () { StageMorph.prototype.fireStopAllEvent = function () { var ide = this.parentThatIsA(IDE_Morph); - this.threads.resumeAll(this.stage); + //this.threads.resumeAll(this.stage); // leads to a strange Note bug this.keysPressed = {}; this.threads.stopAll(); this.stopAllActiveSounds(); diff --git a/threads.js b/threads.js index 7e87614..fd75e3d 100644 --- a/threads.js +++ b/threads.js @@ -1395,7 +1395,7 @@ Process.prototype.doStopAll = function () { if (this.homeContext.receiver) { stage = this.homeContext.receiver.parentThatIsA(StageMorph); if (stage) { - stage.threads.resumeAll(stage); + //stage.threads.resumeAll(stage); // leads to a strange Note bug stage.keysPressed = {}; stage.threads.stopAll(); stage.stopAllActiveSounds(); -- cgit v1.3.1 From 4013e79a7421b9e6baacc8e34ae7a8ef188b38cb Mon Sep 17 00:00:00 2001 From: Gubolin Date: Fri, 8 Aug 2014 11:59:35 +0200 Subject: fix yet another note pause bug --- threads.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index fd75e3d..77ad720 100644 --- a/threads.js +++ b/threads.js @@ -427,7 +427,10 @@ Process.prototype.resume = function () { this.isPaused = false; this.pauseOffset = null; if (this.context.activeNote) { - this.context.activeNote.play(); + if (this.context.activeNote.oscillator === null) { + // prevents Note from resuming twice + this.context.activeNote.play(); + } } }; -- cgit v1.3.1