If you are tired of guessing note timings or hardcoding arrays of integers, give it a try. Compose in the piano roll. Code in Lua. Let midi2lua handle the handshake. Have you used MIDI with Lua before? Are you building a rhythm game or a synth tool? Let me know in the comments below.
Instead of hardcoding noteOn(60, 100) a thousand times, you feed your MIDI file into midi2lua , and it outputs a table like this: midi2lua
Turning MIDI notes into executable code for games, visuals, and custom DAW tools. If you are tired of guessing note timings
function love.update(dt) -- Convert real time to ticks (simplified) current_tick = current_tick + (dt * (bpm / 60) * ticks_per_beat) Let midi2lua handle the handshake
Bridging the Gap: An Introduction to midi2lua for Interactive Music
Want a boss in your RPG to cast spells on specific beats of the background music? Convert the MIDI percussion track to Lua. When the Lua clock hits tick 1920 , spawn the fireball. It is deterministic and perfectly synced.
for _, track in ipairs(midi_data.tracks) do for _, event in ipairs(track) do if event.tick <= current_tick and not event.triggered then if event.type == "note_on" then playSound(noteToFrequency(event.note)) end event.triggered = true end end end end Most midi2lua converters are command-line tools or simple Python/Lua scripts.