MidiPlayerTK.MidiSynth

Base class wich contains all the stuff to build a Wave Table Synth..
More...

Inheritance diagram for MidiPlayerTK.MidiSynth:
MidiPlayerTK.MidiFilePlayer MidiPlayerTK.MidiFilePlayer MidiPlayerTK.MidiInReader MidiPlayerTK.MidiStreamPlayer MidiPlayerTK.MidiStreamPlayer MidiPlayerTK.MidiExternalPlayer MidiPlayerTK.MidiSpatializer MidiPlayerTK.MidiExternalPlayer MidiPlayerTK.MidiSpatializer

Public Types

enum  ModeSpatializer { Channel , Track }
 

Public Member Functions

int MPTK_ChannelBankGetIndex (int channel)
 
int MPTK_ChannelControllerGet (int channel, int controller)
 
int MPTK_ChannelCount ()
 
bool MPTK_ChannelEnableGet (int channel)
 
void MPTK_ChannelEnableSet (int channel, bool enable)
 
int MPTK_ChannelForcedPresetGet (int channel)
 
bool MPTK_ChannelForcedPresetSet (int channel, int preset, int bank=-1)
 
string MPTK_ChannelInfo (int channel)
 
int MPTK_ChannelNoteCount (int channel)
 
bool MPTK_ChannelPresetChange (int channel, int preset, int bank=-1)
 
int MPTK_ChannelPresetGetIndex (int channel)
 
string MPTK_ChannelPresetGetName (int channel)
 
float MPTK_ChannelVolumeGet (int channel)
 
void MPTK_ChannelVolumeSet (int channel, float volume)
 
void MPTK_ChorusSetDefault ()
 
void MPTK_ClearAllSound (bool destroyAudioSource=false, int _idSession=-1)
 
void MPTK_InitSynth (int channelCount=16, bool resetActiveVoices=false)
 
void MPTK_ResetStat ()
 
void MPTK_ReverbSetDefault ()
 
void MPTK_SFChorusSetDefault ()
 
void MPTK_SFFilterSetDefault ()
 
void MPTK_SFReverbSetDefault ()
 
void MPTK_StartSequencerMidi ()
 
void MPTK_StopSynth ()
 
IEnumerator MPTK_WaitAllNotesOff (int _idSession=-1)
 
delegate void OnAudioFrameStartHandler (double synthTime)
 

Public Attributes

bool MPTK_ApplyModLfo
 
bool MPTK_ApplyRealTimeModulator
 
bool MPTK_ApplyVibLfo
 
bool MPTK_AudioSettingFromUnity
 
bool MPTK_AutoBuffer = true
 
int MPTK_AutoCleanVoiceLimit
 
bool MPTK_CorePlayer
 
float MPTK_CutOffVolume = 0.0001f
 
bool MPTK_DirectSendToPlayer
 
bool MPTK_EnableChangeTempo
 
bool MPTK_EnableFreeSynthRate = false
 
bool MPTK_EnablePanChange
 
bool MPTK_EnablePresetDrum
 
bool MPTK_KillByExclusiveClass = true
 
float MPTK_LeanSynthStarting = 0.05f
 
bool MPTK_LogEvents
 
bool MPTK_LogWave
 
bool MPTK_ReleaseSameNote = true
 
uint MPTK_ReleaseTimeMin = 500000
 
float MPTK_ReleaseTimeMod = 1f
 
bool MPTK_ResetChannel = true
 
float MPTK_SFChorusAmplify
 
float MPTK_SFFilterFreqOffset = 0f
 
float MPTK_SFReverbAmplify
 
bool MPTK_SpatialSynthEnabled
 
int MPTK_StatVoiceCountActive
 
int MPTK_StatVoiceCountFree
 
int MPTK_StatVoiceCountPlaying
 
int MPTK_StatVoicePlayed
 
float MPTK_StatVoiceRatioReused
 
bool MPTK_WeakDevice
 
Action< int, long, int, int > OnBeatEvent
 Action executed at each quarter with: More...
 
EventSynthClass OnEventSynthAwake
 
EventSynthClass OnEventSynthStarted
 
Func< MPTKEvent, bool > OnMidiEvent
 
bool playOnlyFirstWave
 

Static Public Attributes

static List< MidiFilePlayerSpatialSynths
 

Properties

bool MPTK_ApplySFChorus [get, set]
 Apply chorus effect as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace(10%). More...
 
bool MPTK_ApplySFFilter [get, set]
 
bool MPTK_ApplySFReverb [get, set]
 Apply reverberation effect as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace(40%). More...
 
bool MPTK_ApplyUnityChorus [get, set]
 
bool MPTK_ApplyUnityReverb [get, set]
 
float MPTK_ChorusDelay [get, set]
 
float MPTK_ChorusDepth [get, set]
 
float MPTK_ChorusDryMix [get, set]
 
float MPTK_ChorusRate [get, set]
 
float MPTK_ChorusWetMix1 [get, set]
 
float MPTK_ChorusWetMix2 [get, set]
 
float MPTK_ChorusWetMix3 [get, set]
 
int MPTK_IndexSynthBuffSize [get, set]
 
int MPTK_IndexSynthRate [get, set]
 
string MPTK_InstrumentPlayed [get]
 
bool MPTK_IsSpatialSynthMaster [get]
 
bool MPTK_KeepPlayingNonLooped [get, set]
 
float MPTK_MaxDistance [get, set]
 
bool MPTK_PauseOnDistance [get, set]
 
float MPTK_ReverbDecayHFRatio [get, set]
 
float MPTK_ReverbDecayTime [get, set]
 
float MPTK_ReverbDelay [get, set]
 
float MPTK_ReverbDensity [get, set]
 
float MPTK_ReverbDiffusion [get, set]
 
float MPTK_ReverbDryLevel [get, set]
 
float MPTK_ReverbHFReference [get, set]
 
float MPTK_ReverbLevel [get, set]
 
float MPTK_ReverbLFReference [get, set]
 
float MPTK_ReverbReflectionDelay [get, set]
 
float MPTK_ReverbReflectionLevel [get, set]
 
float MPTK_ReverbRoom [get, set]
 
float MPTK_ReverbRoomHF [get, set]
 
float MPTK_ReverbRoomLF [get, set]
 
float MPTK_SFChorusDepth [get, set]
 
float MPTK_SFChorusLevel [get, set]
 
float MPTK_SFChorusSpeed [get, set]
 
float MPTK_SFChorusWidth [get, set]
 
float MPTK_SFFilterQModOffset [get, set]
 
float MPTK_SFReverbDamp [get, set]
 
float MPTK_SFReverbLevel [get, set]
 
float MPTK_SFReverbRoomSize [get, set]
 
float MPTK_SFReverbWidth [get, set]
 
bool MPTK_Spatialize [get, set]
 
int MPTK_SpatialSynthIndex [get]
 
int MPTK_SynthRate [get, set]
 
string MPTK_TrackName [get]
 
int MPTK_TransExcludedChannel [get, set]
 
int MPTK_Transpose [get, set]
 
float MPTK_Volume [get, set]
 

Events

OnAudioFrameStartHandler OnAudioFrameStart
 

Detailed Description

Base class wich contains all the stuff to build a Wave Table Synth.

Load SoundFont and samples, process midi event, play voices, controllers, generators ...
This class is inherited by others class to build these prefabs: MidiStreamPlayer, MidiFilePlayer, MidiInReader.
It is not recommended to instanciate directly this class, rather add prefabs to the hierarchy of your scene and use attributs and methods from an instance of them in your script.

Example: midiFilePlayer.MPTK_ChorusDelay = 0.2 or midiStreamPlayer.MPTK_InitSynth()

class extension pro

Version
Maestro Pro

Member Enumeration Documentation

◆ ModeSpatializer

Spatializer Mode for the prefab MidiSpatializer

Version
Maestro Pro
Enumerator
Channel 

Spatial Synth are enabled to dispatch note-on by channels.
As a reminder, only one instrument at at time can be played by a MIDI channel
Instrument (preset) are defined by channel with the MIDI message MPTKCommand.PatchChange

Track 

Spatial Synth are enabled to dispatch note-on by tracks defined in the MIDI.
As a reminder, multiple channels can be played on a tracks, so multiple instruments can be played on a Synth.
Track name are defined with the Meta MIDI message SequenceTrackName. This MIDI message is always defined in MIDI, so name can be missing.

Member Function Documentation

◆ MPTK_ChannelBankGetIndex()

int MidiPlayerTK.MidiSynth.MPTK_ChannelBankGetIndex ( int  channel)

Get the current bank associated to the channel.
Each MIDI channel can play a different preset and bank.

Parameters
channelMIDI channel must be between 0 and 15
Returns
channel preset index or -1 if channel error
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelControllerGet()

int MidiPlayerTK.MidiSynth.MPTK_ChannelControllerGet ( int  channel,
int  controller 
)

Get the value of the controller for the channel.
Each MIDI channel can play a different preset.

Parameters
channelMIDI channel must be between 0 and 15
controllerMIDI Controller must be between 0 and 127. See MPTKEvent::Controller
Returns
controller value or 0 if channel error

◆ MPTK_ChannelCount()

int MidiPlayerTK.MidiSynth.MPTK_ChannelCount ( )

Get channel length. The midi norm is 16, but MPTK can manage up to 32 channels (experimental).

Parameters
channelmust be between 0 and 15
Returns
channel count

◆ MPTK_ChannelEnableGet()

bool MidiPlayerTK.MidiSynth.MPTK_ChannelEnableGet ( int  channel)

Is channel is enabled or disabled.

Parameters
channelchannel, must be between 0 and 15
Returns
true if channel is enabled
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelEnableSet()

void MidiPlayerTK.MidiSynth.MPTK_ChannelEnableSet ( int  channel,
bool  enable 
)

Disable (mute) or enable (unmute) a MIDI channel or all channels when playing.
But all channels are unmuted when MIDI start playing (MidiFilePlayer::MPTK_Play).
By the way, to mute channels just before the playing, use the MidiFilePlayer::OnEventStartPlayMidi. Have a look to the demo: Assets\MidiPlayer\Demo\FreeMVP\MidiLoop.cs

// Start is called before the first frame update
void Start()
{
// Find existing MidiFilePlayer in the scene hierarchy
// ---------------------------------------------------
midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
if (midiFilePlayer == null)
{
Debug.LogWarning("Can't find a MidiFilePlayer Prefab in the current Scene Hierarchy. Add it with the Maestro menu.");
return;
}
midiFilePlayer.MPTK_PlayOnStart = false;
// Set Listeners
// -------------
// triggered when MIDI starts playing (Indeed, will be triggered at every restart)
midiFilePlayer.OnEventStartPlayMidi.AddListener(StartPlay);
// triggered when MIDI ends playing (Indeed, will be triggered at every end of restart)
midiFilePlayer.OnEventEndPlayMidi.AddListener(EndPlay);
// triggered every time a group of MIDI events are ready to be played by the MIDI synth.
midiFilePlayer.OnEventNotesMidi.AddListener(MidiReadEvents);
LoadAndPlay();
}
public void StartPlay(string midiname)
{
// Enable or disable MIDI channel. it's not possible before because channel are not yet allocated
for (int channel = 0; channel < 16; channel++)
// Enable only ChannelSelected or all channels if ChannelSelected equal -1
if (channel == ChannelSelected || ChannelSelected == -1)
midiFilePlayer.MPTK_ChannelEnableSet(channel, true);
else
// Disable this channel
midiFilePlayer.MPTK_ChannelEnableSet(channel, false);
Debug.Log($"<color=green>Start at tick:{midiFilePlayer.MPTK_TickCurrent}</color>" +
$" MPTK_DeltaTicksPerQuarterNote:{midiFilePlayer.MPTK_MidiLoaded.MPTK_DeltaTicksPerQuarterNote}" +
$" MPTK_NumberBeatsMeasure:{midiFilePlayer.MPTK_MidiLoaded.MPTK_NumberBeatsMeasure}" +
$" MPTK_NumberQuarterBeat:{midiFilePlayer.MPTK_MidiLoaded.MPTK_NumberQuarterBeat}");
}
Parameters
channelmust be between 0 and 15 to apply on one channel, -1 to apply to all channels from 0 to 15 v2.9.0
enabletrue to unmute (default), false to mute channel

◆ MPTK_ChannelForcedPresetGet()

int MidiPlayerTK.MidiSynth.MPTK_ChannelForcedPresetGet ( int  channel)

Set forced preset on the channel. MIDI will allways playing with this preset even if a MIDI Preset Change message is received.
Set to -1 to disable this behavior.

Parameters
channel
Returns
preset index, -1 if not set
int preset = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
int bank = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{preset} / {bank}");
int forcedPreset = (int)GUILayout.HorizontalSlider(preset, -1f, 127f);
if (forcedPreset != preset)
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcedPreset);

Another example:

GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelForcedPresetSet()

bool MidiPlayerTK.MidiSynth.MPTK_ChannelForcedPresetSet ( int  channel,
int  preset,
int  bank = -1 
)

Set a Preset on a channel to force the MIDI Synth to always playing with this instrument even if MIDI 'Preset Change' or 'Bank change' messages are received.
Set Preset to -1 to restore the Preset and Bank defined in the MIDI file.

Parameters
channel0 to 15 channel
presetPreset to force in the range 0 to 127 preset. Set to -1 to restore the Preset and Bank known from the MIDI file.
bankOptionnal. Bank to force in the range 0 to 128. Set to -1 to restore to the last bank known from the MIDI file.
Returns
true if the preset/bank exists in the current SoudFont, otherwise false
// Example of changing the forced preset with the Unity GUI.
// ---------------------------------------------------------
int preset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127
// The forced bank is defined from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(preset, -1f, 127f);
if (forcePreset != preset)
{
// Force a preset whatever the MIDI events from the MIDI file.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset);
}

Another example with MidiExternalPlayer.

// To force the preset from the start of the playing,
// the forced preset and the forced bank must be set
// after the MIDI is loaded and before any MIDI message is played.
// The OnEventStartPlayMidi event is perfect for that.
// ---------------------------------------------------------------
// Get the prefab added to the hierarchy of the current scene
MidiExternalPlayer midiPlayer = FindObjectOfType<MidiExternalPlayer>();
// Set the listener on the event OnEventStartPlayMidi
midiPlayer.OnEventStartPlayMidi.AddListener((string midiName) =>
{
// Each time the MIDI is started this script is run
// Force preset 70 for note-on on channel 0 (Bassoon is GM SoundFont)
midiPlayer.MPTK_ChannelForcedPresetSet(0, 70, 1);
});
Play a Local MIDI file or from a Web site. This class must be used with the prefab MidiExternalPlayer
Definition: MidiExternalPlayer.cs:42
EventStartMidiClass OnEventStartPlayMidi
Definition: MidiFilePlayer.cs:696
bool MPTK_ChannelForcedPresetSet(int channel, int preset, int bank=-1)
Definition: MidiSynth.cs:2095

◆ MPTK_ChannelInfo()

string MidiPlayerTK.MidiSynth.MPTK_ChannelInfo ( int  channel)

Build an information string about the channel. It's also a good pretext to display an example of Channel API.
Exemple of return

  • Channel:2 Enabled [Preset:18, Bank:0] 'Rock Organ' Count:1 Volume:1
  • Channel:4 Muted [Preset:F44, Bank:0] 'Stereo Strings Trem' Count:33 Volume:0,50
Parameters
channelindex channel
Returns
Information string
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelNoteCount()

int MidiPlayerTK.MidiSynth.MPTK_ChannelNoteCount ( int  channel)

Get count of notes played since the start of the MIDI.

Parameters
channelmust be between 0 and 15
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelPresetChange()

bool MidiPlayerTK.MidiSynth.MPTK_ChannelPresetChange ( int  channel,
int  preset,
int  bank = -1 
)

Change the Preset and/or Bank associated to a Channel.
The new value of the bank or preset are registered in the channel even if the preset or bannk is not found.
Each channel can have a different bank/preset set.
Note 1: When bank is changed, the preset list is not updated (MidiPlayerGlobal.MPTK_ListPreset). Call MidiPlayerGlobal.MPTK_SelectBankInstrument to refresh this list.
Note 2: When playing a MIDI file, MIDI messages like "Patch Change" and "ControlChange BankSelectMsb" will override value registered with this method.
Note 3: To change globally the bank, use instead the global methods: MidiPlayerGlobal.MPTK_SelectBankInstrument or MidiPlayerGlobal.MPTK_SelectBankDrum.
Note 4: The method MPTK_ChannelForcedPresetSet can be used to force the preset whatever the MIDI messages.

// Change bank or preset with free value with MPTK_ChannelPresetChange
// -------------------------------------------------------------------
// Select any value in the range 0 and 16383 for the bank
int bank = (int)Slider("Free Bank", midiStreamPlayer.MPTK_ChannelBankGetIndex(StreamChannel), 0, 128 * 128 - 1, alignright: false, wiLab: 80, wiSlider: 200, wiLabelValue: 100);
// Select any value in the range 0 and 127 for the preset
int prst = (int)Slider("Free Preset", midiStreamPlayer.MPTK_ChannelPresetGetIndex(StreamChannel), 0, 127, alignright: false, wiLab: 80, wiSlider: 200);
// If user made change for bank or preset ...
if (bank != midiStreamPlayer.MPTK_ChannelBankGetIndex(StreamChannel) ||
prst != midiStreamPlayer.MPTK_ChannelPresetGetIndex(StreamChannel))
{
// ... apply the change to the MidiStreamPlayer for the current channel.
// If the bank or the preset doestn't exist
// - the method returns false
// - the bank and preset are still registered in the channel
// - when a note-on is received on this channel, the first preset of the first bank is used to play (usually piano).
bool ret = midiStreamPlayer.MPTK_ChannelPresetChange(StreamChannel, prst, bank);
// Read the current bank, preset and preset name selected
int newbank = midiStreamPlayer.MPTK_ChannelBankGetIndex(StreamChannel);
int newpreset = midiStreamPlayer.MPTK_ChannelPresetGetIndex(StreamChannel);
string newname = midiStreamPlayer.MPTK_ChannelPresetGetName(StreamChannel);
Debug.Log($"MPTK_ChannelPresetChange result:{ret} bank:{newbank} preset:{newpreset} '{newname}'");
}
Parameters
channel0 to 15. There is 16 channels available in the MIDI norm.
presetThe total number of presets available depend on the soundfont selected
bankOptionnal, if not set or -1 the current bank will be applied (or default bank if never set). Default bank is defined globally: menu MPTK / SoundFont Setup.
Returns
true if the bank and the preset were found else false

◆ MPTK_ChannelPresetGetIndex()

int MidiPlayerTK.MidiSynth.MPTK_ChannelPresetGetIndex ( int  channel)

Get channel preset index.

Parameters
channelmust be between 0 and 15
Returns
channel preset index or -1 if channel error
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelPresetGetName()

string MidiPlayerTK.MidiSynth.MPTK_ChannelPresetGetName ( int  channel)

Get the current preset name for the channel.
Each MIDI channel can play a different preset.

Parameters
channelMIDI channel must be between 0 and 15
Returns
channel preset name or "" if channel error
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelVolumeGet()

float MidiPlayerTK.MidiSynth.MPTK_ChannelVolumeGet ( int  channel)

Get the volume of the channel

Parameters
channelmust be between 0 and 15
Returns
volume of the channel, between 0 and 1
GUILayout.BeginHorizontal();
GUILayout.Label("Channel Preset Preset / Bank Count Enabled Volume", myStyle.TitleLabel3);
GUILayout.EndHorizontal();
for (int channel = 0; channel < midiFilePlayer.MPTK_ChannelCount(); channel++)
{
GUILayout.BeginHorizontal();
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_ChannelInfo(channel));
// Display preset
GUILayout.Label(midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set", myStyle.TitleLabel3, GUILayout.MaxWidth(150));
// Display preset and bank index
string sPreset = "";
int presetForced = midiFilePlayer.MPTK_ChannelForcedPresetGet(channel);
if (presetForced == -1)
{
// Preset not forced, get the preset defined on this channel by the Midi
sPreset = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel).ToString();
}
else
{
sPreset = $"F{presetForced}";
}
int bankIndex = midiFilePlayer.MPTK_ChannelBankGetIndex(channel);
GUILayout.Label($"{sPreset} / {bankIndex}", myStyle.LabelRight/*, GUILayout.Width(80)*/);
int current = midiFilePlayer.MPTK_ChannelPresetGetIndex(channel);
// Slider to change the preset on this channel from -1 (disable forced) to 127.
// Forced bank from the inspector.
int forcePreset = (int)GUILayout.HorizontalSlider(current,
-1f, 127f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(100));
if (forcePreset != current)
{
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_ChannelNoteCount(channel),-5}", myStyle.LabelRight, GUILayout.Width(60));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(60));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_ChannelEnableGet(channel), "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_ChannelEnableGet(channel))
{
midiFilePlayer.MPTK_ChannelEnableSet(channel, state);
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_ChannelPresetGetName(channel) ?? "not set"); /*2.84*/
}
// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_ChannelVolumeGet(channel);
GUILayout.Label($"{Math.Round(currentVolume, 2)}", myStyle.LabelRight, GUILayout.Width(40));
float volume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f, myStyle.SliderBar, myStyle.SliderThumb, GUILayout.Width(60));
if (volume != currentVolume)
{
midiFilePlayer.MPTK_ChannelVolumeSet(channel, volume);
}
GUILayout.EndHorizontal();
}

◆ MPTK_ChannelVolumeSet()

void MidiPlayerTK.MidiSynth.MPTK_ChannelVolumeSet ( int  channel,
float  volume 
)

Set the volume for a channel as a percentage.

Parameters
channelmust be between 0 and 15 or -1 to apply to all channels
volumepercentage of volume from the global volume for the channel, must be between 0 and 1

◆ MPTK_ChorusSetDefault()

void MidiPlayerTK.MidiSynth.MPTK_ChorusSetDefault ( )

Set Chorus Unity default value as defined with Unity.

Version
Maestro Pro

◆ MPTK_ClearAllSound()

void MidiPlayerTK.MidiSynth.MPTK_ClearAllSound ( bool  destroyAudioSource = false,
int  _idSession = -1 
)

Clear all sound by sending note off.
That could take some seconds because release time for sample need to be played.

if (GUILayout.Button("Clear"))
midiStreamPlayer.MPTK_ClearAllSound(true);
Parameters
destroyAudioSourceuseful only in non core mode
_idSessionclear only for sample playing with this session, -1 for all (default)

◆ MPTK_InitSynth()

void MidiPlayerTK.MidiSynth.MPTK_InitSynth ( int  channelCount = 16,
bool  resetActiveVoices = false 
)

Initialize the synthetizer: channel, voices, modulator.
It's not useful to call this method if you are using prefabs (MidiFilePlayer, MidiStreamPlayer, ...).
Each gameObjects created from these prefabs have their own, autonomous and isolated synth.

Parameters
channelCountNumber of channel to create, default 16. Any other values are experimental!
resetActiveVoicesNot more used

◆ MPTK_ResetStat()

void MidiPlayerTK.MidiSynth.MPTK_ResetStat ( )

Reset voices statistics

◆ MPTK_ReverbSetDefault()

void MidiPlayerTK.MidiSynth.MPTK_ReverbSetDefault ( )

Set Reverb Unity default value as defined with Unity.

Version
Maestro Pro

◆ MPTK_SFChorusSetDefault()

void MidiPlayerTK.MidiSynth.MPTK_SFChorusSetDefault ( )

Set Chrous SoundFont default value as defined in fluidsynth.
FLUID_CHORUS_DEFAULT_N 3
FLUID_CHORUS_DEFAULT_LEVEL 2.0 but set to 0.9 (thank John)
FLUID_CHORUS_DEFAULT_SPEED 0.3
FLUID_CHORUS_DEFAULT_DEPTH 8.0
FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE
WIDTH 10

Version
Maestro Pro

◆ MPTK_SFFilterSetDefault()

void MidiPlayerTK.MidiSynth.MPTK_SFFilterSetDefault ( )

Set Filter SoundFont default value as defined in fluidsynth.

Version
Maestro Pro

◆ MPTK_SFReverbSetDefault()

void MidiPlayerTK.MidiSynth.MPTK_SFReverbSetDefault ( )

Set Reverb SoundFont default value as defined in fluidsynth.
FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f
FLUID_REVERB_DEFAULT_DAMP 0.0f
FLUID_REVERB_DEFAULT_WIDTH 0.5f
FLUID_REVERB_DEFAULT_LEVEL 0.9f

Version
Maestro Pro

Default chorus voice count

◆ MPTK_StartSequencerMidi()

void MidiPlayerTK.MidiSynth.MPTK_StartSequencerMidi ( )

Start the MIDI sequencer: each midi events are read and play in a dedicated thread.
This thread is automatically started by prefabs MidiFilePlayer, MidiListPlayer, MidiExternalPlayer.

◆ MPTK_StopSynth()

void MidiPlayerTK.MidiSynth.MPTK_StopSynth ( )

Stop processing samples by the synth and the MIDI sequencer.

◆ MPTK_WaitAllNotesOff()

IEnumerator MidiPlayerTK.MidiSynth.MPTK_WaitAllNotesOff ( int  _idSession = -1)

Wait until all notes are off.
That could take some seconds due to the samples release time.
Therefore, the method exit after a timeout of 3 seconds.
*** Use this method only as a coroutine ***

// Call this method with: StartCoroutine(NextPreviousWithWait(false));
// See TestMidiFilePlayerScripting.cs
public IEnumerator NextPreviousWithWait(bool next)
{
midiFilePlayer.MPTK_Stop();
yield return midiFilePlayer.MPTK_WaitAllNotesOff(midiFilePlayer.IdSession);
if (next)
midiFilePlayer.MPTK_Next();
else
midiFilePlayer.MPTK_Previous();
CurrentIndexPlaying = midiFilePlayer.MPTK_MidiIndex;
yield return 0;
}
Parameters
_idSessionclear only for samples playing with this session, -1 for all
Returns

◆ OnAudioFrameStartHandler()

delegate void MidiPlayerTK.MidiSynth.OnAudioFrameStartHandler ( double  synthTime)

Delegate for the event OnAudioFrameStartHandler. see OnAudioFrameStart.

Version
Maestro Pro
Parameters
synthTime

Member Data Documentation

◆ MPTK_ApplyModLfo

bool MidiPlayerTK.MidiSynth.MPTK_ApplyModLfo

Apply LFO effect defined in the SoundFont

◆ MPTK_ApplyRealTimeModulator

bool MidiPlayerTK.MidiSynth.MPTK_ApplyRealTimeModulator

Apply real time modulatoreffect defined in the SoundFont: pitch bend, control change, enveloppe modulation

◆ MPTK_ApplyVibLfo

bool MidiPlayerTK.MidiSynth.MPTK_ApplyVibLfo

Apply vibrato effect defined in the SoundFont

◆ MPTK_AudioSettingFromUnity

bool MidiPlayerTK.MidiSynth.MPTK_AudioSettingFromUnity

If true then rate synth and buffer size will be automatically defined by Unity in accordance of the capacity of the hardware. - V2.89.0 -
Look at Unity menu "Edit / Project Settings..." and select between best latency and best performance.
If false, then rate and buffer size can be defined manually ... but with the risk of bad audio quality. It's more an experimental capacities!

◆ MPTK_AutoBuffer

bool MidiPlayerTK.MidiSynth.MPTK_AutoBuffer = true

Voice buffering is important to get better performance. But you can disable this fonction with this parameter.

◆ MPTK_AutoCleanVoiceLimit

int MidiPlayerTK.MidiSynth.MPTK_AutoCleanVoiceLimit

Free voices older than MPTK_AutoCleanVoiceLimit are removed when count is over than MPTK_AutoCleanVoiceTime

◆ MPTK_CorePlayer

bool MidiPlayerTK.MidiSynth.MPTK_CorePlayer

If true then MIDI events are read and play from a dedicated thread.
If false, MidiSynth will use AudioSource gameobjects to play sound.
This properties must be defined before running the application from the inspector.
The default is true.
Warning: The non core mode player (MPTK_CorePlayer=false) will be removed with the next major version (V3)

◆ MPTK_CutOffVolume

float MidiPlayerTK.MidiSynth.MPTK_CutOffVolume = 0.0001f

When amplitude of a sample is below this value the playing of sample is stopped.
Can be increase for better performance (when a lot of samples are played concurrently) but with degraded quality because sample could be stopped too early. Remember: Amplitude can varying between 0 and 1.

Version
2.9.1 // was 0.03

◆ MPTK_DirectSendToPlayer

bool MidiPlayerTK.MidiSynth.MPTK_DirectSendToPlayer

If true (default) then MIDI events are sent automatically to the midi player. Set to false if you want to process events without playing sound. OnEventNotesMidi Unity Event can be used to process each notes.

◆ MPTK_EnableChangeTempo

bool MidiPlayerTK.MidiSynth.MPTK_EnableChangeTempo

Enable MIDI events tempo change from the MIDI file when playing. If disabled, only the first tempo change found in the MIDI will be applied (or 120 if not tempo change). Disable it when you want to change tempo by your script.

◆ MPTK_EnableFreeSynthRate

bool MidiPlayerTK.MidiSynth.MPTK_EnableFreeSynthRate = false

Allow direct setting of the Synth Rate

◆ MPTK_EnablePanChange

bool MidiPlayerTK.MidiSynth.MPTK_EnablePanChange

Should change pan from MIDI Events or from SoundFont ?
Pan is disabled when Spatialization is activated.

◆ MPTK_EnablePresetDrum

bool MidiPlayerTK.MidiSynth.MPTK_EnablePresetDrum

Should accept change Preset for Drum canal 9 (drum) ?
Could sometimes create unexpected music with MIDI files not compliant with the MIDI standard. Example that could produce unexpected music. Generally, default drum bank is set to 128. With these events on channel 9,
preset 0 of the bank 0 will be selected for the drum ... and that will be, in general, a piano

  • Bank change channel 9 = 0
  • Preset change channel 9 = 0 @Attention
  • with MidiFilePlayer, MPTK_EnablePresetDrum isset to false by default
  • with MidiStreamPlayer, MPTK_EnablePresetDrum is set to true by default (all the MIDI events are generated by your script. Also, you know what!)

◆ MPTK_KillByExclusiveClass

bool MidiPlayerTK.MidiSynth.MPTK_KillByExclusiveClass = true

Find the exclusive class of this voice. If set, kill all voices that match the exclusive class
and are younger than the first voice process created by this noteon event.

◆ MPTK_LeanSynthStarting

float MidiPlayerTK.MidiSynth.MPTK_LeanSynthStarting = 0.05f

A lean startup of the volume of the synth is useful to avoid weird sound at the beginning of the application (in some cases).
This parameter sets the speed of the increase of the volume of the audio source.
Set to 1 for an immediate full volume at start.

◆ MPTK_LogEvents

bool MidiPlayerTK.MidiSynth.MPTK_LogEvents

Log midi events (v2.9.0 moved from MidiFilePlayer)

◆ MPTK_LogWave

bool MidiPlayerTK.MidiSynth.MPTK_LogWave

Log for each wave to be played

◆ MPTK_ReleaseSameNote

bool MidiPlayerTK.MidiSynth.MPTK_ReleaseSameNote = true

If the same note is hit twice on the same channel, then the older voice process is advanced to the release stage.
It's the default Midi processing.

◆ MPTK_ReleaseTimeMin

uint MidiPlayerTK.MidiSynth.MPTK_ReleaseTimeMin = 500000

[Only when CorePlayer=False] Define a minimum release time at noteoff in 100 iem nanoseconds.
Default 50 ms is a good tradeoff. Below some unpleasant sound could be heard. Useless when MPTK_CorePlayer is true.

◆ MPTK_ReleaseTimeMod

float MidiPlayerTK.MidiSynth.MPTK_ReleaseTimeMod = 1f

When a note is stopped with a noteoff or when the duration is over, note continue to play for a short time depending the instrument.

This parameter is a multiplier to increase or decrease the default release time defined in the SoundFont for each instrument.
Recommended values between 0.1 and 10. Default is 1 (no modification of the release time).
Performance issue: the longer it lasts the more CPU is used after the noteon. With a long release time, a lot of samples will be played simultaneously.

◆ MPTK_ResetChannel

bool MidiPlayerTK.MidiSynth.MPTK_ResetChannel = true

Reset channel information when MIDI start playing. V2.89.0

◆ MPTK_SFChorusAmplify

float MidiPlayerTK.MidiSynth.MPTK_SFChorusAmplify

Chorus level is defined in the SoundFont in the range [0, 1].
This parameter is added to the the default SoundFont value.
Range must be [-1, 1]

Version
Maestro Pro

◆ MPTK_SFFilterFreqOffset

float MidiPlayerTK.MidiSynth.MPTK_SFFilterFreqOffset = 0f

Frequency cutoff is defined in the SoundFont for each notes.
This parameter increase or decrease the default SoundFont value. Range: -2000 to 3000

Version
Maestro Pro

◆ MPTK_SFReverbAmplify

float MidiPlayerTK.MidiSynth.MPTK_SFReverbAmplify

Reverberation level is defined in the SoundFont in the range [0, 1].
This parameter is added to the the default SoundFont value. Range must be [-1, 1]

Version
Maestro Pro

◆ MPTK_SpatialSynthEnabled

bool MidiPlayerTK.MidiSynth.MPTK_SpatialSynthEnabled

In spatialization mode not all MidiSynths are enabled.

Version
Maestro Pro

◆ MPTK_StatVoiceCountActive

int MidiPlayerTK.MidiSynth.MPTK_StatVoiceCountActive

Count of the active voices (playing and releasing) - Readonly

◆ MPTK_StatVoiceCountFree

int MidiPlayerTK.MidiSynth.MPTK_StatVoiceCountFree

Count of the free voices for reusing on need.
Voice older than AutoCleanVoiceTime are removed but only when count is over than AutoCleanVoiceLimit - Readonly

◆ MPTK_StatVoiceCountPlaying

int MidiPlayerTK.MidiSynth.MPTK_StatVoiceCountPlaying

Count of the active voices (playing excluding voices in release step) - Readonly

◆ MPTK_StatVoicePlayed

int MidiPlayerTK.MidiSynth.MPTK_StatVoicePlayed

Count of voice played since the start of the synth

◆ MPTK_StatVoiceRatioReused

float MidiPlayerTK.MidiSynth.MPTK_StatVoiceRatioReused

Percentage of voice reused during the synth life. 0: any reuse, 100:all voice reused (unattainable, of course!)

◆ MPTK_WeakDevice

bool MidiPlayerTK.MidiSynth.MPTK_WeakDevice

Should play on a weak device (cheaper smartphone) ? Apply only with AudioSource mode (MPTK_CorePlayer=False).
Playing MIDI files with WeakDevice activated could cause some bad interpretation of MIDI Event, consequently bad sound.

◆ OnBeatEvent

Action<int, long, int, int> MidiPlayerTK.MidiSynth.OnBeatEvent

Action executed at each quarter with:

  • time: time in milliseconds since the start of the playing MIDI.
  • tick: current tick.
  • measure: current measure (start from 1).
  • beat: current beat (start from 1).
    Note
  • Action is executed even if there is there no MIDI event on the beat.
  • Accuracy is garantee.
  • Direct call to Unity API is not possible but Debug.Log and Maestro API (example, play a sound at each beat) are allowed.
    Version
    2.10.0
    // See TestMidiFilePlayerScripting.cs for the demo.
    void Start()
    {
    MidiFilePlayer midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
    midiFilePlayer.OnBeatEvent = OnBeatAction;
    }
    void OnBeatAction(int time, long tick, int measure, int beat)
    {
    Debug.Log($"Beat - time:{time} tick:{tick} tempoMap:{midiFilePlayer.MPTK_MidiLoaded.MPTK_CurrentTempoMap.Index} measure:{measure} beat:{beat}");
    }
    Play a MIDI file from the MidiDB. This class must be used with the prefab MidiFilePlayer....
    Definition: MidiFilePlayer.cs:69

◆ OnEventSynthAwake

EventSynthClass MidiPlayerTK.MidiSynth.OnEventSynthAwake

Unity event fired at awake of the synthesizer. Name of the gameobject component is passed as a parameter.
Setting this callback function by script (AddListener) is not recommended. It's better to set callback function from the inspector.

Example of script (but it's recommended to set callback function from the inspector).

...
midiStreamPlayer.OnEventSynthAwake.AddListener(StartLoadingSynth);
...
public void StartLoadingSynth(string name)
{
Debug.LogFormat("Synth {0} loading", name);
}

◆ OnEventSynthStarted

EventSynthClass MidiPlayerTK.MidiSynth.OnEventSynthStarted

Unity event fired at start of the synthesizer. Name of the gameobject component is passed as a parameter.
Setting this callback function by script (AddListener) is not recommended. It's better to set callback function from the inspector.

Example of script (it's recommended to set callback function from the inspector).

public void EndLoadingSynth(string name)
{
Debug.LogFormat($"Synth {name} loaded, now change bank and preset");
// It's recommended to defined callback method (here EndLoadingSynth) in the prefab MidiStreamPlayer from the Unity editor inspector.
// EndLoadingSynth will be called when the synthesizer will be ready.
// These calls will not work in Unity Awake() or Startup() because Midi synth must be ready when changing preset and/or bank.
// Mandatory for updating UI list but not for playing sample.
// The default instrument and drum banks are defined with the popup "SoundFont Setup Alt-F" in the Unity editor.
// This method can be used by script to change the instrument bank and build presets available for it: MPTK_ListPreset.
// Don't forget to initialize your MidiStreamPlayer variable, see link below:
// https://paxstellar.fr/api-mptk-v2/#DefinedVariablePrefab
// Channel 0: set Piano (if SoundFont is GeneralUser GS v1.471)
// Define bank with CurrentBank (value defined in inspector to 0).
midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent() { Command = MPTKCommand.ControlChange, Controller = MPTKController.BankSelectMsb, Value = CurrentBank, Channel = StreamChannel, });
Debug.LogFormat($" Bank '{CurrentBank}' defined on channel {StreamChannel}");
// Defined preset with CurrentPreset (value defined in inspector to 0).
midiStreamPlayer.MPTK_ChannelPresetChange(StreamChannel, CurrentPreset);
Debug.LogFormat($" Preset '{midiStreamPlayer.MPTK_ChannelPresetGetName(0)}' defined on channel {StreamChannel}");
// Playing a preset from another bank in the channel 1
// Channel 1: set Laser Gun (if SoundFont is GeneralUser GS v1.471)
int channel = 1, bank = 2, preset = 127;
midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent() { Command = MPTKCommand.ControlChange, Controller = MPTKController.BankSelectMsb, Value = bank, Channel = channel, });
midiStreamPlayer.MPTK_ChannelPresetChange(channel, preset);
// MPTK_GetPatchName mandatory for getting the patch nane when the bank is not the default bank.
Debug.LogFormat($" Preset '{MidiPlayerGlobal.MPTK_GetPatchName(bank, preset)}' defined on channel {channel} and bank {bank}");
}
Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all ot...
Definition: MPTKEvent.cs:418
Singleton class to manage all globales MPTK features. More information here: https://paxstellar....
Definition: MidiPlayerGlobal.cs:16
static bool MPTK_SelectBankInstrument(int nbank)
Definition: MidiPlayerGlobal.cs:526
MPTKController
Definition: MPTKEvent.cs:130
MPTKCommand
Definition: MPTKEvent.cs:12

◆ OnMidiEvent

Func<MPTKEvent, bool> MidiPlayerTK.MidiSynth.OnMidiEvent

This function is called by the MIDI sequencer before sending the MIDI message to the MIDI synthesizer.
From version 2.10.0 the callback must return a boolean (see example). true to keep the event, false to skip it.

It can be used like a MIDI events preprocessor: it's possible to change the value of the MIDI events and therefore change the playback of the song.
The callback function receives a MPTKEvent object by reference (normal, it's a C# class).
Look at https://mptkapi.paxstellar.com/d9/d50/class_midi_player_t_k_1_1_m_p_t_k_event.html
Many changes are possible on the MIDI event: change note, velocity, channel, skip ..., even changing the MIDI type of the message!!!
See below some examples of run-time changes.

Version
Maestro Pro
Note
  • The callback is running on a system thread not on the Unity thread. Unity API call is not possible except for the Debug.Log (to be gently used, it consumes CPU)
  • Avoid heavy processing or waiting inside the callback otherwise MIDI playing accuracy will be bad.
  • The midiEvent is passed by reference to the callback, so re-instanciate object (midiEvent = new MPTKEvent()) or set to null, has no effect!
  • MIDI position attributs (Tick and RealTime) can be used in your algo but changing their values has no effect, it's too late!
  • Changing SetTempo event is too late for the MIDI Sequencer (already taken into account). But you can use midiFilePlayer.MPTK_Tempo to change the tempo
Some examples:
// See TestMidiFilePlayerScripting.cs for the demo.
void Start()
{
MidiFilePlayer midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
midiFilePlayer.OnMidiEvent = PreProcessMidi;
}
// Some example
bool PreProcessMidi(MPTKEvent midiEvent)
{
bool playEvent=true;
switch (midiEvent.Command)
{
case MPTKCommand.NoteOn:
if (midiEvent.Channel != 9)
// transpose 2 octaves
midiEvent.Value += 24;
else
// Drums are muted
playEvent= false;
break;
case MPTKCommand.PatchChange:
// Remove all patch change: all channels will played the default preset 0!!!
midiEvent.Command = MPTKCommand.MetaEvent;
midiEvent.Meta = MPTKMeta.TextEvent;
midiEvent.Info = "Patch Change removed";
break;
case MPTKCommand.MetaEvent:
if (midiEvent.Meta == MPTKMeta.SetTempo)
// Tempo forced to 100
midiFilePlayer.MPTK_Tempo = 100
break;
}
// true: plays this event, false to skip
return playEvent;
}
MPTKMeta Meta
Definition: MPTKEvent.cs:488
MPTKCommand Command
Definition: MPTKEvent.cs:476
int Channel
Definition: MPTKEvent.cs:535
MPTKMeta
Definition: MPTKEvent.cs:320

◆ playOnlyFirstWave

bool MidiPlayerTK.MidiSynth.playOnlyFirstWave

Preset are often composed with 2 or more samples, classically for left and right channel. Check this to play only the first sample found


◆ SpatialSynths

List<MidiFilePlayer> MidiPlayerTK.MidiSynth.SpatialSynths
static

Contains each Midi Synth for each channel or track when the prefab MidiSpatializer is used and IsMidiChannelSpace=true.
Warning: only one MidiSpatializer can be used in a hierarchy.

Property Documentation

◆ MPTK_ApplySFChorus

bool MidiPlayerTK.MidiSynth.MPTK_ApplySFChorus
getset

Apply chorus effect as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace(10%).

Version
Maestro Pro

◆ MPTK_ApplySFFilter

bool MidiPlayerTK.MidiSynth.MPTK_ApplySFFilter
getset

Apply frequency low-pass filter as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace (40%).

Version
Maestro Pro

◆ MPTK_ApplySFReverb

bool MidiPlayerTK.MidiSynth.MPTK_ApplySFReverb
getset

Apply reverberation effect as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace(40%).

Version
Maestro Pro

◆ MPTK_ApplyUnityChorus

bool MidiPlayerTK.MidiSynth.MPTK_ApplyUnityChorus
getset

Apply Chorus Unity effect to the AudioSource. The effect is applied to all voices.

Version
Maestro Pro

◆ MPTK_ApplyUnityReverb

bool MidiPlayerTK.MidiSynth.MPTK_ApplyUnityReverb
getset

Apply Reverb Unity effect to the AudioSource. The effect is applied to all voices.

Version
Maestro Pro

◆ MPTK_ChorusDelay

float MidiPlayerTK.MidiSynth.MPTK_ChorusDelay
getset

Chorus delay in ms.
Range from 0.1 to 100. Default = 40 ms.

Version
Maestro Pro

◆ MPTK_ChorusDepth

float MidiPlayerTK.MidiSynth.MPTK_ChorusDepth
getset

Chorus modulation depth.
Range from 0 to 1. Default = 0.03.

Version
Maestro Pro

◆ MPTK_ChorusDryMix

float MidiPlayerTK.MidiSynth.MPTK_ChorusDryMix
getset

Volume of original signal to pass to output.
Range from 0 to 1. Default = 0.5.

Version
Maestro Pro

◆ MPTK_ChorusRate

float MidiPlayerTK.MidiSynth.MPTK_ChorusRate
getset

Chorus modulation rate in hz.
Range from 0 to 20. Default = 0.8 hz.

Version
Maestro Pro

◆ MPTK_ChorusWetMix1

float MidiPlayerTK.MidiSynth.MPTK_ChorusWetMix1
getset

Volume of 1st chorus tap.
Range from 0 to 1. Default = 0.5.

Version
Maestro Pro

◆ MPTK_ChorusWetMix2

float MidiPlayerTK.MidiSynth.MPTK_ChorusWetMix2
getset

Volume of 2nd chorus tap. This tap is 90 degrees out of phase of the first tap.
Range from 0 to 1. Default = 0.5.

Version
Maestro Pro

◆ MPTK_ChorusWetMix3

float MidiPlayerTK.MidiSynth.MPTK_ChorusWetMix3
getset

Volume of 3rd chorus tap. This tap is 90 degrees out of phase of the second tap.
Range from 0 to 1. Default = 0.5.

Version
Maestro Pro

◆ MPTK_IndexSynthBuffSize

int MidiPlayerTK.MidiSynth.MPTK_IndexSynthBuffSize
getset

Set or Get synth buffer size -1:default, 0:64, 1;128, 2:256, 3:512, 4:1024, 5:2048.
The change is global for all prefab. It's better to stop playing for all prefab before changing on fly to avoid bad noise or crash.

◆ MPTK_IndexSynthRate

int MidiPlayerTK.MidiSynth.MPTK_IndexSynthRate
getset

Set or Get sample rate output of the synth. -1:default, 0:24000, 1:36000, 2:48000, 3:60000, 4:72000, 5:84000, 6:96000.
It's better to stop playing before changing on fly to avoid bad noise.

◆ MPTK_InstrumentPlayed

string MidiPlayerTK.MidiSynth.MPTK_InstrumentPlayed
get

If spatialization is track mode, contains the last instrument played on this track.

Version
Maestro Pro

◆ MPTK_IsSpatialSynthMaster

bool MidiPlayerTK.MidiSynth.MPTK_IsSpatialSynthMaster
get

True if this MidiSynth is the master synth responsible to read midi events and to dispatch to other MidiSynths

Version
Maestro Pro

◆ MPTK_KeepPlayingNonLooped

bool MidiPlayerTK.MidiSynth.MPTK_KeepPlayingNonLooped
getset

When the value is true, NoteOff and Duration for non-looped samples are ignored and the samples play through to the end.

◆ MPTK_MaxDistance

float MidiPlayerTK.MidiSynth.MPTK_MaxDistance
getset

If MPTK_Spatialize is enabled, the volume of the audio source depends on the distance between the audio source and the listener. Beyong this distance, the volume is set to 0 and the midi player is paused. No effect if MPTK_Spatialize is disabled.

◆ MPTK_PauseOnDistance

bool MidiPlayerTK.MidiSynth.MPTK_PauseOnDistance
getset

[obsolete] replaced by MPTK_Spatialize"); V2.83

◆ MPTK_ReverbDecayHFRatio

float MidiPlayerTK.MidiSynth.MPTK_ReverbDecayHFRatio
getset

Decay HF Ratio : High-frequency to low-frequency decay time ratio.
Ranges from 0.1 to 2.0.

Version
Maestro Pro

◆ MPTK_ReverbDecayTime

float MidiPlayerTK.MidiSynth.MPTK_ReverbDecayTime
getset

Reverberation decay time at low-frequencies in seconds.
Ranges from 0.1 to 20. Default is 1.

Version
Maestro Pro

◆ MPTK_ReverbDelay

float MidiPlayerTK.MidiSynth.MPTK_ReverbDelay
getset

Late reverberation delay time relative to first reflection in seconds.
Ranges from 0 to 0.1. Default is 0.04

Version
Maestro Pro

◆ MPTK_ReverbDensity

float MidiPlayerTK.MidiSynth.MPTK_ReverbDensity
getset

Reverberation density (modal density) in percent.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_ReverbDiffusion

float MidiPlayerTK.MidiSynth.MPTK_ReverbDiffusion
getset

Reverberation diffusion (echo density) in percent.
Ranges from 0 to 1. Default is 1.

Version
Maestro Pro

◆ MPTK_ReverbDryLevel

float MidiPlayerTK.MidiSynth.MPTK_ReverbDryLevel
getset

Mix level of dry signal in output.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_ReverbHFReference

float MidiPlayerTK.MidiSynth.MPTK_ReverbHFReference
getset

Reference high frequency in Hz.
Ranges from 1000 to 20000. Default is 5000

Version
Maestro Pro

◆ MPTK_ReverbLevel

float MidiPlayerTK.MidiSynth.MPTK_ReverbLevel
getset

Late reverberation level relative to room effect.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_ReverbLFReference

float MidiPlayerTK.MidiSynth.MPTK_ReverbLFReference
getset

Reference low-frequency in Hz.
Ranges from 20 to 1000. Default is 250

Version
Maestro Pro

◆ MPTK_ReverbReflectionDelay

float MidiPlayerTK.MidiSynth.MPTK_ReverbReflectionDelay
getset

Late reverberation level relative to room effect.
Ranges from -10000.0 to 2000.0. Default is 0.0.

Version
Maestro Pro

◆ MPTK_ReverbReflectionLevel

float MidiPlayerTK.MidiSynth.MPTK_ReverbReflectionLevel
getset

Early reflections level relative to room effect.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_ReverbRoom

float MidiPlayerTK.MidiSynth.MPTK_ReverbRoom
getset

Room effect level at low frequencies.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_ReverbRoomHF

float MidiPlayerTK.MidiSynth.MPTK_ReverbRoomHF
getset

Room effect high-frequency level.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_ReverbRoomLF

float MidiPlayerTK.MidiSynth.MPTK_ReverbRoomLF
getset

Room effect low-frequency level.
Ranges from 0 to 1.

Version
Maestro Pro

◆ MPTK_SFChorusDepth

float MidiPlayerTK.MidiSynth.MPTK_SFChorusDepth
getset

Set the SoundFont chorus effect depth
Chorus depth [0, 256]

Version
Maestro Pro

◆ MPTK_SFChorusLevel

float MidiPlayerTK.MidiSynth.MPTK_SFChorusLevel
getset

Set the SoundFont chorus effect level [0, 10]
Default value set to 0.9 (was 2f, thank John)

Version
Maestro Pro

◆ MPTK_SFChorusSpeed

float MidiPlayerTK.MidiSynth.MPTK_SFChorusSpeed
getset

Set the SoundFont chorus effect speed
Chorus speed in Hz [0.1, 5]

Version
Maestro Pro

◆ MPTK_SFChorusWidth

float MidiPlayerTK.MidiSynth.MPTK_SFChorusWidth
getset

Set the SoundFont chorus effect width
The chorus unit process a monophonic input signal and produces stereo output controlled by WIDTH macro.
Width allows to get a gradually stereo effect from minimum (monophonic) to maximum stereo effect. [0, 10]

Version
Maestro Pro

◆ MPTK_SFFilterQModOffset

float MidiPlayerTK.MidiSynth.MPTK_SFFilterQModOffset
getset

Quality Factor is defined in the SoundFont for each notes.
This parameter increase or decrease the default SoundFont value. Range: -96 to 96.

Version
Maestro Pro

◆ MPTK_SFReverbDamp

float MidiPlayerTK.MidiSynth.MPTK_SFReverbDamp
getset

Set the SoundFont reverb effect damp [0,1].
Controls the reverb time frequency dependency. This controls the reverb time for the frequency sample rate/2
When 0, the reverb time for high frequencies is the same as for DC frequency.
When > 0, high frequencies have less reverb time than lower frequencies.

Version
Maestro Pro

◆ MPTK_SFReverbLevel

float MidiPlayerTK.MidiSynth.MPTK_SFReverbLevel
getset

Set the SoundFont reverb effect level.

Version
Maestro Pro

◆ MPTK_SFReverbRoomSize

float MidiPlayerTK.MidiSynth.MPTK_SFReverbRoomSize
getset

Set the SoundFont reverb effect room size. Controls concave reverb time between 0 (0.7 s) and 1 (12.5 s)

Version
Maestro Pro

◆ MPTK_SFReverbWidth

float MidiPlayerTK.MidiSynth.MPTK_SFReverbWidth
getset

Set the SoundFont reverb effect width [0,100].
Controls the left/right output separation.
When 0, there are no separation and the signal on left and right output is the same.This sounds like a monophonic signal.
When 100, the separation between left and right is maximum.

Version
Maestro Pro

◆ MPTK_Spatialize

bool MidiPlayerTK.MidiSynth.MPTK_Spatialize
getset

Should the Spatialization effect must be enabled?
See here how to setup spatialization with Unity https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Spatialization-Parameters if MPTK_Spatialize is true:
AudioSource.maxDistance = MPTK_MaxDistance
AudioSource.spatialBlend = 1
AudioSource.spatialize = true
AudioSource.spatializePostEffects = true

◆ MPTK_SpatialSynthIndex

int MidiPlayerTK.MidiSynth.MPTK_SpatialSynthIndex
get

Index of the MidiSynth for the dedicated Channel or Track when the prefab MidiSpatializer is used.
If MPTK_ModeSpatializer = Channel then represent the playing channel.
If MPTK_ModeSpatializer = Track then represent the playing track.
The value is -1 for the Midi reader because no voice is played.

◆ MPTK_SynthRate

int MidiPlayerTK.MidiSynth.MPTK_SynthRate
getset

Get the the current synth rate or set free value (only if MPTK_EnableFreeSynthRate is true).

◆ MPTK_TrackName

string MidiPlayerTK.MidiSynth.MPTK_TrackName
get

If spatialization is track mode, contains the last name of the track .

Version
Maestro Pro

◆ MPTK_TransExcludedChannel

int MidiPlayerTK.MidiSynth.MPTK_TransExcludedChannel
getset

Transpose will apply to all channels except this one. Set to -1 to apply to all channel. V2.89.0
Default is 9 because generally we don't want to transpose drum channel.

◆ MPTK_Transpose

int MidiPlayerTK.MidiSynth.MPTK_Transpose
getset

Transpose note from -24 to 24

◆ MPTK_Volume

float MidiPlayerTK.MidiSynth.MPTK_Volume
getset

Global Volume. apply to all channels.
Must be >=0 and <= 1

Event Documentation

◆ OnAudioFrameStart

OnAudioFrameStartHandler MidiPlayerTK.MidiSynth.OnAudioFrameStart

this event is triggered at each start of a new audio frame from the audio engine.

The parameter (double) is the current synth time in milliseconds. See example of use.
The callbach function will not run on the Unity thread, so you can't call Unity API except Debug.Log.

Version
Maestro Pro
// See Assets\MidiPlayer\Demo\ProDemos\Script\EuclideSeq\TestEuclideanRhythme.cs for the full code.
public void Play()
{
if (IsPlaying)
midiStream.OnAudioFrameStart += PlayHits;
else
midiStream.OnAudioFrameStart -= PlayHits;
}
private void PlayHits(double synthTimeMS)
{
if (lastSynthTime <= 0d)
// First call, init the last time
lastSynthTime = synthTimeMS;
// Calculate time in millisecond since the last loop
double deltaTime = synthTimeMS - lastSynthTime;
lastSynthTime = synthTimeMS;
timeMidiFromStartPlay += deltaTime;
// Calculate time since last beat played
timeSinceLastBeat += deltaTime;
// Slider SldTempo in BPM.
// 60 BPM means 60 beats in each minute, 1 beat per second, 1000 ms between beat.
// 120 BPM would be twice as fast: 120 beats in each minute, 2 per second, 500 ms between beat.
// Calculate the delay between two quarter notes in millisecond
CurrentTempo = (60d / SldTempo.Value) * 1000d;
// Is it time to play a hit ?
if (IsPlaying && timeSinceLastBeat > CurrentTempo)
{
timeSinceLastBeat = 0d;
CurrentBeat++;
}
}