Retrieves the events in a MIDI stream.

DWORD BASS_MIDI_StreamGetEvents(
    HSTREAM handle,
    int track,
    DWORD filter,
    BASS_MIDI_EVENT *events


handleThe MIDI stream to get the events from.
trackThe track to get the events from... 0 = 1st track, -1 = all tracks.
filterThe type of events to retrieve... 0 = all events. See BASS_MIDI_StreamEvent for a list of possible event types.
eventsPointer to an array to receive the events... NULL = get the number of events without getting the events themselves.

Return value

If successful, the number of events is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTAVAILThe stream does not have an event sequence.
BASS_ERROR_ILLPARAMtrack is not valid.


This function should first be called with events = NULL to get the number of events, before allocating an array of the required size and retrieving the events. The events are ordered chronologically, and by track number (lowest first) if multiple events have the same position. Global events (eg. tempo) are always placed in the 1st track, even if they were originally in a different track in the MIDI file.

BASS_MIDI_StreamGetEventsEx can be used to get a portion of the events instead of all of them.


Retrieve all events in the 1st track.
DWORD eventc=BASS_MIDI_StreamGetEvents(handle, 0, 0, NULL); // get number of events in 1st track
BASS_MIDI_EVENT *events=(BASS_MIDI_EVENT*)malloc(eventc*sizeof(BASS_MIDI_EVENT)); // allocate event array
BASS_MIDI_StreamGetEvents(handle, 0, 0, events); // get the events

Retrieve all note events in the 2nd track.

DWORD eventc=BASS_MIDI_StreamGetEvents(handle, 1, MIDI_EVENT_NOTE, NULL); // get number of note events in 2nd track
BASS_MIDI_EVENT *events=(BASS_MIDI_EVENT*)malloc(eventc*sizeof(BASS_MIDI_EVENT)); // allocate event array
BASS_MIDI_StreamGetEvents(handle, 1, MIDI_EVENT_NOTE, events); // get the events

See also

BASS_MIDI_StreamCreateFile, BASS_MIDI_StreamGetEvent, BASS_MIDI_StreamGetEventsEx, BASS_MIDI_EVENT structure