Base class for loading a Midi file.
Internal used by MidiFilePlayer, MidiListPlayer, MidiFileWrite2, MidiFileLoader.
It is better to use the prefab and class MidiFileLoader if you want to only load a Midi file.
More...
Public Member Functions | |
double | MPTK_ConvertTickToTime (long tick) |
Convert the tick duration to a real time duration in millisecond regarding the current tempo. More... | |
long | MPTK_ConvertTimeToTick (double time) |
Convert a real time duration in millisecond to a number of tick regarding the current tempo. More... | |
bool | MPTK_Load (byte[] datamidi, bool strict=false) |
Load Midi from an array of bytes More... | |
bool | 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 More... | |
bool | MPTK_Load (MidiFileWriter2 mfw2) |
Load Midi from a MidiFileWriter2 object More... | |
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. More... | |
bool | MPTK_LoadFile (string filename, bool strict=false) |
Load Midi from a local file More... | |
List< MPTKEvent > | 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. More... | |
MPTKEvent | MPTK_SearchEventFromTime (double time) |
Search for a Midi event from a time position with millisecond precision. So time=12.3 and time=12.9 will find the same event. More... | |
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. More... | |
Public Attributes | |
int | 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. More... | |
TimeSpan | MPTK_Duration |
Duration (TimeSpan) of the midi. More... | |
float | MPTK_DurationMS |
Duration (milliseconds) of the midi. More... | |
double | MPTK_InitialTempo |
Initial tempo found in the Midi. More... | |
int | MPTK_KeySigMajorMinor |
From KeySignature event: Specifies the scale of the MIDI file. More... | |
int | MPTK_KeySigSharpsFlats |
From KeySignature event: 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 More... | |
MPTKEvent | MPTK_LastEventPlayed |
Last Midi event read from the list More... | |
float | MPTK_LoadTime |
Time to load the current midi file (millisecond) More... | |
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/ More... | |
int | 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/ More... | |
int | 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/ More... | |
int | MPTK_NumberQuarterBeat |
From TimeSignature event: number of quarter notes in a beat. Equal 2 Power TimeSigDenominator. https://paxstellar.fr/2020/09/11/midi-timing/ More... | |
double | MPTK_PositionFirstNote |
Position in millisecond for the first note found More... | |
long | MPTK_TickCurrent |
long | MPTK_TickFirstNote |
Tick position for the first note found More... | |
long | MPTK_TickLast |
Last tick position in Midi: Time of the last midi event in sequence expressed in number of "ticks". MPTK_TickLast / MPTK_DeltaTicksPerQuarterNote equal the duration time of a quarter-note regardless the defined tempo. More... | |
int | MPTK_TicksInMetronomeClick |
From TimeSignature event: 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/ More... | |
int | MPTK_TimeSigDenominator |
From TimeSignature event: The denominator specifies the number of quarter notes in a beat. 2 represents a quarter-note, 3 represents an eighth-note, etc. https://paxstellar.fr/2020/09/11/midi-timing/ More... | |
int | 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/ More... | |
int | MPTK_TrackCount |
Count of track read in the Midi file More... | |
Properties | |
double | MPTK_CurrentTempo [get] |
Current tempo played by the internal Midi sequencer. More... | |
Base class for loading a Midi file.
Internal used by MidiFilePlayer, MidiListPlayer, MidiFileWrite2, MidiFileLoader.
It is better to use the prefab and class MidiFileLoader if you want to only load a Midi file.
Class for loading a Midi file. No sequencer, no synthetizer, so music playing capabilities. Usefull to load all the Midi events from a Midi and process, transform, write them to what you want.
double MidiPlayerTK.MidiLoad.MPTK_ConvertTickToTime | ( | long | tick | ) |
Convert the tick duration to a real time duration in millisecond regarding the current tempo.
tick | duration in ticks |
long MidiPlayerTK.MidiLoad.MPTK_ConvertTimeToTick | ( | double | time | ) |
Convert a real time duration in millisecond to a number of tick regarding the current tempo.
time | duration in milliseconds |
bool MidiPlayerTK.MidiLoad.MPTK_Load | ( | byte[] | datamidi, |
bool | strict = false |
||
) |
Load Midi from an array of bytes
datamidi | byte arry midi |
strict | If true will error on non-paired note events, default:false |
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
index | |
strict | If true will error on non-paired note events, default:false |
bool MidiPlayerTK.MidiLoad.MPTK_Load | ( | MidiFileWriter2 | mfw2 | ) |
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.
midiname | Midi file name without path and extension |
strict | if true, check strict compliance with the Midi norm |
bool MidiPlayerTK.MidiLoad.MPTK_LoadFile | ( | string | filename, |
bool | strict = false |
||
) |
Load Midi from a local file
filename | Midi path and filename to load |
strict | if true struct respect of the midi norm is checked |
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.
fromTicks | ticks start, default 0 |
toTicks | ticks end, default end of Midi file |
MPTKEvent MidiPlayerTK.MidiLoad.MPTK_SearchEventFromTime | ( | double | time | ) |
Search for a Midi event from a time position with millisecond precision.
So time=12.3 and time=12.9 will find the same event.
time | position in milliseconds |
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.
time | position in milliseconds |
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.
TimeSpan MidiPlayerTK.MidiLoad.MPTK_Duration |
Duration (TimeSpan) of the midi.
float MidiPlayerTK.MidiLoad.MPTK_DurationMS |
Duration (milliseconds) of the midi.
double MidiPlayerTK.MidiLoad.MPTK_InitialTempo |
Initial tempo found in the Midi.
int MidiPlayerTK.MidiLoad.MPTK_KeySigMajorMinor |
From KeySignature event: Specifies the scale of the MIDI file.
0
the scale is major. 1
the scale is minor. https://www.recordingblogs.com/wiki/midi-key-signature-meta-messageint MidiPlayerTK.MidiLoad.MPTK_KeySigSharpsFlats |
From KeySignature event: 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
MPTKEvent MidiPlayerTK.MidiLoad.MPTK_LastEventPlayed |
Last Midi event read from the list
float MidiPlayerTK.MidiLoad.MPTK_LoadTime |
Time to load the current midi file (millisecond)
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/
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/
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/
int MidiPlayerTK.MidiLoad.MPTK_NumberQuarterBeat |
From TimeSignature event: number of quarter notes in a beat.
Equal 2 Power TimeSigDenominator.
https://paxstellar.fr/2020/09/11/midi-timing/
double MidiPlayerTK.MidiLoad.MPTK_PositionFirstNote |
Position in millisecond for the first note found
long MidiPlayerTK.MidiLoad.MPTK_TickCurrent |
Set or get the current tick position in the Midi when playing.
Midi tick is an easy way to identify a position in a song independently of the time which could vary with tempo change.
The count of ticks for a quarter is constant all along a Midi: see properties MPTK_DeltaTicksPerQuarterNote.
Example: with a time signature of 4/4 the ticks length of a bar is 4 * MPTK_DeltaTicksPerQuarterNote.
Warning: if you want to set the start position, set MPTK_TickCurrent inside the processing of the event OnEventStartPlayMidi
because MPTK_Play() reset the start position to 0.
Other possibility to change the position in the Midi is to use the property MPTK_Position: set or get the position in milliseconds
but tempo change event will impact also this time. More info here https://paxstellar.fr/2020/09/11/midi-timing/
long MidiPlayerTK.MidiLoad.MPTK_TickFirstNote |
Tick position for the first note found
long MidiPlayerTK.MidiLoad.MPTK_TickLast |
Last tick position in Midi: Time of the last midi event in sequence expressed in number of "ticks".
MPTK_TickLast / MPTK_DeltaTicksPerQuarterNote equal the duration time of a quarter-note regardless the defined tempo.
int MidiPlayerTK.MidiLoad.MPTK_TicksInMetronomeClick |
From TimeSignature event: 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 MidiPlayerTK.MidiLoad.MPTK_TimeSigDenominator |
From TimeSignature event: The denominator specifies the number of quarter notes in a beat.
2 represents a quarter-note,
3 represents an eighth-note, etc.
https://paxstellar.fr/2020/09/11/midi-timing/
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/
int MidiPlayerTK.MidiLoad.MPTK_TrackCount |
Count of track read in the Midi file
|
get |
Current tempo played by the internal Midi sequencer.