BASS MIDI

BASS_MIDI_StreamEvent


Applies an event to a channel in a MIDI stream.

BOOL BASS_MIDI_StreamEvent(
    HSTREAM handle,
    DWORD chan,
    DWORD event,
    DWORD param
);

Parameters

handleThe MIDI stream to apply the event to.
chanThe MIDI channel to apply the event to... 0 = channel 1.
eventThe event to apply, see the table below.
paramThe event parameter.

Event types, with param definitions.

MIDI_EVENT_NOTEPress or release a key, or stop without sustain/decay.
param : LOBYTE = key number (0-127, 60=middle C), HIBYTE = velocity (0=release, 1-127=press, 255=stop).
MIDI_EVENT_PROGRAMSelect the preset/instrument to use. Standard soundfont presets follow the General MIDI standard, and generally also include Roland GS variations in other banks (accessible via the MIDI_EVENT_BANK event).
param : preset number (0-65535).
MIDI_EVENT_CHANPRESSet the channel pressure.
param : pressure level (0-127).
MIDI_EVENT_KEYPRESSet a key's pressure/aftertouch.
param : LOBYTE = key number (0-127), HIBYTE = pressure level (0-127).
MIDI_EVENT_PITCHSet the pitch wheel position.
param : pitch wheel position (0-16383, 8192=normal/middle).
MIDI_EVENT_BANKSelect the bank to use (MIDI controller 0).
param : bank number MSB (0-127).
MIDI_EVENT_MODULATIONSet the modulation (MIDI controller 1)
param : modulation level (0-127).
MIDI_EVENT_PORTATIMESet the portamento time (MIDI controller 5).
param : portamento time (0-127).
MIDI_EVENT_VOLUMESet the volume (MIDI controller 7).
param : volume level (0-127).
MIDI_EVENT_PANSet the pan position (MIDI controller 10).
param : pan position (0-128, 0=left, 64=middle, 127=right, 128=random).
MIDI_EVENT_EXPRESSIONSet the expression (MIDI controller 11).
param : expression level (0-127).
MIDI_EVENT_BANK_LSBSelect the bank LSB to use (MIDI controller 32).
param : bank number LSB (0-127).
MIDI_EVENT_SUSTAINSet the sustain pedal/switch (MIDI controller 64).
param : sustain is on? (0-63=no, 64-127=yes).
MIDI_EVENT_PORTAMENTOSet the portamento switch (MIDI controller 65).
param : portamento is on? (0-63=no, 64-127=yes).
MIDI_EVENT_SOSTENUTOSet the sostenuto pedal/switch (MIDI controller 66).
param : sostenuto is on? (0-63=no, 64-127=yes).
MIDI_EVENT_SOFTSet the soft pedal/switch (MIDI controller 67).
param : soft is on? (0-63=no, 64-127=yes).
MIDI_EVENT_RESONANCESet the low-pass filter resonance (MIDI controller 71, NRPN 121h)
param : resonance level (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_RELEASESet the release time (MIDI controller 72, NRPN 166h)
param : release time (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_ATTACKSet the attack time (MIDI controller 73, NRPN 163h)
param : attack time (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_CUTOFFSet the low-pass filter cutoff (MIDI controller 74, NRPN 120h)
param : cutoff level (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_DECAYSet the decay time (MIDI controller 75, NRPN 164h)
param : decay time (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_PORTANOTESet the portamento start key; the next note starts at this key (MIDI controller 84).
param : key number (1-127, 60=middle C).
MIDI_EVENT_REVERBSet the reverb send level (MIDI controller 91)
param : reverb level (0-127).
MIDI_EVENT_CHORUSSet the chorus send level (MIDI controller 93)
param : chorus level (0-127).
MIDI_EVENT_USERFXSet the user effect send level (MIDI controller 94). This will have no audible effect unless custom processing is applied to the user effect mix via BASS_MIDI_StreamGetChannel.
param : user effect level (0-127).
MIDI_EVENT_SOUNDOFFStop all sounds (MIDI controller 120).
param : not used.
MIDI_EVENT_RESETReset controllers (MIDI controller 121), that is modulation=0, expression=127, sustain=0, portamento=0, release time=64, attack time=64, pitch wheel=8192, channel pressure=0.
param : not used.
MIDI_EVENT_NOTESOFFRelease all keys (MIDI controller 123).
param : not used.
MIDI_EVENT_MODESet poly/mono mode (MIDI controllers 126 & 127).
param : mode (0=poly, 1=mono, 2=legato).
MIDI_EVENT_CONTROLUnhandled controller. This has no effect on the MIDI stream, but can be useful for custom processing purposes with a BASS_SYNC_MIDI_EVENT sync.
param : LOBYTE = controller number, HIBYTE = controller value.
MIDI_EVENT_PITCHRANGESet pitch wheel range (MIDI RPN 0).
param : range in semitones.
MIDI_EVENT_FINETUNESet the fine tuning (MIDI RPN 1).
param : finetune in cents (0-16383, 0=-100, 8192=normal, 16383=+100).
MIDI_EVENT_COARSETUNESet the coarse tuning (MIDI RPN 2).
param : finetune in semitones (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_DRUMSSet the percussion/drums channel switch. The bank and program are reset to 0 when this changes.
param : use drums? (0=no, 1=yes).
MIDI_EVENT_DRUM_CUTOFFSet the low-pass filter cutoff of a drum key (MIDI NRPN 14knh)
param : LOBYTE = key number (0-127), HIBYTE = cutoff level (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_DRUM_RESONANCESet the low-pass filter resonance of a drum key (MIDI NRPN 15knh)
param : LOBYTE = key number (0-127), HIBYTE = resonance level (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_DRUM_COARSETUNESet the coarse tuning of a drum key (MIDI NRPN 18knh).
param : LOBYTE = key number (0-127), HIBYTE = finetune in semitones (0-127, 0=-64, 64=normal, 127=+63).
MIDI_EVENT_DRUM_FINETUNESet the fine tuning of a drum key (MIDI NRPN 19knh).
param : LOBYTE = key number (0-127), HIBYTE = finetune in cents (0-127, 0=-100, 64=normal, 127=+100).
MIDI_EVENT_DRUM_LEVELSet the level of a drum key (MIDI NRPN 1Aknh)
param : LOBYTE = key number (0-127), HIBYTE = level (0-127, 127=normal/full).
MIDI_EVENT_DRUM_PANSet the pan position of a drum key (MIDI NRPN 1Cknh).
param : LOBYTE = key number (0-127), HIBYTE = pan position (0-128, 0=random, 1=left, 64=middle, 127=right, 128=normal).
MIDI_EVENT_DRUM_REVERBSet the reverb send level of a drum key (MIDI NRPN 1Dknh)
param : LOBYTE = key number (0-127), HIBYTE = reverb level (0-127, 127=normal/full).
MIDI_EVENT_DRUM_CHORUSSet the chorus send level of a drum key (MIDI NRPN 1Eknh)
param : LOBYTE = key number (0-127), HIBYTE = chorus level (0-127, 127=normal/full).
MIDI_EVENT_DRUM_USERFXSet the user effect send level of a drum key (MIDI NRPN 1Fknh)
param : LOBYTE = key number (0-127), HIBYTE = user effect level (0-127, 127=normal/full).
MIDI_EVENT_SCALETUNINGSet the tuning of a note in every octave.
param : LOWORD = tuning change in cents (0-16383, 0=-100, 8192=normal, 16383=+100), HIWORD = note (0-11, 0=C).
MIDI_EVENT_MOD_FILTERSet the maximum effect of modulation (MIDI controller 1) on filter cutoff.
param : filter cutoff effect in cents (0=-9600, 9600=none, 19200=+9600).
MIDI_EVENT_MOD_PITCHSet the maximum effect of modulation (MIDI controller 1) on pitch.
param : pitch effect in semitones (0=-24, 24=none, 48=+24).
MIDI_EVENT_MOD_VIBRATOSet the maximum effect of modulation (MIDI controller 1) on vibrato depth (MIDI RPN 5).
param : vibrato depth effect in cents (0=none, 128=100, 256=200, etc).
MIDI_EVENT_MOD_VOLUMESet the maximum effect of modulation (MIDI controller 1) on volume.
param : volume effect percentage (0=-100, 100=none, 200=+100).
MIDI_EVENT_CHANPRES_FILTERSet the maximum effect of channel pressure on filter cutoff.
param : filter cutoff effect in cents (0=-9600, 9600=none, 19200=+9600).
MIDI_EVENT_CHANPRES_PITCHSet the maximum effect of channel pressure on pitch.
param : pitch effect in semitones (0=-24, 24=none, 48=+24).
MIDI_EVENT_CHANPRES_VIBRATOSet the maximum effect of channel pressure on vibrato depth.
param : vibrato depth effect in cents (0=none, 128=100, 256=200, etc).
MIDI_EVENT_CHANPRES_VOLUMESet the maximum effect of channel pressure on volume.
param : volume effect percentage (0=-100, 100=none, 200=+100).
MIDI_EVENT_KEYPRES_FILTERSet the maximum effect of key pressure/aftertouch on filter cutoff.
param : filter cutoff effect in cents (0=-9600, 9600=none, 19200=+9600).
MIDI_EVENT_KEYPRES_PITCHSet the maximum effect of key pressure/aftertouch on pitch.
param : pitch effect in semitones (0=-24, 24=none, 48=+24).
MIDI_EVENT_KEYPRES_VIBRATOSet the maximum effect of key pressure/aftertouch on vibrato depth.
param : vibrato depth effect in cents (0=none, 128=100, 256=200, etc).
MIDI_EVENT_KEYPRES_VOLUMESet the maximum effect of key pressure/aftertouch on volume.
param : volume effect percentage (0=-100, 100=none, 200=+100).

Global events.

MIDI_EVENT_SYSTEM,
MIDI_EVENT_SYSTEMEX
Set the system mode, resetting everything to the system's defaults. MIDI_SYSTEM_DEFAULT is basically identical to MIDI_SYSTEM_GS, except that channel 10 is melodic if there are not 16 channels. MIDI_EVENT_SYSTEM does not reset things in any additional channels allocated to a MIDI file stream via the BASS_ATTRIB_MIDI_CHANS attribute, while MIDI_EVENT_SYSTEMEX does. If the system mode is unchanged and the BASS_MIDI_NOSYSRESET flag is set on the MIDI stream, then MIDI_EVENT_SYSTEM has no effect (MIDI_EVENT_SYSTEMEX still does).
param : system mode (MIDI_SYSTEM_DEFAULT, MIDI_SYSTEM_GM1, MIDI_SYSTEM_GM2, MIDI_SYSTEM_GS, MIDI_SYSTEM_XG).
MIDI_EVENT_TEMPOSet the tempo (MIDI meta event 81). Changing the tempo affects the stream length, and the BASS_ChannelGetLength byte value will no longer be valid.
param : tempo in microseconds per quarter note.
MIDI_EVENT_MASTERVOLSet the master volume.
param : volume level (0-16383, 0=silent, 16383=normal/full).
MIDI_EVENT_REVERB_TIMESet the reverb time.
param : reverb time in milliseconds.
MIDI_EVENT_REVERB_DELAYSet the reverb delay.
param : reverb delay in 10ths of a millisecond.
MIDI_EVENT_REVERB_LOCUTOFFSet the reverb low-pass cutoff
param : reverb low-pass cutoff in hertz (0=off).
MIDI_EVENT_REVERB_HICUTOFFSet the reverb high-pass cutoff
param : reverb high-pass cutoff in hertz (0=off).
MIDI_EVENT_REVERB_LEVELSet the reverb level
param : reverb level (0=off, 100=0dB, 200=+6dB).
MIDI_EVENT_CHORUS_DELAYSet the chorus delay.
param : chorus delay in 10ths of a millisecond.
MIDI_EVENT_CHORUS_DEPTHSet the chorus depth.
param : chorus depth in 10ths of a millisecond.
MIDI_EVENT_CHORUS_RATESet the chorus rate.
param : chorus rate in 100ths of a hertz.
MIDI_EVENT_CHORUS_FEEDBACKSet the chorus feedback level.
param : chorus feedback level (0=-100%, 100=off, 200=+100%).
MIDI_EVENT_CHORUS_LEVELSet the chorus level.
param : chorus level (0=off, 100=0dB, 200=+6dB).
MIDI_EVENT_CHORUS_REVERBSet the chorus send to reverb level.
param : chorus send to reverb level (0=off, 100=0dB, 200=+6dB).
MIDI_EVENT_USERFX_LEVELSet the user effect level.
param : user effect level (0=off, 100=0dB, 200=+6dB).
MIDI_EVENT_USERFX_CHORUSSet the user effect send to chorus level.
param : user effect send to chorus level (0=off, 100=0dB, 200=+6dB).
MIDI_EVENT_USERFX_REVERBSet the user effect send to reverb level.
param : user effect send to reverb level (0=off, 100=0dB, 200=+6dB).

Other (non-MIDI) events.

MIDI_EVENT_MIXLEVELSet the level.
param : the level (0=silent, 100=0dB, 200=+6dB).
MIDI_EVENT_TRANSPOSETranspose all notes. Changes take effect from the next note played, and affect melodic channels only (not drum channels).
param : transposition amount in semitones (0=-100, 100=normal, 200=+100).

Other (non-MIDI) global events.

MIDI_EVENT_SPEEDSet a tempo modification. Changing the tempo affects the stream length, and the BASS_ChannelGetLength byte value will no longer be valid. The modification does not affect seeking.
param : speed in 100ths of a percent (100=1%/min, 10000=100%/normal, 20000=200%).

Return value

If successful, TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_ILLPARAMOne of the other parameters is invalid.
BASS_ERROR_NOTAVAILTempo does not apply to streams created with BASS_MIDI_StreamCreate.

Remarks

Apart from the "global" events, all events apply only to the specified MIDI channel.

Except for the "non-MIDI" events, events applied to a MIDI file stream can subsequently be overridden by events in the file itself, and will also be overridden when seeking or looping. That can be avoided by using additional channels, allocated via the BASS_ATTRIB_MIDI_CHANS attribute.

BASS_SYNC_MIDI_EVENT syncs are not triggered by this function. If sync triggering is wanted, BASS_MIDI_StreamEvents can be used instead.

If the MIDI stream is being played (it is not a decoding channel), then there will be some delay in the effect of the event being heard. This latency can be reduced by making use of the BASS_CONFIG_BUFFER and BASS_CONFIG_UPDATEPERIOD config options when creating the stream.

If multiple events need to be applied at the same time, BASS_MIDI_StreamEvents can be used instead of this function.

Example

Play the middle C note (key 60) with a velocity of 100, on channel 1 for 2 seconds.
BASS_MIDI_StreamEvent(handle, 0, MIDI_EVENT_NOTE, MAKEWORD(60, 100)); // press the key
Sleep(2000); // wait 2 seconds
BASS_MIDI_StreamEvent(handle, 0, MIDI_EVENT_NOTE, 60); // release the key

See also

BASS_MIDI_StreamCreate, BASS_MIDI_StreamEvents, BASS_MIDI_StreamGetEvent