Refactor logicalTime as incremental
This commit is contained in:
13
src/Clock.ts
13
src/Clock.ts
@ -33,7 +33,8 @@ export class Clock {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ctx: AudioContext;
|
ctx: AudioContext;
|
||||||
elapsed: number
|
elapsed: number;
|
||||||
|
logicalTime: number;
|
||||||
transportNode: TransportNode | null;
|
transportNode: TransportNode | null;
|
||||||
private _bpm: number;
|
private _bpm: number;
|
||||||
time_signature: number[];
|
time_signature: number[];
|
||||||
@ -45,6 +46,7 @@ export class Clock {
|
|||||||
this.time_position = { bar: 0, beat: 0, pulse: 0 };
|
this.time_position = { bar: 0, beat: 0, pulse: 0 };
|
||||||
this.time_signature = [4, 4];
|
this.time_signature = [4, 4];
|
||||||
this.elapsed = 0;
|
this.elapsed = 0;
|
||||||
|
this.logicalTime = 0;
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
this._bpm = 120;
|
this._bpm = 120;
|
||||||
this._ppqn = 48;
|
this._ppqn = 48;
|
||||||
@ -144,10 +146,6 @@ export class Clock {
|
|||||||
return this._ppqn;
|
return this._ppqn;
|
||||||
}
|
}
|
||||||
|
|
||||||
get logicalTime(): number {
|
|
||||||
return this.tick * this.pulse_duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
get realTime(): number {
|
get realTime(): number {
|
||||||
return this.elapsed;
|
return this.elapsed;
|
||||||
}
|
}
|
||||||
@ -163,6 +161,11 @@ export class Clock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public incrementTick() {
|
||||||
|
this.tick++;
|
||||||
|
this.logicalTime += this.pulse_duration;
|
||||||
|
}
|
||||||
|
|
||||||
public nextTickFrom(time: number, nudge: number): number {
|
public nextTickFrom(time: number, nudge: number): number {
|
||||||
/**
|
/**
|
||||||
* Compute the time remaining before the next clock tick.
|
* Compute the time remaining before the next clock tick.
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export class TransportNode extends AudioWorkletNode {
|
|||||||
} else if (message.data.type === "bang") {
|
} else if (message.data.type === "bang") {
|
||||||
if (this.app.settings.send_clock)
|
if (this.app.settings.send_clock)
|
||||||
this.app.api.MidiConnection.sendMidiClock();
|
this.app.api.MidiConnection.sendMidiClock();
|
||||||
this.app.clock.tick++;
|
this.app.clock.incrementTick();
|
||||||
const futureTimeStamp = this.app.clock.convertTicksToTimeposition(
|
const futureTimeStamp = this.app.clock.convertTicksToTimeposition(
|
||||||
this.app.clock.tick
|
this.app.clock.tick
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user