Midi Player Tool Kit for Unity  Version 2.88.1
Add Midi Music to your Unity App, Build Rhytm Game, Create Music Generator ... see how here.
MidiPlayerTK.MPTKEvent

Midi Event class for MPTK. This class is more simple to use that the standard Midi structure.
The main property is Command, the content and role of other properties (as Value) depend on the value of Command. Look at the Value property.
With this class, you can: play and stop a note, change instrument (preset, patch, ...), change some control as modulation (Pro) ...
Use this class in relation with these classes: More...

Inherits ICloneable, and ICloneable.

Public Types

enum class  EnumLength
 Note length as https://en.wikipedia.org/wiki/Note_value More...
 

Public Member Functions

 MPTKEvent (ulong data)
 Create a MPTK Midi event from a midi input message More...
 
void MTPK_ClearSynthParameter ()
 [Pro] V2.88.2 Reset synth parameter to default soundfont value. More...
 
float MTPK_GetSynthParameterDefaultValue (fluid_gen_type genType)
 [Pro] V2.88.2 Get the default soundfont value for the generator.
Each generator has a specific range of value, see generators list here.
Also the value returned by this method is normalized (value between 0 and 1). More...
 
bool MTPK_ModifySynthParameter (fluid_gen_type genType, float value, MPTKModeGeneratorChange mode)
 [Pro] Apply modification on default SoundFont generator value. Can be applied independently for each notes,
can be applied before the note is played and in real time when the note is playing.
Each generator has a specific range of value, see generators list here.
Also the value used by this method is normalized (value between 0 and 1). See here for more details.
More...
 
ulong ToData ()
 Build a packet midi message from a MPTKEvent. Example: 0x00403C90 for a noton (90h, 3Ch note, 40h volume) More...
 
override string ToString ()
 Build a string description of the Midi event. V2.83 removes
on each returns string More...
 

Static Public Member Functions

static string MTPK_GetSynthParameterLabel (fluid_gen_type genType)
 [Pro] V2.88.2 Get the label for the generator. More...
 
static List< MPTKListItemMTPK_GetSynthParameterListGenerator ()
 [Pro] V2.88.2 Get the list of modifiable generators.
It's a list of MPTKListItem where the properties are:
More...
 

Public Attributes

int Channel
 Midi channel fom 0 to 15 (9 for drum) More...
 
MPTKCommand Command
 Midi Command code. Defined the type of message. See MPTKCommand (Note On, Control Change, Patch Change...) More...
 
MPTKController Controller
 Controller code. When the Command is ControlChange, contains the code fo the controller to change (Modulation, Pan, Bank Select ...).
Value properties will contains the value of the controller. See MPTKController. More...
 
long Delay
 Short delay before playing the note in millisecond. New with V2.82, works only in Core mode.
Apply only on NoteOn event. More...
 
long Duration
 Contains a value in relation with the Command. More...
 
GenModifier[] GensModifier
 List of generators modifier associated to the voices being played. Null if any modifier defined. More...
 
int IdSession
 Associate an Id with this event.
When reading a Midi file with MidiFilePlayer: this Id is unique for all Midi events played for this Midi.
Consequently, when switching Midi, MPTK_ClearAllSound is able to clear (note-off) only the voices associated with this Midi file.
Switching between Midi playing is very quick.
Could also be used for other prefab as MidiStreamPlayer for your specific need, but don't change this properties with MidiFilePlayer. More...
 
int Index
 Event Index in the midi list (defined only when Midi events are read from a Midi stream) More...
 
string Info
 Information hold by textual meta event when Command = MetaEvent More...
 
int Length
 Duration of the note in Midi Tick. MidiFilePlayer.MPTK_NoteLength can be used to convert this duration.
Not used for MidiStreamPlayer, length is set only when reading a Midi file. https://en.wikipedia.org/wiki/Note_value More...
 
MPTKMeta Meta
 MetaEvent Code. When the Command is MetaEvent, contains the code of the meta event (Lyric, TimeSignature, ...).
Others properties will contains the value of the meta. See MPTKMeta (TextEvent, Lyric, TimeSignature, ...).
More...
 
float RealTime
 V2.88 Real time in milliseconds of this event from the start of the midi depending the tempo change. More...
 
uint Source
 Origin of the message. Midi ID if from Midi Input else zero. V2.83: rename source to Source et set public. More...
 
object Tag
 V2.87 Tag information for application purpose More...
 
long Tick
 Time in Midi Tick (part of a Beat) of the Event since the start of playing the midi file. This time is independent of the Tempo or Speed. Not used for MidiStreamPlayer. More...
 
long TickTime
 V2.86 Time in System.DateTime when the Event is created or read from the Midi file.
Not to be confused with Tick properties which is a position inside a Midi file. Sure, the name of this properties was a bad idea, could be renamed in a future version ;-) Can be read from a system thread. More...
 
long Track
 Track index of the event in the midi. Track 0 is the first track 'MTrk' read from the midi file. More...
 
int Value
 Contains a value in relation with the Command. More...
 
int Velocity
 Velocity between 0 and 127. Used only if Command equal NoteOn. More...
 
List< fluid_voice > Voices
 List of voices associated to this Event for playing a NoteOn event. More...
 

Properties

bool IsOver [get]
 Check if playing of this midi event is over (all voices are OFF) More...
 
long MPTK_DeltaTimeMillis [get]
 V2.86 Delta time in milliseconds since the creation of this event. Mainly useful to evaluate MPTK latency.
Look for MidiSynth::StatSynthLatency, MidiSynth::StatSynthLatencyLAST, .... More...
 
long MPTK_DeltaTimeTick [get]
 V2.86 Delta time in system ticks (calculated with DateTime.UtcNow.Ticks) since the creation of this event.
Mainly useful to evaluate MPTK latency. One system ticks equal 100 nano second.
look for MidiSynth::StatSynthLatency, MidiSynth::StatSynthLatencyLAST, .... More...
 

Detailed Description

Midi Event class for MPTK. This class is more simple to use that the standard Midi structure.
The main property is Command, the content and role of other properties (as Value) depend on the value of Command. Look at the Value property.
With this class, you can: play and stop a note, change instrument (preset, patch, ...), change some control as modulation (Pro) ...
Use this class in relation with these classes:

  • MidiStreamPlayer generate Midi Music from your own algorithm.
  • MidiFileLoader to read Midi events from a Midi file.
  • MidiFilePlayer process Midi events, thank to the class event OnEventNotesMidi when Midi events are played from the internal Midi sequencer.
    See here https://paxstellar.fr/class-mptkevent
    !
    ! // Change instrument to Marimba for channel 0
    ! NotePlaying = new MPTKEvent() {
    ! Command = MPTKCommand.NoteOn,
    ! Value = 12, // generally Marimba but depend on the SoundFont selected
    ! Channel = 0 }; // Instrument are defined by channel. So at any time, only 16 différents instruments can be used simultaneously.
    ! midiStreamPlayer.MPTK_PlayEvent(NotePlaying);
    !
    ! // Play a C5 during one second with the Marimba instrument
    ! NotePlaying = new MPTKEvent() {
    ! Command = MPTKCommand.NoteOn,
    ! Value = 60, // play a C5 note
    ! Channel = 0,
    ! Duration = 1000, // one second
    ! Velocity = 100 };
    ! midiStreamPlayer.MPTK_PlayEvent(NotePlaying);
    !
    long Duration
    Contains a value in relation with the Command.
    Definition: MPTKEvent.cs:359
    MPTKCommand Command
    Midi Command code. Defined the type of message. See MPTKCommand (Note On, Control Change,...
    Definition: MPTKEvent.cs:266
    int Velocity
    Velocity between 0 and 127. Used only if Command equal NoteOn.
    Definition: MPTKEvent.cs:331
    int Value
    Contains a value in relation with the Command.
    Definition: MPTKEvent.cs:321
    int Channel
    Midi channel fom 0 to 15 (9 for drum)
    Definition: MPTKEvent.cs:326
    MPTKCommand
    MIDI command codes. Defined the action to be done with the message: note on/off, change instrument,...
    Definition: MPTKEvent.cs:15

Member Enumeration Documentation

◆ EnumLength

Constructor & Destructor Documentation

◆ MPTKEvent()

MidiPlayerTK.MPTKEvent.MPTKEvent ( ulong  data)

Create a MPTK Midi event from a midi input message

Parameters
data

Member Function Documentation

◆ MTPK_ClearSynthParameter()

void MidiPlayerTK.MPTKEvent.MTPK_ClearSynthParameter ( )

[Pro] V2.88.2 Reset synth parameter to default soundfont value.

◆ MTPK_GetSynthParameterDefaultValue()

float MidiPlayerTK.MPTKEvent.MTPK_GetSynthParameterDefaultValue ( fluid_gen_type  genType)

[Pro] V2.88.2 Get the default soundfont value for the generator.
Each generator has a specific range of value, see generators list here.
Also the value returned by this method is normalized (value between 0 and 1).

Parameters
genTypesee MTPK_ModifySynthParameter
Returns
Return the normalized value of the parameter

◆ MTPK_GetSynthParameterLabel()

static string MidiPlayerTK.MPTKEvent.MTPK_GetSynthParameterLabel ( fluid_gen_type  genType)
static

[Pro] V2.88.2 Get the label for the generator.

Parameters
genTypesee MTPK_ModifySynthParameter
Returns
Return the label of the generator

◆ MTPK_GetSynthParameterListGenerator()

static List<MPTKListItem> MidiPlayerTK.MPTKEvent.MTPK_GetSynthParameterListGenerator ( )
static

[Pro] V2.88.2 Get the list of modifiable generators.
It's a list of MPTKListItem where the properties are:

Parameters
genTypesee MTPK_ModifySynthParameter
Returns
Return a list of modifiable generator (don't modify this list!)

◆ MTPK_ModifySynthParameter()

bool MidiPlayerTK.MPTKEvent.MTPK_ModifySynthParameter ( fluid_gen_type  genType,
float  value,
MPTKModeGeneratorChange  mode 
)

[Pro] Apply modification on default SoundFont generator value. Can be applied independently for each notes,
can be applied before the note is played and in real time when the note is playing.
Each generator has a specific range of value, see generators list here.
Also the value used by this method is normalized (value between 0 and 1). See here for more details.

// Create a midi event for a C5 note (60) with default value: infinite duration, channel = 0, and velocity = 127 (max)
mptkEvent = new MPTKEvent() { Value = 60 };
// Fine tuning (pitch)
mptkEvent.MTPK_ModifySynthParameter(fluid_gen_type.GEN_FINETUNE, 0.52f, MPTKModeGeneratorChange.Override);
// Change low pass filter frequency
mptkEvent.MTPK_ModifySynthParameter(fluid_gen_type.GEN_FILTERFC, 0.6f, MPTKModeGeneratorChange.Override);
midiStream.MPTK_PlayDirectEvent(mptkEvent);
!
Parameters
genTypeType of generator to modify. Not all generators are authorized to real time modification.
  • GEN_MODLFOTOPITCH Modulation LFO to pitch
  • GEN_VIBLFOTOPITCH Vibrato LFO to pitch
  • GEN_MODENVTOPITCH Modulation envelope to pitch
  • GEN_FILTERFC Filter cutoff
  • GEN_FILTERQ Filter Q
  • GEN_MODLFOTOFILTERFC Modulation LFO to filter cutoff
  • GEN_MODENVTOFILTERFC Modulation envelope to filter cutoff
  • GEN_MODLFOTOVOL Modulation LFO to volume
  • GEN_CHORUSSEND Chorus send amount
  • GEN_REVERBSEND Reverb send amount
  • GEN_PAN Stereo panning
  • GEN_MODLFODELAY Modulation LFO delay
  • GEN_MODLFOFREQ Modulation LFO frequency
  • GEN_VIBLFODELAY Vibrato LFO delay
  • GEN_VIBLFOFREQ Vibrato LFO frequency
  • GEN_MODENVDELAY Modulation envelope delay
  • GEN_MODENVATTACK Modulation envelope attack
  • GEN_MODENVHOLD Modulation envelope hold
  • GEN_MODENVDECAY Modulation envelope decay
  • GEN_MODENVSUSTAIN Modulation envelope sustain
  • GEN_MODENVRELEASE Modulation envelope release
  • GEN_VOLENVDELAY Volume envelope delay
  • GEN_VOLENVATTACK Volume envelope attack
  • GEN_VOLENVHOLD Volume envelope hold
  • GEN_VOLENVDECAY Volume envelope decay
  • GEN_VOLENVSUSTAIN Volume envelope sustain
  • GEN_VOLENVRELEASE Volume envelope release
  • GEN_ATTENUATION Volume attenuation
  • GEN_COARSETUNE Coarse tuning
  • GEN_FINETUNE Fine tuning
valueNormalized value for the generator between 0 and 1.
  • 0 set the minimum value for the generator
  • 1 set the maximum value for the generator
modeDefine how to apply the value
  • Override: the SoundFont value is overridden.
  • Reinforce: the value is added to the default value.
  • Restaure: the default SoundFont value is used.
Returns
true if change has been done

◆ ToData()

ulong MidiPlayerTK.MPTKEvent.ToData ( )

Build a packet midi message from a MPTKEvent. Example: 0x00403C90 for a noton (90h, 3Ch note, 40h volume)

Returns

◆ ToString()

override string MidiPlayerTK.MPTKEvent.ToString ( )

Build a string description of the Midi event. V2.83 removes
on each returns string

Returns

Member Data Documentation

◆ Channel

int MidiPlayerTK.MPTKEvent.Channel

Midi channel fom 0 to 15 (9 for drum)

◆ Command

MPTKCommand MidiPlayerTK.MPTKEvent.Command

Midi Command code. Defined the type of message. See MPTKCommand (Note On, Control Change, Patch Change...)

◆ Controller

MPTKController MidiPlayerTK.MPTKEvent.Controller

Controller code. When the Command is ControlChange, contains the code fo the controller to change (Modulation, Pan, Bank Select ...).
Value properties will contains the value of the controller. See MPTKController.

◆ Delay

long MidiPlayerTK.MPTKEvent.Delay

Short delay before playing the note in millisecond. New with V2.82, works only in Core mode.
Apply only on NoteOn event.

◆ Duration

long MidiPlayerTK.MPTKEvent.Duration

Contains a value in relation with the Command.

  • Command = NoteOn
    • Duration contains duration of the note in millisecond. Set -1 to play indefinitely.
  • Command = MetaEvent
    • Meta = SetTempo
      • Duration contains new tempo (quarter per minute).
    • Meta = TimeSignature
      • Duration contains the Denominator (Beat unit: 1 means 2, 2 means 4 (crochet), 3 means 8 (quaver), 4 means 16, ...).
    • Meta = KeySignature
      • Duration contains the MajorMinor flag.

◆ GensModifier

GenModifier [] MidiPlayerTK.MPTKEvent.GensModifier

List of generators modifier associated to the voices being played. Null if any modifier defined.

◆ IdSession

int MidiPlayerTK.MPTKEvent.IdSession

Associate an Id with this event.
When reading a Midi file with MidiFilePlayer: this Id is unique for all Midi events played for this Midi.
Consequently, when switching Midi, MPTK_ClearAllSound is able to clear (note-off) only the voices associated with this Midi file.
Switching between Midi playing is very quick.
Could also be used for other prefab as MidiStreamPlayer for your specific need, but don't change this properties with MidiFilePlayer.

◆ Index

int MidiPlayerTK.MPTKEvent.Index

Event Index in the midi list (defined only when Midi events are read from a Midi stream)

◆ Info

string MidiPlayerTK.MPTKEvent.Info

Information hold by textual meta event when Command = MetaEvent

◆ Length

int MidiPlayerTK.MPTKEvent.Length

Duration of the note in Midi Tick. MidiFilePlayer.MPTK_NoteLength can be used to convert this duration.
Not used for MidiStreamPlayer, length is set only when reading a Midi file. https://en.wikipedia.org/wiki/Note_value

◆ Meta

MPTKMeta MidiPlayerTK.MPTKEvent.Meta

MetaEvent Code. When the Command is MetaEvent, contains the code of the meta event (Lyric, TimeSignature, ...).
Others properties will contains the value of the meta. See MPTKMeta (TextEvent, Lyric, TimeSignature, ...).

◆ RealTime

float MidiPlayerTK.MPTKEvent.RealTime

V2.88 Real time in milliseconds of this event from the start of the midi depending the tempo change.

◆ Source

uint MidiPlayerTK.MPTKEvent.Source

Origin of the message. Midi ID if from Midi Input else zero. V2.83: rename source to Source et set public.

◆ Tag

object MidiPlayerTK.MPTKEvent.Tag

V2.87 Tag information for application purpose

◆ Tick

long MidiPlayerTK.MPTKEvent.Tick

Time in Midi Tick (part of a Beat) of the Event since the start of playing the midi file. This time is independent of the Tempo or Speed. Not used for MidiStreamPlayer.

◆ TickTime

long MidiPlayerTK.MPTKEvent.TickTime

V2.86 Time in System.DateTime when the Event is created or read from the Midi file.
Not to be confused with Tick properties which is a position inside a Midi file. Sure, the name of this properties was a bad idea, could be renamed in a future version ;-) Can be read from a system thread.

◆ Track

long MidiPlayerTK.MPTKEvent.Track

Track index of the event in the midi. Track 0 is the first track 'MTrk' read from the midi file.

◆ Value

int MidiPlayerTK.MPTKEvent.Value

Contains a value in relation with the Command.

  • Command = NoteOn
    • Value contains midi note. 60=C5, 61=C5#, ..., 72=C6, ... . Look at this class for conversion table: HelperNoteLabel
  • Command = ControlChange
    • Value contains controller value, see MPTKController
  • Command = PatchChange
    • Value contains patch/preset/instrument value. See the current SoundFont to find value associated to each instrument.
  • Command = MetaEvent
    • Meta = SetTempo
      • Value contains new Microseconds Per Quarter Note
    • Meta = TimeSignature
      • Value contains the numerator (number of beats in a bar).
    • Meta = KeySignature
      • Value contains contains the SharpsFlats (number of sharp)

◆ Velocity

int MidiPlayerTK.MPTKEvent.Velocity

Velocity between 0 and 127. Used only if Command equal NoteOn.

◆ Voices

List<fluid_voice> MidiPlayerTK.MPTKEvent.Voices

List of voices associated to this Event for playing a NoteOn event.

Property Documentation

◆ IsOver

bool MidiPlayerTK.MPTKEvent.IsOver
get

Check if playing of this midi event is over (all voices are OFF)

◆ MPTK_DeltaTimeMillis

long MidiPlayerTK.MPTKEvent.MPTK_DeltaTimeMillis
get

V2.86 Delta time in milliseconds since the creation of this event. Mainly useful to evaluate MPTK latency.
Look for MidiSynth::StatSynthLatency, MidiSynth::StatSynthLatencyLAST, ....

◆ MPTK_DeltaTimeTick

long MidiPlayerTK.MPTKEvent.MPTK_DeltaTimeTick
get

V2.86 Delta time in system ticks (calculated with DateTime.UtcNow.Ticks) since the creation of this event.
Mainly useful to evaluate MPTK latency. One system ticks equal 100 nano second.
look for MidiSynth::StatSynthLatency, MidiSynth::StatSynthLatencyLAST, ....