Skip to content

A lightweight C# library for synchronizing audio and code events in an artist-driven context.

License

Notifications You must be signed in to change notification settings

cadenceblorbo/midi2event

Repository files navigation


MIDI2EventLogo

A lightweight C# library for synchronizing audio and code events in an artist-driven context.

Report Bug/Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Current Limitations
  5. Roadmap
  6. License
  7. Contact
  8. Acknowledgments

About The Project

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.

(back to top)

Getting Started

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;

(back to top)

Usage

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.

Unity Pointers

  • 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.
  • For the best synchronization, it is recommended to calculate the deltaTime passed into MIDI2Event using AudioSource.timeSamples.

Godot Pointers

Coming Soon (?)

(back to top)

Current Limitations

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.)

(back to top)

Roadmap

  • Basic Features
  • Expanded MIDI Support
    • More Formats
    • More Chunks
  • Premade Engine Packages
    • Unity
    • Godot
  • Formal Documentation

(back to top)

License

Distributed under the GNU Lesser General Public License, Version 3. See LICENSE.txt for more information.

(back to top)

Contact

Cadence Hagenauer - devilstritone#0000 - cadence.hagenauer@gmail.com

Project Link: https://github.com/cadenceblorbo/midi2event

(back to top)

Acknowledgments

(back to top)

About

A lightweight C# library for synchronizing audio and code events in an artist-driven context.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages