BASS.NET API for the Un4seen BASS Audio Library

MIDIFILTERPROC Delegate

BASS.NET API for the Un4seen BASS Audio Library
User defined callback function to filter events.

Namespace:  Un4seen.Bass.AddOn.Midi
Assembly:  Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
Syntax

public delegate bool MIDIFILTERPROC(
	int handle,
	int track,
	IntPtr eventPtr,
	bool seeking,
	IntPtr user
)

Parameters

handle
Type: SystemInt32
The MIDI stream handle.
track
Type: SystemInt32
The track that the event is from... 0 = 1st track.
eventPtr
Type: SystemIntPtr
Pointer to the BASS_MIDI_EVENT structure.
seeking
Type: SystemBoolean
= the event is being processed while seeking, = the event is being played.
user
Type: SystemIntPtr
The user instance data given when BASS_MIDI_StreamSetFilter(Int32, Boolean, MIDIFILTERPROC, IntPtr) was called.

Return Value

Type: Boolean
Return to process the event, and to drop the event.
Remarks

The event's type (eventtype), 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(Int32, Int32, BASSMIDIEvent, Int32), but not BASS_MIDI_StreamEvents(Int32, BASSMIDIEventMode, BASS_MIDI_EVENT, Int32).

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.

Examples

A filtering function that drops all notes with a velocity lower than 10:
C#
private void MidiFilterProc(int handle, int track, IntPtr eventPtr, bool seeking, IntPtr user)
{
    var midievent = BASS_MIDI_EVENT.FromIntPtr(eventPtr);

    if (midievent.eventtype == BASSMIDIEvent.MIDI_EVENT_NOTE)
    {
        // got a note
        int vel = Utils.HighWord32(midievent.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;
C#
private void MidiFilterProc(int handle, int track, IntPtr eventPtr, bool seeking, IntPtr user)
{
    var midievent = BASS_MIDI_EVENT.FromIntPtr(eventPtr);

    if (midievent.eventtype == BASSMIDIEvent.MIDI_EVENT_BANK && midievent.param == 2)
    {
        // got a bank 2 request
        midievent.param = 1; // change it to bank 1
    }
    return true; // process the event
}
See Also

Reference