From d3c864ff5c230219446edfd5048d591738d48d81 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 16 Aug 2023 13:44:09 +0200 Subject: [PATCH] adding ebeat function --- src/API.ts | 9 +++++++-- src/Clock.ts | 15 +++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/API.ts b/src/API.ts index edaf30a..89a199e 100644 --- a/src/API.ts +++ b/src/API.ts @@ -23,7 +23,6 @@ interface Pattern { }; } - /** * This is an override of the basic "includes" method. */ @@ -806,11 +805,17 @@ export class UserAPI { get ebeat(): number { /** * Returns the current beat number since the origin of time - * TODO: fix! Why is this not working? */ return this.app.clock.beats_since_origin; } + get epulse(): number { + /** + * Returns the current number of pulses elapsed since origin of time + */ + return this.app.clock.pulses_since_origin; + } + onbar(n: number, ...bar: number[]): boolean { // n is acting as a modulo on the bar number const bar_list = [...Array(n).keys()].map((i) => i + 1); diff --git a/src/Clock.ts b/src/Clock.ts index 29bad01..2d6d793 100644 --- a/src/Clock.ts +++ b/src/Clock.ts @@ -41,13 +41,13 @@ export class Clock { tick: number constructor(public app: Editor, ctx: AudioContext) { + this.time_position = { bar: 0, beat: 0, pulse: 0 } + this.time_signature = [4, 4]; + this.tick = 0; + this.bpm = 120; + this.ppqn = 48; this.transportNode = null; this.ctx = ctx; - this.tick = 0; - this.time_position = { bar: 0, beat: 0, pulse: 0 } - this.bpm = 120; - this.time_signature = [4, 4]; - this.ppqn = 48; ctx.audioWorklet.addModule(TransportProcessor).then((e) => { this.transportNode = new TransportNode(ctx, {}, this.app); this.transportNode.connect(ctx.destination); @@ -70,7 +70,6 @@ export class Clock { return nextBarinTicks - currentBeatInTicks } - get beats_per_bar(): number { /** * Returns the number of beats per bar. @@ -82,6 +81,10 @@ export class Clock { return (this.time_position.bar - 1) * this.beats_per_bar + this.time_position.beat; } + get pulses_since_origin(): number { + return (this.beats_since_origin * this.ppqn) + this.time_position.pulse + } + get pulse_duration(): number { /** * Returns the duration of a pulse in seconds.