From db795abfbc0b4e9594b9e92790c55c7ae762016a Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 27 Feb 2018 11:48:49 -0500 Subject: [PATCH] Use tempo stored in stage --- src/extensions/scratch3_music/index.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/extensions/scratch3_music/index.js b/src/extensions/scratch3_music/index.js index 386c2c4a..2c7e59b3 100644 --- a/src/extensions/scratch3_music/index.js +++ b/src/extensions/scratch3_music/index.js @@ -43,13 +43,6 @@ class Scratch3MusicBlocks { */ this.runtime = runtime; - /** - * The current tempo in beats per minute. The tempo is a global property of the project, - * not a property of each sprite, so it is not stored in the MusicState object. - * @type {number} - */ - this.tempo = 60; - /** * The number of drum and instrument sounds currently being played simultaneously. * @type {number} @@ -759,7 +752,7 @@ class Scratch3MusicBlocks { * @private */ _beatsToSec (beats) { - return (60 / this.tempo) * beats; + return (60 / this.getTempo()) * beats; } /** @@ -829,7 +822,7 @@ class Scratch3MusicBlocks { */ changeTempo (args) { const change = Cast.toNumber(args.TEMPO); - const tempo = change + this.tempo; + const tempo = change + this.getTempo(); this._updateTempo(tempo); } @@ -840,7 +833,10 @@ class Scratch3MusicBlocks { */ _updateTempo (tempo) { tempo = MathUtil.clamp(tempo, Scratch3MusicBlocks.TEMPO_RANGE.min, Scratch3MusicBlocks.TEMPO_RANGE.max); - this.tempo = tempo; + const stage = this.runtime.getTargetForStage(); + if (stage) { + stage.tempo = tempo; + } } /** @@ -848,7 +844,11 @@ class Scratch3MusicBlocks { * @return {number} - the current tempo, in beats per minute. */ getTempo () { - return this.tempo; + const stage = this.runtime.getTargetForStage(); + if (stage) { + return stage.tempo; + } + return 60; } }