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
handle | The MIDI stream to apply the event to. |
chan | The MIDI channel to apply the event to... 0 = channel 1. |
event | The event to apply, see the table below. |
param | The event parameter. |
Event types, with param definitions.
MIDI_EVENT_NOTE | Press 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_PROGRAM | Select 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_CHANPRES | Set the channel pressure. param : pressure level (0-127). |
MIDI_EVENT_KEYPRES | Set a key's pressure/aftertouch. param : LOBYTE = key number (0-127), HIBYTE = pressure level (0-127). |
MIDI_EVENT_PITCH | Set the pitch wheel position. param : pitch wheel position (0-16383, 8192=normal/middle). |
MIDI_EVENT_BANK | Select the bank to use (MIDI controller 0). param : bank number MSB (0-127). |
MIDI_EVENT_MODULATION | Set the modulation (MIDI controller 1) param : modulation level (0-127). |
MIDI_EVENT_PORTATIME | Set the portamento time (MIDI controller 5). param : portamento time (0-127). |
MIDI_EVENT_VOLUME | Set the volume (MIDI controller 7). param : volume level (0-127). |
MIDI_EVENT_PAN | Set the pan position (MIDI controller 10). param : pan position (0-128, 0=left, 64=middle, 127=right, 128=random). |
MIDI_EVENT_EXPRESSION | Set the expression (MIDI controller 11). param : expression level (0-127). |
MIDI_EVENT_BANK_LSB | Select the bank LSB to use (MIDI controller 32). param : bank number LSB (0-127). |
MIDI_EVENT_SUSTAIN | Set the sustain pedal/switch (MIDI controller 64). param : sustain is on? (0-63=no, 64-127=yes). |
MIDI_EVENT_PORTAMENTO | Set the portamento switch (MIDI controller 65). param : portamento is on? (0-63=no, 64-127=yes). |
MIDI_EVENT_SOSTENUTO | Set the sostenuto pedal/switch (MIDI controller 66). param : sostenuto is on? (0-63=no, 64-127=yes). |
MIDI_EVENT_SOFT | Set the soft pedal/switch (MIDI controller 67). param : soft is on? (0-63=no, 64-127=yes). |
MIDI_EVENT_RESONANCE | Set the low-pass filter resonance (MIDI controller 71, NRPN 121h) param : resonance level (0-127, 0=-64, 64=normal, 127=+63). |
MIDI_EVENT_RELEASE | Set the release time (MIDI controller 72, NRPN 166h) param : release time (0-127, 0=-64, 64=normal, 127=+63). |
MIDI_EVENT_ATTACK | Set the attack time (MIDI controller 73, NRPN 163h) param : attack time (0-127, 0=-64, 64=normal, 127=+63). |
MIDI_EVENT_CUTOFF | Set the low-pass filter cutoff (MIDI controller 74, NRPN 120h) param : cutoff level (0-127, 0=-64, 64=normal, 127=+63). |
MIDI_EVENT_DECAY | Set the decay time (MIDI controller 75, NRPN 164h) param : decay time (0-127, 0=-64, 64=normal, 127=+63). |
MIDI_EVENT_PORTANOTE | Set the portamento start key; the next note starts at this key (MIDI controller 84). param : key number (1-127, 60=middle C). |
MIDI_EVENT_REVERB | Set the reverb send level (MIDI controller 91) param : reverb level (0-127). |
MIDI_EVENT_CHORUS | Set the chorus send level (MIDI controller 93) param : chorus level (0-127). |
MIDI_EVENT_USERFX | Set 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_SOUNDOFF | Stop all sounds (MIDI controller 120). param : not used. |
MIDI_EVENT_RESET | Reset 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_NOTESOFF | Release all keys (MIDI controller 123). param : not used. |
MIDI_EVENT_MODE | Set poly/mono mode (MIDI controllers 126 & 127). param : mode (0=poly, 1=mono, 2=legato). |
MIDI_EVENT_CONTROL | Unhandled 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_PITCHRANGE | Set pitch wheel range (MIDI RPN 0). param : range in semitones. |
MIDI_EVENT_FINETUNE | Set the fine tuning (MIDI RPN 1). param : finetune in cents (0-16383, 0=-100, 8192=normal, 16383=+100). |
MIDI_EVENT_COARSETUNE | Set the coarse tuning (MIDI RPN 2). param : finetune in semitones (0-127, 0=-64, 64=normal, 127=+63). |
MIDI_EVENT_DRUMS | Set 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_CUTOFF | Set 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_RESONANCE | Set 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_COARSETUNE | Set 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_FINETUNE | Set 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_LEVEL | Set 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_PAN | Set 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_REVERB | Set 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_CHORUS | Set 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_USERFX | Set 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_SCALETUNING | Set 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_FILTER | Set 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_PITCH | Set the maximum effect of modulation (MIDI controller 1) on pitch. param : pitch effect in semitones (0=-24, 24=none, 48=+24). |
MIDI_EVENT_MOD_VIBRATO | Set 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_VOLUME | Set the maximum effect of modulation (MIDI controller 1) on volume. param : volume effect percentage (0=-100, 100=none, 200=+100). |
MIDI_EVENT_CHANPRES_FILTER | Set the maximum effect of channel pressure on filter cutoff. param : filter cutoff effect in cents (0=-9600, 9600=none, 19200=+9600). |
MIDI_EVENT_CHANPRES_PITCH | Set the maximum effect of channel pressure on pitch. param : pitch effect in semitones (0=-24, 24=none, 48=+24). |
MIDI_EVENT_CHANPRES_VIBRATO | Set 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_VOLUME | Set the maximum effect of channel pressure on volume. param : volume effect percentage (0=-100, 100=none, 200=+100). |
MIDI_EVENT_KEYPRES_FILTER | Set 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_PITCH | Set the maximum effect of key pressure/aftertouch on pitch. param : pitch effect in semitones (0=-24, 24=none, 48=+24). |
MIDI_EVENT_KEYPRES_VIBRATO | Set 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_VOLUME | Set 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_TEMPO | Set 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_MASTERVOL | Set the master volume. param : volume level (0-16383, 0=silent, 16383=normal/full). |
MIDI_EVENT_REVERB_TIME | Set the reverb time. param : reverb time in milliseconds. |
MIDI_EVENT_REVERB_DELAY | Set the reverb delay. param : reverb delay in 10ths of a millisecond. |
MIDI_EVENT_REVERB_LOCUTOFF | Set the reverb low-pass cutoff param : reverb low-pass cutoff in hertz (0=off). |
MIDI_EVENT_REVERB_HICUTOFF | Set the reverb high-pass cutoff param : reverb high-pass cutoff in hertz (0=off). |
MIDI_EVENT_REVERB_LEVEL | Set the reverb level param : reverb level (0=off, 100=0dB, 200=+6dB). |
MIDI_EVENT_CHORUS_DELAY | Set the chorus delay. param : chorus delay in 10ths of a millisecond. |
MIDI_EVENT_CHORUS_DEPTH | Set the chorus depth. param : chorus depth in 10ths of a millisecond. |
MIDI_EVENT_CHORUS_RATE | Set the chorus rate. param : chorus rate in 100ths of a hertz. |
MIDI_EVENT_CHORUS_FEEDBACK | Set the chorus feedback level. param : chorus feedback level (0=-100%, 100=off, 200=+100%). |
MIDI_EVENT_CHORUS_LEVEL | Set the chorus level. param : chorus level (0=off, 100=0dB, 200=+6dB). |
MIDI_EVENT_CHORUS_REVERB | Set the chorus send to reverb level. param : chorus send to reverb level (0=off, 100=0dB, 200=+6dB). |
MIDI_EVENT_USERFX_LEVEL | Set the user effect level. param : user effect level (0=off, 100=0dB, 200=+6dB). |
MIDI_EVENT_USERFX_CHORUS | Set the user effect send to chorus level. param : user effect send to chorus level (0=off, 100=0dB, 200=+6dB). |
MIDI_EVENT_USERFX_REVERB | Set 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_MIXLEVEL | Set the level. param : the level (0=silent, 100=0dB, 200=+6dB). |
MIDI_EVENT_TRANSPOSE | Transpose 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_SPEED | Set 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_HANDLE | handle is not valid. |
BASS_ERROR_ILLPARAM | One of the other parameters is invalid. |
BASS_ERROR_NOTAVAIL | Tempo 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