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

Base class for loading a MIDI file and reading MIDI event in a MIDI sequencer. It's not possible to instanciate directly this class.
Rather, use MidiFilePlayer to load a MIDI This class is used by MidiFilePlayer, MidiListPlayer, MidiFileWrite2, MidiFileLoader (see members MPTK_MidiLoaded of these classes).
. More...

Public Member Functions

void MPTK_Clear ()
 Removes all information about the MIDI loaded.
bool MPTK_Load (int index, bool strict=false, bool extendedText=false)
 Load Midi from midi MPTK referential (Unity resource).
The index of the Midi file can be found in the windo "Midi File Setup". Display with menu MPTK / Midi File Setup
If result is true, MPTK_MidiEvents contains list of MIDI events.
bool MPTK_Load (byte[] datamidi, bool strict=false)
 Load Midi from an array of bytes. If result is true, MPTK_MidiEvents contains list of MIDI events.
bool MPTK_Load (string midiname, bool strict=false)
 Load Midi from a Midi file from Unity resources. The Midi file must be present in Unity MidiDB ressource folder.
List< MPTKEventMPTK_ReadMidiEvents (long fromTicks=0, long toTicks=long.MaxValue)
 Read the list of midi events available in the Midi from a ticks position to an end position.
double MPTK_ConvertTickToTime (long tick)
long MPTK_ConvertTimeToTick (double time)
MPTKEvent MPTK_SearchEventFromTime (double time)
 Search for a Midi event from a time position expressed in millisecond.
So time=19.3 and time=19.9 will find the same event.
.
long MPTK_SearchTickFromTime (double time)
 Search a tick position in the current midi from a position in millisecond.
Warning: this method loop on the whole midi to find the position.
Could be CPU costly but this method take care of the tempo change in the Midi.
Use MPTK_ConvertTimeToTick if there is no tempo change in the midi.
MPTKEvent.EnumLength NoteLength (MPTKEvent mptkEvent)
 https://en.wikipedia.org/wiki/Note_value
void MPTK_DisplayMidiAttributes ()
 Display in console the attributes of the MIDI loaded - v2.9.0.
void MPTK_CalculateTiming ()
 Calculate all timing in the MIDI file:
MPTKEvent MPTK_FindLastNote ()
 Find the last MIDI event note-on.
void MPTK_ComputeDuration ()
 Calculate MPTK_Duration, MPTK_DurationMS, MPTK_TickLast from the MIDI events list MPTK_MidiEvents.
bool MPTK_LoadFile (string filename, bool strict=false)
 Load MIDI file from a local file (Moved to PRO since version 2.89.5).
bool MPTK_Load (MPTKWriter mfw2)
 Load Midi from a MidiFileWriter2 object.

Static Public Member Functions

static int MPTK_BPM2MPQN (int bpm)
static int MPTK_MPQN2BPM (int microsecondsPerQuaterNote)
static int MPTK_SearchEventFromTick (List< MPTKEvent > midiEvents, long tickSearched)
 Search for a MIDI event from a tick position. v2.9.0
.
static List< MPTKEventMPTK_SortEvents (List< MPTKEvent > midiEvents, bool logPerf=false)
 Sort MIDI event list based on tick value, but for the same tick value, priority for 'bank change' then 'preset change'.

Public Attributes

List< MPTKEventMPTK_MidiEvents
 List of MIDI events loaded and played by the MIDI sequencer. It's possible to modify directly the content but with unpredictable results!
int MPTK_MicrosecondsPerQuarterNote
 Read from the SetTempo event: The tempo is given in micro seconds per quarter beat. To convert this to BPM we needs to use the following equation:BPM = 60,000,000/[tt tt tt] Warning: this value can change during the playing when a change tempo event is find.
https://paxstellar.fr/2020/09/11/midi-timing/.
int MPTK_DeltaTicksPerQuarterNote
 Delta Ticks Per Beat Note (or DTPQN) represent the duration time in "ticks" which make up a quarter-note.
For example, with 96 a duration of an eighth-note in the file would be 48.
From a MIDI file, this value is found in the MIDI Header and remains constant for all the MIDI file.
More info here https://paxstellar.fr/2020/09/11/midi-timing/
.
double MPTK_Pulse
 Real-time duration in millisecond of a MIDI tick. This value is updated when a tempo change is found.
The pulse length is the minimum time in millisecond between two MIDI events.
.
double MPTK_InitialTempo
 Initial tempo found in the MIDI. Available from MPTK_MidiLoaded attribut from MidiFilePLayer or MidiExternal.
TimeSpan MPTK_Duration
 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.
float MPTK_DurationMS
 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.
bool MPTK_EnableChangeTempo
 Should enable or disable change tempo from MIDI Events ? If disabled, the first tempo defined (or default to 120 BPM) will be used for all the MIDI played.
long MPTK_TickStart
 Tick to start playing the MIDI.
long MPTK_TickEnd
 Tick to end playing the MIDI. All MIDI events with MIDI tick higher or equal are not played.
long MPTK_TickLast
 Tick value of the last MIDI event found in the MIDI loaded.
long MPTK_TickCurrent
 Get the tick value of the last MIDI event played.
Set the tick value of the next MIDI event to played.
Unlike MPTK_TickPlayer, which is continuously updated, this property is only updated when a MIDI event is read from the sequencer.
bool MPTK_RawSeek
 This parameter is used when changing the playback position in a MIDI.
By default (false), all events except note-on are played from the beginning of the MIDI to the new position, to put the synthesizer back in the right context (tempo, selected instruments, controller, ...).
If set to true, the current playback position is set, but the previous context is retained. This can have undesirable (or funny!) effects on some MIDI, but it also makes it possible to change position much more quickly.
It's a choice to be made according to your needs.
.
long MPTK_TickPlayer
 Get the real-time tick value of the MIDI player.
Unlike MPTK_TickCurrent which is only updated when a MIDI event is read, this property is updated continuously while the MIDI thread is playing.
long MPTK_TickFirstNote
 Tick position for the first note-on found.
Most MIDI doesn't start playing a note immediately. There is often a delay.
Use this attribute to know the tick position where the player will start playing a sound.
See also MPTK_PositionFirstNote.
long MPTK_TickLastNote
 Tick position for the last note-on found.
There are often other MIDI events after the last note-on: for example, the track-end event.
Use this attribute to know the tick position at which all sound will stop.
See also MPTK_PositionLastNote which returns the last MIDI tick.
MPTKEvent MPTK_EventLastNote
 Last MIDI event note-on found in MIDI.
There are often other MIDI events after the last note-on: for example, the track-end event.
Use this attribute to know the tick position time when all sound will stop.
See also MPTK_PositionLastNote which returns the last MIDI tick.
double MPTK_PositionFirstNote
 Real-time position in milliseconds for the first note-on found.
Most MIDI doesn't start playing a note immediately. There is often a delay.
Use this attribute to know the real time at which it will start.
See also MPTK_TickFirstNote.
double MPTK_PositionLastNote
 Real-time position in milliseconds for the last note-on found in the MIDI.
There are often other MIDI events after the last note-on: for example, the track-end event.
Use this attribute to know the real time when all sound will stop.
See also MPTK_DurationMS which gives the full duration of all MIDI events including track end, start and end control, ....
See also MPTK_TickLastNote.
long MPTK_MeasureLastNote
 Measure position for the last note-on found.
There is often other MIDI events after the last note-on: for example event track-end.
MPTKEvent MPTK_LastEventPlayed
 Current MIDI event read when the MIDI sequencer is playing the MIDI. See MPTK_TickCurrent.
List< MPTKTempoMPTK_TempoMap
 List of all tempo changes found in the MIDI.
List< MPTKSignatureMPTK_SignMap
 List of all signature changes found in the MIDI.
int MPTK_CurrentIndexTempoMap
 Current index of the Tempo segment.
MPTKTempo MPTK_CurrentTempoMap
 Current Tempo Map.
int MPTK_CurrentIndexSignMap
 Current index of the Signature segment.
MPTKSignature MPTK_CurrentSignMap
 Current Signature segment.
int MPTK_TimeSigNumerator
 Updated from TimeSignature event when playing MIDI: The numerator counts the number of beats in a measure.
For example a numerator of 4 means that each bar contains four beats.
This is important to know because usually the first beat of each bar has extra emphasis.
In MIDI the denominator value is stored in a special format. i.e. the real denominator = 2 ^ MPTK_TimeSigNumerator
https://paxstellar.fr/2020/09/11/midi-timing/.
int MPTK_TimeSigDenominator
 Updated from TimeSignature event when playing MIDI: The denominator specifies the number of quarter notes in a beat.
int MPTK_NumberBeatsMeasure
 Updated from TimeSignature event when playing MIDI: the numerator counts the number of beats in a measure.
For example a numerator of 4 means that each bar contains four beats.
.
int MPTK_NumberQuarterBeat
 Updated from TimeSignature event when playing MIDI: describe of what note value a beat is (ie, how many quarter notes there are in a beat).
int MPTK_TicksInMetronomeClick
 Updated from TimeSignature event when playing MIDI: The standard MIDI clock ticks every 24 times every quarter note (crotchet)
So a MPTK_TicksInMetronomeClick value of 24 would mean that the metronome clicks once every quarter note.
A MPTK_TicksInMetronomeClick value of 6 would mean that the metronome clicks once every 1/8th of a note (quaver).
https://paxstellar.fr/2020/09/11/midi-timing/.
int MPTK_No32ndNotesInQuarterNote
 Updated from TimeSignature event when playing MIDI: This value specifies the number of 1/32nds of a note happen every MIDI quarter note.
It is usually 8 which means that a quarter note happens every quarter note.
https://paxstellar.fr/2020/09/11/midi-timing/.
int MPTK_KeySigSharpsFlats
 Updated from KeySignature event when playing MIDI: values between -7 and 7 and specifies the key signature in terms of number of flats (if negative) or sharps (if positive) https://www.recordingblogs.com/wiki/midi-key-signature-meta-message.
int MPTK_KeySigMajorMinor
 Updated from KeySignature event when playing MIDI: specifies the scale of the MIDI file.
int MPTK_TrackCount
 Count of track in the MIDI file.
float MPTK_LoadTime
 Processing time in millisecond for loading the MIDI file.
bool MPTK_LogLoadEvents
 If true display in console all midi events when a MIDI file is loaded. v2.9.0
Set to true could increase greatly the load time. To be used only for debug.
bool MPTK_ExtendedText
bool MPTK_KeepNoteOff
 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.
bool KeepNoteOff
bool MPTK_KeepEndTrack
 If set to true, the meta MIDI events 'End Track' are kept and the MIDI duration includes the 'End Track' events.
Default value is false.
int MPTK_CurrentMeasure
 Current measure of the current event played [Pro].
int MPTK_CurrentBeat
 Current beat of the current event played [Pro].

Properties

double MPTK_CurrentTempo [get, set]
 Get or change the current tempo played by the internal MIDI sequencer. Available from MPTK_MidiLoaded attribut from MidiFilePLayer or MidiExternal.

Detailed Description

Base class for loading a MIDI file and reading MIDI event in a MIDI sequencer. It's not possible to instanciate directly this class.
Rather, use MidiFilePlayer to load a MIDI This class is used by MidiFilePlayer, MidiListPlayer, MidiFileWrite2, MidiFileLoader (see members MPTK_MidiLoaded of these classes).
.

Member Function Documentation

◆ MPTK_Load() [1/4]

bool MidiPlayerTK.MidiLoad.MPTK_Load ( int index,
bool strict = false,
bool extendedText = false )

Load Midi from midi MPTK referential (Unity resource).
The index of the Midi file can be found in the windo "Midi File Setup". Display with menu MPTK / Midi File Setup
If result is true, MPTK_MidiEvents contains list of MIDI events.

public MidiLoad MidiLoaded;
// .....
MidiLoaded = new MidiLoad();
MidiLoaded.MPTK_Load(14) // index for "Beattles - Michelle"
Debug.Log("Duration:" + MidiLoaded.MPTK_Duration);
TimeSpan MPTK_Duration
Real duration expressed in TimeSpan of the full midi from the first event (tick=0) to the last event....
Definition MidiLoad.cs:111
bool MPTK_Load(int index, bool strict=false, bool extendedText=false)
Load Midi from midi MPTK referential (Unity resource). The index of the Midi file can be found in th...
Definition MidiLoad.cs:491
Parameters
index
strictIf true will error on non-paired note events, default:false
Returns
true if loaded

◆ MPTK_Load() [2/4]

bool MidiPlayerTK.MidiLoad.MPTK_Load ( byte[] datamidi,
bool strict = false )

Load Midi from an array of bytes. If result is true, MPTK_MidiEvents contains list of MIDI events.

Parameters
datamidibyte arry midi
strictIf true will error on non-paired note events, default:false
Returns
true if loaded

◆ MPTK_Load() [3/4]

bool MidiPlayerTK.MidiLoad.MPTK_Load ( string midiname,
bool strict = false )

Load Midi from a Midi file from Unity resources. The Midi file must be present in Unity MidiDB ressource folder.

public MidiLoad MidiLoaded;
// .....
MidiLoaded = new MidiLoad();
MidiLoaded.MPTK_Load("Beattles - Michelle")
Debug.Log("Duration:" + MidiLoaded.MPTK_Duration);
Parameters
midinameMidi file name without path and extension
strictif true, check strict compliance with the Midi norm
Returns
true if loaded

◆ MPTK_ReadMidiEvents()

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

Read the list of midi events available in the Midi from a ticks position to an end position.

Parameters
fromTicksticks start, default 0
toTicksticks end, default end of Midi file
Returns

◆ MPTK_ConvertTickToTime()

double MidiPlayerTK.MidiLoad.MPTK_ConvertTickToTime ( long tick)
Deprecated
Convert the tick duration to a real time duration in millisecond regarding the current tempo. Please investigate the tempo map capabilities, see MPTK_TempoMap.
Parameters
tickduration in ticks
Returns
duration in milliseconds

◆ MPTK_ConvertTimeToTick()

long MidiPlayerTK.MidiLoad.MPTK_ConvertTimeToTick ( double time)
Deprecated
Convert a real time duration in millisecond to a number of tick regarding the current tempo. Please investigate the tempo map capabilities, see MPTK_TempoMap.
Parameters
timeduration in milliseconds
Returns
duration in ticks

◆ MPTK_SearchEventFromTime()

MPTKEvent MidiPlayerTK.MidiLoad.MPTK_SearchEventFromTime ( double time)

Search for a Midi event from a time position expressed in millisecond.
So time=19.3 and time=19.9 will find the same event.
.

Parameters
timeposition in milliseconds
Returns
MPTKEvent or null

◆ MPTK_SearchTickFromTime()

long MidiPlayerTK.MidiLoad.MPTK_SearchTickFromTime ( double time)

Search a tick position in the current midi from a position in millisecond.
Warning: this method loop on the whole midi to find the position.
Could be CPU costly but this method take care of the tempo change in the Midi.
Use MPTK_ConvertTimeToTick if there is no tempo change in the midi.

Parameters
timeposition in milliseconds
Returns
position in ticks

◆ MPTK_BPM2MPQN()

int MidiPlayerTK.MidiLoad.MPTK_BPM2MPQN ( int bpm)
static
Deprecated
MidiLoad.BeatPerMinute2QuarterPerMicroSecond is deprecated and will be removed. Please investigate MPTKEvent.BeatPerMinute2QuarterPerMicroSecond.

◆ MPTK_MPQN2BPM()

int MidiPlayerTK.MidiLoad.MPTK_MPQN2BPM ( int microsecondsPerQuaterNote)
static
Deprecated
MidiLoad.QuarterPerMicroSecond2BeatPerMinute is deprecated and will be removed. Please investigate MPTKEvent.QuarterPerMicroSecond2BeatPerMinute.

◆ NoteLength()

MPTKEvent.EnumLength MidiPlayerTK.MidiLoad.NoteLength ( MPTKEvent mptkEvent)

https://en.wikipedia.org/wiki/Note_value

Parameters
mptkEvent
Returns

◆ MPTK_DisplayMidiAttributes()

void MidiPlayerTK.MidiLoad.MPTK_DisplayMidiAttributes ( )

Display in console the attributes of the MIDI loaded - v2.9.0.

Parameters
tmEvents

◆ MPTK_ComputeDuration()

void MidiPlayerTK.MidiLoad.MPTK_ComputeDuration ( )

Calculate MPTK_Duration, MPTK_DurationMS, MPTK_TickLast from the MIDI events list MPTK_MidiEvents.

This is done automatically when loading a MIDI file but not when MIDI events are added by script. In this case you will have to call this method.

◆ MPTK_Load() [4/4]

bool MidiPlayerTK.MidiLoad.MPTK_Load ( MPTKWriter mfw2)

Load Midi from a MidiFileWriter2 object.

Parameters
mfw2MidiFileWriter2 object
Returns
true if loaded

◆ MPTK_SortEvents()

List< MPTKEvent > MidiPlayerTK.MidiLoad.MPTK_SortEvents ( List< MPTKEvent > midiEvents,
bool logPerf = false )
static

Sort MIDI event list based on tick value, but for the same tick value, priority for 'bank change' then 'preset change'.

Note
  • Before v2.14.1 Realloc of the list is done, the new sorted list is available at return.
  • v2.14.1 sort in place, no realloc but MIDI list in parameter will be sorted
  • Good performance for high disorder.
Parameters
midiEvents
logPerf
Returns
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("It's possible to change the MIDI events before playing. This demo loads the selected MIDI, adds some notes and plays the MIDI without reloading it. Result not guaranteed!", 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);
long quarterPosition = tickPositionToInsert / midiFilePlayer.MPTK_DeltaTicksPerQuarterNote;
long newQuarter = (long)HelperDemo.GUI_Slider("Tick position by quarter:", (long)quarterPosition, 0, (long)midiFilePlayer.MPTK_TickLast / midiFilePlayer.MPTK_DeltaTicksPerQuarterNote,
alignCaptionRight: false, enableButton: true, widthCaption: 170, widthSlider: 250, widthLabelValue: 50);
if (newQuarter != quarterPosition)
{
quarterPosition = newQuarter;
tickPositionToInsert = quarterPosition * midiFilePlayer.MPTK_DeltaTicksPerQuarterNote;
}
channelToInsert = (int)HelperDemo.GUI_Slider("Channel to insert:", channelToInsert, 0, 15,
alignCaptionRight: false, enableButton: true, widthCaption: 170, widthSlider: 250, widthLabelValue: 50);
HelperDemo.GUI_Horizontal(HelperDemo.Zone.BEGIN, null, GUILayout.Width(500));
clearNote = GUILayout.Toggle(clearNote, "Clear MIDI list before inserting");
GUILayout.Space(10);
randomNote = GUILayout.Toggle(randomNote, "Random Note");
GUILayout.Space(10);
randomDuration = GUILayout.Toggle(randomDuration, "Random Duration");
GUILayout.Space(10);
calculateTiming = GUILayout.Toggle(calculateTiming, "Timing Recalculation");
HelperDemo.GUI_Horizontal(HelperDemo.Zone.END);
HelperDemo.GUI_Horizontal(HelperDemo.Zone.BEGIN);
if (GUILayout.Button("Insert And Play", GUILayout.Width(120)))
{
#if MPTK_PRO
// Better to stop playing.
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}");
if (clearNote)
midiFilePlayer.MPTK_MidiEvents.Clear();
// Insert weird notes in this beautiful MIDI!
// ------------------------------------------
long tickToInsert = tickPositionToInsert;
for (int insertNote = 0; insertNote < countNoteToInsert; insertNote++)
{
int note;
if (randomNote)
note = UnityEngine.Random.Range(50, 73); // Random notes between 48 (C4) and 72 (C6)
else
note = 60 + insertNote % 12; // Hust a remap of notes!
int eightCount; // How many eight duration to generate
if (randomDuration)
eightCount = UnityEngine.Random.Range(0, 9); // max 8, so a whole note
else
eightCount = 2; // a quarter
int tickDuration = eightCount * midiFilePlayer.MPTK_DeltaTicksPerQuarterNote;
// Add a note
midiFilePlayer.MPTK_MidiEvents.Insert(0,
new MPTKEvent()
{
Channel = channelToInsert,
Command = MPTKCommand.NoteOn,
Value = note,
Length = tickDuration,
Duration = (long)(tickDuration * midiFilePlayer.MPTK_Pulse), // Transform ticks to millisecond
Tick = tickToInsert,
});
// Add a text
midiFilePlayer.MPTK_MidiEvents.Insert(0,
new MPTKEvent()
{
Command = MPTKCommand.MetaEvent,
Meta = MPTKMeta.TextEvent,
Info = $"Add a weird note {HelperNoteLabel.LabelFromMidi(note)}",
Tick = tickToInsert,
});
// Move to the next insert, add length of note added.
tickToInsert += tickDuration;
}
// New events has been inserted, MIDI events list must be sorted by tick value.
// ---------------------------------------------------------------------------
midiFilePlayer.MPTK_SortEvents();
if (calculateTiming)
{
// Timing recalculation is not useful for all use cases.
// Avoid if possible because this takes time and realloc data.
midiFilePlayer.midiLoaded.MPTK_CalculateTiming();
}
// Then play the event list modified (not guaranteed to be 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.LinkTo("https://mptkapi.paxstellar.com/d7/deb/class_midi_player_t_k_1_1_midi_file_player.html#a7c1b1b1efab0022731f69e5161952c59");
if (GUILayout.Button("View MIDI events", GUILayout.Width(120)))
{
midiFilePlayer.MPTK_MidiEvents.ForEach(midi => Debug.Log(midi));
}
HelperDemo.GUI_Horizontal(HelperDemo.Zone.END);
HelperDemo.GUI_Vertical(HelperDemo.Zone.END);
HelperDemo.GUI_Horizontal(HelperDemo.Zone.END);
}

Member Data Documentation

◆ MPTK_Pulse

double MidiPlayerTK.MidiLoad.MPTK_Pulse

Real-time duration in millisecond of a MIDI tick. This value is updated when a tempo change is found.
The pulse length is the minimum time in millisecond between two MIDI events.
.

Note
  • Depends on the current tempo, the MPTK_DeltaTicksPerQuarterNote and the Speed.
  • Formula: Pulse = (60000000 / MPTK_CurrentTempo) / MPTK_DeltaTicksPerQuarterNote / 1000 / Speed

◆ MPTK_InitialTempo

double MidiPlayerTK.MidiLoad.MPTK_InitialTempo

Initial tempo found in the MIDI. Available from MPTK_MidiLoaded attribut from MidiFilePLayer or MidiExternal.

if (midiPlayer.MPTK_MidiLoaded != null)
infoMidi += $"Initial Tempo: {midiPlayer.MPTK_MidiLoaded.MPTK_InitialTempo:F2}\n";
Note
  • Available only when a MIDI is loaded.

◆ MPTK_TickStart

long MidiPlayerTK.MidiLoad.MPTK_TickStart

Tick to start playing the MIDI.

// Full source code in MidiLoop.cs
void LoadAndPlay()
{
// Preload the MIDI file to be able to set MIDI attributes before playing
midiFilePlayer.MPTK_Load();
SetLoopingMode();
midiFilePlayer.MPTK_Play(alreadyLoaded: true);
}
private void SetLoopingMode()
{
// Set start / end position by bar
midiFilePlayer.MPTK_MidiLoaded.MPTK_TickStart = ConvertBarToTick(StartBar);
midiFilePlayer.MPTK_MidiLoaded.MPTK_TickEnd = ConvertBarToTick(EndBar);
midiFilePlayer.MPTK_ModeStopVoice = MidiFilePlayer.ModeStopPlay.StopWhenAllVoicesReleased;
midiFilePlayer.MPTK_MidiAutoRestart = true;
}
// Convert a bar number (musical score concept) to a tick position (MIDI concept).\n
long ConvertBarToTick(int bar)
{
// was MPTK_NumberQuarterBeat, replaced by MPTK_NumberBeatsMeasure
return (long)(bar * midiFilePlayer.MPTK_MidiLoaded.MPTK_NumberBeatsMeasure * midiFilePlayer.MPTK_MidiLoaded.MPTK_DeltaTicksPerQuarterNote);
}

◆ MPTK_TickEnd

long MidiPlayerTK.MidiLoad.MPTK_TickEnd

Tick to end playing the MIDI. All MIDI events with MIDI tick higher or equal are not played.

// Full source code in MidiLoop.cs
void LoadAndPlay()
{
// Preload the MIDI file to be able to set MIDI attributes before playing
midiFilePlayer.MPTK_Load();
SetLoopingMode();
midiFilePlayer.MPTK_Play(alreadyLoaded: true);
}
private void SetLoopingMode()
{
// Set start / end position by bar
midiFilePlayer.MPTK_MidiLoaded.MPTK_TickStart = ConvertBarToTick(StartBar);
midiFilePlayer.MPTK_MidiLoaded.MPTK_TickEnd = ConvertBarToTick(EndBar);
midiFilePlayer.MPTK_ModeStopVoice = MidiFilePlayer.ModeStopPlay.StopWhenAllVoicesReleased;
midiFilePlayer.MPTK_MidiAutoRestart = true;
}
// Convert a bar number (musical score concept) to a tick position (MIDI concept).\n
long ConvertBarToTick(int bar)
{
// was MPTK_NumberQuarterBeat, replaced by MPTK_NumberBeatsMeasure
return (long)(bar * midiFilePlayer.MPTK_MidiLoaded.MPTK_NumberBeatsMeasure * midiFilePlayer.MPTK_MidiLoaded.MPTK_DeltaTicksPerQuarterNote);
}

◆ MPTK_TickCurrent

long MidiPlayerTK.MidiLoad.MPTK_TickCurrent

Get the tick value of the last MIDI event played.
Set the tick value of the next MIDI event to played.
Unlike MPTK_TickPlayer, which is continuously updated, this property is only updated when a MIDI event is read from the sequencer.

A MIDI tick is an easy way to identify a position in a song, independent of time, which can vary with tempo change events.
The number of ticks per quarter note is constant throughout a MIDI, it's a property of the whole MIDI. see MPTK_DeltaTicksPerQuarterNote.
With a 4/4 time signature, the length of a bar is 4 * MPTK_DeltaTicksPerQuarterNote.
More info here https://paxstellar.fr/2020/09/11/midi-timing/ @notes

  • Works only when the MIDI sequencer is playing.
  • It's not possible to set the current tick when MIDI is not playing. Instead, use the OnEventStartPlayMidi event to change the start position.
  • See also MidiFilePlayer.MPTK_Position: set or get the position in milliseconds.

◆ MPTK_RawSeek

bool MidiPlayerTK.MidiLoad.MPTK_RawSeek

This parameter is used when changing the playback position in a MIDI.
By default (false), all events except note-on are played from the beginning of the MIDI to the new position, to put the synthesizer back in the right context (tempo, selected instruments, controller, ...).
If set to true, the current playback position is set, but the previous context is retained. This can have undesirable (or funny!) effects on some MIDI, but it also makes it possible to change position much more quickly.
It's a choice to be made according to your needs.
.

Note
  • Value returns to false (default) each time a MIDI is loaded. You can load the MIDI with MPTK_Load(), change this parameter and play the MIDI with #MPTK_Play(). ///

◆ MPTK_TickPlayer

long MidiPlayerTK.MidiLoad.MPTK_TickPlayer

Get the real-time tick value of the MIDI player.
Unlike MPTK_TickCurrent which is only updated when a MIDI event is read, this property is updated continuously while the MIDI thread is playing.

More info about tick here https://paxstellar.fr/2020/09/11/midi-timing/ @notes

  • Works only when MIDI is playing.
  • Can't be changed.
  • Used by the MIDI Editor (pro) to display the sequencer position in real time.
  • Available from MidiFilePlayer.MPTK_MidiLoaded
    void Update()
    {
    if (mfPlayer != null && mfPlayer.MPTK_MidiLoaded != null)
    TextMidiTime.text = $"Real-time MIDI sequencer position: {mfPlayer.MPTK_MidiLoaded.MPTK_TickPlayer}";
    }

◆ MPTK_EventLastNote

MPTKEvent MidiPlayerTK.MidiLoad.MPTK_EventLastNote

Last MIDI event note-on found in MIDI.
There are often other MIDI events after the last note-on: for example, the track-end event.
Use this attribute to know the tick position time when all sound will stop.
See also MPTK_PositionLastNote which returns the last MIDI tick.

Version
v2.12.1

◆ MPTK_TimeSigDenominator

int MidiPlayerTK.MidiLoad.MPTK_TimeSigDenominator

Updated from TimeSignature event when playing MIDI: The denominator specifies the number of quarter notes in a beat.

◆ MPTK_NumberBeatsMeasure

int MidiPlayerTK.MidiLoad.MPTK_NumberBeatsMeasure

Updated from TimeSignature event when playing MIDI: the numerator counts the number of beats in a measure.
For example a numerator of 4 means that each bar contains four beats.
.

Note

◆ MPTK_NumberQuarterBeat

int MidiPlayerTK.MidiLoad.MPTK_NumberQuarterBeat

Updated from TimeSignature event when playing MIDI: describe of what note value a beat is (ie, how many quarter notes there are in a beat).

Note
This value is updated at each time signature meta event played.
Calculated with 2^MPTK_TimeSigDenominatorn
  • 1 for a whole-note
  • 2 for a half-note
  • 4 for a quarter-note
  • 8 for an eighth-note, etc.

Equal 2 Power TimeSigDenominator.
https://paxstellar.fr/2020/09/11/midi-timing/

◆ MPTK_KeySigMajorMinor

int MidiPlayerTK.MidiLoad.MPTK_KeySigMajorMinor

Updated from KeySignature event when playing MIDI: specifies the scale of the MIDI file.

◆ MPTK_ExtendedText

bool MidiPlayerTK.MidiLoad.MPTK_ExtendedText

If the value is true, text read from Text META (e.g. lyrics) will be read with UTF8 encoding. The default is false.
The MIDI standard only allows ASCII characters for this META, but with this extension you will be able to read and display
characters like Korean, Chinese, Japanese and even French accented letters ;-)

Version
2.11.3

◆ KeepNoteOff

bool MidiPlayerTK.MidiLoad.KeepNoteOff
Deprecated
v2.9.0 rather use MPTK_KeepNoteOff

Property Documentation

◆ MPTK_CurrentTempo

double MidiPlayerTK.MidiLoad.MPTK_CurrentTempo
getset

Get or change the current tempo played by the internal MIDI sequencer. Available from MPTK_MidiLoaded attribut from MidiFilePLayer or MidiExternal.

if (midiPlayer.MPTK_MidiLoaded != null)
infoMidi += $"Current Tempo: {midiPlayer.MPTK_MidiLoaded.MPTK_CurrentTempo:F2}\n";
Note
  • Available only when a MIDI is loaded.
  • Warning: changing the current tempo when playing has no impact on the calculated duration of the MIDI. https://en.wikipedia.org/wiki/Tempo