BASS MIDI

MIDIFILTERPROC callback


User defined callback function to filter events.

BOOL CALLBACK MidiFilterProc(
    HSTREAM handle,
    DWORD track,
    BASS_MIDI_EVENT *event,
    BOOL seeking,
    void *user
);

Parameters

handleThe MIDI stream handle.
trackThe track that the event is from... 0 = 1st track.
eventPointer to the event structure.
seekingTRUE = the event is being processed while seeking, FALSE = the event is being played.
userThe user instance data given when BASS_MIDI_StreamSetFilter was called.

Return value

Return TRUE to process the event, and FALSE to drop the event.

Remarks

The event's type (event), parameter (param), and channel (chan) can be modified, but not its position (tick or pos). It is also possible to apply additional events at the same time via BASS_MIDI_StreamEvent, but not BASS_MIDI_StreamEvents.

MIDI_EVENT_NOTE, MIDI_EVENT_NOTESOFF, and MIDI_EVENT_SOUNDOFF events are ignored while seeking so they will not be received by a filtering function then. MIDI_EVENT_TEMPO events can be changed while seeking but doing so when seeking in bytes (BASS_POS_BYTE) will result in reaching a different position. Seeking in ticks (BASS_POS_MIDI_TICK) is unaffected by tempo changes. The MIDI_EVENT_SPEED event can be used to modify the tempo without affecting seeking.

Example

A filtering function that drops all notes with a velocity lower than 10.
BOOL CALLBACK MidiFilterProc(HSTREAM handle, DWORD track, BASS_MIDI_EVENT *event, BOOL seeking, void *user)
{
    if (event->event==MIDI_EVENT_NOTE) { // got a note
        int vel=HIBYTE(event->param); // extract the velocity
        if (vel<10 && vel>0) return FALSE; // drop the note if velocity is below 10 and not 0 (note off)
    }
    return TRUE; // process the event
}

A filtering function that changes bank 2 to bank 1.

BOOL CALLBACK MidiFilterProc(HSTREAM handle, DWORD track, BASS_MIDI_EVENT *event, BOOL seeking, void *user)
{
    if (event->event==MIDI_EVENT_BANK && event->param==2) // got a bank 2 request
    	event->param==1; // change it to bank 1
    return TRUE; // process the event
}

See also

BASS_MIDI_StreamSetFilter, BASS_MIDI_EVENT structure