From ca8bc2b45db61f89cfb57394ffe3433849df14ef Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 10 Jan 2017 18:04:54 -0500 Subject: [PATCH] move global tempo setting to audio engine --- src/index.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 8686ff4..b21ecc1 100644 --- a/src/index.js +++ b/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); };