MidiPlayerTK.MidiListPlayer

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

Inherits MonoBehaviour.

class inhiriting

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

Public Types

enum  enStatusPlayer { Starting , Playing , Ending , Stopped }
 

Public Member Functions

void MPTK_AddMidi (string name, float start=0, float end=0)
 
void MPTK_ChangeMidi (string name, int indexList)
 
MPTK_MidiPlayItem MPTK_GetAt (int index)
 
void MPTK_NewList ()
 
void MPTK_Next ()
 
void MPTK_Pause ()
 
void MPTK_Play ()
 
void MPTK_Previous ()
 
void MPTK_ReIndexMidi ()
 
void MPTK_RemoveMidi (string name)
 
void MPTK_RemoveMidiAt (int index)
 
void MPTK_RePlay ()
 
void MPTK_Stop ()
 
void MPTK_UnPause ()
 

Public Attributes

MidiListPlayerStatus MPTK_MidiFilePlayer_1
 
MidiListPlayerStatus MPTK_MidiFilePlayer_2
 
float MPTK_OverlayTimeMS
 
List< MPTK_MidiPlayItemMPTK_PlayList
 
EventEndMidiClass OnEventEndPlayMidi
 
EventStartMidiClass OnEventStartPlayMidi
 

Properties

TimeSpan MPTK_Duration [get]
 
bool MPTK_IsPaused [get]
 
bool MPTK_IsPlaying [get]
 
bool MPTK_MidiLoop [get, set]
 
int MPTK_PlayIndex [get, set]
 
bool MPTK_PlayOnStart [get, set]
 
double MPTK_Position [get, set]
 
long MPTK_TickCurrent [get, set]
 
long MPTK_TickLast [get]
 
float MPTK_Volume [get, set]
 

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)
{
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} "
);
}
Midi Player status for the two MIDI Players defined in the MidiListPlayer.
Definition: MidiListPlayer.cs:115

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_ChangeMidi()

void MidiPlayerTK.MidiListPlayer.MPTK_ChangeMidi ( string  name,
int  indexList 
)

Change a Midi in the list

Parameters
name
indexList

◆ 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);

◆ MPTK_NewList()

void MidiPlayerTK.MidiListPlayer.MPTK_NewList ( )

Create an empty list

◆ MPTK_Next()

void MidiPlayerTK.MidiListPlayer.MPTK_Next ( )

Play next Midi in list

◆ MPTK_Pause()

void MidiPlayerTK.MidiListPlayer.MPTK_Pause ( )

Pause the current playing

◆ MPTK_Play()

void MidiPlayerTK.MidiListPlayer.MPTK_Play ( )

Play the midi in list at MPTK_PlayIndex position

◆ MPTK_Previous()

void MidiPlayerTK.MidiListPlayer.MPTK_Previous ( )

Play previous Midi in list

◆ MPTK_ReIndexMidi()

void MidiPlayerTK.MidiListPlayer.MPTK_ReIndexMidi ( )

Recalculate the index of the midi from the list.

◆ MPTK_RemoveMidi()

void MidiPlayerTK.MidiListPlayer.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.

midiListPlayer.MPTK_RemoveMidi("Albinoni - Adagio");

◆ 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_RePlay()

void MidiPlayerTK.MidiListPlayer.MPTK_RePlay ( )

Restart playing the current midi file

◆ MPTK_Stop()

void MidiPlayerTK.MidiListPlayer.MPTK_Stop ( )

Stop playing

◆ MPTK_UnPause()

void MidiPlayerTK.MidiListPlayer.MPTK_UnPause ( )

Pause the current playing

Member Data Documentation

◆ MPTK_MidiFilePlayer_1

MidiListPlayerStatus MidiPlayerTK.MidiListPlayer.MPTK_MidiFilePlayer_1

First MidiFilePlayer to play the Midi

◆ MPTK_MidiFilePlayer_2

MidiListPlayerStatus MidiPlayerTK.MidiListPlayer.MPTK_MidiFilePlayer_2

Second MidiFilePlayer to play the Midi

◆ MPTK_OverlayTimeMS

float MidiPlayerTK.MidiListPlayer.MPTK_OverlayTimeMS

Duration of overlay between playing two midi in milliseconds

◆ MPTK_PlayList

List<MPTK_MidiPlayItem> MidiPlayerTK.MidiListPlayer.MPTK_PlayList

Play list

◆ OnEventEndPlayMidi

EventEndMidiClass MidiPlayerTK.MidiListPlayer.OnEventEndPlayMidi

Define unity event to trigger at the end playing of each Midi in the list

◆ OnEventStartPlayMidi

EventStartMidiClass MidiPlayerTK.MidiListPlayer.OnEventStartPlayMidi

Define unity event to trigger at the start playing of each Midi in the list

Property Documentation

◆ MPTK_Duration

TimeSpan MidiPlayerTK.MidiListPlayer.MPTK_Duration
get

Duration of the currrent midi playing. This duration can change during the playing when Change Tempo Event are processed.

◆ MPTK_IsPaused

bool MidiPlayerTK.MidiListPlayer.MPTK_IsPaused
get

Is Midi is paused ?

◆ MPTK_IsPlaying

bool MidiPlayerTK.MidiListPlayer.MPTK_IsPlaying
get

Is Midi is playing ?

◆ MPTK_MidiLoop

bool MidiPlayerTK.MidiListPlayer.MPTK_MidiLoop
getset

Should the playing be restarted at the beginning of the list when the playlist is finished?

◆ MPTK_PlayIndex

int MidiPlayerTK.MidiListPlayer.MPTK_PlayIndex
getset

Play a specific Midi in the list.

◆ MPTK_PlayOnStart

bool MidiPlayerTK.MidiListPlayer.MPTK_PlayOnStart
getset

Should the Midi much restart at first of the list when playing list is over?

◆ 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;
}

◆ MPTK_TickCurrent

long MidiPlayerTK.MidiListPlayer.MPTK_TickCurrent
getset

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/

◆ MPTK_TickLast

long MidiPlayerTK.MidiListPlayer.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.

◆ MPTK_Volume

float MidiPlayerTK.MidiListPlayer.MPTK_Volume
getset

Volume of midi playing. Must be >=0 and <= 1