From 3a69a2561cb7d3ee0d3578ffb598993744d5a8ea Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 2 Oct 2023 21:21:11 +0200 Subject: [PATCH] half working cps link --- packages/core/zyklus.mjs | 3 ++- packages/desktopbridge/cyclistbridge.mjs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/core/zyklus.mjs b/packages/core/zyklus.mjs index 3d25b0544..6d6610898 100644 --- a/packages/core/zyklus.mjs +++ b/packages/core/zyklus.mjs @@ -43,7 +43,8 @@ function createClock( clear(); }; const getPhase = () => phase; + const setPhase = (_phase) => (phase = _phase); // setCallback - return { setDuration, start, stop, pause, duration, interval, getPhase, minLatency }; + return { setDuration, start, stop, pause, duration, interval, getPhase, setPhase, minLatency }; } export default createClock; diff --git a/packages/desktopbridge/cyclistbridge.mjs b/packages/desktopbridge/cyclistbridge.mjs index b4071403a..bb6acf24c 100644 --- a/packages/desktopbridge/cyclistbridge.mjs +++ b/packages/desktopbridge/cyclistbridge.mjs @@ -14,16 +14,18 @@ export class CyclistBridge extends Cyclist { } const { started, cps, phase, timestamp } = payload; - // TODO: I'm not sure how to hook this up this cps adjustment in Strudel - // (if cps !== clock_cps) { - // updateClock(cps) - // } + if (cps !== this.cps) { + this.setCps(cps); + } // TODO: I'm not sure how to hook this up this phase adjustment in Strudel // a phase adjustment message is sent every 30 seconds from backend to keep clocks in sync - // if (Math.abs(phase - this.clock.getPhase()) > someDelta) { - // setCyclistPhase(phase) - // } + const phaseDiff = Math.abs(phase - this.clock.getPhase()); + if (phaseDiff > 0.1) { + console.log('set phase from', this.clock.getPhase(), 'to', phase); + // hmmm this seems wrong... + //this.clock.setPhase(phase); + } if (this.started !== started && started != null) { if (started) { @@ -49,10 +51,8 @@ export class CyclistBridge extends Cyclist { if (!this.pattern) { throw new Error('Scheduler: no pattern set! call .setPattern first.'); } - let x = Date.now(); const linkmsg = { - // TODO: change this to value of "main" clock cps - cps: 0, + cps: this.cps, started: true, timestamp: Date.now(), phase: this.clock.getPhase(),