MidiFilterTrackEvents

DWORD WINAPI MidiFilterTrackEvents
(
	HANDLE hSequence, 
	WORD wTrack, 
	QWORD qwFirst, 
	QWORD qwLast, 
	DWORD dwFormat, 
	QWORD qwFilter, 
	LPBRELS_FILTERED_EVENT* lpFilteredEvents
);

This function gets a range of events of the specified type from a track.

Parameters

Return values

Returns the number of retrieved events or zero if none is available or an error occurred. The reasons for an error are an invalid sequence handle, an invalid track index, an invalid event range or event type.

Remarks

You can use an apropriate combination of the following values in the parameter qwFilter:

ConstantEvent
FILTER_SEQUENCENUMBER Retrieves sequence number (0x00) events
FILTER_TEXT Retrieves generic text (0x01) events
FILTER_COPYRIGHT Retrieves copyright (0x02)
FILTER_TRACKNAME Retrieves track name (0x03) events
FILTER_INSTRUMENTNAME Retrieves instrument name (0x04) events
FILTER_LYRIC Retrieves lyrics (0x05) events
FILTER_MARKER Retrieves marker (0x06) events
FILTER_CUEPOINT Retrieves cue point (0x07) events
FILTER_CHANNELPREFIX Retrieves channel prefix (0x20) events
FILTER_ENDOFTRACK Retrieves end-of-track (0x2F) events
FILTER_TEMPO Retrieves tempo change (0x51) events
FILTER_SMPTEOFFSET Retrieves SMPTE offset (0x54) events
FILTER_TIMESIGNATURE Retrieves time signature (0x58) events
FILTER_KEYSIGNATURE Retrieves key signature (0x59) events
FILTER_SEQUENCERSPECIFIC Retrieves sequencer specific (0x7F) events
FILTER_SYSTEMEXCLUSIVE Retrieves system exclusive (0xF0) events
FILTER_NOTEOFF Retrieves note off (0x8n) events
FILTER_NOTEON Retrieves note on (0x9n) events
FILTER_KEYAFTERTOUCH Retrieves key-aftertouch (0xAn) events
FILTER_CONTROLLER Retrieves controller setting (0xBn) events
FILTER_PROGRAM Retrieves program change (0xCn) events
FILTER_CHANNELPRESSURE Retrieves channel pressure (0xDn) events
FILTER_PITCHWHEEL Retrieves pitch change (0xEn) events
FILTER_MTCQUARTERFRAME Retrieves MTC Quarter Frame (0xF1) events
FILTER_SONGPOSITIONPOINTER Retrieves Song Position Pointer (0xF2) events
FILTER_SONGSELECT Retrieves Song Select (0xF3) events
FILTER_TUNEREQUEST Retrieves Tune Request (0xF6) events
FILTER_MIDICLOCK Retrieves Midi Clock (0xF8) events
FILTER_MIDISTART Retrieves Midi Start (0xFA) events
FILTER_MIDICONTINUE Retrieves Midi Continue (0xFB) events
FILTER_MIDISTOP Retrieves Midi Stop (0xFC) events
FILTER_ACTIVESENSE Retrieves Active sense (0xFE) events
The following filters are special:
FILTER_NOTES Retrieves notes. Each note is stored in an element of the BRELS_FILTERED_EVENT array. The index of each note on event is stored in the qwStart member of the structure. The index of each note off is stored in the qwEnd member of the structure. When the note off event is out of the searched interval, the qwEnd index points to the end-of-track (0x2F) event
FILTER_OTHER Retrieves events not listed here.
FILTER_ALL Retrieves all events.

You do not retrieve the events themselves, but their indexes. You can use functions like MidiEventGet to read the event data or call MidiGetTrackEvents to retrieve the actual data.

The function allocates the lpFilteredEvents events array. After you have finished with it, call MidiFreeBuffer to deallocate it.

The following example counts how many notes a track has:

Example

void NoteCount(HANDLE Sequence, WORD wTrack)
{
	int nFilters, nEvents;
	LPBRELS_FILTERED_EVENT lpFilter;
	char temp[256];

	// Event count
	nEvents = MidiTrackGet(Sequence, wTrack, EVENT_COUNT);

	// Retrieves notes and filters count
	nFilters = MidiFilterTrackEvents(Sequence, wTrack, 0, nEvents-1, MIDI_INDEX, FILTER_NOTES, &lpFilter);

	// Releases the allocated array
	MidiFreeBuffer(lpFilter);

	// Shows the count
	itoa(nFilters, (char*) &temp, 10);
	MessageBox(NULL, (char*) &temp, "Note count", MB_OK);
};

Further information

Released in November 19th, 2003
Updated in April 29th, 2004
Property of Breno de Lima Sarmento
Home page: http://www27.brinkster.com/brels
E-mail: breno_sarmento@hotmail.com
ICQ: 78977999 ()