summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-08-05 12:01:41 +0200
committerGubolin <gubolin@fantasymail.de>2014-08-05 12:01:41 +0200
commitad400763c1f4cd10675a9e6bc56d1630d8c6cb5d (patch)
tree7dad539d6e3a7dda5b8145be4032fa9f9dd9f1f5
parent5a485b466779e26259323173f453275bece79713 (diff)
downloadsnap-ad400763c1f4cd10675a9e6bc56d1630d8c6cb5d.tar.gz
snap-ad400763c1f4cd10675a9e6bc56d1630d8c6cb5d.zip
mute Notes immediately
-rw-r--r--objects.js13
-rw-r--r--threads.js15
2 files changed, 21 insertions, 7 deletions
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();
};