Description of a MIDI Event. The heart of MPTK! Essential to handling MIDI by script from all others classes as MidiStreamPlayer, MidiFilePlayer, MidiFileLoader, ...

Inherits ICloneable, and ICloneable.

Public Types

enum  EnumLength

Public Member Functions

 MPTKEvent (ulong data)
void MTPK_ClearSynthParameter ()
float MTPK_GetSynthParameterDefaultValue (fluid_gen_type genType)
bool MTPK_ModifySynthParameter (fluid_gen_type genType, float value, MPTKModeGeneratorChange mode)
ulong ToData ()
override string ToString ()

Static Public Member Functions

static string MTPK_GetSynthParameterLabel (fluid_gen_type genType)
static List< MPTKListItemMTPK_GetSynthParameterListGenerator ()

Public Attributes

int Channel
MPTKCommand Command
MPTKController Controller
long Delay
long Duration
GenModifier[] GensModifier
int IdSession
int Index
string Info
int Length
MPTKMeta Meta
float RealTime
uint Source
object Tag
long Tick
long TickTime
long Track
int Value
int Velocity
List< fluid_voice > Voices


bool IsOver [get]
long MPTK_DeltaTimeMillis [get]
long MPTK_DeltaTimeTick [get]

Detailed Description

Description of a MIDI Event. The heart of MPTK! Essential to handling MIDI by script from all others classes as MidiStreamPlayer, MidiFilePlayer, MidiFileLoader, ...

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:

Member Enumeration Documentation

◆ EnumLength

Constructor & Destructor Documentation

◆ MPTKEvent()

MidiPlayerTK.MPTKEvent.MPTKEvent ( ulong  data)

Create a MPTK Midi event from a midi input message


Member Function Documentation

◆ MTPK_ClearSynthParameter()

void MidiPlayerTK.MPTKEvent.MTPK_ClearSynthParameter ( )

[MPTK PRO] Reset synth parameter to default soundfont value.

◆ MTPK_GetSynthParameterDefaultValue()

float MidiPlayerTK.MPTKEvent.MTPK_GetSynthParameterDefaultValue ( fluid_gen_type  genType)

[MPTK PRO] 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).

genTypesee MTPK_ModifySynthParameter
Return the normalized value of the parameter

◆ MTPK_GetSynthParameterLabel()

static string MidiPlayerTK.MPTKEvent.MTPK_GetSynthParameterLabel ( fluid_gen_type  genType)

[MPTK PRO] Get the label for the generator.

genTypesee MTPK_ModifySynthParameter
Return the label of the generator

◆ MTPK_GetSynthParameterListGenerator()

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

[MPTK PRO] Get the list of modifiable generators.
It's a list of MPTKListItem where the properties are:

genTypesee MTPK_ModifySynthParameter
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 

[MPTK 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);
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.
See here real value for each parameters.
  • 0 set the minimum value for the generator. For example, with an envelope parameter, 0 will set -12000 (min for this type of parameters.
  • 1 set the maximum value for the generator. For example, with an envelope parameter, 1 will set 12000 (max for this type of parameters.
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.
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)


◆ ToString()

override string MidiPlayerTK.MPTKEvent.ToString ( )

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


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

[MPTK PRO] 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

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

◆ MPTK_DeltaTimeMillis

long MidiPlayerTK.MPTKEvent.MPTK_DeltaTimeMillis

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

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, ....