midiEventsPlayed
Description
This event is fired when the synthesizer played certain midi events. This allows reacing on various low level audio playback elements like notes/rests played or metronome ticks.
Refer to the related guide to learn more about this feature.
midiEventsPlayedJavaScript |
alphaTab.midiEventsPlayedjQuery |
alphaTab.midiEventsPlayedHTML |
MidiEventsPlayed.net |
Types
function(args)JavaScript |
Action<MidiEventsPlayedEventArgs>.net |
Parameters
Parameters | Type | Summary |
---|---|---|
argsJavaScript | alphaTab.synth.MidiEventsPlayedEventArgs | The information about the played events. |
args.net | AlphaTab.Synth.MidiEventsPlayedEventArgs | The information about the played events. |
MidiEventsPlayedEventArgs Properties
Parameters | Type | Summary |
---|---|---|
eventsJavaScript | alphaTab.midi.MidiEvent[] | The played midi events. |
Events.net | IList<AlphaTab.Midi.MidiEvent> | The current time position within the song in milliseconds. |
Following midi event classes exist which represent the usual events of a midi file.
alphaTab.midi.MidiEvent
General midi events which can be represented by 32bit (e.g. note on, note off, control changes, pitch bends).
Parameters | Type | Summary |
---|---|---|
trackAll | number | The track to which this event belongs. |
messageAll | number | The 32-bit encoded raw midi message. |
tickAll | number | The absolute midi tick of when this event is played. |
channelAll | number | The midi channel to which this event belongs (not valid for all events). |
commandAll | alphaTab.midi.MidiEventType | The type of this event. |
data1All | number | The first data byte (meaning depends on midi event type) |
data2All | number | The second data byte (meaning depends on midi event type) |
alphaTab.midi.MetaEvent
Any Meta Events.
Parameters | Type | Summary |
---|---|---|
metaStatusAll | alphaTab.midi.MetaEventType | The type of meta event. |
alphaTab.midi.MetaDataEvent
Meta Events with a related data array (e.g. time signature changes).
Parameters | Type | Summary |
---|---|---|
dataAll | Uint8Array | The raw binary data attached to this meta event. |
alphaTab.midi.MetaNumberEvent
Meta Events with a number value (e.g. tempo changes).
Parameters | Type | Summary |
---|---|---|
valueAll | number | The number value of this meta event. |
alphaTab.midi.Midi20PerNotePitchBendEvent
A Midi 2.0 comparable per-note pitch bend.
Parameters | Type | Summary |
---|---|---|
noteKeyAll | number | The key of the note on the related channel which should be bent. |
pitchAll | number | The 32 bit pitch wheel value according to the Midi 2.0 standard. |
alphaTab.midi.SystemCommonEvent
Not used in alphaTab by default.
alphaTab.midi.SystemExclusiveEvent
For special alphaTab specific events (e.g. rest played, metronome tick).
Parameters | Type | Summary |
---|---|---|
dataAll | Uint8Array | The raw binary data attached to this event. |
isMetronomeAll | boolean | Whether this event is a metronome tick event. |
metronomeNumeratorAll | boolean | If the event is a metronome event it contains the zero based metronome numerator according to the time signature (e.g. 0, 1, 2 on a 3/4 signature). |
metronomeDurationInTicksAll | boolean | If the event is a metronome event it contains the current duration of the metronome event in ticks. |
metronomeDurationInMillisecondsAll | boolean | If the event is a metronome event it contains the current duration of the metronome event in milliseconds. This duration is assuming playback speed=1. |
isRestAll | boolean | Whether this event is a rest play event. |
manufacturerIdAll | number | The manufacturer ID of this specific event (0x7D for alphaTab). |
Examples
- JavaScript
- jQuery
- C#
var api = new alphaTab.AlphaTabApi(document.querySelector('#alphaTab'));
api.midiEventsPlayedFilter = [alphaTab.midi.MidiEventType.SystemExclusive2];
api.midiEventsPlayed.on(function(e) {
for(const midi of e.events) {
if(midi.isMetronome) {
console.log('Metronome tick ' + midi.tick);
}
}
});
$('#alphaTab')
.alphaTab('midiEventsPlayedFilter', [alphaTab.midi.MidiEventType.SystemExclusive2])
.on('alphaTab.midiEventsPlayed', (e, args) => {
for(const midi of args.events) {
if(midi.isMetronome) {
console.log('Metronome tick ' + midi.tick);
}
}
});
var api = new AlphaTabApi<MyControl>(...);
api.MidiEventsPlayedFilter = new MidiEventType[] { AlphaTab.Midi.MidiEventType.SystemExclusive2 };
api.MidiEventsPlayed.On(e =>
{
foreach(var midi of e.events)
{
if(midi is AlphaTab.Midi.SystemExclusiveEvent sysex && sysex.IsMetronome)
{
Console.WriteLine("Metronome tick " + midi.Tick);
}
}
});