-- Example: Handling incoming MIDI data in Lua -- Triggered when a key is pressed or released function onNoteEvent(channel, note, velocity) if velocity > 0 then print(string.format("Note ON: Key %d on Channel %d with Velocity %d", note, channel, velocity)) -- Custom Logic: Trigger an action if middle C (60) is pressed if note == 60 then triggerMacro() end else print(string.format("Note OFF: Key %d on Channel %d", note, channel)) end end -- Triggered when a knob or fader is moved function onControlChange(channel, ccNumber, value) print(string.format("CC Change: Knob %d shifted to Value %d", ccNumber, value)) -- Custom Logic: Scale a visual element's opacity based on fader position local opacity = value / 127 setElementOpacity(opacity) end function triggerMacro() print("Executing custom workflow automation...") end Use code with caution. Key Benefits of Using Lua for MIDI
-- player.lua (requires LÖVE or any Lua with timing) local song = require("song")
Midi2Lua provides a straightforward interface with three primary functions:
At its core, midi2lua is a parser/transpiler that reads a standard .mid file and outputs a containing every note, velocity, and control change. midi2lua
Streamers and flight simulator enthusiasts use Midi2Lua to turn old MIDI hardware into custom control decks. Flight sim pilots can map physical MIDI radio knobs to adjust cockpit altimeters via Lua scripts that interface directly with games like Microsoft Flight Simulator. Getting Started: A Basic Example
| Domain | Example | |--------|---------| | Game engines | Roblox (using sound or custom note events), LOVE2D, Defold | | Music visualisers | LED strips, live visuals triggered by note‑on/off | | Chiptune trackers | Convert MIDI to Lua tables for software synth engines | | Interactive installations | Schedule events based on musical time |
midi2lua does not magically create sound. It gives you . You still need a soundfont or a synthesizer (like Soloud , FMOD , or Roblox’s Sound objects) to turn those note pitches into audio. Think of it as the sheet music, not the orchestra. -- Example: Handling incoming MIDI data in Lua
: A MIDI processing tool that allows you to write Lua scripts to manipulate MIDI events in real-time within a DAW .
In live entertainment, software platforms like use Lua for advanced lighting desk customization. By translating incoming MIDI timecode or notes into Lua commands, lighting designers can write scripts that trigger complex visual sequences, parse device states, or dynamically alter fixture properties on the fly based on what the band is playing. 3. Custom Gaming Macros and Hotkeys
local song = note = 60, time = 0.5, velocity = 100, note = 64, time = 1.0, velocity = 90, -- ... more notes Use code with caution. Flight sim pilots can map physical MIDI radio
The Lua runtime matches the MIDI input to a specific script template and executes the corresponding code instantly. Writing a Basic midi2lua Script
For game developers, composers, and creative technologists, translating musical intent into functional code has historically been a tedious manual process. emerges as a critical utility, acting as a bridge that converts MIDI (Musical Instrument Digital Interface) data into Lua code , a scripting language heavily used in gaming engines like Roblox, LÖVE (Love2D), and various proprietary systems.
LuaMidi provides a pure Lua library for reading and writing MIDI files with an exceptionally friendly API. It abstracts away technical complexities like delta-time calculations and NoteOn/NoteOff pairing, presenting MIDI data in completely human-readable structures. A simple example shows its elegance: creating a C major scale requires just a few lines of code, with notes specified as intuitive strings like “C3” and “D3”.
So what can you do with midi2lua? Here are a few example use cases:
is a conversion tool or script primarily used within the Roblox community to transform MIDI music files into Lua scripts . These scripts are typically designed for "auto piano" players, allowing users to play complex songs perfectly on in-game virtual pianos. Key Features & Functionality