Plays 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...
Play and Stop MIDI | |
| enum | ModeStopPlay { StopNoWaiting , StopWhenAllVoicesReleased , StopWhenAllVoicesEnded } |
| Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true. See also MPTK_ModeStopVoice More... | |
| virtual string | MPTK_MidiName [get, set] |
| int | MPTK_MidiIndex [get, set] |
| bool | MPTK_PlayOnStart [get, set] |
| bool | MPTK_MidiAutoRestart [get, set] |
| bool | MPTK_IsPaused [get] |
| bool | MPTK_IsPlaying [get] |
| string | midiNameToPlay |
| Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true. See also MPTK_ModeStopVoice More... | |
| bool | MPTK_StartPlayAtFirstNote |
| bool | MPTK_StopPlayOnLastNote |
| ModeStopPlay | MPTK_ModeStopVoice |
| bool | MPTK_PauseOnFocusLoss |
| static string[] | ModeStopPlayLabel = { "Stop No Waiting", "Stop When All Voices Are Released", "Stop When All Voices Are Ended" } |
| Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true. See also MPTK_ModeStopVoice More... | |
| virtual void | MPTK_Play (bool alreadyLoaded=false) |
| void | MPTK_Stop () |
| void | MPTK_Stop (bool stopAllSound=true, float wait=-1f) |
| void | MPTK_RePlay () |
| void | MPTK_Pause (float timeToPauseMS=-1f) |
| void | MPTK_UnPause () |
| void | MPTK_Next () |
| void | MPTK_Previous () |
| bool | MPTK_SearchMidiToPlay (string searchPartOfName) |
| void | MPTK_PlayNextOrPrevious (int offset) |
| void | MPTK_SwitchMidiWithDelay (int index, string name, float volume, float delayToStopMillisecond, float delayToStartMillisecond) |
| virtual void | MPTK_Play (float delayRampUp, float startDelay=0) |
| void | MPTK_Play (byte[] data) |
| void | MPTK_Play (MPTKWriter mfw2, float delayRampUp=0f, float fromPosition=0, float toPosition=0, long fromTick=0, long toTick=0, bool timePosition=true) |
| virtual void | MPTK_Stop (float delayRampDown, float stopDelay=0) |
MIDI Channels | |
| MPTKChannels | MPTK_Channels [get] |
Position and Duration | |
| double | MPTK_Position [get, set] |
| TimeSpan | MPTK_Duration [get] |
| float | MPTK_DurationMS [get] |
| long | MPTK_TickLast [get] |
| long | MPTK_TickFirstNote [get] |
| long | MPTK_TickLastNote [get] |
| double | MPTK_PositionFirstNote [get] |
| double | MPTK_PositionLastNote [get] |
| int | MPTK_TrackCount [get] |
| long | MPTK_TickCurrent [get, set] |
| bool | MPTK_RawSeek [get, set] |
| MPTKEvent | MPTK_LastEventPlayed [get] |
| double | MPTK_Pulse [get] |
| double | MPTK_PulseLenght [get] |
| TimeSpan | MPTK_PlayTime [get] |
| double | MPTK_RealTime [get] |
MIDI Properties | |
| float | MPTK_Speed [get, set] |
| bool | MPTK_Loop [get, set] |
| double | MPTK_Tempo [get, set] |
| string | MPTK_SequenceTrackName [get] |
| string | MPTK_ProgramName [get] |
| string | MPTK_TrackInstrumentName [get] |
| string | MPTK_TextEvent [get] |
| string | MPTK_Copyright [get] |
| List< MPTKEvent > | MPTK_MidiEvents [get] |
| int | MPTK_Quantization [get, set] |
| int | MPTK_DeltaTicksPerQuarterNote [get] |
| void | MPTK_ResetTranspose () |
| MPTKEvent.EnumLength | MPTK_NoteLength (MPTKEvent note) |
MIDI Loading and Reading | |
| MidiLoad | MPTK_MidiLoaded [get] |
| bool | MPTK_KeepNoteOff [get, set] |
| bool | MPTK_KeepEndTrack [get, set] |
| bool | MPTK_ExtendedText [get, set] |
| bool | MPTK_LogLoadEvents |
| LoadingStatusMidiEnum | MPTK_StatusLastMidiLoaded |
| string | MPTK_WebRequestError |
| MidiLoad | MPTK_Load () |
| List< MPTKEvent > | MPTK_ReadMidiEvents (long fromTicks=0, long toTicks=long.MaxValue) |
| void | MPTK_SortEvents () |
| MidiLoad | MPTK_Load (string uri) |
MIDI Events | |
| EventNotesMidiClass | OnEventNotesMidi |
| EventStartMidiClass | OnEventStartPlayMidi |
| EventEndMidiClass | OnEventEndPlayMidi |
Inner Loop | |
Defines looping conditions inside the MIDI sequencer [Pro]. An instance is automatically created when the MidiFilePlayer prefab is loaded. | |
| MPTKInnerLoop | MPTK_InnerLoop |
Plays 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.
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:
Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true. See also MPTK_ModeStopVoice
| MidiLoad MidiPlayerTK.MidiFilePlayer.MPTK_Load | ( | ) |
Loads 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.
| MidiLoad MidiPlayerTK.MidiFilePlayer.MPTK_Load | ( | string | uri | ) |
Loads a MIDI file from a local desktop file. Example paths:
| uri | URI or path to the MIDI file. |
| void MidiPlayerTK.MidiFilePlayer.MPTK_Next | ( | ) |
Plays next MIDI from the list of midi defined in MPTK (see Unity menu Midi)
| MPTKEvent.EnumLength MidiPlayerTK.MidiFilePlayer.MPTK_NoteLength | ( | MPTKEvent | note | ) |
Return note length as https://en.wikipedia.org/wiki/Note_value
| note |
| void MidiPlayerTK.MidiFilePlayer.MPTK_Pause | ( | float | timeToPauseMS = -1f | ) |
Pause the current playing. Use MPTK_UnPause to continue playing.
| timeToPauseMS | time to pause in milliseconds. default or < 0 : indefinitely |
|
virtual |
Plays the midi file defined with MPTK_MidiName or MPTK_MidiIndex. In the most part of the case, just call midiFilePlayer.MPTK_Play() in your script. But sometimes, you want to apply some changes on the MIDI file before playing it. The script example below describes how to load a MIDI file, apply some changes and play it. Thank to the parameter 'alreadyLoaded'. When true, the MIDI has been already loaded with MPTK_Load()
| alreadyLoaded | true: the MIDI has already been loaded (see MPTK_Load() v2.9.0 |
Reimplemented in MidiPlayerTK.MidiExternalPlayer.
| void MidiPlayerTK.MidiFilePlayer.MPTK_Play | ( | byte[] | data | ) |
Plays a MIDI file from a byte array.
Check MPTK_StatusLastMidiLoaded to get the load status.
|
virtual |
Plays the MIDI file defined by MPTK_MidiName or MPTK_MidiIndex with ramp-up to the volume defined by MPTK_Volume.
The time to get a MIDI playing at full MPTK_Volume is delayRampUp + startDelay.
A delayed start can also be set.
| delayRampUp | Ramp-up delay, in milliseconds, to reach the default volume. |
| startDelay | Delayed start, in milliseconds. V2.89.1 |
| 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 |
||
| ) |
Plays a MIDI from a MidiFileWriter2 object.
| mfw2 | A MidiFileWriter2 object. |
| delayRampUp |
| void MidiPlayerTK.MidiFilePlayer.MPTK_PlayNextOrPrevious | ( | int | offset | ) |
Plays the next or previous MIDI from the MidiDB list.
| offset | Forward or backward offset in the list. 1 = next, -1 = previous. |
| void MidiPlayerTK.MidiFilePlayer.MPTK_Previous | ( | ) |
Plays previous MIDI from the list of midi defined in MPTK (see Unity menu Midi)
| List< MPTKEvent > MidiPlayerTK.MidiFilePlayer.MPTK_ReadMidiEvents | ( | long | fromTicks = 0, |
| long | toTicks = long.MaxValue |
||
| ) |
Read the list of midi events available in the MIDI from a ticks tick to an end tick.
| fromTicks | ticks start, default 0 |
| toTicks | ticks end, default end of MIDI file |
| void MidiPlayerTK.MidiFilePlayer.MPTK_RePlay | ( | ) |
Restart playing of the current midi file
| void MidiPlayerTK.MidiFilePlayer.MPTK_ResetTranspose | ( | ) |
Force all notes to return to their original values before transposing.
Useful when looping on a MIDI with a transpose value different than 0. When returning to 0 (no transpose) the note value can be reset to their original value.
| bool MidiPlayerTK.MidiFilePlayer.MPTK_SearchMidiToPlay | ( | string | searchPartOfName | ) |
Finds a MIDI in the Unity Resources folder MidiDB whose name contains searchPartOfName (case-sensitive).
Sets MPTK_MidiIndex and MPTK_MidiName if the MIDI is found.
| searchPartOfName | Part of the MIDI name to search for in the MIDI list (case-sensitive). |
| void MidiPlayerTK.MidiFilePlayer.MPTK_SortEvents | ( | ) |
MIDI list events must be sorted by ticks before playing. It's mandatory if the list is modified.
| void MidiPlayerTK.MidiFilePlayer.MPTK_Stop | ( | ) |
Stops MIDI playback and cancels all sounds. This operation is performed in background, so MIDI may really stop after this method returns.
| void MidiPlayerTK.MidiFilePlayer.MPTK_Stop | ( | bool | stopAllSound = true, |
| float | wait = -1f |
||
| ) |
Stops MIDI playback and cancels all sounds. This operation is performed in background, so MIDI may really stop after this method returns.
| stopAllSound | Set to true to stop all sounds (default), otherwise currently playing notes will continue until they finish. |
| wait | With Legacy mode and if greater than -1 (v2.16), waits until MIDI playback is fully stopped or the specified wait time (in milliseconds) is reached. Otherwise, returns immediately. |
|
virtual |
Stops playback after a delay. After the stop delay (0 by default), the volume decreases until playback stops.
The time to get a real MIDI stop is delayRampDown + stopDelay.
| delayRampDown | Fade-out time in milliseconds. |
| stopDelay | Delayed stop in milliseconds. V2.89.1 |
| void MidiPlayerTK.MidiFilePlayer.MPTK_SwitchMidiWithDelay | ( | int | index, |
| string | name, | ||
| float | volume, | ||
| float | delayToStopMillisecond, | ||
| float | delayToStartMillisecond | ||
| ) |
Switches playback between two MIDIs with ramp-up.
This method is useful for integration with Bolt: main MIDI parameters are defined in one call.
| index | Index of the MIDI to play. Used only if name is null or empty. |
| name | Name of the MIDI to play. Can be part of the MIDI name. If set, this parameter has priority over index . |
| volume | Volume of the MIDI. Use -1 to keep the default volume. |
| delayToStopMillisecond | Delay before stopping the currently playing MIDI (with volume decrease), or delay before playback if no MIDI is playing. |
| delayToStartMillisecond | Delay to reach full MIDI volume (ramp-up volume). |
| void MidiPlayerTK.MidiFilePlayer.MPTK_UnPause | ( | ) |
UnPause the current playing when MidiPlayer is paused with MPTK_Pause.
|
protected |
Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true. See also MPTK_ModeStopVoice
|
static |
Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true. See also MPTK_ModeStopVoice
| MPTKInnerLoop MidiPlayerTK.MidiFilePlayer.MPTK_InnerLoop |
| bool MidiPlayerTK.MidiFilePlayer.MPTK_LogLoadEvents |
If true display in console all midi events when a MIDI file is loaded.
| ModeStopPlay MidiPlayerTK.MidiFilePlayer.MPTK_ModeStopVoice |
Defined the behavior of the MIDI player when playback is stopped with MPTK_Stop or restarted when the last MIDI events is reached and MPTK_MidiAutoRestart is set to true.
Code example:
| bool MidiPlayerTK.MidiFilePlayer.MPTK_PauseOnFocusLoss |
Should the MIDI playing must be paused when the application lost the focus?
| bool MidiPlayerTK.MidiFilePlayer.MPTK_StartPlayAtFirstNote |
If the value is true, MIDI playing will begin at the first note found in the MIDI.
Obviously, all previous events are processed, but at the same tick as the first note-on.
Often, the first note is not set at the beginning of the MIDI file (which is 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.
| 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.
| bool MidiPlayerTK.MidiFilePlayer.MPTK_StopPlayOnLastNote |
By default, the end of a MIDI file is not the last note. It is the last MIDI event.
If this value is true, MIDI playback will stop at the last note found in the MIDI file
and the OnEventEndPlay will be triggered at the last note.
| string MidiPlayerTK.MidiFilePlayer.MPTK_WebRequestError |
Contains the error from the web request when loading MIDI from an URL
| EventEndMidiClass MidiPlayerTK.MidiFilePlayer.OnEventEndPlayMidi |
Specify the Unity event that is triggered when the end of the MIDI list of events is reached.
| 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.
| EventStartMidiClass MidiPlayerTK.MidiFilePlayer.OnEventStartPlayMidi |
Define the Unity event to be triggered at the start of Midi playback.
At this moment, the MIDI file is loaded, the MIDI synth is initialised, but no MIDI event has been read yet.
This is the right time to defined some specific behaviors.
|
get |
Description and list of MIDI Channels associated to the MIDI synth.
Each MIDI synth has 16 channels that carry all the relevant MIDI information.
They serve to distinguish between instruments and provide independent control over each one.
By transmitting MIDI messages on their respective channels, you can alter the instrument, volume, pitch, and other parameters.
Within the Maestro Midi Player Toolkit, MIDI channels are designated numerically from 0 to 15. Notably, channel 9 is set aside specifically for drum sounds.
|
get |
Gets 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.
|
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/
|
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.
|
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.
|
getset |
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 ;-)
|
get |
Is MIDI file playing is paused ?
|
get |
Is MIDI file is playing ?
|
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.
|
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 which 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.
Sets to false if there is no need (could greatly increases the MIDI list events).
Sets to true to keep 'note-off' events.
|
get |
Last MIDI event played by the MIDI sequencer
|
getset |
|
getset |
When the value is true, the current MIDI playing is restarted when it reaches the end of the MIDI file or #MPTK_MidiLoaded.MPTK_TickEnd.
|
get |
Gets a list of all the MPTK MIDI events that are available in the MIDI.
|
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.
| index | Index of the MIDI, start from 0 |
|
get |
Gets detailed information about MIDI playback. This readonly property is available only when a MIDI has been loaded.
|
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.
|
getset |
Whether the MIDI playback starts when the application starts?
|
get |
Real time in TimeSpan format from the beginning of play. It's an access to the MIDI timer used by the MIDI sequencer.
|
getset |
Gets or sets the current position in the MIDI in milliseconds.
When a new position is set, the corresponding tick in the MIDI event list is searched for by comparing it with the MPTKEvent.RealTime value, and the current MIDI playback is moved to this new tick position.
Here, more information about Midi Timing https://paxstellar.fr/2020/09/11/midi-timing/
|
get |
Real time tick in milliseconds 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 which it will start.
See also MPTK_TickFirstNote
|
get |
Real time tick in milliseconds 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
|
get |
Gets 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.
|
get |
Length in milliseconds of a MIDI tick. The pulse length is the minimum time in milliseconds 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.
|
get |
Gets or sets the current position in the MIDI in milliseconds.
When a new position is set, the corresponding tick in the MIDI event list is searched for by comparing it with the MPTKEvent.RealTime value, and the current MIDI playback is moved to this new tick position.
Here, more information about Midi Timing https://paxstellar.fr/2020/09/11/midi-timing/
|
getset |
Level of quantization :
|
getset |
This parameter controls how the playback position is adjusted within a MIDI file. By default (false), when the playback position is changed, all events except "note-on" are replayed from the start of the MIDI file up to the new position. This ensures the synthesizer is correctly updated with the appropriate context (tempo, selected instruments, controllers, etc.).
If set to true, the playback position is updated directly; consequently, the current context is preserved.
While this approach can lead to unintended (or amusing!) effects in some MIDI files, it allows for much faster position changes.
|
get |
Real time in milliseconds from the beginning of play. It's an access to the MIDI timer used by the MIDI sequencer.
|
get |
Gets 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.
|
getset |
Percentage of the default playback speed. Range 0.1 (10% of the current BPM) to 10 (1000%). Default is 1 for normal speed.
Speed also applied to the duration of the sample played at voice level (often multiple voices are played for one note).
|
getset |
Gets or sets the current tempo played by the internal MIDI sequencer (independent from MPTK_Speed).
Return QuarterPerMinuteValue similar to BPM (Beat Per Measure).
|
get |
Gets 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.
|
getset |
Gets the tick value of the last MIDI event played.
Sets the tick value of the next MIDI event to played.
MIDI tick is an easy way to identify a position 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/
|
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
|
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".
|
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.
|
get |
Count of track read in the MIDI file
|
get |
Gets 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.