From 0c5437e1c58655950c811e268d7897afd6e16b91 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Fri, 27 Oct 2023 10:00:21 +0200 Subject: [PATCH] Account for deviation --- src/Clock.ts | 8 ++++++-- src/classes/SoundEvent.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Clock.ts b/src/Clock.ts index fab3172..43d173a 100644 --- a/src/Clock.ts +++ b/src/Clock.ts @@ -152,6 +152,10 @@ export class Clock { return this.elapsed; } + get deviation(): number { + return Math.abs(this.logicalTime - this.realTime) + } + set ppqn(ppqn: number) { if (ppqn > 0 && this._ppqn !== ppqn) { this._ppqn = ppqn; @@ -215,8 +219,8 @@ export class Clock { * * @remark also sends a MIDI message if a port is declared */ - this.app.clock.tick = -1; - this.time_position = { bar: -1, beat: -1, pulse: -1 }; + this.app.clock.tick = 0; + this.time_position = { bar: 0, beat: 0, pulse: 0 }; this.app.api.MidiConnection.sendStopMessage(); this.transportNode?.stop(); } diff --git a/src/classes/SoundEvent.ts b/src/classes/SoundEvent.ts index 80ac9f8..799ee51 100644 --- a/src/classes/SoundEvent.ts +++ b/src/classes/SoundEvent.ts @@ -463,10 +463,10 @@ export class SoundEvent extends AudibleEvent { this.values.chord.forEach((obj: { [key: string]: number }) => { const copy = { ...this.values }; copy.freq = obj.freq; - superdough(copy, this.nudge, this.values.dur); + superdough(copy, this.nudge - this.app.clock.deviation, this.values.dur); }); } else { - superdough(this.values, this.nudge, this.values.dur); + superdough(this.values, this.nudge - this.app.clock.deviation, this.values.dur); } }; }