BASS_MIDI_StreamCreateEvents
Creates a sample stream from a sequence of MIDI events.
HSTREAM BASS_MIDI_StreamCreateEvents(
BASS_MIDI_EVENT *events,
DWORD ppqn,
DWORD flags,
DWORD freq
);
Parameters
| events | Pointer to an array containing the event sequence to play.
|
| ppqn | The Pulses Per Quarter Note, or ticks per beat.
|
| flags | Any combination of these flags.
| BASS_SAMPLE_8BITS | Use 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the sample data will be 16-bit.
| | BASS_SAMPLE_FLOAT | Use 32-bit floating-point sample data. See Floating-point channels for more info.
| | BASS_SAMPLE_MONO | Decode/play the MIDI in mono (uses less CPU than stereo). This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init.
| | BASS_SAMPLE_SOFTWARE | Force the stream to not use hardware mixing.
| | BASS_SAMPLE_3D | Enable 3D functionality. This requires that the BASS_DEVICE_3D flag was specified when calling BASS_Init. 3D channels must also be mono, so BASS_SAMPLE_MONO is automatically applied. The SPEAKER flags cannot be used together with this flag.
| | BASS_SAMPLE_FX | Enable the old implementation of DirectX 8 effects. See the DX8 effect implementations section for details. Use BASS_ChannelSetFX to add effects to the stream.
| | BASS_STREAM_AUTOFREE | Automatically free the stream when playback ends.
| | BASS_STREAM_DECODE | Decode/render the sample data, without playing it. Use BASS_ChannelGetData to retrieve decoded sample data. The BASS_SAMPLE_3D, BASS_STREAM_AUTOFREE and SPEAKER flags cannot be used together with this flag. The BASS_SAMPLE_SOFTWARE and BASS_SAMPLE_FX flags are also ignored.
| | BASS_SPEAKER_xxx | Speaker assignment flags. The BASS_SAMPLE_MONO flag is automatically applied when using a mono speaker assignment flag.
| | BASS_MIDI_NOFX | Disable reverb and chorus processing, saving some CPU time. This flag can be toggled at any time using BASS_ChannelFlags| BASS_MIDI_SINCINTER | Use sinc interpolated sample mixing. This increases the sound quality, but also requires more CPU. Otherwise linear interpolation is used.
.
| |
|
| freq | Sample rate to render/play the MIDI at... 0 = the rate specified in the BASS_Init call, 1 = the device's current output rate (or the BASS_Init rate if that is not available).
|
Return value
If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
Error codes
| BASS_ERROR_INIT | BASS_Init has not been successfully called.
|
| BASS_ERROR_NOTAVAIL | Only decoding channels (BASS_STREAM_DECODE) are allowed when using the "no sound" device. The BASS_STREAM_AUTOFREE flag is also unavailable to decoding channels.
|
| BASS_ERROR_ILLPARAM | ppqn cannot be 0.
|
| BASS_ERROR_POSITION | The events must be in chronological order (within each track).
|
| BASS_ERROR_FORMAT | The sample format is not supported by the device/drivers. If the stream is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they are not supported.
|
| BASS_ERROR_SPEAKER | The specified SPEAKER flags are invalid. The device/drivers do not support them or 3D functionality is enabled.
|
| BASS_ERROR_MEM | There is insufficient memory.
|
| BASS_ERROR_NO3D | Could not initialize 3D support.
|
| BASS_ERROR_UNKNOWN | Some other mystery problem!
|
Remarks
This function creates a 16 channel MIDI stream to play a predefined sequence of MIDI events. Any of the standard MIDI events listed in the BASS_MIDI_StreamEvent section can be used, but the MIDI_EVENT_MIXLEVEL, MIDI_EVENT_TRANSPOSE, and MIDI_EVENT_SYSTEMEX events are not available and will be ignored. The sequence should end with a MIDI_EVENT_END event. Multiple tracks are possible via the MIDI_EVENT_END_TRACK event, which signals the end of a track; the next event will be in a new track.
The event sequence is copied, so the events array does not need to persist beyond the function call.
Soundfonts provide the sounds that are used to render a MIDI stream. A default soundfont configuration is applied initially to the new MIDI stream, which can subsequently be overridden using BASS_MIDI_StreamSetFonts.
Platform-specific
Away from Windows, all mixing is done in software (by BASS), so the BASS_SAMPLE_SOFTWARE flag is unnecessary. The BASS_SAMPLE_FX flag is also ignored. On Android and iOS, sinc interpolation requires a NEON-supporting CPU; the BASS_MIDI_SINCINTER flag will otherwise be ignored.
Example
Play a middle C note (key 60) on a violin every 2 seconds.
BASS_MIDI_EVENT events[]={
{MIDI_EVENT_TEMPO, 500000, 0, 0}, // set the tempo to 0.5 seconds per quarter note
{MIDI_EVENT_PROGRAM, 40, 0, 0}, // select the violin preset
{MIDI_EVENT_NOTE, MAKEWORD(60, 100), 0, 0}, // press the key
{MIDI_EVENT_NOTE, 60, 0, 200}, // release the key after 200 ticks
{MIDI_EVENT_END, 0, 0, 400} // end after 400 ticks
};
HSTREAM stream=BASS_MIDI_StreamCreateEvents(events, 100, BASS_SAMPLE_LOOP, 0); // create a looping stream from the events
BASS_ChannelPlay(stream, 0); // start playing it
See also
BASS_MIDI_StreamCreate, BASS_MIDI_StreamCreateFile, BASS_MIDI_StreamGetChannel, BASS_MIDI_StreamLoadSamples, BASS_MIDI_StreamSetFonts, BASS_ATTRIB_MIDI_CPU, BASS_CONFIG_MIDI_DEFFONT, BASS_CONFIG_MIDI_VOICES
BASS_ChannelGetInfo, BASS_ChannelPlay, BASS_ChannelSetAttribute, BASS_ChannelSetDSP, BASS_ChannelSetFX, BASS_ChannelSetLink, BASS_StreamFree