minor fixes

This commit is contained in:
2023-08-02 18:11:49 +02:00
parent 3e3dd368c1
commit 162cc2fae3
3 changed files with 30 additions and 36 deletions

View File

@ -164,9 +164,14 @@ export class UserAPI {
// Transport functions
// =============================================================
bpm(bpm: number): void {
bpm(bpm?: number): number {
if (bpm === undefined)
return this.app.clock.bpm
this.app.clock.bpm = bpm
return bpm
}
tempo = this.bpm
time_signature(numerator: number, denominator: number): void {
this.app.clock.time_signature = [numerator, denominator]
@ -211,8 +216,12 @@ export class UserAPI {
get pulse(): number { return this.app.clock.time_position.pulse }
get beat(): number { return this.app.clock.time_position.beat }
onbar(...bar: number[]): boolean {
return bar.some(b => b === this.app.clock.time_position.bar)
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);
console.log(bar_list)
console.log(bar.some(b => bar_list.includes(b % n)))
return bar.some(b => bar_list.includes(b % n))
}
onbeat(...beat: number[]): boolean {
@ -234,7 +243,6 @@ export class UserAPI {
}
mod(...pulse: number[]): boolean { return pulse.some(p => this.app.clock.time_position.pulse % p === 0) }
modbar(...bar: number[]): boolean { return bar.some(b => this.app.clock.time_position.bar % b === 0) }
// =============================================================
@ -244,9 +252,8 @@ export class UserAPI {
// Small ZZFX interface for playing with this synth
zzfx = (...thing: number[]) => zzfx(...thing);
playSound = async (values: object) => {
sound = async (values: object) => {
await this.load;
webaudioOutput(sound(values), 0.01) // TODO: timestamp précis du temps d'exécution
webaudioOutput(sound(values), 0.00)
}
}

View File

@ -14,7 +14,7 @@ export class TransportNode extends AudioWorkletNode {
this.currentPulsePosition = 0;
this.nextPulsePosition = -1;
this.executionLatency = 0;
this.lastLatencies = [0, 0, 0, 0, 0];
this.lastLatencies = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
this.indexOfLastLatencies = 0;
setInterval(() => this.ping(), 1000);
}
@ -27,7 +27,7 @@ export class TransportNode extends AudioWorkletNode {
handleMessage = (message) => {
if (message.data && message.data.type === "ping") {
const delay = performance.now() - message.data.t;
console.log(delay);
// console.log(delay);
} else if (message.data && message.data.type === "bang") {
let { futureTimeStamp, timeToNextPulse, nextPulsePosition } = this.convertTimeToNextBarsBeats(message.data.currentTime);
@ -38,10 +38,12 @@ export class TransportNode extends AudioWorkletNode {
const now = performance.now();
this.app.clock.time_position = futureTimeStamp;
this.$clock.innerHTML = `[${futureTimeStamp.bar} | ${futureTimeStamp.beat} | ${zeroPad(futureTimeStamp.pulse, '2')}]`;
tryEvaluate( this.app, this.app.global_buffer );
tryEvaluate(
this.app,
this.app.global_buffer
);
this.hasBeenEvaluated = true;
this.currentPulsePosition = nextPulsePosition;
this.app.api.midi_clock();
const then = performance.now();
this.lastLatencies[this.indexOfLastLatencies] = then - now;
this.indexOfLastLatencies = (this.indexOfLastLatencies + 1) % this.lastLatencies.length;
@ -86,7 +88,7 @@ export class TransportNode extends AudioWorkletNode {
const futureBarNumber = futureBeatNumber / beatsPerBar;
const futureTimeStamp = {
bar: Math.floor(futureBarNumber) + 1,
beat: Math.floor(futureBarNumber) % beatsPerBar + 1,
beat: Math.floor(futureBeatNumber) % beatsPerBar + 1,
pulse: Math.floor(this.nextPulsePosition) % this.app.clock.ppqn
};
this.app.clock.tick++
@ -95,19 +97,5 @@ export class TransportNode extends AudioWorkletNode {
timeToNextPulse,
nextPulsePosition
};
// TODO: correction
// const barNumber = Math.floor(beatNumber / beatsPerBar) + 1;
// const beatsPerBar = this.app.clock.time_signature[0];
// const beatWithinBar = Math.floor(beatNumber % beatsPerBar) + 1;
// const ppqnPosition = Math.floor((beatNumber % 1) * this.app.clock.ppqn);
// return {
// bar: barNumber,
// beat: beatWithinBar,
// ppqn: ppqnPosition,
// delta: delta
// };
}
}

View File

@ -127,8 +127,6 @@ export class Editor {
// CodeMirror Management
// ================================================================================
console.log(this.settings)
this.fontSize = new Compartment();
this.vimModeCompartment = new Compartment();
const vimPlugin = this.settings.vimMode ? vim() : [];
@ -679,11 +677,12 @@ document.addEventListener("keydown", startOnEnter);
document.getElementById("start-button")!.addEventListener("click", startClock);
// When the user leaves the page, all the universes should be saved in the localStorage
// window.addEventListener("beforeunload", () => {
// event.preventDefault();
// event.returnValue = "";
// // Iterate over all local files and set the candidate to the committed
// app.currentFile.candidate = app.view.state.doc.toString();
// app.currentFile.committed = app.view.state.doc.toString();
// app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
// });
window.addEventListener("beforeunload", () => {
event.preventDefault();
event.returnValue = "";
// Iterate over all local files and set the candidate to the committed
app.currentFile.candidate = app.view.state.doc.toString();
app.currentFile.committed = app.view.state.doc.toString();
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
app.clock.stop()
});