nlaha / godot-midi

MIDI file parsing and event playback in Godot 4.1+
MIT License
52 stars 5 forks source link

Rewrite MIDI parsing/playback to support tempo changes and parallel processing of meta events #24

Closed nlaha closed 3 weeks ago

nlaha commented 1 month ago

Some MIDI files that include tempo changes or other meta-events do so in a separate MIDI track. The current system for parsing files into Godot resources loops through an array of events for each track. This means that track 0 is going to be processed before track 1.

The problem arises when programs like FL Studio put all the tempo change events (or other meta events) in track 0, so they all get processed before track 1 is even read. By the time track 1 is read, all the tempo change events have been ingested.

This means we need to either:

  1. Loop over each MIDI track for each tick in the parsing stage
  2. Loop over each MIDI track for each tick in the playback stage, and build a system to interpret MIDI meta events (tempo changes) in the playback class (midi_player.cpp)