From ae7c9d8cb6c10cbf9fe3e41b307f991284ef4692 Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Thu, 21 Sep 2023 00:00:45 +0300 Subject: [PATCH] Fix sync problem --- src/classes/SoundEvent.ts | 4 ++-- src/classes/ZPlayer.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/classes/SoundEvent.ts b/src/classes/SoundEvent.ts index 700246e..4b8580c 100644 --- a/src/classes/SoundEvent.ts +++ b/src/classes/SoundEvent.ts @@ -295,10 +295,10 @@ export class SoundEvent extends AudibleEvent { this.values.chord.forEach((obj: { [key: string]: number }) => { const copy = { ...this.values }; copy.freq = obj.freq - superdough(copy, 1 / 4, this.values.dur || 0.5); + superdough(copy, this.values.dur*2, this.values.dur); }); } else { - superdough(this.values, 1 / 4, this.values.dur || 0.5); + superdough(this.values, this.values.dur*2, this.values.dur); } }; } diff --git a/src/classes/ZPlayer.ts b/src/classes/ZPlayer.ts index 7a03692..89ba073 100644 --- a/src/classes/ZPlayer.ts +++ b/src/classes/ZPlayer.ts @@ -134,8 +134,10 @@ export class Player extends Event { }; sound(name: string) { + if (this.areWeThereYet()) { const event = this.next() as Pitch | Chord | ZRest; + const noteLengthInSeconds = this.app.clock.convertPulseToSecond(event.duration*4*this.app.clock.ppqn); if (event instanceof Pitch) { const obj = event.getExisting( "freq", @@ -145,7 +147,7 @@ export class Player extends Event { "octave", "parsedScale" ); - obj.dur = event.duration; + obj.dur = noteLengthInSeconds; return new SoundEvent(obj, this.app).sound(name); } else if (event instanceof Chord) { const pitches = event.pitches.map((p) => { @@ -158,7 +160,7 @@ export class Player extends Event { "parsedScale" ); }); - return new SoundEvent({dur: event.duration}, this.app).chord(pitches).sound(name); + return new SoundEvent({dur: noteLengthInSeconds}, this.app).chord(pitches).sound(name); } else if (event instanceof ZRest) { return RestEvent.createRestProxy(event.duration, this.app); }