Table of Contents
MIDI2Event allows users to synchronize code events to music by encoding event charts using MIDI data. Notes in the MIDI chart can be linked to events, triggering them in time with the separate audio file. You can think of the MIDI data as operating similar to an Audio-Animatronic, where the MIDI notes in the chart are not used to generate audio, but rather to generate behavior. This eliminates the need for creating custom charting software, and enables charts to be created by artists and developers in whatever DAW they already use (as the MIDI file format is widely supported).
This library was primarily created for the sake of game developers, but could be applied to other fields.
Download the latest LibOnly archive or the .dll and place it in your project. Import the MIDI2Event namespace at the top of your script with a using
statement:
using MIDI2Event;
First, create a MIDI2EventSystem using its constructor, passing in the path to your MIDI chart (and an optional lowest octave if your DAW doesn't use -1 as its lowest):
MIDI2EventSystem(string filePath, int lowestOctave = -1)
To subscribe events to this system, use the MIDI2EventSystem.Subscribe()
method:
public Action Subscribe(
Action action,
Notes note = 0,
int octave = 0,
SubType type = SubType.NoteStart
)
This method allows you to specify what event you want an Action
to be triggered by. Currently, you can trigger an action using:
SubType.NoteStart
SubType.NoteStop
SubType.ChartEnd
If you are using a note-based event, you can specify which note and octave to assign the Action
to.
Call MIDI2EventSystem.Update()
in whatever update function your engine/tool has, passing in the deltaTime in seconds (preferably calculated from the samples of the playing audio).
You can control the playback of the event system using Play()
, Pause()
, Stop()
, and Reset()
.
Currently, the user is responsible for implementing control over the actual audio that plays, as that is dependent on the engine/tool you are using. There are plans to make premade packages for Godot and Unity in the future.
- MIDI charts must be stored in a StreamingAssets folder to be accessible in the build.
- In my experience, the best import settings to use for associated audio clips is to disable Load In Background, use the Decompress On Load load type, and disable Preload Audio Data.
- This will require you to manually load the audio before using it with
AudioClip.LoadAudioData()
.
- This will require you to manually load the audio before using it with
- For the best synchronization, it is recommended to calculate the deltaTime passed into MIDI2Event using
AudioSource.timeSamples
.
Coming Soon (?)
As this library was developed for personal use at first, it currently has limitations on the kind of MIDI data that can be used:
- MIDI data must use format 0 (consisting of a single MIDI track).
- Delta-time must be encoded using ticks per quarter note.
(This page has more details on the MIDI file format.)
- Basic Features
- Expanded MIDI Support
- More Formats
- More Chunks
- Premade Engine Packages
- Unity
- Godot
- Formal Documentation
Distributed under the GNU Lesser General Public License, Version 3. See LICENSE.txt
for more information.
Cadence Hagenauer - devilstritone#0000 - cadence.hagenauer@gmail.com
Project Link: https://github.com/cadenceblorbo/midi2event