Here you will see how to add Midi Musics in your Unity application in a few steps.
if you are starting a new project go to 1-Project chapter bellow.
But if you are updating Midi Player ToolKit, some older classes will remain in the folders because Unity import won’t removed these files and you will get tricky issues. Consequently, please follow this steps:
- backup your project,
- remove the entire current version in the Unity Editor project panel. Which means: remove folder MidiPlayer.
- and go to 1-Project chapter below.
1.2 – Import Unity package in your Unity application, you will get something like this in your project:
Tips : Free version comes with a default SoundFont (GeneralUser_GS_SoftSynth_v144) and some examples of Midi files. However, you can delete all the Midi files and add your favorites (see Midi Player Tool Kit Setup below) even with the free version 😉
SoundFont(R) is a registered trademark of E-mu Systems, Inc.
Recommendations: to facilitate installation of futures updates of MPTK, please follow these rules otherwise you will lost compatibility with the futures versions.
- Create your assets apart of the MidiPlayer assets folder.
- Don’t change anything in MPTK scripts or hierarchy.
- Don’t change anything in Prefab.
- Use only documented API.
2 – Hierarchy
2.1 – Add to your Unity hierarchy, one or more “MidiFilePlayer” Prefab from “MidiPlayer/Prefab”. Each one can plays a different Midi file. Of course, add the prefab directly at the top level of your hierarchy or attached to another gameObject (2D or 3D Object, Camera, Light … ). As you want!
2.2 – Check that you have an AudioListener component somewhere in the hierarchy of your scene. This component is typically associated with the “Main Camera”.
Tips: Unless you are an expert of MPTK, never try to use directly MPTK source files as MidiFilePlayer.cs. Some components are required to play Midi Music. Always use Prefab!
3 – From the MidiFilePlayer Inspector
3.1 – Firstly, select one MidiFilePlayer in the hierarchy, then look at the Inspector.
3.2.1 – Secondly, select the Midi File to play. But, if no Midi is available, see How to add Midi file.
3.2.2 – Most importantly, check that “Play At Startup” and “Send To Synth” are selected (default value).
3.2.3 – It’s over! Now you can run your Unity application, the Midi begins to play!
After that, you can try to change some parameters in the inspector: play speed, transpose, add effects… See here to have a description of all parameters.