|
1 | 1 | import { processEventInternal } from "./process_event"; |
2 | 2 | import { processTick } from "./process_tick"; |
3 | | -import { |
4 | | - assignMIDIPortInternal, |
5 | | - loadNewSequenceInternal |
6 | | -} from "./song_control"; |
| 3 | +import { assignMIDIPortInternal, loadNewSequenceInternal } from "./song_control"; |
7 | 4 | import { setTimeToInternal } from "./play"; |
8 | 5 |
|
9 | 6 | import { MIDI_CHANNEL_COUNT } from "../synthesizer/audio_engine/engine_components/synth_constants"; |
10 | 7 | import { BasicMIDI } from "../midi/basic_midi"; |
11 | 8 | import type { SpessaSynthProcessor } from "../synthesizer/processor"; |
12 | | -import { |
13 | | - type MIDIController, |
14 | | - midiControllers, |
15 | | - midiMessageTypes |
16 | | -} from "../midi/enums"; |
| 9 | +import { type MIDIController, midiControllers, midiMessageTypes } from "../midi/enums"; |
17 | 10 | import type { SequencerEvent, SequencerEventData } from "./types"; |
18 | 11 | import { SpessaSynthWarn } from "../utils/loggin"; |
19 | 12 | import { arrayToHexString } from "../utils/other"; |
@@ -501,26 +494,34 @@ export class SpessaSynthSequencer { |
501 | 494 |
|
502 | 495 | /** |
503 | 496 | * Jumps to a MIDI tick without any further processing. |
504 | | - * @param tick The MIDI tick to jump to. |
| 497 | + * @param targetTicks The MIDI tick to jump to. |
505 | 498 | * @protected |
506 | 499 | */ |
507 | | - protected jumpToTick(tick: number) { |
| 500 | + protected jumpToTick(targetTicks: number) { |
508 | 501 | if (!this._midiData) { |
509 | 502 | return; |
510 | 503 | } |
511 | 504 | this.sendMIDIAllOff(); |
512 | | - const seconds = this._midiData.midiTicksToSeconds(tick); |
| 505 | + const seconds = this._midiData.midiTicksToSeconds(targetTicks); |
513 | 506 | this.callEvent("timeChange", { newTime: seconds }); |
514 | 507 |
|
515 | 508 | // Recalculate time and reset indexes |
516 | 509 | this.recalculateStartTime(seconds); |
517 | 510 | this.playedTime = seconds; |
518 | 511 | this.eventIndexes.length = 0; |
519 | 512 | for (const track of this._midiData.tracks) { |
520 | | - const idx = track.events.findIndex((e) => e.ticks >= tick); |
| 513 | + const idx = track.events.findIndex((e) => e.ticks >= targetTicks); |
521 | 514 | // Not length - 1 since we want to mark the track as finished |
522 | 515 | this.eventIndexes.push(idx < 0 ? track.events.length : idx); |
523 | 516 | } |
| 517 | + |
| 518 | + // Correct tempo |
| 519 | + // Some softy-looped files (example: th06_06.mid) have slightly mismatched tempos |
| 520 | + const targetTempo = this._midiData.tempoChanges.find( |
| 521 | + (t) => t.ticks <= targetTicks |
| 522 | + )!; |
| 523 | + this.oneTickToSeconds = |
| 524 | + 60 / (targetTempo.tempo * this._midiData.timeDivision); |
524 | 525 | } |
525 | 526 |
|
526 | 527 | /* |
|
0 commit comments