Maestro - Midi Player Tool Kit for Unity Version 2.19.0
Loading...
Searching...
No Matches
Loading and Activation

Load SoundFonts from internal resources, local files, or remote URLs. More...

Functions

bool MidiPlayerTK.MPTKSoundFont.Load (string path=null)
 Loads a SoundFont file on the fly while the application is running (MPTK Pro).

Detailed Description

Load SoundFonts from internal resources, local files, or remote URLs.

Function Documentation

◆ Load()

bool MidiPlayerTK.MPTKSoundFont.Load ( string path = null)

Loads a SoundFont file on the fly while the application is running (MPTK Pro).

Note
This method returns immediately with a boolean status: false if the load was canceled, or true if the load is in progress. Since loading may take time, use LoadedCallback to be notified when the SoundFont is ready or if an error occurs. StatusSoundFont provides the current loading status, and ProgressCallback can be used to track progress.
Parameters
pathSFThe path to the SoundFont, loading from:
  • Local desktop when path starts with file://
  • a web resource when starts with http:// or https://
  • else from the internal MPTK soundfont DB with this name,
  • if null or empty, the default internal soundfont is selected.
Returns
  • true if loading is in progress. Define LoadedCallback to get information when loading is complete.
  • false if an error is detected in the parameters. The callback LoadedCallback is not called if the return value is false.
List<MidiSynth> midiSynths = new List<MidiSynth>();
midiSynths.AddRange(FindObjectsByType<MidiFilePlayer>(FindObjectsSortMode.None));
foreach (MidiSynth midiSynth in midiSynths)
{
midiSynth.MPTK_SoundFont.ProgressCallback = (float progress) =>
{
SoundfontInProgress(progress, midiSynth);
};
// This callback will be triggered when the soundfont is ready.
midiSynth.MPTK_SoundFont.LoadedCallback = (MidiSynth synth) =>
{
SoundfontIsReady(synth);
};
// Prepare switching between SoundFonts for each selected synth.
// Here we load the SoundFont from the URI defined in the UI.
// Set download options defined in the UI.
// -------------------------------------------------------------------
midiSynth.MPTK_SoundFont.LoadFromCache = True;
midiSynth.MPTK_SoundFont.SaveToCache = True;
midiSynth.MPTK_SoundFont.DownloadOnly = False;
bool result = midiSynth.MPTK_SoundFont.Load("https://mptkapi.paxstellar.com/GeneralUser-GS-v2.0.1.sf2");
if (!result)
Debug.Log($"TestLoadSF - Download canceled, status:{MidiPlayerGlobal.MPTK_StatusLastSoundFontLoaded} URI:{InputURLSoundFontAtRun.text}");
}
Core sample-based SoundFont synthesizer (base class).
Definition MidiSynth.cs:66
MPTKSoundFont MPTK_SoundFont
At runtime, SoundFonts can be loaded dynamically from the local file system or directly from the web....
Definition MidiSynth.cs:244
bool Load(string path=null)
Loads a SoundFont file on the fly while the application is running (MPTK Pro).
Definition MPTKSoundFontPro.cs:151
See also
LoadedCallback
ProgressCallback
StatusSoundFont
LoadFromCache
SaveToCache
DownloadOnly