mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 22:12:48 -05:00
single tempo owned by audioengine
This commit is contained in:
parent
9b3119c96e
commit
2058b2dd19
1 changed files with 5 additions and 8 deletions
13
src/index.js
13
src/index.js
|
@ -32,6 +32,8 @@ function AudioEngine () {
|
|||
// this.input = new Tone.Gain();
|
||||
// this.input.connect(Tone.Master);
|
||||
|
||||
// global tempo in bpm (beats per minute)
|
||||
this.currentTempo = 60;
|
||||
}
|
||||
|
||||
AudioEngine.prototype.createPlayer = function () {
|
||||
|
@ -70,11 +72,6 @@ function AudioPlayer (audioEngine) {
|
|||
this.instrumentNum;
|
||||
this.setInstrument(1);
|
||||
|
||||
// tempo in bpm (beats per minute)
|
||||
// default is 60bpm
|
||||
|
||||
this.currentTempo = 60;
|
||||
|
||||
this.currentVolume = 100;
|
||||
}
|
||||
|
||||
|
@ -142,7 +139,7 @@ AudioPlayer.prototype.waitForBeats = function (beats) {
|
|||
return new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
resolve();
|
||||
}, ((60 / storedContext.currentTempo) * 1000 * beats));
|
||||
}, ((60 / storedContext.audioEngine.currentTempo) * 1000 * beats));
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -243,12 +240,12 @@ AudioPlayer.prototype.changeVolume = function (value) {
|
|||
|
||||
AudioPlayer.prototype.setTempo = function (value) {
|
||||
var newTempo = this._clamp(value, 10, 1000);
|
||||
this.currentTempo = newTempo;
|
||||
this.audioEngine.currentTempo = newTempo;
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.changeTempo = function (value) {
|
||||
var newTempo = this._clamp(this.currentTempo + value, 10, 1000);
|
||||
this.currentTempo = newTempo;
|
||||
this.audioEngine.currentTempo = newTempo;
|
||||
};
|
||||
|
||||
AudioPlayer.prototype._clamp = function (input, min, max) {
|
||||
|
|
Loading…
Reference in a new issue