move global tempo setting to audio engine

This commit is contained in:
Eric Rosenbaum 2017-01-10 18:04:54 -05:00
parent b540c8ec7b
commit ca8bc2b45d

View file

@ -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);
};