Fix pause/stop issue
This commit is contained in:
15
src/Clock.ts
15
src/Clock.ts
@ -163,11 +163,11 @@ export class Clock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get realTime(): number {
|
get realTime(): number {
|
||||||
return this.app.audioContext.currentTime - this.lastPlayPressTime - this.totalPauseTime;
|
return this.app.audioContext.currentTime - this.totalPauseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
get deviation(): number {
|
get deviation(): number {
|
||||||
return Math.abs(this.logicalTime - this.realTime)
|
return Math.abs(this.logicalTime - this.realTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
set ppqn(ppqn: number) {
|
set ppqn(ppqn: number) {
|
||||||
@ -217,9 +217,7 @@ export class Clock {
|
|||||||
this.running = true;
|
this.running = true;
|
||||||
this.app.api.MidiConnection.sendStartMessage();
|
this.app.api.MidiConnection.sendStartMessage();
|
||||||
this.lastPlayPressTime = this.app.audioContext.currentTime;
|
this.lastPlayPressTime = this.app.audioContext.currentTime;
|
||||||
if (this.tick > 0) {
|
this.totalPauseTime += (this.lastPlayPressTime - this.lastPauseTime);
|
||||||
this.totalPauseTime += this.app.audioContext.currentTime - this.lastPauseTime;
|
|
||||||
}
|
|
||||||
this.transportNode?.start();
|
this.transportNode?.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +231,7 @@ export class Clock {
|
|||||||
this.transportNode?.pause();
|
this.transportNode?.pause();
|
||||||
this.app.api.MidiConnection.sendStopMessage();
|
this.app.api.MidiConnection.sendStopMessage();
|
||||||
this.lastPauseTime = this.app.audioContext.currentTime;
|
this.lastPauseTime = this.app.audioContext.currentTime;
|
||||||
|
this.logicalTime = this.realTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
public stop(): void {
|
||||||
@ -242,9 +241,9 @@ export class Clock {
|
|||||||
* @remark also sends a MIDI message if a port is declared
|
* @remark also sends a MIDI message if a port is declared
|
||||||
*/
|
*/
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.app.clock.tick = 0;
|
this.tick = 0;
|
||||||
this.logicalTime = 0;
|
this.lastPauseTime = this.app.audioContext.currentTime;
|
||||||
this.totalPauseTime = 0;
|
this.logicalTime = this.realTime;
|
||||||
this.time_position = { bar: 0, beat: 0, pulse: 0 };
|
this.time_position = { bar: 0, beat: 0, pulse: 0 };
|
||||||
this.app.api.MidiConnection.sendStopMessage();
|
this.app.api.MidiConnection.sendStopMessage();
|
||||||
this.transportNode?.stop();
|
this.transportNode?.stop();
|
||||||
|
|||||||
@ -82,7 +82,7 @@ export class Player extends Event {
|
|||||||
};
|
};
|
||||||
|
|
||||||
origin = (): number => {
|
origin = (): number => {
|
||||||
return this.app.clock.pulses_since_origin;
|
return this.app.clock.pulses_since_origin + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
pulse = (): number => {
|
pulse = (): number => {
|
||||||
|
|||||||
Reference in New Issue
Block a user