Midi2lua

midi2lua: A methodical guide

Overview

  1. Read MIDI file header to get format, number of tracks, and division (TPQN).
  2. For each track: iterate delta-time + events. Maintain absolute tick position by summing delta-times.
  3. Handle running status (reuse previous status byte when omitted).
  4. Convert meta events (especially Set Tempo) and sysex appropriately.
  5. Maintain current tempo map (list of tempo change events with tick position and microseconds per quarter-note).
  6. Convert absolute ticks to seconds using the active tempo for each tick span. If tempo changes occur between ticks, split conversion at tempo boundaries.
  7. Emit Lua event tables, choosing whether to output Note On/Off pairs as single note events with duration or keep as separate on/off events.

8.3 Time Signature Awareness

Incorporate metrical structure for loop points or measure‑based callbacks. midi2lua

Find a Converter: Tools like the MIDI2LUA web converter allow you to upload a .mid file and receive a Lua script output. midi2lua: A methodical guide Overview

Features

LuaMidi Library (GitHub): A pure Lua library for reading and writing MIDI files. It provides an abstraction of MIDI data (NoteOn/NoteOff) into human-readable Lua objects. Read MIDI file header to get format, number

Learn about the technical side of reading and writing MIDI files with the LuaMidi library on GitHub

3. Input → Output Transformation

Input (MIDI file)

If you want, I can: