From 72b74ac18debb62d65f551ba16f9c9feb4a864be Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 17 Apr 2019 13:16:38 +0900 Subject: Reverted clock --- desktop/core/io/midi.js | 4 +--- desktop/sources/scripts/clock.js | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/desktop/core/io/midi.js b/desktop/core/io/midi.js index 86b2e2d..5e815c9 100644 --- a/desktop/core/io/midi.js +++ b/desktop/core/io/midi.js @@ -117,10 +117,8 @@ function Midi (terminal) { switch (msg.data[0]) { case 0xF8: this.count = (this.count + 1) % 6 - if (this.count % 8 === 0) { - terminal.clock.stop() + if (this.count % 4 === 0) { terminal.clock.tap() - terminal.run() } break case 0xFA: diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index 41d44de..ae231ba 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -44,14 +44,14 @@ function Clock (terminal) { } this.play = function () { - if (!this.isPaused) { return } + if (!this.isPaused) { console.warn('Already playing'); return } console.log('Clock', 'Play') this.isPaused = false this.set(this.speed.target, this.speed.target, true) } this.stop = function () { - if (this.isPaused) { return } + if (this.isPaused) { console.warn('Already stopped'); return } console.log('Clock', 'Stop') terminal.io.midi.silence() this.isPaused = true @@ -69,8 +69,10 @@ function Clock (terminal) { } if (this.intervals.length === 8) { const sum = this.intervals.reduce((sum, interval) => { return sum + interval }) - const bpm = Math.floor((1000 / sum) * 60) * 2 - this.set(bpm, bpm) + const bpm = parseInt((1000 / sum) * 60) + if (Math.abs(bpm - this.speed.target) > 1) { + this.set(null, bpm) + } } const now = performance.now() -- cgit v1.2.3