limit evaluation to once per pulse

This commit is contained in:
2023-07-28 18:08:12 +02:00
parent cf3428b3c3
commit 04b757fbfa
2 changed files with 14 additions and 3 deletions

View File

@ -2,8 +2,6 @@ import { Editor } from "./main";
import { tryEvaluate } from "./Evaluator";
// @ts-ignore
import { ZZFX, zzfx } from "zzfx";
// import * as Tone from 'tone';
export class UserAPI {

View File

@ -10,14 +10,27 @@ export class TransportNode extends AudioWorkletNode {
this.port.start();
/** @type {HTMLSpanElement} */
this.$clock = document.getElementById("clockviewer");
this.hasBeenEvaluated = false;
this.currentPulse = 0;
}
/** @type {(this: MessagePort, ev: MessageEvent<any>) => any} */
handleMessage = (message) => {
if (message.data && message.data.type === "bang") {
let info = this.convertTimeToBarsBeats(message.data.currentTime);
this.app.clock.time_position = { bar: info.bar, beat: info.beat, pulse: info.ppqn }
this.$clock.innerHTML = `[${info.bar} | ${info.beat} | ${zeroPad(info.ppqn, '2')}]`
tryEvaluate( this.app, this.app.global_buffer );
// Evaluate the global buffer only once per ppqn value
if (this.currentPulse !== info.ppqn) {
this.hasBeenEvaluated = false;
}
if (!this.hasBeenEvaluated) {
tryEvaluate( this.app, this.app.global_buffer );
this.hasBeenEvaluated = true;
this.currentPulse = info.ppqn;
}
}
};