Since: 1.2.0-alpha.100

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.

midiEventsPlayed.net

Types

function(args)JavaScript
Action<MidiEventsPlayedEventArgs>.net

Parameters

ParametersTypeSummary
argsJavaScriptalphaTab.synth.MidiEventsPlayedEventArgsThe information about the played events.
args.netAlphaTab.Synth.MidiEventsPlayedEventArgsThe information about the played events.

MidiEventsPlayedEventArgs Properties

ParametersTypeSummary
eventsJavaScriptalphaTab.midi.MidiEvent[]The played midi events.
Events.netIList<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).

ParametersTypeSummary
trackAllnumberThe track to which this event belongs.
messageAllnumberThe 32-bit encoded raw midi message.
tickAllnumberThe absolute midi tick of when this event is played.
channelAllnumberThe midi channel to which this event belongs (not valid for all events).
commandAllalphaTab.midi.MidiEventTypeThe type of this event.
data1AllnumberThe first data byte (meaning depends on midi event type)
data2AllnumberThe second data byte (meaning depends on midi event type)

alphaTab.midi.MetaEvent

Any Meta Events.

ParametersTypeSummary
metaStatusAllalphaTab.midi.MetaEventTypeThe type of meta event.

alphaTab.midi.MetaDataEvent

Meta Events with a related data array (e.g. time signature changes).

ParametersTypeSummary
dataAllUint8ArrayThe raw binary data attached to this meta event.

alphaTab.midi.MetaNumberEvent

Meta Events with a number value (e.g. tempo changes).

ParametersTypeSummary
valueAllnumberThe number value of this meta event.

alphaTab.midi.Midi20PerNotePitchBendEvent

A Midi 2.0 comparable per-note pitch bend.

ParametersTypeSummary
noteKeyAllnumberThe key of the note on the related channel which should be bent.
pitchAllnumberThe 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).

ParametersTypeSummary
dataAllUint8ArrayThe raw binary data attached to this event.
isMetronomeAllbooleanWhether this event is a metronome tick event.
metronomeNumeratorAllbooleanIf 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).
metronomeDurationInTicksAllbooleanIf the event is a metronome event it contains the current duration of the metronome event in ticks.
metronomeDurationInMillisecondsAllbooleanIf the event is a metronome event it contains the current duration of the metronome event in milliseconds. This duration is assuming playback speed=1.
isRestAllbooleanWhether this event is a rest play event.
manufacturerIdAllnumberThe manufacturer ID of this specific event (0x7D for alphaTab).

Examples

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);
}
}
});