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.
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:
- 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.
- MidiFileWriter2 generate MIDI Music file from your own algorithm.
- MidiStreamPlayer real-time generation of MIDI Music from your own algorithm.
See here https://paxstellar.fr/class-mptkevent and here https://mptkapi.paxstellar.com/d9/d50/class_midi_player_t_k_1_1_m_p_t_k_event.html
Also, below an example with MidiStreamPlayer
Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all ot...
Definition: MPTKEvent.cs:45
long Duration
Definition: MPTKEvent.cs:176
MPTKCommand Command
Definition: MPTKEvent.cs:100
int Velocity
Definition: MPTKEvent.cs:164
int Value
Definition: MPTKEvent.cs:154
int Channel
Definition: MPTKEvent.cs:159
Build and Play Real Time Music in relation with user actions or algorithms. This class must be used w...
Definition: MidiStreamPlayer.cs:36
void MPTK_StartMidiStream()
Definition: MidiStreamPlayer.cs:65
void MPTK_PlayEvent(MPTKEvent mptkEvent)
Definition: MidiStreamPlayer.cs:95
MPTKCommand
Definition: MPTKEnum.cs:12
◆ EnumLength
◆ MPTKEvent()
MidiPlayerTK.MPTKEvent.MPTKEvent |
( |
ulong |
data | ) |
|
Create a MPTK Midi event from a midi input message
- Parameters
-
◆ 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
-
bpm | Beats 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
-
b1 | byte 0 - less significant |
b2 | byte 1 |
b3 | byte 2 |
b4 | byte 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
◆ ExtractFromInt()
static byte MidiPlayerTK.MPTKEvent.ExtractFromInt |
( |
uint |
v, |
|
|
int |
n |
|
) |
| |
|
static |
Extract byte position 'n' from an integer
- Parameters
-
v | value build with BuildIntFromBytes |
n | byte 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
-
- 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
-
- 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
-
- 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
-
- 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
mptkEvent.ModifySynthParameter(fluid_gen_type.GEN_FINETUNE, 0.52f, MPTKModeGeneratorChange.Override);
mptkEvent.ModifySynthParameter(fluid_gen_type.GEN_FILTERFC, 0.6f, MPTKModeGeneratorChange.Override);
midiStream.MPTK_PlayDirectEvent(mptkEvent);
- Parameters
-
genType | Type 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
|
value | Normalized 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.
|
mode | Define 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
-
- Returns
- v - (v / 100) * 100
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
◆ Beat
int MidiPlayerTK.MPTKEvent.Beat |
Beat in measure of this event (have sense only for noteon). Measure is calculated with the Time Signature event when a MIDI file is loaded.
By default the time signature is 4/4.
- Version
- 2.10.0
◆ Channel
int MidiPlayerTK.MPTKEvent.Channel |
Midi channel fom 0 to 15 (9 for drum)
◆ Command
MIDI Command code. Defined the type of message. See MPTKCommand (Note On, Control Change, Patch Change...)
◆ Controller
◆ 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.
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 |
Initial Event Index in the MIDI list, set only when a MIDI file is loaded.
◆ Info
string MidiPlayerTK.MPTKEvent.Info |
◆ Length
int MidiPlayerTK.MPTKEvent.Length |
◆ 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.
- Version
- 2.10.0
◆ 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 MPTK_Speed of the MidiPlayer.
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 of use 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 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 |
◆ Voices
List<fluid_voice> MidiPlayerTK.MPTKEvent.Voices |
List of voices associated to a NoteOn Event. It's frequent that multiple samples are used simultaneously for playing a note.
◆ IsOver
bool MidiPlayerTK.MPTKEvent.IsOver |
|
get |
Check if playing of this midi event is over (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.