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 From 39f116833d83140da09fa61b1661917a29e92683 Mon Sep 17 00:00:00 2001 From: unthingable Date: Tue, 29 Sep 2020 00:29:27 +0200 Subject: stay synced to MIDI clock while paused --- desktop/sources/scripts/clock.js | 39 +++++++++++++++++++++++---------- desktop/sources/scripts/core/io/midi.js | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index a30c766..1cc5efa 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -56,14 +56,17 @@ function Clock (client) { client.update() } - this.play = function (msg = false) { - console.log('Clock', 'Play', msg) + this.play = function (msg = false, force = false) { + console.log('Clock', 'Play', msg, force) if (this.isPaused === false) { return } this.isPaused = false - if (this.isPuppet === 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 + if (!pulse.frame || force) { // no frames counted while paused or restard demanded (via MIDI clock PLAY) + this.setFrame(0) // make sure frame aligns with pulse count for an accurate beat + pulse.frame = 0 + pulse.count = 5 // by MIDI standard next pulse is the beat + } } else { if (msg === true) { client.io.midi.sendClockStart() } this.setSpeed(this.speed.target, this.speed.target, true) @@ -74,7 +77,7 @@ function Clock (client) { console.log('Clock', 'Stop') if (this.isPaused === true) { return } this.isPaused = true - if (this.isPuppet === true) { + if (this.isPuppet === true) { console.warn('Clock', 'External Midi control') } else { if (msg === true || client.io.midi.isClock) { client.io.midi.sendClockStop() } @@ -86,9 +89,15 @@ function Clock (client) { // External Clock - const pulse = { count: 0, last: null, timer: null } + const pulse = { + count: 0, + last: null, + timer: null, + frame: 0 // paused frame counter + } this.tap = function () { + pulse.count = (pulse.count + 1) % 6 pulse.last = performance.now() if (!this.isPuppet) { console.log('Clock', 'Puppeteering starts..') @@ -98,17 +107,25 @@ function Clock (client) { if (performance.now() - pulse.last < 2000) { return } this.untap() }, 2000) + } else { + if (pulse.count == 0) { + if (this.isPaused) { pulse.frame++ } + else { + if (pulse.frame > 0) { + this.setFrame(client.orca.f + pulse.frame) + pulse.frame = 0 + } + client.run() + } + } } - if (this.isPaused) { return } - if (pulse.count == 0) { client.run() } - pulse.count = (pulse.count + 1) % 6 } this.untap = function () { console.log('Clock', 'Puppeteering stops..') clearInterval(pulse.timer) this.isPuppet = false - pulse.count = 1 + pulse.frame = 0 pulse.last = null this.setTimer(this.speed.value) } diff --git a/desktop/sources/scripts/core/io/midi.js b/desktop/sources/scripts/core/io/midi.js index 285cebd..7f4875a 100644 --- a/desktop/sources/scripts/core/io/midi.js +++ b/desktop/sources/scripts/core/io/midi.js @@ -129,7 +129,7 @@ function Midi (client) { break case 0xFA: console.log('MIDI', 'Start Received') - client.clock.play() + client.clock.play(false, true) break case 0xFB: console.log('MIDI', 'Continue Received') -- cgit v1.2.3 From 6cce494cd0a5cd1e69cf266deb6d51c3ddb3ddf3 Mon Sep 17 00:00:00 2001 From: unthingable Date: Tue, 29 Sep 2020 00:46:02 +0200 Subject: re-sync on MIDI clock START while playing --- desktop/sources/scripts/clock.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index 1cc5efa..3a3e1e1 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -58,11 +58,11 @@ function Clock (client) { this.play = function (msg = false, force = false) { console.log('Clock', 'Play', msg, force) - if (this.isPaused === false) { return } + if (this.isPaused === false && !force) { return } this.isPaused = false if (this.isPuppet === true) { console.warn('Clock', 'External Midi control') - if (!pulse.frame || force) { // no frames counted while paused or restard demanded (via MIDI clock PLAY) + if (!pulse.frame || force) { // no frames counted while paused or restard demanded (via MIDI clock START) this.setFrame(0) // make sure frame aligns with pulse count for an accurate beat pulse.frame = 0 pulse.count = 5 // by MIDI standard next pulse is the beat -- cgit v1.2.3 From 227cd8d7758697761d06aac962f3d7047ab50e07 Mon Sep 17 00:00:00 2001 From: unthingable Date: Tue, 29 Sep 2020 01:32:28 +0200 Subject: minor cleanup --- desktop/sources/scripts/clock.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index 3a3e1e1..d89a516 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -56,13 +56,13 @@ function Clock (client) { client.update() } - this.play = function (msg = false, force = false) { - console.log('Clock', 'Play', msg, force) - if (this.isPaused === false && !force) { return } + this.play = function (msg = false, midiStart = false) { + console.log('Clock', 'Play', msg, midiStart) + if (this.isPaused === false && !midiStart) { return } this.isPaused = false if (this.isPuppet === true) { console.warn('Clock', 'External Midi control') - if (!pulse.frame || force) { // no frames counted while paused or restard demanded (via MIDI clock START) + if (!pulse.frame || midiStart) { // no frames counted while paused (starting from no clock, unlikely) or triggered by MIDI clock START this.setFrame(0) // make sure frame aligns with pulse count for an accurate beat pulse.frame = 0 pulse.count = 5 // by MIDI standard next pulse is the beat -- cgit v1.2.3 From 38223158cc61c17e9f7e3b847d4b6f6d51872f65 Mon Sep 17 00:00:00 2001 From: unthingable Date: Tue, 29 Sep 2020 09:36:54 +0200 Subject: lost clock should not unpause Orca --- desktop/sources/scripts/clock.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index d89a516..66a5448 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -127,7 +127,9 @@ function Clock (client) { this.isPuppet = false pulse.frame = 0 pulse.last = null - this.setTimer(this.speed.value) + if (!this.isPaused) { + this.setTimer(this.speed.value) + } } // Timer -- cgit v1.2.3 From 594241c2513564a72721acaea55685103ec31ee8 Mon Sep 17 00:00:00 2001 From: unthingable Date: Tue, 29 Sep 2020 10:08:29 +0200 Subject: minor fix, remove extraneous else --- desktop/sources/scripts/clock.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js index 66a5448..95086cf 100644 --- a/desktop/sources/scripts/clock.js +++ b/desktop/sources/scripts/clock.js @@ -107,16 +107,15 @@ function Clock (client) { if (performance.now() - pulse.last < 2000) { return } this.untap() }, 2000) - } else { - if (pulse.count == 0) { - if (this.isPaused) { pulse.frame++ } - else { - if (pulse.frame > 0) { - this.setFrame(client.orca.f + pulse.frame) - pulse.frame = 0 - } - client.run() + } + if (pulse.count == 0) { + if (this.isPaused) { pulse.frame++ } + else { + if (pulse.frame > 0) { + this.setFrame(client.orca.f + pulse.frame) + pulse.frame = 0 } + client.run() } } } -- cgit v1.2.3