mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 14:02:29 -05:00
move global tempo setting to audio engine
This commit is contained in:
parent
b540c8ec7b
commit
ca8bc2b45d
1 changed files with 11 additions and 10 deletions
21
src/index.js
21
src/index.js
|
@ -38,6 +38,8 @@ function AudioEngine () {
|
|||
|
||||
// global tempo in bpm (beats per minute)
|
||||
this.currentTempo = 60;
|
||||
this.minTempo = 10;
|
||||
this.maxTempo = 1000;
|
||||
|
||||
// instrument player for play note blocks
|
||||
this.instrumentPlayer = new InstrumentPlayer(this.input);
|
||||
|
@ -46,6 +48,15 @@ function AudioEngine () {
|
|||
this.drumPlayer = new DrumPlayer(this.input);
|
||||
}
|
||||
|
||||
AudioEngine.prototype.setTempo = function (value) {
|
||||
// var newTempo = this._clamp(value, this.minTempo, this.maxTempo);
|
||||
this.currentTempo = value;
|
||||
};
|
||||
|
||||
AudioEngine.prototype.changeTempo = function (value) {
|
||||
this.setTempo(this.currentTempo + value);
|
||||
};
|
||||
|
||||
AudioEngine.prototype.createPlayer = function () {
|
||||
return new AudioPlayer(this);
|
||||
};
|
||||
|
@ -240,16 +251,6 @@ AudioPlayer.prototype.changeVolume = function (value) {
|
|||
this.setVolume(this.currentVolume + value);
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.setTempo = function (value) {
|
||||
var newTempo = this._clamp(value, 10, 1000);
|
||||
this.audioEngine.currentTempo = newTempo;
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.changeTempo = function (value) {
|
||||
var newTempo = this._clamp(this.audioEngine.currentTempo + value, 10, 1000);
|
||||
this.audioEngine.currentTempo = newTempo;
|
||||
};
|
||||
|
||||
AudioPlayer.prototype._clamp = function (input, min, max) {
|
||||
return Math.min(Math.max(input, min), max);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue