From e06cd58c3509b01a8eb9814ba986a54120d7b876 Mon Sep 17 00:00:00 2001 From: unthingable Date: Mon, 28 Sep 2020 10:48:08 +0200 Subject: MIDI clock slave mode: fix timing and note-off behavior - play() will reset both frame and pulse counts to 0, for alingment - stop() will silence - tap() will update immediately upon play(), not on the next frame --- desktop/sources/scripts/clock.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index a170e2c..a30c766 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -60,19 +60,27 @@ function Clock (client) { console.log('Clock', 'Play', msg) if (this.isPaused === false) { return } this.isPaused = false - if (this.isPuppet === true) { console.warn('Clock', 'External Midi control'); return } - if (msg === true) { client.io.midi.sendClockStart() } - this.setSpeed(this.speed.target, this.speed.target, true) + if (this.isPuppet === true) { + console.warn('Clock', 'External Midi control') + pulse.count = 0 // works in conjunction with `tap` advancing on 0 + this.setFrame(0) // make sure frame aligns with pulse count for an accurate beat + } else { + if (msg === true) { client.io.midi.sendClockStart() } + this.setSpeed(this.speed.target, this.speed.target, true) + } } this.stop = function (msg = false) { console.log('Clock', 'Stop') if (this.isPaused === true) { return } this.isPaused = true - if (this.isPuppet === true) { console.warn('Clock', 'External Midi control'); return } - if (msg === true || client.io.midi.isClock) { client.io.midi.sendClockStop() } + if (this.isPuppet === true) { + console.warn('Clock', 'External Midi control') + } else { + if (msg === true || client.io.midi.isClock) { client.io.midi.sendClockStop() } + this.clearTimer() + } client.io.midi.allNotesOff() - this.clearTimer() client.io.midi.silence() } @@ -92,11 +100,8 @@ function Clock (client) { }, 2000) } if (this.isPaused) { return } - pulse.count = pulse.count + 1 - if (pulse.count % 6 === 0) { - client.run() - pulse.count = 0 - } + if (pulse.count == 0) { client.run() } + pulse.count = (pulse.count + 1) % 6 } this.untap = function () { -- cgit v1.2.3