MidiPlayerTK.MidiFilePlayer

Play a MIDI file from the MidiDB. This class must be used with the prefab MidiFilePlayer.
See "Midi File Setup" in the Unity menu MPTK for adding MIDI in MidiDB.
More...

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

Public Types

enum  ModeStopPlay { StopNoWaiting , StopWhenAllVoicesReleased , StopWhenAllVoicesEnded }
 Defined when the MIDI player is stopped. More...
 
- Public Types inherited from MidiPlayerTK.MidiSynth
enum  ModeSpatializer { Channel , Track }
 

Public Member Functions

MidiLoad MPTK_Load ()
 
MidiLoad MPTK_Load (string uri)
 
void MPTK_Next ()
 
MPTKEvent.EnumLength MPTK_NoteLength (MPTKEvent note)
 
void MPTK_Pause (float timeToPauseMS=-1f)
 
virtual void MPTK_Play (bool alreadyLoaded=false)
 
void MPTK_Play (byte[] data)
 
virtual void MPTK_Play (float delayRampUp, float startDelay=0)
 
void MPTK_Play (MPTKWriter mfw2, float delayRampUp=0f, float fromPosition=0, float toPosition=0, long fromTick=0, long toTick=0, bool timePosition=true)
 
void MPTK_PlayNextOrPrevious (int offset)
 
void MPTK_Previous ()
 
List< MPTKEventMPTK_ReadMidiEvents (long fromTicks=0, long toTicks=long.MaxValue)
 
void MPTK_RePlay ()
 
bool MPTK_SearchMidiToPlay (string searchPartOfName)
 
void MPTK_SortEvents ()
 
void MPTK_Stop (bool stopAllSound=true)
 
virtual void MPTK_Stop (float delayRampDown, float stopDelay=0)
 
void MPTK_SwitchMidiWithDelay (int index, string name, float volume, float delayToStopMillisecond, float delayToStartMillisecond)
 
void MPTK_UnPause ()
 
- Public Member Functions inherited from MidiPlayerTK.MidiSynth
void MPTK_ClearAllSound (bool destroyAudioSource=false, int _idSession=-1)
 
void MPTK_InitSynth (int channelCount=16, bool preserveChannelInfo=false)
 
void MPTK_ResetStat ()
 
void MPTK_StartSequencerMidi ()
 
void MPTK_StartSynth ()
 
void MPTK_StopSynth ()
 
IEnumerator MPTK_WaitAllNotesOff (int _idSession=-1)
 
delegate void OnAudioFrameStartHandler (double synthTime)
 

Public Attributes

MPTKInnerLoop MPTK_InnerLoop
 
bool MPTK_LogLoadEvents
 
ModeStopPlay MPTK_ModeStopVoice
 
bool MPTK_PauseOnFocusLoss
 
bool MPTK_StartPlayAtFirstNote
 
LoadingStatusMidiEnum MPTK_StatusLastMidiLoaded
 
EventEndMidiClass OnEventEndPlayMidi
 
EventNotesMidiClass OnEventNotesMidi
 
EventStartMidiClass OnEventStartPlayMidi
 
- Public Attributes inherited from MidiPlayerTK.MidiSynth
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
 
int MPTK_InstrumentNum
 
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_SpatialSynthEnabled
 
int MPTK_StatVoiceCountActive
 
int MPTK_StatVoiceCountFree
 
int MPTK_StatVoiceCountPlaying
 
int MPTK_StatVoiceCountReused
 
int MPTK_StatVoicePlayed
 
int 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
 

Properties

string MPTK_Copyright [get]
 
int MPTK_DeltaTicksPerQuarterNote [get]
 
TimeSpan MPTK_Duration [get]
 
float MPTK_DurationMS [get]
 
bool MPTK_IsPaused [get]
 
bool MPTK_IsPlaying [get]
 
bool MPTK_KeepEndTrack [get, set]
 
bool MPTK_KeepNoteOff [get, set]
 
MPTKEvent MPTK_LastEventPlayed [get]
 
bool MPTK_Loop [get, set]
 
bool MPTK_MidiAutoRestart [get, set]
 
List< MPTKEventMPTK_MidiEvents [get]
 
int MPTK_MidiIndex [get, set]
 
MidiLoad MPTK_MidiLoaded [get]
 
virtual string MPTK_MidiName [get, set]
 
bool MPTK_PlayOnStart [get, set]
 
TimeSpan MPTK_PlayTime [get]
 
double MPTK_Position [get, set]
 
double MPTK_PositionFirstNote [get]
 
double MPTK_PositionLastNote [get]
 
string MPTK_ProgramName [get]
 
double MPTK_PulseLenght [get]
 
int MPTK_Quantization [get, set]
 
double MPTK_RealTime [get]
 
string MPTK_SequenceTrackName [get]
 
float MPTK_Speed [get, set]
 
double MPTK_Tempo [get, set]
 
string MPTK_TextEvent [get]
 
long MPTK_TickCurrent [get, set]
 
long MPTK_TickFirstNote [get]
 
long MPTK_TickLast [get]
 
long MPTK_TickLastNote [get]
 
int MPTK_TrackCount [get]
 
string MPTK_TrackInstrumentName [get]
 
- Properties inherited from MidiPlayerTK.MidiSynth
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]
 
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]
 

Additional Inherited Members

- Static Public Attributes inherited from MidiPlayerTK.MidiSynth
static List< MidiFilePlayerSpatialSynths
 
- Events inherited from MidiPlayerTK.MidiSynth
OnAudioFrameStartHandler OnAudioFrameStart
 

Detailed Description

Play a MIDI file from the MidiDB. This class must be used with the prefab MidiFilePlayer.
See "Midi File Setup" in the Unity menu MPTK for adding MIDI in MidiDB.

Attention

There is no need to writing a script. For a simple usage, all the job can be done in the prefab inspector.
For more information see here https://paxstellar.fr/midi-file-player-detailed-view-2/
But for specific interactions, this class can be useful. Some use cases:

// This example randomly select a MIDI to play.
using MidiPlayerTK; // Add a reference to the MPTK namespace at the top of your script
using UnityEngine;
public class YourClass : MonoBehaviour
{
// See TestMidiFilePlayerScripting.cs for a more detailed usage of this class.
public void RandomPlay()
{
// Need a reference to the prefab MidiFilePlayer that you have added in your scene hierarchy.
MidiFilePlayer midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
// Random select for the Midi
midiFilePlayer.MPTK_MidiIndex = UnityEngine.Random.Range(0, MidiPlayerGlobal.MPTK_ListMidi.Count);
// Play! How to make more simple?
midiFilePlayer.MPTK_Play();
}
}
Play a MIDI file from the MidiDB. This class must be used with the prefab MidiFilePlayer....
Definition: MidiFilePlayer.cs:69
virtual void MPTK_Play(bool alreadyLoaded=false)
Definition: MidiFilePlayer.cs:980
Singleton class to manage all globales MPTK features. More information here: https://paxstellar....
Definition: MidiPlayerGlobal.cs:16
static List< MPTKListItem > MPTK_ListMidi
Definition: MidiPlayerGlobal.cs:377
Definition: MidiFileEditorPlayer.cs:6

Member Enumeration Documentation

◆ ModeStopPlay

Defined when the MIDI player is stopped.

Enumerator
StopNoWaiting 

Stop immeadiately (a short delay could occurs related to the Unity FPS).

StopWhenAllVoicesReleased 

Stop when all notes enter in the release phase (when note-of occurs or the duration is reaches).

StopWhenAllVoicesEnded 

Stop when all notes are in the ended phase (after the release phase). This delay is dependant of the instrument. A drum has a short release phase, a piano a medium delay, a tubullar bells a very long delay.

Member Function Documentation

◆ MPTK_Load() [1/2]

MidiLoad MidiPlayerTK.MidiFilePlayer.MPTK_Load ( )

Load the midi file defined with MPTK_MidiName or MPTK_MidiIndex. It's an optional action before playing a midi file with MPTK_Play()
Use this method to get all MIDI events before start playing.

Note
  • Logs are displayed in case of error.
  • Look at MPTK_StatusLastMidiLoaded for load status information.
  • Look at MPTK_MidiLoaded for detailed information about the MIDI loaded.
    private void GetMidiInfo()
    {
    MidiLoad midiloaded = midiFilePlayer.MPTK_Load();
    if (midiloaded != null)
    {
    infoMidi = "Duration: " + midiloaded.MPTK_Duration.TotalSeconds + " seconds\n";
    infoMidi += "Tempo: " + midiloaded.MPTK_InitialTempo + "\n";
    List<MPTKEvent> listEvents = midiloaded.MPTK_ReadMidiEvents();
    infoMidi += "Count MIDI Events: " + listEvents.Count + "\n";
    Debug.Log(infoMidi);
    }
    }
    Base class for loading a MIDI file and reading MIDI event in a MIDI sequencer. It's not possible to i...
    Definition: MidiLoad.cs:18
    bool MPTK_Load(int index, bool strict=false, bool extendedText=false)
    Definition: MidiLoad.cs:459
    List< MPTKEvent > MPTK_ReadMidiEvents(long fromTicks=0, long toTicks=long.MaxValue)
    Definition: MidiLoad.cs:576


Returns
MidiLoad to access all the properties of the midi loaded, null in case of error look at MPTK_StatusLastMidiLoaded

◆ MPTK_Load() [2/2]

MidiLoad MidiPlayerTK.MidiFilePlayer.MPTK_Load ( string  uri)

Load a MIDI file from a local desktop file. Example of path:

  • Mac: "/Users/xxx/Desktop/WellTempered.mid"
  • Windows: "C:\Users\xxx\Desktop\BIM\Sound\Midi\DreamOn.mid"
    Note
  • Logs are displayed in case of error.
  • Look at MPTK_StatusLastMidiLoaded for load status information.
  • Look at MPTK_MidiLoaded for detailed information about the MIDI loaded.
    Version
    Maestro Pro
Parameters
uriuri or path to the midi file
Returns
MidiLoad to access all the properties of the midi loaded or null in case of error

◆ MPTK_Next()

void MidiPlayerTK.MidiFilePlayer.MPTK_Next ( )

Play next MIDI from the list of midi defined in MPTK (see Unity menu Midi)

◆ MPTK_NoteLength()

MPTKEvent.EnumLength MidiPlayerTK.MidiFilePlayer.MPTK_NoteLength ( MPTKEvent  note)

Return note length as https://en.wikipedia.org/wiki/Note_value

Parameters
note
Returns
MPTKEvent.EnumLength

◆ MPTK_Pause()

void MidiPlayerTK.MidiFilePlayer.MPTK_Pause ( float  timeToPauseMS = -1f)

Pause the current playing

Parameters
timeToPauseMStime to pause in milliseconds. default or < 0 : indefinitely

◆ MPTK_Play() [1/4]

virtual void MidiPlayerTK.MidiFilePlayer.MPTK_Play ( bool  alreadyLoaded = false)
virtual

Play the midi file defined with MPTK_MidiName or MPTK_MidiIndex.

Parameters
alreadyLoadedtrue: the MIDI has already been loaded (see MPTK_Load() v2.9.0

Reimplemented in MidiPlayerTK.MidiExternalPlayer.

◆ MPTK_Play() [2/4]

void MidiPlayerTK.MidiFilePlayer.MPTK_Play ( byte[]  data)

Play the midi file from a byte array.
Look at MPTK_StatusLastMidiLoaded to get status.

Version
Maestro Pro
// Example of using with Windows or MACOs
using (Stream fsMidi = new FileStream(filepath, FileMode.Open, FileAccess.Read))
{
byte[] data = new byte[fsMidi.Length];
fsMidi.Read(data, 0, (int) fsMidi.Length);
midiFilePlayer.MPTK_Play(data);
}

◆ MPTK_Play() [3/4]

virtual void MidiPlayerTK.MidiFilePlayer.MPTK_Play ( float  delayRampUp,
float  startDelay = 0 
)
virtual

Play the midi file defined with MPTK_MidiName or MPTK_MidiIndex with ramp-up to the volume defined with MPTK_Volume.
The time to get a MIDI playing at full MPTK_Volume is delayRampUp + startDelay.
A delayed start can also be set.

Version
Maestro Pro
Parameters
delayRampUpramp-up delay in milliseconds to get the default volume
startDelaydelayed start in milliseconds V2.89.1

◆ MPTK_Play() [4/4]

void MidiPlayerTK.MidiFilePlayer.MPTK_Play ( MPTKWriter  mfw2,
float  delayRampUp = 0f,
float  fromPosition = 0,
float  toPosition = 0,
long  fromTick = 0,
long  toTick = 0,
bool  timePosition = true 
)

Play the midi from a MidiFileWriter2 object

Version
Maestro Pro
private void PlayDirectlyMidiSequence(string name, MPTKWriter mfw)
{
// Play MIDI with the MidiExternalPlay prefab without saving MIDI in a file
MidiFilePlayer midiPlayer = FindObjectOfType<MidiFilePlayer>();
if (midiPlayer == null)
{
Debug.LogWarning("Can't find a MidiFilePlayer Prefab in the current Scene Hierarchy. Add it with the MPTK menu.");
return;
}
midiPlayer.MPTK_Stop();
mfw.MidiName = name;
midiPlayer.OnEventStartPlayMidi.RemoveAllListeners();
midiPlayer.OnEventStartPlayMidi.AddListener((string midiname) =>
{
startPlaying = DateTime.Now;
Debug.Log($"Start playing '{midiname}'");
});
midiPlayer.OnEventEndPlayMidi.RemoveAllListeners();
midiPlayer.OnEventEndPlayMidi.AddListener((string midiname, EventEndMidiEnum reason) =>
{
Debug.Log($"End playing '{midiname}' {reason} Real Duration={(DateTime.Now - startPlaying).TotalSeconds:F3} seconds");
});
midiPlayer.OnEventNotesMidi.RemoveAllListeners();
midiPlayer.OnEventNotesMidi.AddListener((List<MPTKEvent> events) =>
{
foreach (MPTKEvent midievent in events)
Debug.Log($"At {midievent.RealTime:F1} \t\t{midievent}");
});
// In case of an inner loop has been defined in a Meta
midiPlayer.MPTK_InnerLoop.OnEventInnerLoop = (MPTKInnerLoop.InnerLoopPhase mode, long tickPlayer, long tickSeek, int count) =>
{
Debug.Log($"Inner Loop {mode} - MPTK_TickPlayer:{tickPlayer} --> TickSeek:{tickSeek} Count:{count}/{midiPlayer.MPTK_InnerLoop.Max}");
return true;
};
// Sort the events by ascending absolute time
// Calculate time, measure and quarter for each events
mfw.CalculateTiming(logPerf: true);
midiPlayer.MPTK_MidiAutoRestart = midiAutoRestart;
midiPlayer.MPTK_Play(mfw2: mfw);
}
Create, build, write, import, play MIDI by script. See full example with these scripts:
Definition: MPTKWriter.cs:28
void CalculateTiming(bool logPerf=false, bool logDebug=false)
Definition: MPTKWriter.cs:1121
void StableSortEvents(bool logPerf=false)
Definition: MPTKWriter.cs:1079
void MPTK_Stop(bool stopAllSound=true)
Definition: MidiFilePlayer.cs:1045
EventEndMidiClass OnEventEndPlayMidi
Definition: MidiFilePlayer.cs:742
EventStartMidiClass OnEventStartPlayMidi
Definition: MidiFilePlayer.cs:706
EventNotesMidiClass OnEventNotesMidi
Definition: MidiFilePlayer.cs:660
Parameters
mfw2aMidiFileWriter2 object
delayRampUp

◆ MPTK_PlayNextOrPrevious()

void MidiPlayerTK.MidiFilePlayer.MPTK_PlayNextOrPrevious ( int  offset)

Play next or previous Midi from the MidiDB list.

Version
Maestro Pro
Parameters
offsetForward or backward count in the list. 1:the next, -1:the previous

◆ MPTK_Previous()

void MidiPlayerTK.MidiFilePlayer.MPTK_Previous ( )

Play previous MIDI from the list of midi defined in MPTK (see Unity menu Midi)

◆ MPTK_ReadMidiEvents()

List< MPTKEvent > MidiPlayerTK.MidiFilePlayer.MPTK_ReadMidiEvents ( long  fromTicks = 0,
long  toTicks = long.MaxValue 
)

V2.88.2 - Read the list of midi events available in the MIDI from a ticks tick to an end tick.

private void TheMostSimpleDemoForMidiPlayer()
{
MidiFilePlayer midiplayer = FindObjectOfType<MidiFilePlayer>();
if (midiplayer == null)
{
Debug.LogWarning("Can't find a MidiFilePlayer Prefab in the current Scene Hierarchy. Add it with the MPTK menu.");
return;
}
// Index of the midi from the Midi DB (find it with 'Midi File Setup' from the menu MPTK)
midiplayer.MPTK_MidiIndex = 10;
// Open and load the Midi
if (midiplayer.MPTK_Load() != null)
{
// Read midi event to a List<>
List<MPTKEvent> mptkEvents = midiplayer.MPTK_ReadMidiEvents(1000, 10000);
// Loop on each Midi events
foreach (MPTKEvent mptkEvent in mptkEvents)
{
// Log if event is a note on
if (mptkEvent.Command == MPTKCommand.NoteOn)
Debug.Log($"Note on Time:{mptkEvent.RealTime} millisecond Note:{mptkEvent.Value} Duration:{mptkEvent.Duration} millisecond Velocity:{mptkEvent.Velocity}");
// Uncomment to display all Midi events
//Debug.Log(mptkEvent.ToString());
}
}
}
Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all ot...
Definition: MPTKEvent.cs:45
MPTKCommand Command
Definition: MPTKEvent.cs:100
MidiLoad MPTK_Load()
Definition: MidiFilePlayer.cs:1258
List< MPTKEvent > MPTK_ReadMidiEvents(long fromTicks=0, long toTicks=long.MaxValue)
Definition: MidiFilePlayer.cs:1302
MPTKCommand
Definition: MPTKEnum.cs:12
Parameters
fromTicksticks start, default 0
toTicksticks end, default end of MIDI file
Returns

◆ MPTK_RePlay()

void MidiPlayerTK.MidiFilePlayer.MPTK_RePlay ( )

Restart playing of the current midi file

◆ MPTK_SearchMidiToPlay()

bool MidiPlayerTK.MidiFilePlayer.MPTK_SearchMidiToPlay ( string  searchPartOfName)

Find a Midi in the Unity resources folder MidiDB which contains searchPartOfName in it's name (case sensitive).
Set MPTK_MidiIndex and MPTK_MidiName if the MIDI has been found

Note
  • Add Midi files to your project with the Unity menu Maestro.
Version
Maestro Pro
// Find the first Midi file name in MidiDB which contains "Adagio in it's name"
if (midiFilePlayer.MPTK_SearchMidiToPlay("Adagio"))
{
Debug.Log($"MPTK_SearchMidiToPlay: {MPTK_MidiIndex} {MPTK_MidiName}");
// And play it
midiFilePlayer.MPTK_Play();
}
Parameters
searchPartOfNamePart of MIDI name to search in MIDI list (case sensitive)
Returns
true if found else false

◆ MPTK_SortEvents()

void MidiPlayerTK.MidiFilePlayer.MPTK_SortEvents ( )

MIDI list events must be sorted by ticks before playing. It's mandatory if the list is modified.

Version
2.0.0 - Maestro Pro
private void OnGUI_ModifyMidiAndPlay()
{
HelperDemo.GUI_Horizontal(HelperDemo.Zone.BEGIN, myStyle.BacgDemosLight);
HelperDemo.GUI_Indent(widthIndent);
HelperDemo.GUI_Vertical(HelperDemo.Zone.BEGIN, myStyle.BacgDemosLight);
GUILayout.Label("When the MIDI is loaded, it's possible to alter the MIDI events brfore playing them. Result not garantee!", myStyle.TitleLabel3);
countNoteToInsert = (int)HelperDemo.GUI_Slider("Count notes to insert:", (float)countNoteToInsert, 1, 100,
alignCaptionRight: false, enableButton: true, widthCaption: 170, widthSlider: 250, widthLabelValue: 50);
tickPositionToInsert = (long)HelperDemo.GUI_Slider("Tick position to insert:", (long)tickPositionToInsert, 0, (long)midiFilePlayer.MPTK_TickLast,
alignCaptionRight: false, enableButton: true, widthCaption: 170, widthSlider: 250, widthLabelValue: 50);
if (GUILayout.Button("Insert And Play", GUILayout.Width(120)))
{
#if MPTK_PRO
// Better to stop the MIDIplaying.
midiFilePlayer.MPTK_Stop();
// There is no need of note-off events.
midiFilePlayer.MPTK_KeepNoteOff = false;
// MPTK_MidiName must contains the name of the MIDI to load.
if (midiFilePlayer.MPTK_Load() != null)
{
Debug.Log($"Duration: {midiFilePlayer.MPTK_Duration.TotalSeconds} seconds");
Debug.Log($"Count MIDI Events: {midiFilePlayer.MPTK_MidiEvents.Count}");
// Insert weird notes in the beautiful MIDI!
for (int insertNote = 1; insertNote <= countNoteToInsert; insertNote++)
midiFilePlayer.MPTK_MidiEvents.Insert(0,
new MPTKEvent()
{
Channel = 0,
Command = MPTKCommand.NoteOn,
Value = 60 + insertNote % 12,
Duration = midiFilePlayer.MPTK_DeltaTicksPerQuarterNote,
Tick = tickPositionToInsert + insertNote * midiFilePlayer.MPTK_DeltaTicksPerQuarterNote
});
// New event has been inserted, MIDI events list must be sorted by tick.
midiFilePlayer.MPTK_SortEvents();
// ... then play the modified list of events (any garantee to create the hit of the year!).
midiFilePlayer.MPTK_Play(alreadyLoaded: true);
}
#else
Debug.LogWarning("MIDI preload and alter MIDI events are available only with the PRO version");
#endif
}
HelperDemo.GUI_Vertical(HelperDemo.Zone.END);
HelperDemo.GUI_Horizontal(HelperDemo.Zone.END);
}

◆ MPTK_Stop() [1/2]

void MidiPlayerTK.MidiFilePlayer.MPTK_Stop ( bool  stopAllSound = true)

Stop playing immediately and clear all sounds. Note: clearing the sound is not possible out of the Unity thread, in this case set stopAllSound to false.

Parameters
stopAllSoundstop all sounds if true (default value) else notes will be stop after theirs normal duration.

◆ MPTK_Stop() [2/2]

virtual void MidiPlayerTK.MidiFilePlayer.MPTK_Stop ( float  delayRampDown,
float  stopDelay = 0 
)
virtual

Stop playing within a delay. After the stop delay (0 by default), the volume decrease until the playing is stopped.
The time to get a real MIDI stop is delayRampDown + stopDelay.

Version
Maestro Pro
Parameters
delayRampDowndecrease time in millisconds
stopDelaydelayed stop in milliseconds V2.89.1

◆ MPTK_SwitchMidiWithDelay()

void MidiPlayerTK.MidiFilePlayer.MPTK_SwitchMidiWithDelay ( int  index,
string  name,
float  volume,
float  delayToStopMillisecond,
float  delayToStartMillisecond 
)

Switch playing between two MIDIs with ramp-up.
This method is useful for an integration with Bolt: main MIDI parameters are defined in one call.

Version
Maestro Pro
Parameters
indexIndex of the MIDI to play. Index is used only if name parameter is null or empty.
nameName of the MIDI to play. Can be part of the MIDI Name. If set, this parameter has the priority over index parameter.
volumeVolume of the MIDI. -1 to not change the default volume
delayToStopMillisecondDelay to stop the current MIDI playing (with volume decrease) or delay before playing the MIDI if no MIDI is playing
delayToStartMillisecondDelay to get the MIDI at full volume (ramp-up volume)

◆ MPTK_UnPause()

void MidiPlayerTK.MidiFilePlayer.MPTK_UnPause ( )

UnPause the current playing

Member Data Documentation

◆ MPTK_InnerLoop

MPTKInnerLoop MidiPlayerTK.MidiFilePlayer.MPTK_InnerLoop

Defined looping condition inside the MIDI Sequencer [Pro]. Instance is automatically created when the MidiFilePlayer prefab is loaded/n See class #MPTKInnerLoop.

// Full source code in TestInnerLoop.cs
// As usual with a MVP demo, focus is on the essentials:
// - no value check,
// - limited error catch,
// - no optimization,
// - limited functions
// - ...
// Contains a reference to the current InnerLoop instance, useful only for clarity in the demo ...
private MPTKInnerLoop innerLoop;
// Start is called before the first frame update
void Start()
{
// Find a MidiFilePlayer in the scene hierarchy
// (Innerloop works also with MidiExternalPlayer, see TestMidiGenerator.cs)
// ----------------------------------------------
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;
}
// Preload the MIDI file to be able to set MIDI attributes before playing.
// In particular MPTK_InnerLoop which is cleared when MIDI is loaded.
midiFilePlayer.MPTK_Load();
// Get a shortcut (for clarity) to the inner loop instance (instanciated in the awake phase of the MidiFilePlayer)
// You can also instanciate or manage your own references and set midiFilePlayer.MPTK_InnerLoop with your MPTKInnerLoop instance.
innerLoop = midiFilePlayer.MPTK_InnerLoop;
// No log for this demo, rather we prefer using a callback.
innerLoop.Log = false;
// Define C# event of type Func() for each loop phase change: Start --> Resume --> Resume --> ... -> Exit
// If return is false then looping can be earlier ended.
// It's also possible to set innerLoop.Finished to True at all places in your script
// but the loop will finished only when tickPlayer reaches the end of the loop.
innerLoop.OnEventInnerLoop = (MPTKInnerLoop.InnerLoopPhase mode, long tickPlayer, long tickSeek, int count) =>
{
Debug.Log($"Inner Loop {mode} - MPTK_TickPlayer:{tickPlayer} --> TickSeek:{tickSeek} Count:{count}/{innerLoop.Max}");
if (mode == MPTKInnerLoop.InnerLoopPhase.Exit)
// Set the value for the Unity User Interface to be able to reactivate the loop.
LoopFinished = true;
return true;
};
innerLoop.Enabled = true;
midiFilePlayer.MPTK_Play(alreadyLoaded: true);
}
// Update is called once per frame
void Update()
{
if (midiFilePlayer != null && midiFilePlayer.MPTK_MidiLoaded != null)
{
// Display current real-time tick value of the MIDI sequencer
TickPlayer = midiFilePlayer.MPTK_MidiLoaded.MPTK_TickPlayer;
// Display tick value of the last MIDI event read by the MIDI sequencer.
TickCurrent = midiFilePlayer.MPTK_MidiLoaded.MPTK_TickCurrent;
// Display current measure and beat value of the last MIDI event read by the MIDI sequencer.
MeasurePlayer = $"{midiFilePlayer.MPTK_MidiLoaded.MPTK_CurrentMeasure}.{midiFilePlayer.MPTK_MidiLoaded.MPTK_CurrentBeat} - Last measure: {midiFilePlayer.MPTK_MidiLoaded.MPTK_MeasureLastNote}";
// These parameters can be changed dynamically with the inspector
innerLoop.Max = LoopMax;
innerLoop.Start = TickStart;
innerLoop.Resume = TickResume;
innerLoop.End = TickEnd;
innerLoop.Finished = LoopFinished;
// These values are read from the inner loop instance and display on the UI.
loopEnabled = innerLoop.Enabled;
LoopCount = innerLoop.Count;
// Calculate tick position of a measure (just for a demo how to calculate tick from bar).
// So, it's easy to create loop based on measure.
Tick = MPTKSignature.MeasureToTick(midiFilePlayer.MPTK_MidiLoaded.MPTK_SignMap, Measure);
// Add quarter. Beat start at the begin of the measure (Beat = 1).
Tick += (Quarter - 1) * midiFilePlayer.MPTK_DeltaTicksPerQuarterNote;
}
}
Setting for MIDI inner loop [Pro]. Look at MidiFilePlayer.MPTK_InnerLoop Example:
Definition: MPTKInnerLoop.cs:16
bool Enabled
Definition: MPTKInnerLoop.cs:62
InnerLoopPhase
Definition: MPTKInnerLoop.cs:26
int Count
Definition: MPTKInnerLoop.cs:94
bool Log
Definition: MPTKInnerLoop.cs:20
Version
2.10.0

◆ MPTK_LogLoadEvents

bool MidiPlayerTK.MidiFilePlayer.MPTK_LogLoadEvents

If true display in console all midi events when a MIDI file is loaded.

Note
Set to true will increase greatly the MIDI load time. To be used only for debug purpose.
Version
2.10.0

◆ MPTK_ModeStopVoice

ModeStopPlay MidiPlayerTK.MidiFilePlayer.MPTK_ModeStopVoice

Defined how the MIDI player is stopped or restarted when the last MIDI events is reached.

Version
2.9.1
Note
No impact on MPTK_Duration which remains the same (including the duration of the last note).

◆ MPTK_PauseOnFocusLoss

bool MidiPlayerTK.MidiFilePlayer.MPTK_PauseOnFocusLoss

Should the MIDI playing must be paused when the application lost the focus?

◆ MPTK_StartPlayAtFirstNote

bool MidiPlayerTK.MidiFilePlayer.MPTK_StartPlayAtFirstNote

When the value is true, playing begin at the first note found. Obviously all previous events (except note-on) are processed but all at the tick 0.

Often, the first note is not set at the beginning of the MIDI file (tick=0), alSo there is a delay before playing the first note.
This setting is useful to start playing sound immediately. Works also when looping.

Note
  • No impact on MPTK_Duration that remains the same, so there is a shift between the real time of the MIDI and the theoretical duration.

◆ MPTK_StatusLastMidiLoaded

LoadingStatusMidiEnum MidiPlayerTK.MidiFilePlayer.MPTK_StatusLastMidiLoaded

Status of the last midi loaded. The status is updated in a coroutine, so the status can change at each frame.

◆ OnEventEndPlayMidi

EventEndMidiClass MidiPlayerTK.MidiFilePlayer.OnEventEndPlayMidi

Define the Unity event triggered when end of the MIDI list events is reached.

Note
  • With v2.9.0 this event is trigerred even if the note is still in play. That could be unpleasant if you want yo loop on the MIDI.
  • Enable "Keep MIDI End Track" (MPTK_KeepEndTrack) or "Keep Note Off" (MPTK_KeepNoteOff) when loading the MIDI file to sync the end of the playing with the real end of the MIDI.
using MidiPlayerTK; // Add a reference to the MPTK namespace at the top of your script
using UnityEngine;
public class YourClass : MonoBehaviour
{
MidiFilePlayer midiFilePlayer;
void Start()
{
// Get a reference to the prefab MidiFilePlayer from the hierarchy in the scene
midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
// Add a listener on the MIDI File Player.
// NotesToPlay will be called for each new group of notes read by the MIDI sequencer from the MIDI file.
midiFilePlayer.OnEventEndPlayMidi.AddListener(EndPlay);
}
public void EndPlay(string midiname, EventEndMidiEnum reason)
{
Debug.LogFormat($"End playing midi {midiname} reason:{reason}");
}
}

◆ OnEventNotesMidi

EventNotesMidiClass MidiPlayerTK.MidiFilePlayer.OnEventNotesMidi

Method triggered for each MIDI event (or group of MIDI events) ready to be played by the MIDI synth. All these events are on same MIDI tick
. The callback method is able to directly interacts with Unity gameObject (same thread).
A List<MPTKEvent> is passed to the delegate.

Note
It's not possible to alter playing music by modifying note properties (pitch, velocity, ....) in the callback.
using MidiPlayerTK; // Add a reference to the MPTK namespace at the top of your script
using UnityEngine;
public class YourClass : MonoBehaviour
{
MidiFilePlayer midiFilePlayer;
void Start()
{
// Get a reference to the prefab MidiFilePlayer from the hierarchy in the scene
midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
// Add a listener on the MIDI File Player.
// NotesToPlay will be called for each new group of notes read by the MIDI sequencer from the MIDI file.
midiFilePlayer.OnEventNotesMidi.AddListener(NotesToPlay);
}
// This method will be called by the MIDI sequencer just before the notes
// are playing by the MIDI synthesizer (if 'Send To Synth' is enabled)
public void NotesToPlay(List<MPTKEvent> mptkEvents)
{
Debug.Log("Received " + mptkEvents.Count + " MIDI Events");
// Loop on each MIDI events
foreach (MPTKEvent mptkEvent in mptkEvents)
{
// Log if event is a note on
if (mptkEvent.Command == MPTKCommand.NoteOn)
Debug.Log($"Note on Time:{mptkEvent.RealTime} millisecond Note:{mptkEvent.Value} Duration:{mptkEvent.Duration} millisecond Velocity:{mptkEvent.Velocity}");
// Uncomment to display all MIDI events
// Debug.Log(mptkEvent.ToString());
}
}
}

◆ OnEventStartPlayMidi

EventStartMidiClass MidiPlayerTK.MidiFilePlayer.OnEventStartPlayMidi

Define the Unity event to be triggered at start of playing the Midi.
MIDI File is loaded, Midi Synth is initialized, but so far any MIDI event has been read.
This is the right time to defined some specific behaviors.

using MidiPlayerTK; // Add a reference to the MPTK namespace at the top of your script
using UnityEngine;
public class YourClass : MonoBehaviour
{
MidiFilePlayer midiFilePlayer;
void Start()
{
// Get a reference to the prefab MidiFilePlayer from the hierarchy in the scene
midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
// Add a listener on the MIDI File Player.
// NotesToPlay will be called for each new group of notes read by the MIDI sequencer from the MIDI file.
midiFilePlayer.OnEventStartPlayMidi.AddListener(StartPlay);
}
public void StartPlay(string midiname)
{
Debug.LogFormat($"Start playing midi {midiname}");
// Disable MIDI channel 9 (generally drums)
midiFilePlayer.MPTK_ChannelEnableSet(9, false);
// Set start tick
midiFilePlayer.MPTK_TickCurrent = 500;
}
}

Property Documentation

◆ MPTK_Copyright

string MidiPlayerTK.MidiFilePlayer.MPTK_Copyright
get

Get Copyright if defined in the MIDI file with MIDI MetaEventType = Copyright
See detail here https://ccrma.stanford.edu/~craig/14q/midifile/MidiFileFormat.html
Can be used only when the MIDI is playing.

◆ MPTK_DeltaTicksPerQuarterNote

int MidiPlayerTK.MidiFilePlayer.MPTK_DeltaTicksPerQuarterNote
get

Delta Ticks Per Beat Note. Indicate the duration time in "ticks" which make up a quarter-note.
For instance, if 96, then a duration of an eighth-note in the file would be 48.
More info here https://paxstellar.fr/2020/09/11/midi-timing/

Move forward one quarter
midiFilePlayer.MPTK_TickCurrent = midiFilePlayer.MPTK_TickCurrent + midiFilePlayer.MPTK_DeltaTicksPerQuarterNote;

◆ MPTK_Duration

TimeSpan MidiPlayerTK.MidiFilePlayer.MPTK_Duration
get

Real duration expressed in TimeSpan of the full midi from the first event (tick=0) to the last event.
If MPTK_KeepEndTrack is false, the MIDI events End Track are not considered to calculate this time.
The tempo changes are taken into account if MPTK_EnableChangeTempo is set to true before loading the MIDI.

◆ MPTK_DurationMS

float MidiPlayerTK.MidiFilePlayer.MPTK_DurationMS
get

Real duration expressed in milliseconds of the full midi from the first event (tick=0) to the last event.
If MPTK_KeepEndTrack is false, the MIDI events End Track are not considered to calculate this time.
The tempo changes are taken into account if MPTK_EnableChangeTempo is set to true before loading the MIDI.

◆ MPTK_IsPaused

bool MidiPlayerTK.MidiFilePlayer.MPTK_IsPaused
get

Is MIDI file playing is paused ?

◆ MPTK_IsPlaying

bool MidiPlayerTK.MidiFilePlayer.MPTK_IsPlaying
get

Is MIDI file is playing ?

◆ MPTK_KeepEndTrack

bool MidiPlayerTK.MidiFilePlayer.MPTK_KeepEndTrack
getset

When set to true, meta MIDI event End Track are keep. Default is false.
If set to true, the End Track Event are taken into account for calculate the full duration of the MIDI.
See MPTK_DurationMS.

◆ MPTK_KeepNoteOff

bool MidiPlayerTK.MidiFilePlayer.MPTK_KeepNoteOff
getset

A MIDI file is a kind of keyboard simulation: in general, a key pressed generates a 'note-on' and a key release generates a 'note-off'.
But there is an other possibility in a MIDI file: create a 'note-on' with a velocity=0 wich must act as a 'midi-off'
By default, MPTK create only one MPTK event with the command NoteOn and a duration.
But in some cases, you could want to keep the note-off events if they exist in the MIDI file.
Set to false if there is no need (could greatly increases the MIDI list events).
Set to true to keep 'note-off' events.

◆ MPTK_LastEventPlayed

MPTKEvent MidiPlayerTK.MidiFilePlayer.MPTK_LastEventPlayed
get

Last MIDI event played by the MIDI sequencer

◆ MPTK_Loop

bool MidiPlayerTK.MidiFilePlayer.MPTK_Loop
getset

Deprecated:
with 2.10.0 MPTK_Loop is deprecated. Please investigate MPTK_MidiRestart or MPTK_InnerLoop (Pro) for a better looping accuracy.

◆ MPTK_MidiAutoRestart

bool MidiPlayerTK.MidiFilePlayer.MPTK_MidiAutoRestart
getset

When the value is true, the current MIDI playing is restarted when it reaches the end or #MPTK_MidiLoaded.MPTK_TickEnd.

Note
  • The MIDI file is not reloaded, the restart is quite immediate.
  • #MPTK_MidiLoaded.MPTK_TickStart and #MPTK_MidiLoaded.MPTK_TickEnd are useful to defined start and end playing position.
  • Looping is processed in the Unity thread, also one Unity frame or more is needed to restart the playing of the MIDI.
  • Better looping accuracy can be done with MPTK_InnerLoop (pro).

◆ MPTK_MidiEvents

List<MPTKEvent> MidiPlayerTK.MidiFilePlayer.MPTK_MidiEvents
get

Get all the MPTK MIDI events available in the midi file.

◆ MPTK_MidiIndex

int MidiPlayerTK.MidiFilePlayer.MPTK_MidiIndex
getset

Select a MIDI file to play by its Index from the MIDIDB.
The Index of a MIDI file is displayed in the popup from the MidiFilePlayer inspector and in the window "Midi File Setup" from the MPTK menu in the editor.

// Play the MIDI index 33
midiFilePlayer.MPTK_MidiIndex = 33;
midiFilePlayer.MPTK_Play();
Parameters
indexIndex of the MIDI, start from 0

◆ MPTK_MidiLoaded

MidiLoad MidiPlayerTK.MidiFilePlayer.MPTK_MidiLoaded
get

Get detailed information about the MIDI playing. This readonly properties is available only when a MIDI has been loaded.

◆ MPTK_MidiName

virtual string MidiPlayerTK.MidiFilePlayer.MPTK_MidiName
getset

Select a MIDI from the MIDIDB to play by its name.
Use the exact name as seen in the MIDI setup windows (Unity menu MPTK/ without any path or extension.
Tips: Add MIDI files to your project with the Unity menu MPTK.

// Play the MIDI "Albinoni - Adagio"
midiFilePlayer.MPTK_MidiName = "Albinoni - Adagio";
midiFilePlayer.MPTK_Play();

◆ MPTK_PlayOnStart

bool MidiPlayerTK.MidiFilePlayer.MPTK_PlayOnStart
getset

Should the MIDI start playing when the application starts?

◆ MPTK_PlayTime

TimeSpan MidiPlayerTK.MidiFilePlayer.MPTK_PlayTime
get

Real time in TimeSpan format from the beginning of play. It's an access to the MIDI timer used by the MIDI sequencer.

Note
#CurrentTempo or MPTK_Speed change have no direct impact on this value.

◆ MPTK_Position

double MidiPlayerTK.MidiFilePlayer.MPTK_Position
getset

Set or get the current position in the MIDI in milliseconds.

Note
  • Works only when the MIDI is playing.
  • You can't set the position before or just after MPTK_Play() because MPTK_Play() reset the position at the start.
  • Rather, set the position when the event OnEventStartPlayMidi() is triggered. See example bellow.
  • Look also the properties MPTK_TickCurrent to change the tick by MIDI ticks.
  • When the MIDI is playing look at the inspector of the MidiFilePlayer prefab to read (or change) the current position in seconds and find the position you want.

Here, more information about Midi Timing https://paxstellar.fr/2020/09/11/midi-timing/

public MidiFilePlayer midiFilePlayer;
void Start()
{
// Find the prefab MidiFilePlayer in your scene
midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
// Event trigger when midi file start playing
midiFilePlayer.OnEventStartPlayMidi.AddListener(info => StartPlay("Event set by script"));
// beginning playing
midiFilePlayer.MPTK_Play();
}
// Method executed when the MIDI file start playing
public void StartPlay(string name)
{
// The MIDI will start playing at 5 seconds from the beginning of the MIDI
midiFilePlayer.MPTK_Position = 5000;
}
void Update()
{
if ('condition from your application is true')
// The MIDI will continue playing at 10 seconds from the beginning of the MIDI
midiFilePlayer.MPTK_Position = 10000;
}

◆ MPTK_PositionFirstNote

double MidiPlayerTK.MidiFilePlayer.MPTK_PositionFirstNote
get

Real time tick in millisecond for the first note-on found.
Most MIDI don't start playing a note immediately. There is often a delay.
Use this attribute to known the real time wich it will start.
See also MPTK_TickFirstNote

◆ MPTK_PositionLastNote

double MidiPlayerTK.MidiFilePlayer.MPTK_PositionLastNote
get

Real time tick in millisecond for the last note-on found in the MIDI.
There is often other MIDI events after the last note-on: for example event track-end.
Use this attribute to known the real time when all sound will be stop.
See also the MPTK_DurationMS which provides the full time of all MIDI events including track-end, control at the beginning and at the end, ....
See also MPTK_TickLastNote

◆ MPTK_ProgramName

string MidiPlayerTK.MidiFilePlayer.MPTK_ProgramName
get

Get Program track name if defined in the MIDI file with MIDI MetaEventType = ProgramName
See detail here https://ccrma.stanford.edu/~craig/14q/midifile/MidiFileFormat.html
Can be used only when the MIDI is playing.

◆ MPTK_PulseLenght

double MidiPlayerTK.MidiFilePlayer.MPTK_PulseLenght
get

Lenght in millisecond of a MIDI tick. The pulse length is the minimum time in millisecond between two MIDI events.
It's like a definition of graphical resolution but for MIDI: the MIDI sequencer will not be able to play two separate MIDI events in a time below this value.

Note
  • Depends on the current tempo (#MPTK_CurrentTempo) and the MPTK_DeltaTicksPerQuarterNote and Speed.
  • Read Only.
  • Formula: PulseLenght = MPTK_CurrentTempo / MPTK_DeltaTicksPerQuarterNote / 1000 / Speed

◆ MPTK_Quantization

int MidiPlayerTK.MidiFilePlayer.MPTK_Quantization
getset

Level of quantization :

  • 0 = None
  • 1 = Beat Note
  • 2 = Eighth Note
  • 3 = 16th Note
  • 4 = 32th Note
  • 5 = 64th Note
  • 6 = 128th Note

◆ MPTK_RealTime

double MidiPlayerTK.MidiFilePlayer.MPTK_RealTime
get

Real time in milliseconds from the beginning of play. It's an access to the MIDI timer used by the MIDI sequencer.

Note
#CurrentTempo or MPTK_Speed change have no direct impact on this value.

◆ MPTK_SequenceTrackName

string MidiPlayerTK.MidiFilePlayer.MPTK_SequenceTrackName
get

Get sequence track name if defined in the MIDI file with MIDI MetaEventType = SequenceTrackName
See detail here https://ccrma.stanford.edu/~craig/14q/midifile/MidiFileFormat.html
Can be used only when the MIDI is playing.

◆ MPTK_Speed

float MidiPlayerTK.MidiFilePlayer.MPTK_Speed
getset

Percentage value of the playing speed. Range 0.1 (10%) to 10 (1000%). Default is 1 for normal speed.

◆ MPTK_Tempo

double MidiPlayerTK.MidiFilePlayer.MPTK_Tempo
getset

Get or change the current tempo played by the internal MIDI sequencer (independent from MPTK_Speed).
Return QuarterPerMinuteValue similar to BPM (Beat Per Measure).

Note
  • Can be handle only when the MIDI is playing.
  • Changing the current tempo when playing has no impact on the calculated duration of the MIDI.

◆ MPTK_TextEvent

string MidiPlayerTK.MidiFilePlayer.MPTK_TextEvent
get

Get Text if defined in the MIDI file with MIDI MetaEventType = TextEvent
See detail here https://ccrma.stanford.edu/~craig/14q/midifile/MidiFileFormat.html
Can be used only when the MIDI is playing.

◆ MPTK_TickCurrent

long MidiPlayerTK.MidiFilePlayer.MPTK_TickCurrent
getset

Get the tick value of the last MIDI event played.
Set the tick value of the next MIDI event to played.

Midi tick is an easy way to identify a tick in a song independently of the time which could vary with tempo change event.
The count of ticks by quarter is constant all along a MIDI, it's a properties of the whole MIDI. see MPTK_DeltaTicksPerQuarterNote.
With a time signature of 4/4 the ticks length of a bar is 4 * MPTK_DeltaTicksPerQuarterNote.
Here, more information about Midi Timing https://paxstellar.fr/2020/09/11/midi-timing/

Note
  • works only when the MIDI is playing.
  • you can't set the tick before or just after MPTK_Play() because MPTK_Play() reset the tick at the start.
  • rather, set the tick when the event OnEventStartPlayMidi() is triggereed. See example below.
  • look also the properties MPTK_Position to change the tick by milliseconds.
  • when the MIDI is playing look at the inspector of the MidiFilePlayer prefab to read (or change) the current tick and find the tick you want.
See example:
public MidiFilePlayer midiFilePlayer;
void Start()
{
// Find the prefab MidiFilePlayer in your scene
midiFilePlayer = FindObjectOfType<MidiFilePlayer>();
// Event trigger when midi file start playing
midiFilePlayer.OnEventStartPlayMidi.AddListener(info => StartPlay("Event set by script"));
// beginning playing
midiFilePlayer.MPTK_Play();
}
// Method executed when the MIDI file start playing
public void StartPlay(string name)
{
// The MIDI will start playing at tick 10000
midiFilePlayer.MPTK_TickCurrent = 10000;
}
void Update()
{
if ('condition from your application is true')
// The MIDI will continue playing at ticks 20000
midiFilePlayer.MPTK_TickCurrent = 20000;
}

◆ MPTK_TickFirstNote

long MidiPlayerTK.MidiFilePlayer.MPTK_TickFirstNote
get

Tick tick for the first note-on found.
Most MIDI don't start playing a note immediately. There is often a delay.
Use this attribute to known the tick tick where the will start to play a sound.
See also MPTK_PositionFirstNote

◆ MPTK_TickLast

long MidiPlayerTK.MidiFilePlayer.MPTK_TickLast
get

Last tick tick in Midi: it's the value of the tick for the last MIDI event in sequence expressed in number of "ticks".

◆ MPTK_TickLastNote

long MidiPlayerTK.MidiFilePlayer.MPTK_TickLastNote
get

Tick tick for the last note-on found.
There is often other MIDI events after the last note-on: for example event track-end.
Use this attribute to known the tick tick time when all sound will be stop.
See also the MPTK_PositionLastNote which provides the last time of the MIDI.

◆ MPTK_TrackCount

int MidiPlayerTK.MidiFilePlayer.MPTK_TrackCount
get

Count of track read in the MIDI file

◆ MPTK_TrackInstrumentName

string MidiPlayerTK.MidiFilePlayer.MPTK_TrackInstrumentName
get

Get Instrument track name if defined in the MIDI file with MIDI MetaEventType = TrackInstrumentName
See detail here https://ccrma.stanford.edu/~craig/14q/midifile/MidiFileFormat.html
Can be used only when the MIDI is playing.