Use tempo stored in stage

This commit is contained in:
Eric Rosenbaum committed 2018-02-27 11:48:49 -05:00
1 parent 7e5e43fbe1
commit db795abfbc
1 file changed
+11 -11
+11 -11
View File
@@ -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;
}
}