diff options
author | Devine Lu Linvega <[email protected]> | 2019-04-12 10:20:04 +0900 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2019-04-12 10:20:04 +0900 |
commit | 98fe367aba7def1280fc67dbbbf79275883dc1df (patch) | |
tree | f5a9d06ffa94473390f6c4cc7886a264aba5634a /desktop/sources/scripts/clock.js | |
parent | 0c88dfe73029ce23a17b56c7e40e0e318813d14a (diff) | |
download | Orca-MidiClock.tar.gz Orca-MidiClock.zip |
Cleaned up the clockMidiClock
Diffstat (limited to 'desktop/sources/scripts/clock.js')
-rw-r--r-- | desktop/sources/scripts/clock.js | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index b53db1f..52d0af4 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -12,17 +12,31 @@ function Clock (terminal) { } this.update = function () { - if (this.speed.target === this.speed.value) { return } + this.animate() + } - this.setTimer(this.speed.value) + this.set = function (value, target = null, setTimer = false) { + if (value) { this.speed.value = clamp(value, 60, 300) } + if (target) { this.speed.target = clamp(target, 60, 300) } + if (setTimer === true) { this.setTimer(this.speed.value) } + } - if (this.speed.value < this.speed.target) { this.speed.value++ } - if (this.speed.value > this.speed.target) { this.speed.value-- } + this.mod = function (mod = 0, animate = false) { + if (animate === true) { + this.set(null, this.speed.target + mod) + } else { + this.set(this.speed.value + mod, this.speed.value + mod, true) + terminal.update() + } + } - this.speed.value = clamp(this.speed.value, 60, 300) - this.speed.target = clamp(this.speed.target, 60, 300) + this.animate = function () { + if (this.speed.target === this.speed.value) { return } + this.set(this.speed.value + (this.speed.value < this.speed.target ? 1 : -1), null, true) } + // Controls + this.togglePlay = function () { if (this.isPaused === true) { this.play() @@ -35,7 +49,7 @@ function Clock (terminal) { if (!this.isPaused) { console.warn('Already playing'); return } console.log('Play') this.isPaused = false - this.setTimer(this.speed.target) + this.set(this.speed.target, this.speed.target, true) } this.stop = function () { @@ -46,6 +60,8 @@ function Clock (terminal) { this.clearTimer() } + // Timer + this.clearTimer = function () { if (this.timer) { clearInterval(this.timer) @@ -53,34 +69,16 @@ function Clock (terminal) { } this.setTimer = function (bpm) { - this.speed.value = bpm this.clearTimer() this.timer = setInterval(() => { terminal.run(); this.update() }, (60000 / bpm) / 4) } - this.setSpeed = function (bpm, animate = false) { - if (animate === true) { - this.speed.target = bpm - } else { - this.speed.target = bpm - this.setTimer(bpm) - } - } - - this.modSpeed = function (mod = 0, animate = false) { - if (animate === true) { - this.speed.target += mod - } else { - this.setTimer(this.speed.value + mod) - this.speed.target = this.speed.value - terminal.update() - } - } - this.resetFrame = function () { terminal.orca.f = 0 } + // UI + this.toString = function () { const diff = this.speed.target - this.speed.value const _offset = diff > 0 ? `+${diff}` : diff < 0 ? diff : '' |