summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-12-07 11:53:41 +0100
committerGubolin <gubolin@fantasymail.de>2014-12-07 11:53:41 +0100
commit22a09b5019ecf7eea6cffd67ae4404987e44135c (patch)
treea1b399ed77a603cc09550327aeceb41823949e16 /threads.js
parent54da483ee90eaac2f92d6aa1ee9394b3a77d2181 (diff)
parent4013e79a7421b9e6baacc8e34ae7a8ef188b38cb (diff)
downloadsnap-22a09b5019ecf7eea6cffd67ae4404987e44135c.tar.gz
snap-22a09b5019ecf7eea6cffd67ae4404987e44135c.zip
Merge branch issue_405
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js27
1 files changed, 25 insertions, 2 deletions
diff --git a/threads.js b/threads.js
index ad0b5dc..5726af3 100644
--- a/threads.js
+++ b/threads.js
@@ -448,11 +448,20 @@ 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) {
+ if (this.context.activeNote.oscillator === null) {
+ // prevents Note from resuming twice
+ this.context.activeNote.play();
+ }
+ }
};
Process.prototype.pauseStep = function () {
@@ -1455,7 +1464,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();
@@ -2898,18 +2907,32 @@ Process.prototype.doPlayNote = function (pitch, beats) {
Process.prototype.doPlayNoteForSecs = function (pitch, secs) {
// interpolated
+ var receiver = this.homeContext.receiver;
+ var volume = receiver.volume;
+ var muted = receiver.parentThatIsA(StageMorph).muted;
+
+ if (muted === true) {
+ volume = 0;
+ }
+
if (!this.context.startTime) {
this.context.startTime = Date.now();
- this.context.activeNote = new Note(pitch);
+ 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();
};