Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be πŸ“–

MIDI Importer

An asset by G0retZ
The page banner background of a mountain and forest
MIDI Importer hero image

Quick Information

0 ratings
MIDI Importer icon image
G0retZ
MIDI Importer

This addon allows you to import and parse MIDI files in your project as any other resource. It handles almost all available MIDI files features and also has some encapsulated tools for easier use.

Supported Engine Version
4.2
Version String
1.0.1
License Version
MIT
Support Level
community
Modified Date
5 months ago
Git URL
Issue URL
spent several days working on this and debugging. Inintially I tryed to use GDScript Midi File Parser but it turned out confusing and not very convenient to use. So I decided to improve it... And now we are here πŸ™ƒ

Godot 4+ Importer for MIDI (.mid) files.

This addon allows you to import and parse MIDI files in your project as any other resource. It handles almost all available MIDI files features and also has some encapsulated tools for easier use.

Some features:

  • Importing MIDI files of all currently available formats (0-2): Single track, polyphony multitrack and multi-sequence.
  • Supports both SMPTE fps and PPQ timnig parsing and calculations.
  • Has built-in tempo-map extraction for any Track.
  • Has encapsulated SMPTE offset calculation in seconds.
  • The MidiData class itself is thoroghly documented and helps to additionally understand the MIDI format behaviour.

Installation:

  1. Add to the addons folder like any other regular plugin.
  2. Enable it in the project settings as usually.

Usage:

Import MIDI file by drag-n-drop as you do with pictures and other resources. Now you can use in a same way as any other resource: drag-n-drop to Nodes, load, preload etc.

Simple example (just plays some sounds from the first track):

var midi_data: MidiData = load("res://samples/smoke-on-the-water.mid")

func _play():
    var inital_delay := midi_data.tracks[0].get_offset_in_seconds()
    match midi_data.header.format:
        MidiData.Header.Format.SINGLE_TRACK, MidiData.Header.Format.MULTI_SONG:
            var us_per_beat: int = 500_000
            for event in midi_data.tracks[0].events:
                inital_delay += midi_data.header.convert_to_seconds(us_per_beat, event.delta_time)
                var tempo := event as MidiData.Tempo
                var note_on := event as MidiData.NoteOn
                if tempo != null:
                    us_per_beat = tempo.us_per_beat
                elif note_on != null:
                    # TODO: wait for inital_delay and play note_on.note
                    inital_delay = 0
        MidiData.Header.Format.MULTI_TRACK:
            var index = 0
            var tempo_map: Array[Vector2i] = midi_data.tracks[0].get_tempo_map()
            var us_per_beat := tempo_map[index].y
            var time: int = 0
            for event in midi_data.tracks[1].events:
                time += event.delta_time
                while time >= tempo_map[index].x:
                    index += 1
                    us_per_beat = tempo_map[index].y
                inital_delay += midi_data.header.convert_to_seconds(us_per_beat, event.delta_time)
                var note_on := event as MidiData.NoteOn
                if note_on != null:
                    # TODO: wait for inital_delay and play note_on.note
                    inital_delay = 0

MIDI Specification resources used:

Enjoy using it!

🌻 If you find this addon helpful, please consider supporting my efforts by buying me a coffee (donating)! I would appreciate it very much 😊

This addon allows you to import and parse MIDI files in your project as any other resource. It handles almost all available MIDI files features and also has some encapsulated tools for easier use.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
MIDI Importer icon image
G0retZ
MIDI Importer

This addon allows you to import and parse MIDI files in your project as any other resource. It handles almost all available MIDI files features and also has some encapsulated tools for easier use.

Supported Engine Version
4.2
Version String
1.0.1
License Version
MIT
Support Level
community
Modified Date
5 months ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers