Base class for loading a Midi file. It is not recommended to instanciate directly this class.
This class is used by MidiFilePlayer, MidiListPlayer, MidiFileWrite2, MidiFileLoader (see members MPTK_MidiLoaded of these classes).
It is better to use the prefab and class MidiFileLoader if you only want to load a Midi file.
More...
Base class for loading a Midi file. It is not recommended to instanciate directly this class.
This class is used by MidiFilePlayer, MidiListPlayer, MidiFileWrite2, MidiFileLoader (see members MPTK_MidiLoaded of these classes).
It is better to use the prefab and class MidiFileLoader if you only want to load a Midi file.
◆ MPTK_ConvertTickToTime()
double MidiPlayerTK.MidiLoad.MPTK_ConvertTickToTime |
( |
long |
tick | ) |
|
Convert the tick duration to a real time duration in millisecond regarding the current tempo.
- Parameters
-
- Returns
- duration in milliseconds
◆ MPTK_ConvertTimeToTick()
long MidiPlayerTK.MidiLoad.MPTK_ConvertTimeToTick |
( |
double |
time | ) |
|
Convert a real time duration in millisecond to a number of tick regarding the current tempo.
- Parameters
-
time | duration in milliseconds |
- Returns
- duration in ticks
◆ MPTK_Load() [1/4]
bool MidiPlayerTK.MidiLoad.MPTK_Load |
( |
byte[] |
datamidi, |
|
|
bool |
strict = false |
|
) |
| |
Load Midi from an array of bytes
- Parameters
-
datamidi | byte arry midi |
strict | If true will error on non-paired note events, default:false |
- Returns
- true if loaded
◆ MPTK_Load() [2/4]
bool MidiPlayerTK.MidiLoad.MPTK_Load |
( |
int |
index, |
|
|
bool |
strict = 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
Base class for loading a Midi file. It is not recommended to instanciate directly this class....
Definition: MidiLoad.cs:19
TimeSpan MPTK_Duration
Definition: MidiLoad.cs:72
bool MPTK_Load(int index, bool strict=false)
Definition: MidiLoad.cs:303
- Parameters
-
index | |
strict | If true will error on non-paired note events, default:false |
- Returns
- true if loaded
◆ MPTK_Load() [3/4]
◆ MPTK_Load() [4/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.
- Parameters
-
midiname | Midi file name without path and extension |
strict | if true, check strict compliance with the Midi norm |
- Returns
- true if loaded
◆ MPTK_LoadFile()
bool MidiPlayerTK.MidiLoad.MPTK_LoadFile |
( |
string |
filename, |
|
|
bool |
strict = false |
|
) |
| |
Load MIDI file from a local file (Moved to PRO since version 2.89.5)
- Parameters
-
filename | Midi path and filename to load (OS dependant) |
strict | if true the MIDI must strictely respect the midi norm |
- Returns
◆ 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
-
fromTicks | ticks start, default 0 |
toTicks | ticks end, default end of Midi file |
- Returns
◆ MPTK_SearchEventFromTime()
MPTKEvent MidiPlayerTK.MidiLoad.MPTK_SearchEventFromTime |
( |
double |
time | ) |
|
Search for a Midi event from a time position expressed in millisecond.
So time=12.3 and time=12.9 will find the same event.
- Parameters
-
time | position 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
-
time | position in milliseconds |
- Returns
- position in ticks
◆ MPTK_DeltaTicksPerQuarterNote
int MidiPlayerTK.MidiLoad.MPTK_DeltaTicksPerQuarterNote |
Read from MIDI Header: Delta Ticks Per Quarter Note. Represent 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 ticks. Also named Division.
◆ MPTK_Duration
TimeSpan MidiPlayerTK.MidiLoad.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.
◆ MPTK_DurationMS
float MidiPlayerTK.MidiLoad.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.
◆ MPTK_EnableChangeTempo
bool MidiPlayerTK.MidiLoad.MPTK_EnableChangeTempo |
Should accept change tempo from MIDI Events ?
◆ MPTK_InitialTempo
double MidiPlayerTK.MidiLoad.MPTK_InitialTempo |
Initial tempo found in the MIDI.
◆ MPTK_KeepEndTrack
bool MidiPlayerTK.MidiLoad.MPTK_KeepEndTrack |
When set to true, meta MIDI event End Track are keep. Default is false.
If set to true, the duration of the MIDI taken into account the End Track Event.
◆ MPTK_KeySigMajorMinor
int MidiPlayerTK.MidiLoad.MPTK_KeySigMajorMinor |
From KeySignature event: Specifies the scale of the MIDI file.
◆ MPTK_KeySigSharpsFlats
int MidiPlayerTK.MidiLoad.MPTK_KeySigSharpsFlats |
◆ MPTK_LastEventPlayed
MPTKEvent MidiPlayerTK.MidiLoad.MPTK_LastEventPlayed |
Current MIDI event read when the MIDI sequencer is playing the MIDI. See MPTK_TickCurrent.
◆ MPTK_LoadTime
float MidiPlayerTK.MidiLoad.MPTK_LoadTime |
Time takne expressed in millisecond for loading the MIDI file.
◆ MPTK_MicrosecondsPerQuarterNote
int MidiPlayerTK.MidiLoad.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/
◆ MPTK_No32ndNotesInQuarterNote
int MidiPlayerTK.MidiLoad.MPTK_No32ndNotesInQuarterNote |
From TimeSignature event: 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/
◆ MPTK_NumberBeatsMeasure
int MidiPlayerTK.MidiLoad.MPTK_NumberBeatsMeasure |
From TimeSignature event: 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.
https://paxstellar.fr/2020/09/11/midi-timing/
◆ MPTK_NumberQuarterBeat
int MidiPlayerTK.MidiLoad.MPTK_NumberQuarterBeat |
◆ MPTK_PositionFirstNote
double MidiPlayerTK.MidiLoad.MPTK_PositionFirstNote |
Real time position 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.MidiLoad.MPTK_PositionLastNote |
Real time position 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_TickCurrent
long MidiPlayerTK.MidiLoad.MPTK_TickCurrent |
◆ MPTK_TickFirstNote
long MidiPlayerTK.MidiLoad.MPTK_TickFirstNote |
Tick position 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 position where the will start to play a sound.
See also MPTK_PositionFirstNote
◆ MPTK_TickLast
long MidiPlayerTK.MidiLoad.MPTK_TickLast |
Tick position of the last MIDI event found.
◆ MPTK_TickLastNote
long MidiPlayerTK.MidiLoad.MPTK_TickLastNote |
Tick position 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 position time when all sound will be stop.
See also the MPTK_PositionLastNote which provides the last tich of the MIDI.
◆ MPTK_TicksInMetronomeClick
int MidiPlayerTK.MidiLoad.MPTK_TicksInMetronomeClick |
◆ MPTK_TimeSigDenominator
int MidiPlayerTK.MidiLoad.MPTK_TimeSigDenominator |
◆ MPTK_TimeSigNumerator
int MidiPlayerTK.MidiLoad.MPTK_TimeSigNumerator |
From TimeSignature event: 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/
◆ MPTK_TrackCount
int MidiPlayerTK.MidiLoad.MPTK_TrackCount |
Count of track in the MIDI file
◆ MPTK_CurrentTempo
double MidiPlayerTK.MidiLoad.MPTK_CurrentTempo |
|
getset |
Get or change the current tempo played by the internal MIDI sequencer.
Can be used only when the MIDI is playing.
Warning: changing the current tempo when playing has no impact on the calculated duration of the MIDI.