MidiPlayerTK.MPTKEvent

Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all others classes as MidiStreamPlayer, MidiFilePlayer, MidiFileLoader, MidiFileWriter2 ...
More...

Inherits ICloneable, and ICloneable.

Public Types

enum  EnumLength
 

Public Member Functions

 MPTKEvent (ulong data)
 
void ClearSynthParameter ()
 
string ConvertToString (bool brief)
 
float GetSynthParameterCurrentValue (fluid_gen_type genType)
 
float GetSynthParameterDefaultValue (fluid_gen_type genType)
 
bool ModifySynthParameter (fluid_gen_type genType, float value, MPTKModeGeneratorChange mode)
 
void StopEvent ()
 
ulong ToData ()
 
override string ToString ()
 Extract value 2 from a double int build with BuildIntFromBytes More...
 

Static Public Member Functions

static int BeatPerMinute2QuarterPerMicroSecond (double bpm)
 
static int BuildIntFromBytes (byte b1, byte b2, byte b3, byte b4)
 Store four bytes into one integer. More...
 
static byte ExtractFromInt (uint v, int n)
 Extract byte position 'n' from an integer More...
 
static string GetSynthParameterLabel (fluid_gen_type genType)
 
static List< MPTKListItemGetSynthParameterListGenerator ()
 
static double QuarterPerMicroSecond2BeatPerMinute (int microsecondsPerQuaterNote)
 

Public Attributes

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

Properties

bool IsOver [get]
 
long LatenceTime [get]
 
long LatenceTimeMillis [get]
 

Detailed Description

Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all others classes as MidiStreamPlayer, MidiFilePlayer, MidiFileLoader, MidiFileWriter2 ...

The MPTKEvent main property is MPTKEvent.Command, the content and role of other properties (as MPTKEvent.Value) depend on the value of MPTKEvent.Command. Look at the MPTKEvent.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

Parameters
data

Member Function Documentation

◆ BeatPerMinute2QuarterPerMicroSecond()

static int MidiPlayerTK.MPTKEvent.BeatPerMinute2QuarterPerMicroSecond ( double  bpm)
static

Convert Beat Per Minute to duration of a quarter in microsecond.
With BPM=1, microsecondsPerQuaterNote=60 000 000 µs -> 60 secondes per quarter (quite slow!)
With BPM=120, microsecondsPerQuaterNote=500 000 µs -> 0.5 seconde per quarter

Parameters
bpmBeats Per Minute (with assumption beat=quarter)
Returns
60000000 / bpm or 500000 if bpm <= 0

◆ BuildIntFromBytes()

static int MidiPlayerTK.MPTKEvent.BuildIntFromBytes ( byte  b1,
byte  b2,
byte  b3,
byte  b4 
)
static

Store four bytes into one integer.

Parameters
b1byte 0 - less significant
b2byte 1
b3byte 2
b4byte 3 - moss significant
Returns
(b4 << 24) | (b3 << 16) | (b2 << 8) | b1

◆ ClearSynthParameter()

void MidiPlayerTK.MPTKEvent.ClearSynthParameter ( )

Reset synth parameter to default soundfont value.

Version
Maestro Pro

◆ ConvertToString()

string MidiPlayerTK.MPTKEvent.ConvertToString ( bool  brief)

Build a string description of the MIDI event. V2.83 removes "end of lines" on each returns string. For a better result when displayed on the console (Debug.Log), enable "Monospace font" in the setting of the console (three vertical dot in the panel)

Returns

◆ ExtractFromInt()

static byte MidiPlayerTK.MPTKEvent.ExtractFromInt ( uint  v,
int  n 
)
static

Extract byte position 'n' from an integer

Parameters
vvalue build with BuildIntFromBytes
nbyte position from 0 (less significant) to 3 (most significant)
Returns
(v >> (8*n)) & 0xFF

◆ GetSynthParameterCurrentValue()

float MidiPlayerTK.MPTKEvent.GetSynthParameterCurrentValue ( fluid_gen_type  genType)

Get the current 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).

Version
Maestro Pro
Parameters
genTypesee ModifySynthParameter
Returns
Return the normalized value of the parameter

◆ GetSynthParameterDefaultValue()

float MidiPlayerTK.MPTKEvent.GetSynthParameterDefaultValue ( fluid_gen_type  genType)

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

Version
Maestro Pro
Parameters
genTypesee ModifySynthParameter
Returns
Return the normalized value of the parameter

◆ GetSynthParameterLabel()

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

Get the label for the generator.

Version
Maestro Pro
Parameters
genTypesee ModifySynthParameter
Returns
Return the label of the generator

◆ GetSynthParameterListGenerator()

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

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

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

◆ ModifySynthParameter()

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

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.

Version
Maestro Pro
// 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.ModifySynthParameter(fluid_gen_type.GEN_FINETUNE, 0.52f, MPTKModeGeneratorChange.Override);
// Change low pass filter frequency
mptkEvent.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.
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.
Returns
true if change has been done

◆ QuarterPerMicroSecond2BeatPerMinute()

static double MidiPlayerTK.MPTKEvent.QuarterPerMicroSecond2BeatPerMinute ( int  microsecondsPerQuaterNote)
static

Convert duration of a quarter in microsecond to Beats Per Minute (with assumption beat=quarter).
With microsecondsPerQuaterNote=500 000 µs, BPM = 120

Parameters
microsecondsPerQuaterNote
Returns
60000000 / bpm or 120 if microsecondsPerQuaterNote <= 0

◆ StopEvent()

void MidiPlayerTK.MPTKEvent.StopEvent ( )

If the MPTKEvent is a note-on then send a not-off event. Equivalent to send a note-off to the synth, the sound enters in the release phase.
Has an effect only on Note On event. v2.9.0 Pro.

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

Extract value 2 from a double int build with BuildIntFromBytes

Parameters
vvalue build with BuildIntFromBytes
Returns
v - (v / 100) * 100

Member Data Documentation

◆ Beat

int MidiPlayerTK.MPTKEvent.Beat

Beat in the measure of this event. Present in all MIDI events, but only has musical meaning for noteon. The beat is calculated using the Time Signature event when a MIDI file is loaded.
By default the time signature is 4/4.

◆ 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

For Command = MPTKCommand.ControlChange contains the controller code (Modulation, Pan, Bank Select ...).
Value properties will contains the value of the controller. See MPTKController.

◆ CreateTime

long MidiPlayerTK.MPTKEvent.CreateTime

V2.9.0 Time from System.DateTime when the Event has been created (in the constructor of this class). Divide by 10000 to get milliseconds.
Replace TickTime from previous version (was confusing).

◆ Delay

long MidiPlayerTK.MPTKEvent.Delay

Short delay before playing the note in millisecond. Available only in Core mode. Apply only on NoteOn event.

◆ Duration

long MidiPlayerTK.MPTKEvent.Duration

When Command = MPTKCommand.NoteOn, contains duration of the note in millisecond.
Set -1 for a noteon played indefinitely.

Version
2.10.0
Note
Others Command roles removed:
  • SetTempo: no longer contains new tempo (quarter per minute)
  • TimeSignature: no longer contains the Denominator (Beat unit: 1 means 2, 2 means 4 (crochet), 3 means 8 (quaver), 4 means 16, ...)
  • KeySignature: no longer contains the MajorMinor flag.

◆ GensModifier

GenModifier [] MidiPlayerTK.MPTKEvent.GensModifier

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

Version
Maestro Pro

◆ 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.
MPTK_ClearAllSound is able to clear (note off) only the voices associated with this MIDI file when switching MIDI.
Switching between MIDI playing is very quick.
Could also be used for other prefab like MidiStreamPlayer for your specific need, but avoid changing this properties with MidiFilePlayer.

◆ Index

int MidiPlayerTK.MPTKEvent.Index

Initial Event Index in the MIDI list, set only when a MIDI file is loaded.

◆ Info

string MidiPlayerTK.MPTKEvent.Info

For Command = MPTKCommand.MetaEvent contains text information hold (TextEvent, Lyric, TimeSignature, ...)

◆ Length

int MidiPlayerTK.MPTKEvent.Length

When Command = MPTKCommand.NoteOn, duration of the note in MIDI Tick.

Duration in ticks is converted in duration in millisecond see (Duration) when the MIDI file is loaded.

Note
Maestro does not use this value for playing a MIDI file but the Duration in millisecond. https://en.wikipedia.org/wiki/Note_value

◆ Measure

int MidiPlayerTK.MPTKEvent.Measure

Measure (bar) when this event will be played. Measure is calculated with the Time Signature event when a MIDI file is loaded.
By default the time signature is 4/4.

◆ Meta

MPTKMeta MidiPlayerTK.MPTKEvent.Meta

For Command = MPTKCommand.MetaEvent contains MetaEvent Code. (Lyric, TimeSignature, ...).
Others properties will contains the value of the meta. See MPTKMeta (TextEvent, Lyric, TimeSignature, ...).

◆ RealTime

float MidiPlayerTK.MPTKEvent.RealTime

Real time in milliseconds of this MIDI Event from the start of the MIDI. It take into account the tempo changes but not MidiFilePlayer.MPTK_Speed
v2.89.6 Correct the time shift when a tempo change is read. Thanks to Ken Scott http://www.youtube.com/vjchaotic for the tip.
Not used for MidiStreamPlayer nor MidiInReader (MIDI events are always in real-time from your app).

◆ 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

Tag information free for use in the application

◆ 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 nor MidiInReader because they are real-time player.

◆ Track

long MidiPlayerTK.MPTKEvent.Track

Track index of the event in the MIDI.
There is any impact on the music played.
It's just a cool way to regroup MIDI events in a ... track like in a sequencer.
Track 0 is the first track read from the MIDI file.

◆ Value

int MidiPlayerTK.MPTKEvent.Value

Contains a value in relation with the Command.

◆ Velocity

int MidiPlayerTK.MPTKEvent.Velocity

When Command = MPTKCommand.NoteOn, the velocity between 0 and 127.

◆ Voices

List<fluid_voice> MidiPlayerTK.MPTKEvent.Voices

List of voices associated to a NoteOn Event. This is a list because it is common for several samples to be used simultaneously to play a note.

Property Documentation

◆ IsOver

bool MidiPlayerTK.MPTKEvent.IsOver
get

Check if this MIDI event has finished playing. All voices are OFF.

◆ LatenceTime

long MidiPlayerTK.MPTKEvent.LatenceTime
get

Delta time in system time (calculated with DateTime.UtcNow.Ticks) since the creation of this event.
Mainly useful to evaluate MPTK latency. One system ticks equal 100 nano second.

Note
Disabled by default. Defined DEBUG_PERF_AUDIO in MidiSynth to activate for debug purpose only.

◆ LatenceTimeMillis

long MidiPlayerTK.MPTKEvent.LatenceTimeMillis
get

Delta time in milliseconds (calculated with DateTime.UtcNow.Ticks) since the creation of this event.
Mainly useful to evaluate MPTK latency. One system ticks equal 100 nano second.

Note
Disabled by default. Defined DEBUG_PERF_AUDIO in MidiSynth to activate for debug purpose only.