Skip to content

Commit a5c7b30

Browse files
committed
pattern update speed match with tempo
1 parent 9cb2fbd commit a5c7b30

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface TrackerRuntimeState {
66
uiModulePtr: number;
77
dummyBufferPtr: number;
88
numChannels: number;
9+
tempoFactor: number;
910
currentRow: number;
1011
lastFrameTime: number;
1112
uiLoopStarted: boolean;
@@ -35,6 +36,7 @@ export function createTrackerRuntimeState(): TrackerRuntimeState {
3536
uiModulePtr: 0,
3637
dummyBufferPtr: 0,
3738
numChannels: 0,
39+
tempoFactor: 1,
3840
currentRow: -1,
3941
lastFrameTime: 0,
4042
uiLoopStarted: false,

src/tracker.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export class TrackerPlaybackController {
7878
}
7979

8080
setTempo(value: number): void {
81+
this.state.tempoFactor = Math.max(0.25, value);
8182
this.player.setTempo(value);
83+
this.state.lastFrameTime = performance.now();
8284
}
8385

8486
setOscilloscopeTheme(lineColor: string, backgroundColor: string): void {
@@ -453,20 +455,21 @@ export class TrackerPlaybackController {
453455
const now = performance.now();
454456
let deltaSeconds = Math.max(0, (now - this.state.lastFrameTime) / 1000);
455457
this.state.lastFrameTime = now;
458+
const tempoFactor = this.state.tempoFactor;
456459

457460
if (deltaSeconds > 0.25) {
458461
const currentSec = this.state.legacyModule._openmpt_module_get_position_seconds(this.state.uiModulePtr);
459462
this.state.legacyModule.ccall(
460463
"openmpt_module_set_position_seconds",
461464
"number",
462465
["number", "number"],
463-
[this.state.uiModulePtr, currentSec + deltaSeconds],
466+
[this.state.uiModulePtr, currentSec + deltaSeconds * tempoFactor],
464467
);
465468
deltaSeconds = 0;
466469
this.state.fractionalFrames = 0;
467470
}
468471

469-
const totalFrames = deltaSeconds * APP_CONSTANTS.sampleRate + this.state.fractionalFrames;
472+
const totalFrames = deltaSeconds * APP_CONSTANTS.sampleRate * tempoFactor + this.state.fractionalFrames;
470473
const frames = Math.floor(totalFrames);
471474
this.state.fractionalFrames = totalFrames - frames;
472475

@@ -487,13 +490,19 @@ export class TrackerPlaybackController {
487490
let patternIndex = -1;
488491
let row = -1;
489492
let pos = -1;
493+
let currentSeconds = -1;
490494

491495
try {
492496
patternIndex = this.state.legacyModule._openmpt_module_get_current_pattern(this.state.uiModulePtr);
493497
row = this.state.legacyModule._openmpt_module_get_current_row(this.state.uiModulePtr);
494498
pos = this.state.legacyModule._openmpt_module_get_current_order(this.state.uiModulePtr);
499+
currentSeconds = this.state.legacyModule._openmpt_module_get_position_seconds(this.state.uiModulePtr);
495500
} catch {}
496501

502+
if (!this.state.seeking && currentSeconds >= 0) {
503+
this.updateProgressUi(currentSeconds, this.getPlaybackDuration());
504+
}
505+
497506
if (patternIndex >= 0 && patternIndex !== this.patternView.getCurrentPattern()) {
498507
this.renderPatternByIndex(patternIndex);
499508
}

0 commit comments

Comments
 (0)