MidiGetTrackEvents

DWORD WINAPI MidiGetTrackEvents
(
	HANDLE hSequence, 
	WORD wTrack, 
	QWORD qwFirst, 
	QWORD qwLast, 
	DWORD dwFormat, 
	LPBRELS_MIDI_EVENT* lpEvents
);

This function copies the selected range of events from a track.

Parameters

Return values

Returns the number of events copied or zero if no event was copied or an error occurred.

Remarks

The function will allocate an array of BRELS_MIDI_EVENT structures and store the address in the pointer provided in lpEvents. After you have finished with the events, deallocate them calling MidiCleanEvents passing the number of events returned by MidiGetTrackEvents and the lpEvents pointer.

If you need to get events of an specified type, use MidiFilterTrackEvents.

When updating events, you must remove the old events and insert updated ones. The following example transposes notes from the specified track by the desired number of tones, up or down:

Example

void Transpose(HANDLE Sequence, WORD wTrack, int Offset)
{
	int i, nEvents;
	LPBRELS_MIDI_EVENT lpEvents;

	// Copies everything from the track
	nEvents = MidiTrackGet(Sequence, wTrack, EVENT_COUNT);
	MidiGetTrackEvents(Sequence, wTrack, 0, nEvents-1, MIDI_INDEX, &lpEvents);

	// Truncates the track
	MidiRemoveTrack(Sequence, wTrack);
	MidiInsertTrack(Sequence, wTrack);

	// Do the transposition on note events (8x and 9x)
	for (i = 0; i < nEvents; i++)
		if ((lpEvents[i].Event >= 0x80) && (lpEvents[i].Event <=0x9F))
			lpEvents[i].Data[0] += Offset;

	// Reinsert the events, now updated
	MidiInsertTrackEvents(Sequence, wTrack, nEvents, lpEvents);

	// Clean up the array
	MidiCleanEvents(nEvents, lpEvents);
};

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: [email protected]
ICQ: 78977999 ()