mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
Merge pull request #953 from ericrosenbaum/bugfix/load-tempo-from-sb2
Load tempo from sb2
This commit is contained in:
commit
5d658b5ecb
4 changed files with 25 additions and 13 deletions
|
@ -43,13 +43,6 @@ class Scratch3MusicBlocks {
|
||||||
*/
|
*/
|
||||||
this.runtime = runtime;
|
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.
|
* The number of drum and instrument sounds currently being played simultaneously.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
|
@ -759,7 +752,7 @@ class Scratch3MusicBlocks {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_beatsToSec (beats) {
|
_beatsToSec (beats) {
|
||||||
return (60 / this.tempo) * beats;
|
return (60 / this.getTempo()) * beats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -829,7 +822,7 @@ class Scratch3MusicBlocks {
|
||||||
*/
|
*/
|
||||||
changeTempo (args) {
|
changeTempo (args) {
|
||||||
const change = Cast.toNumber(args.TEMPO);
|
const change = Cast.toNumber(args.TEMPO);
|
||||||
const tempo = change + this.tempo;
|
const tempo = change + this.getTempo();
|
||||||
this._updateTempo(tempo);
|
this._updateTempo(tempo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,7 +833,10 @@ class Scratch3MusicBlocks {
|
||||||
*/
|
*/
|
||||||
_updateTempo (tempo) {
|
_updateTempo (tempo) {
|
||||||
tempo = MathUtil.clamp(tempo, Scratch3MusicBlocks.TEMPO_RANGE.min, Scratch3MusicBlocks.TEMPO_RANGE.max);
|
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.
|
* @return {number} - the current tempo, in beats per minute.
|
||||||
*/
|
*/
|
||||||
getTempo () {
|
getTempo () {
|
||||||
return this.tempo;
|
const stage = this.runtime.getTargetForStage();
|
||||||
|
if (stage) {
|
||||||
|
return stage.tempo;
|
||||||
|
}
|
||||||
|
return 60;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -320,6 +320,9 @@ const parseScratchObject = function (object, runtime, extensions, topLevel) {
|
||||||
target.rotationStyle = RenderedTarget.ROTATION_STYLE_ALL_AROUND;
|
target.rotationStyle = RenderedTarget.ROTATION_STYLE_ALL_AROUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (object.hasOwnProperty('tempoBPM')) {
|
||||||
|
target.tempo = object.tempoBPM;
|
||||||
|
}
|
||||||
|
|
||||||
target.isStage = topLevel;
|
target.isStage = topLevel;
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,12 @@ class RenderedTarget extends Target {
|
||||||
* @type {!string}
|
* @type {!string}
|
||||||
*/
|
*/
|
||||||
this.rotationStyle = RenderedTarget.ROTATION_STYLE_ALL_AROUND;
|
this.rotationStyle = RenderedTarget.ROTATION_STYLE_ALL_AROUND;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current tempo (used by the music extension)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.tempo = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
const Music = require('../../src/extensions/scratch3_music/index.js');
|
const Music = require('../../src/extensions/scratch3_music/index.js');
|
||||||
const runtime = Object.create(null);
|
|
||||||
|
|
||||||
const blocks = new Music(runtime);
|
const fakeRuntime = {
|
||||||
|
getTargetForStage: () => ({tempo: 60})
|
||||||
|
};
|
||||||
|
|
||||||
|
const blocks = new Music(fakeRuntime);
|
||||||
|
|
||||||
const util = {
|
const util = {
|
||||||
stackFrame: Object.create(null),
|
stackFrame: Object.create(null),
|
||||||
|
|
Loading…
Reference in a new issue