From 38727fa4676a01f3511532e064f511551b00c561 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Mon, 8 Apr 2019 16:43:42 +0200 Subject: [PATCH] accept lists and lists of lists as inputs to all sound playing primitives --- HISTORY.md | 2 ++ src/objects.js | 2 +- src/threads.js | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 037352fa..84dc8321 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -18,6 +18,7 @@ * new sound + music stereo "panning" feature + blocks * new sound attribute getter reporter * new "play sound at sample rate" command + * accept lists and lists of lists as inputs to all sound playing primitives * new "play frequency" commands in the Sounds category * added "neg" selector to monadic function reporter in "Operators" category * added "log2" selector to monadic function reporter in "Operators" category @@ -65,6 +66,7 @@ * Blocks, Objects, Threads: new "play sound at sample rate" command primitive * Objects: added relabelling information for the new "play sound at sample rate" block * Objects, Threads: accept a number as input for a sound - interpret as index +* Objects, Threads: accept lists and lists of lists as inputs to all sound playing primitives ### 2019-04-05 * Objects: eliminated "clicks" when playing music notes diff --git a/src/objects.js b/src/objects.js index b34b199c..a856a46f 100644 --- a/src/objects.js +++ b/src/objects.js @@ -3321,7 +3321,7 @@ SpriteMorph.prototype.addSound = function (audio, name) { this.sounds.add(new Sound(audio, name)); }; -SpriteMorph.prototype.playSound = function (name) { +SpriteMorph.prototype.doPlaySound = function (name) { var stage = this.parentThatIsA(StageMorph), sound = name instanceof Sound ? name : (typeof name === 'number' ? this.sounds.at(name) diff --git a/src/threads.js b/src/threads.js index f4aa94ec..52fe3c88 100644 --- a/src/threads.js +++ b/src/threads.js @@ -2221,10 +2221,17 @@ Process.prototype.blockReceiver = function () { // Process sound primitives (interpolated) +Process.prototype.playSound = function (name) { + if (name instanceof List) { + return this.doPlaySoundAtRate(name, 44100); + } + return this.blockReceiver().doPlaySound(name); +}; + Process.prototype.doPlaySoundUntilDone = function (name) { var sprite = this.blockReceiver(); if (this.context.activeAudio === null) { - this.context.activeAudio = sprite.playSound(name); + this.context.activeAudio = this.playSound(name); } if (name === null || this.context.activeAudio.ended || this.context.activeAudio.terminated) { @@ -2312,9 +2319,12 @@ Process.prototype.doPlaySoundAtRate = function (name, rate) { } else { gain.connect(ctx.destination); } - source.start(); source.pause = source.stop; + source.ended = false; + source.onended = function () {this.ended = true; } + source.start(); rcvr.parentThatIsA(StageMorph).activeSounds.push(source); + return source; }; Process.prototype.reportGetSoundAttribute = function (choice, soundName) {