first boom boom

This commit is contained in:
2023-12-01 10:45:35 +01:00
parent 5b9a59effe
commit bb5dd6b348
2 changed files with 25 additions and 1 deletions

View File

@ -1,8 +1,10 @@
import { Editor } from "./main"; import { Editor } from "./main";
import { tryEvaluate } from "./Evaluator";
// @ts-ignore // @ts-ignore
import { getAudioContext } from "superdough"; import { getAudioContext } from "superdough";
// @ts-ignore // @ts-ignore
import "zyklus"; import "zyklus";
const zeroPad = (num: number, places: number) => String(num).padStart(places, "0");
export interface TimePosition { export interface TimePosition {
/** /**
@ -48,6 +50,7 @@ export class Clock {
lastPauseTime: number; lastPauseTime: number;
lastPlayPressTime: number; lastPlayPressTime: number;
totalPauseTime: number; totalPauseTime: number;
timeviewer: HTMLElement;
constructor( constructor(
public app: Editor, public app: Editor,
@ -64,12 +67,32 @@ export class Clock {
this.lastPauseTime = 0; this.lastPauseTime = 0;
this.lastPlayPressTime = 0; this.lastPlayPressTime = 0;
this.totalPauseTime = 0; this.totalPauseTime = 0;
this.timeviewer = document.getElementById("timeviewer")!;
this.clock = getAudioContext().createClock(this.clockCallback, this.pulse_duration) this.clock = getAudioContext().createClock(this.clockCallback, this.pulse_duration)
} }
clockCallback = (time: number, duration: number, tick: number) => { clockCallback = (time: number, duration: number, tick: number) => {
let deadline = time - getAudioContext().currentTime; let deadline = time - getAudioContext().currentTime;
this.tick = tick; this.tick = tick;
if (this.app.clock.running) {
if (this.app.settings.send_clock) {
this.app.api.MidiConnection.sendMidiClock();
}
const futureTimeStamp = this.app.clock.convertTicksToTimeposition(
this.app.clock.tick,
);
this.app.clock.time_position = futureTimeStamp;
if (futureTimeStamp.pulse % this.app.clock.ppqn == 0) {
this.timeviewer.innerHTML = `${zeroPad(futureTimeStamp.bar, 2)}:${
futureTimeStamp.beat + 1
} / ${this.app.clock.bpm}`;
}
if (this.app.exampleIsPlaying) {
tryEvaluate(this.app, this.app.example_buffer);
} else {
tryEvaluate(this.app, this.app.global_buffer);
}
}
// Implement TransportNode clock callback and update clock info with it // Implement TransportNode clock callback and update clock info with it
@ -222,6 +245,7 @@ export class Clock {
this.app.api.MidiConnection.sendStartMessage(); this.app.api.MidiConnection.sendStartMessage();
this.lastPlayPressTime = this.app.audioContext.currentTime; this.lastPlayPressTime = this.app.audioContext.currentTime;
this.totalPauseTime += this.lastPlayPressTime - this.lastPauseTime; this.totalPauseTime += this.lastPlayPressTime - this.lastPauseTime;
this.clock.start()
} }
public pause(): void { public pause(): void {

View File

@ -474,7 +474,7 @@ export class SoundEvent extends AudibleEvent {
} }
superdough( superdough(
filteredEvent, filteredEvent,
this.nudge - this.app.clock.deviation, this.nudge,
filteredEvent.dur, filteredEvent.dur,
); );
} }