From 4d5e8d9d632bb2116c015bf0862c99d39060836d Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Mon, 31 Jul 2023 13:44:40 +0200 Subject: [PATCH] Super cool function, lezgo --- src/API.ts | 26 +++++++++++++++++++------- src/TransportNode.js | 3 +++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/API.ts b/src/API.ts index a53ccc4..4a00a97 100644 --- a/src/API.ts +++ b/src/API.ts @@ -65,10 +65,8 @@ export class UserAPI { this.MidiConnection.switchMidiOutput(outputName) } - public note(note: number, velocity: number, duration: number): void { - this.MidiConnection.sendMidiNote( - note, velocity, duration - ) + public note(note: number, channel: number, velocity: number, duration: number): void { + this.MidiConnection.sendMidiNote( note, channel, velocity, duration) } public midi_clock(): void { @@ -196,12 +194,26 @@ export class UserAPI { get beats_since_origin(): number { return this.app.clock.beats_since_origin } onbeat(...beat: number[]): boolean { - return ( - beat.includes(this.app.clock.time_position.beat) - && this.app.clock.time_position.pulse == 1 + + let final_pulses: boolean[] = [] + + beat.forEach(b => { + let integral_part = Math.floor(b); + let decimal_part = b - integral_part; + final_pulses.push( + integral_part === this.app.clock.time_position.beat && + this.app.clock.time_position.pulse === decimal_part * this.app.clock.ppqn ) + }); + + return final_pulses.some(p => p == true) + // return ( + // beat.includes(this.app.clock.time_position.beat) + // && this.app.clock.time_position.pulse == 1 + // ) } + evry(...n: number[]): boolean { return n.some(n => this.i % n === 0) } diff --git a/src/TransportNode.js b/src/TransportNode.js index 01e8e24..b31a918 100644 --- a/src/TransportNode.js +++ b/src/TransportNode.js @@ -14,6 +14,8 @@ export class TransportNode extends AudioWorkletNode { this.currentPulse = 0; } + + /** @type {(this: MessagePort, ev: MessageEvent) => any} */ handleMessage = (message) => { if (message.data && message.data.type === "bang") { @@ -30,6 +32,7 @@ export class TransportNode extends AudioWorkletNode { tryEvaluate( this.app, this.app.global_buffer ); this.hasBeenEvaluated = true; this.currentPulse = info.ppqn; + this.app.api.midi_clock(); } } };