Creates a sample stream from a MIDI file.
HSTREAM BASS_MIDI_StreamCreateFile( BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags, DWORD freq );
mem | TRUE = stream the file from memory. | ||||||||||||||||||||||||||||||||||||
file | Filename (mem = FALSE) or a memory location (mem = TRUE). | ||||||||||||||||||||||||||||||||||||
offset | File offset to begin streaming from (only used if mem = FALSE). | ||||||||||||||||||||||||||||||||||||
length | Data length... 0 = use all data up to the end of the file (if mem = FALSE). | ||||||||||||||||||||||||||||||||||||
flags | A combination of these flags.
| ||||||||||||||||||||||||||||||||||||
freq | Sample rate to render/play the MIDI stream 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). |
BASS_ERROR_INIT | BASS_Init has not been successfully called. |
BASS_ERROR_NOTAVAIL | The BASS_STREAM_AUTOFREE flag cannot be combined with the BASS_STREAM_DECODE flag. |
BASS_ERROR_ILLPARAM | The length must be specified when streaming from memory. |
BASS_ERROR_FILEOPEN | The file could not be opened. |
BASS_ERROR_FILEFORM | The file's format is not recognised/supported. |
BASS_ERROR_FORMAT | The sample format is not supported. |
BASS_ERROR_SPEAKER | The specified SPEAKER flags are invalid. |
BASS_ERROR_MEM | There is insufficient memory. |
BASS_ERROR_NO3D | Could not initialize 3D support. |
BASS_ERROR_UNKNOWN | Some other mystery problem! |
A MIDI stream will have 16 MIDI channels by default, but may have more if the MIDI port meta-event (21h) is used in the file. Each port adds 16 channels: port 0 = channels 1-16, port 1 = channels 17-32, etc. Up to 8 ports are supported for a maximum of 128 channels, with any higher ports being mapped to lower ports (modulo 8). If lower ports are unused then higher port(s) will be shifted down to use those lower channels. Channel 10 in each port's block of 16 channels defaults to being a drum channel. Global events from any port will apply to all ports/channels, but system mode/reset events are only applied from the first port that they are encountered; any from other ports are ignored.
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. With the BASS_CONFIG_MIDI_AUTOFONT config option enabled, BASSMIDI will also check for a soundfont of the same name as the MIDI file. By default, linear interpolation will be used in playing the samples from the soundfonts. Sinc interpolation is also available via the BASS_ATTRIB_MIDI_SRC attribute, which increases the sound quality but also uses more CPU.
As well as the standard byte/time-based positioning, MIDI tick-based positioning is also supported. The BASS_POS_MIDI_TICK "mode" can be used with BASS_ChannelGetLength, BASS_ChannelGetPosition and BASS_ChannelSetPosition to deal in ticks. The BASS_ATTRIB_MIDI_PPQN attribute can be used to translate the position to beats.
Marker, instrument name, cue, text, and lyric events can be retrieved via the BASS_MIDI_StreamGetMark function. Syncs can also be used to be notified of their occurrence.
Other texts of each track (eg. track name) are available via the BASS_TAG_MIDI_TRACK+<track> tag, where track=0 is the first track. A pointer to a series of null-terminated strings is given, the final string ending with a double null. The first text in the first track is generally the title of the MIDI file. RIFF MIDI tags are also available via the standard BASS_TAG_RIFF_INFO tag.
Alongside the events played from the MIDI file, custom MIDI events can be applied via the BASS_MIDI_StreamEvent and BASS_MIDI_StreamEvents functions. The events can be played on the same MIDI channels that are used by the MIDI file, or they can be played on additional channels allocated via the BASS_ATTRIB_MIDI_CHANS attribute.
Unlike with most stream formats, the entire MIDI file is loaded to memory. This means the file can be deleted or moved after calling this function, or the memory can be discarded (mem = TRUE).
To play a MIDI file from the internet, use BASS_MIDI_StreamCreateURL. To play a custom sequence of MIDI events, BASS_MIDI_StreamCreateEvents can be used.
HSTREAM stream = BASS_MIDI_StreamCreateFile(FALSE, "afile.mid", 0, 0, 0, 44100);
BASS_ChannelGetInfo, BASS_ChannelGetLength, BASS_ChannelGetTags, BASS_ChannelPlay, BASS_ChannelSetAttribute, BASS_ChannelSetDSP, BASS_ChannelSetFX, BASS_ChannelSetLink, BASS_StreamFree