From 74872654d609bf68c672a19150f02494362d6fd9 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 16 Aug 2023 12:06:50 +0200 Subject: [PATCH] slightly better --- src/API.ts | 6 ++++-- src/Clock.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/API.ts b/src/API.ts index aedb6d4..35ec512 100644 --- a/src/API.ts +++ b/src/API.ts @@ -239,7 +239,6 @@ export class UserAPI { // Ziffers related functions // ============================================================= - public zn(input: string, options: {[key: string]: string|number} = {}): Event { let event = cachedEvent(input, options); @@ -455,8 +454,9 @@ export class UserAPI { return sequence.options.currentIteration === 0; } else { + let pattern_options = { - index: 0, nextTarget: input[0], + index: -1, nextTarget: this.app.clock.ticks_before_new_bar, currentIteration: 0 }; if (typeof input[input.length - 1] === "object") { @@ -467,6 +467,8 @@ export class UserAPI { } pattern_options.currentIteration++; + // TEST + pattern_options.nextTarget = this.app.clock.ticks_before_new_bar if (pattern_options.currentIteration === pattern_options.nextTarget) { pattern_options.index++; diff --git a/src/Clock.ts b/src/Clock.ts index 82827d4..29bad01 100644 --- a/src/Clock.ts +++ b/src/Clock.ts @@ -58,6 +58,19 @@ export class Clock { }) } + get ticks_before_new_bar(): number { + /** + * This function returns the number of ticks sepaating the current moment + * from the beginning of the next bar. + * + * @returns number of ticks until next bar + */ + const currentBeatInTicks = ((this.app.clock.beats_since_origin - 1) * 48) + this.time_position.pulse + 1 + const nextBarinTicks = (this.beats_per_bar * this.ppqn) * this.time_position.bar + 1 + return nextBarinTicks - currentBeatInTicks + } + + get beats_per_bar(): number { /** * Returns the number of beats per bar.