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

Play a list of pre-selected MIDI files from the MidiDB. This class must be used with the prefab MidiListPlayer.
. More...

Classes

class  MPTK_MidiPlayItem
 Define a MIDI file from DBMidi to be added in the list. More...
class  MidiListPlayerStatus
 Midi Player status for the two MIDI Players defined in the MidiListPlayer.
. More...

Public Types

enum  enStatusPlayer { Starting , Playing , Ending , Stopped }
 Status of the player. More...

Public Member Functions

void MPTK_NewList ()
 Create an empty list.
void MPTK_AddMidi (string name, float start=0, float end=0)
 Add a Midi name to the list. Use the exact name defined in Unity resources (folder MidiDB) without any path or extension. Tips: Add Midi files to your project with the Unity menu MPTK or add it directly in the ressource folder and open Midi File Setup to automatically integrate Midi in MPTK.
void MPTK_ChangeMidi (string name, int indexList)
 Change a Midi in the list.
void MPTK_RemoveMidi (string name)
 Remove a Midi name from the list. Use the exact name defined in Unity resources folder MidiDB without any path or extension.
void MPTK_RemoveMidiAt (int index)
 Remove a Midi at position from the list..
MPTK_MidiPlayItem MPTK_GetAt (int index)
 Get description of a play item at position.
void MPTK_ReIndexMidi ()
 Recalculate the index of the midi from the list.
void MPTK_Play ()
 Play the midi in list at MPTK_PlayIndex position.
void MPTK_Stop ()
 Stop playing.
void MPTK_RePlay ()
 Restart playing the current midi file.
void MPTK_Pause ()
 Pause the current playing.
void MPTK_UnPause ()
 Pause the current playing.
void MPTK_Next ()
 Play next Midi in list.
void MPTK_Previous ()
 Play previous Midi in list.

Public Attributes

List< MPTK_MidiPlayItemMPTK_PlayList
 Play list.
EventStartMidiClass OnEventStartPlayMidi
 Define unity event to trigger at the start playing of each Midi in the list.
EventEndMidiClass OnEventEndPlayMidi
 Define unity event to trigger at the end playing of each Midi in the list.
MidiListPlayerStatus MPTK_MidiFilePlayer_1
 First MidiFilePlayer to play the Midi.
MidiListPlayerStatus MPTK_MidiFilePlayer_2
 Second MidiFilePlayer to play the Midi.
float MPTK_OverlayTimeMS
 Duration of overlay between playing two midi in milliseconds.

Properties

float MPTK_Volume [get, set]
 Volume of midi playing. Must be >=0 and <= 1.
int MPTK_PlayIndex [get, set]
 Play a specific Midi in the list.
bool MPTK_PlayOnStart [get, set]
 Should the Midi much restart at first of the list when playing list is over?
bool MPTK_MidiLoop [get, set]
 Should the playing be restarted at the beginning of the list when the playlist is finished?
double MPTK_Position [get, set]
 Set or Get midi position of the currrent midi playing. Position is a time in millisecond. Be carefull when modifying position on fly from GUI, weird behavior can happen If the Midi contains tempo change, the position could not reflect the real time from the beginning. Use MPTK_TickCurrent to change the position in tick which is independent of the tempo and the speed. There is no effect if the Midi is not playing.
long MPTK_TickLast [get]
 Last tick position of the currrent midi playing: Value of the tick for 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.
long MPTK_TickCurrent [get, set]
 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/.
TimeSpan MPTK_Duration [get]
 Duration of the currrent midi playing. This duration can change during the playing when Change Tempo Event are processed.
bool MPTK_IsPaused [get]
 Is Midi is paused ?
bool MPTK_IsPlaying [get]
 Is Midi is playing ?

Detailed Description

Play a list of pre-selected MIDI files from the MidiDB. This class must be used with the prefab MidiListPlayer.
.

Version
Maestro Pro

See "Midi File Setup" in the Unity menu MPTK for adding MIDI in MidiDB.
Two Midi Players are defined in the MidiListPlayer. Only one is played at a given time.
They are switched at the end of a midi with an overlap time between.
See Midi Player Setup (Unity menu MPTK) for adding MIDI in MidiDB.
More information here https://paxstellar.fr/midi-list-player-v2/

private void Update()
{
if (IsDisplayFulllLog != null && IsDisplayFulllLog.isOn)
{
MidiListPlayer.MidiListPlayerStatus current;
current = midiListPlayer.MPTK_GetPlaying;
if (current != null) DisplayLog("Playing", current);
current = midiListPlayer.MPTK_GetStarting;
if (current != null) DisplayLog("Starting", current);
current = midiListPlayer.MPTK_GetEnding;
if (current != null) DisplayLog("Ending ", current);
}
}
private void DisplayLog(string from, MidiListPlayer.MidiListPlayerStatus current)
{
Debug.Log(
$"{from} - Name:{current.MPTK_MidiFilePlayer.name} " +
$"Status:{current.StatusPlayer} " +
$"EndAt:{current.EndAt} " +
$"PlayTime:{current.MPTK_MidiFilePlayer.MPTK_PlayTime} " +
$"MIDI:{current.MPTK_MidiFilePlayer.MPTK_MidiName} " +
$"PctVolume:{current.PctVolume:F2} " +
$"Active Voice:{current.MPTK_MidiFilePlayer.MPTK_StatVoiceCountActive} " +
$"Audio Read MS:{current.MPTK_MidiFilePlayer.StatAudioFilterReadMS:F2} " +
$"Dsp Load Pct:{current.MPTK_MidiFilePlayer.StatDspLoadPCT:F2} "
);
}

Member Enumeration Documentation

◆ enStatusPlayer

Status of the player.

Enumerator
Starting 

Midi Player is beginning to play during the ovelap period.

Playing 

Midi Player is playing at the 100% of the volume.

Ending 

Midi Player is stopping to play during the ovelap period.

Stopped 

Midi player do nothing.

Member Function Documentation

◆ MPTK_AddMidi()

void MidiPlayerTK.MidiListPlayer.MPTK_AddMidi ( string name,
float start = 0,
float end = 0 )

Add a Midi name to the list. Use the exact name defined in Unity resources (folder MidiDB) without any path or extension. Tips: Add Midi files to your project with the Unity menu MPTK or add it directly in the ressource folder and open Midi File Setup to automatically integrate Midi in MPTK.

midiListPlayer.MPTK_AddMidi("Albinoni - Adagio");
midiListPlayer.MPTK_AddMidi("Conan The Barbarian", 10000, 20000);
Parameters
namemidi filename as defined in resources
startstarting time of playing (ms). Default: start of the midi
endendding time of playing (ms). Default: end of midi
public void CreateList()
{
midiListPlayer.MPTK_Stop();
midiListPlayer.MPTK_NewList();
midiListPlayer.MPTK_OverlayTimeMS = 1000f;
midiListPlayer.MPTK_AddMidi("Baez Joan - Plaisir D'Amour", 10000, 20000);
midiListPlayer.MPTK_AddMidi("Bach - Fugue", 25000, 35000);
midiListPlayer.MPTK_PlayIndex = 0;
}
public void UpdateList()
{
midiListPlayer.MPTK_Stop();
midiListPlayer.MPTK_RemoveMidi("Baez Joan - Plaisir D'Amour");
midiListPlayer.MPTK_AddMidi("Louis Armstrong - What A Wonderful World", 25000, 40000);
midiListPlayer.MPTK_PlayIndex = 0;
}

◆ MPTK_RemoveMidiAt()

void MidiPlayerTK.MidiListPlayer.MPTK_RemoveMidiAt ( int index)

Remove a Midi at position from the list..

// Removes the second midi in list (start at 0)
midiListPlayer.MPTK_RemoveMidiAt(1);

◆ MPTK_GetAt()

MPTK_MidiPlayItem MidiPlayerTK.MidiListPlayer.MPTK_GetAt ( int index)

Get description of a play item at position.

// GEt the second midi in list (start at 0)
midiListPlayer.MPTK_GetAt(1);

Property Documentation

◆ MPTK_Position

double MidiPlayerTK.MidiListPlayer.MPTK_Position
getset

Set or Get midi position of the currrent midi playing. Position is a time in millisecond. Be carefull when modifying position on fly from GUI, weird behavior can happen If the Midi contains tempo change, the position could not reflect the real time from the beginning. Use MPTK_TickCurrent to change the position in tick which is independent of the tempo and the speed. There is no effect if the Midi is not playing.

// Be carefull when modifying position on fly from GUI, weird behavior can happen
// Below change is applied only above 2 decimals.
double currentPosition = Math.Round(midiFilePlayer.MPTK_Position / 1000d, 2);
double newPosition = Math.Round(GUILayout.HorizontalSlider((float)currentPosition, 0f, (float)midiFilePlayer.MPTK_RealDuration.TotalSeconds, GUILayout.Width(buttonWidth)), 2);
if (newPosition != currentPosition)
{
Debug.Log("New position " + currentPosition + " --> " + newPosition );
midiFilePlayer.MPTK_Position = newPosition * 1000d;
}