Global MPTK feature
MidiPlayerGlobal is a singleton and static class for managing all global features of MPTK.
For non C# specialist:
- singleton: only one instance can exist at the same time.
- static: the class doesn’t need to be instantiated (done automatically by MPTK) in an object to be used. All properties are shared and are available for all others objects. That is very useful!
The script MidiPlayerGlobal.cs
exists in each MPTK Prefab. But when running, only one is kept in the scene hierarchy.


Inspector [PRO only]

With the inspector, you can:
- Current SoundFont: select a SoundFont from the MPTK SoundFont available.
- Load SoundFont at startup: the selected SoundFont is loaded when application is started. It’s the default behaviors. It’s possible de disable this automatic loading.
- Load Samples at startup (no core mode): the “no core mode” will be removed with the next major version.
- SoundFont URL or file path: with the version Pro it’s possible to dynamically load a SoundFont when running from a local file on your desktop or from a web site. But, SoundFont loading could take some times.
Integration in your script
All methods and properties of MidiPlayerGlobal
are static. So you can use directly by the class name to access it. Look at this page for more information how scripting with MPTK and to download the full documentation.
Look at the MidiPlayerGlobal API for a full information.
Example of methods:
Debug.Log(string.Format("Load Time:{0} s Samples:{1} s Count Presets:{2} Samples:{3}",
MidiPlayerGlobal.MPTK_TimeToLoadSoundFont.TotalSeconds,
MidiPlayerGlobal.MPTK_TimeToLoadWave.TotalSeconds,
MidiPlayerGlobal.MPTK_CountPresetLoaded,
MidiPlayerGlobal.MPTK_CountWaveLoaded));
// Dynamically loading a SoundFont when running: (Pro version)
void Start()
{
MidiPlayerGlobal.OnEventPresetLoaded.AddListener(EndLoadingSF);
MidiPlayerGlobal.MPTK_LoadLiveSF(URLSoundFontAtStart);
}
public void EndLoadingSF()
{
Debug.Log("End loading SF, Maestro ready to play");
}
public void LoadSF()
{
string urlSF= "https://mptkapi.paxstellar.com/GSv1471.sf2";
if (URLSoundFont != null && string.IsNullOrEmpty(URLSoundFont.text))
urlSF = URLSoundFont.text;
MidiPlayerGlobal.MPTK_LoadLiveSF(urlSF);
}