Page tree
Skip to end of metadata
Go to start of metadata


Function to read a MIDI file (.mid). The function creates a MIDI sequence table that contains the data of the MIDI file. See MIDI Sequence Table for details on the fields of the MIDI sequence table.

Available in: Controller.


pathThe path and file name of the MIDI file.string

Return Values

Returns a MIDI sequence table. See MIDI Sequence Table for details.


To explore the following script:

  1. Download C Major Scale.mid.
  2. Create an empty program and add a script module.
  3. Paste the script into the text editor of the script module and adjust the file path of readMidiFile to the location of the file on your system.
  4. Execute the script and play some notes.


-- read note-on events from a MIDI file and play them

midiSequence = readMidiFile("c:/temp/C Major Scale.mid") --[[ please set the file path to the location
                                                              of the file on your system before you run
                                                              the script ]]
numberOfEvents = #midiSequence.tracks[1].events
i = 1

print(midiSequence.songname..".mid loaded!")

function onNote(event)
    -- start from the beginning if the last event has been reached
    if i >= numberOfEvents then
        i = 1
    -- find the next note-on event
        event = midiSequence.tracks[1].events[i]
        i = i + 1
        if i > numberOfEvents then
    until event.type == EventType.noteOn
    -- print and play the note-on events
    local id = playNote(event.note, event.velocity, 0)

1 Comment