BASS_MIDI_StreamCreateFile
Creates a sample stream from a MIDI file.
HSTREAM BASS_MIDI_StreamCreateFile(
DWORD filetype,
void *file,
QWORD offset,
QWORD length,
DWORD flags,
DWORD freq
);
Parameters
| filetype | One of the following.
| BASS_FILE_NAME | file is a filename. This is the default if none is specified.
| | BASS_FILE_MEM | file points to a memory block.
| | BASS_FILE_MEMCOPY | file points to a memory block, which will be copied. This requires BASS 2.4.18 or above.
| | BASS_FILE_HANDLE | file is a file handle (HANDLE) on Windows or a file descriptor (int) on other platforms, and should be seekable. It will be duplicated, so the original can be closed whenever wanted. This requires BASS 2.4.18 or above.
|
|
| file | The file as described by filetype.
|
| offset | File offset to begin reading from.
|
| length | Maximum read length... 0 = to the end of the file.
|
| flags | A combination of these flags.
| BASS_SAMPLE_8BITS | Use 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the stream is 16-bit.
| | BASS_SAMPLE_FLOAT | Use 32-bit floating-point sample data. See Floating-point channels for info.
| | BASS_SAMPLE_MONO | Decode/play the MIDI in mono. This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init.
| | BASS_SAMPLE_3D | Enable 3D functionality. The stream must be mono, so BASS_SAMPLE_MONO is automatically applied. The SPEAKER flags cannot be used together with this flag.
| | BASS_SAMPLE_LOOP | Loop the file. This flag can be toggled at any time using BASS_ChannelFlags.
| | 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.
| | BASS_SPEAKER_xxx | Speaker assignment flags. The BASS_SAMPLE_MONO flag is automatically applied when using a mono speaker assignment flag.
| | BASS_MIDI_ASYNC | Process events asynchronously in BASS_MIDI_StreamEvent and BASS_MIDI_StreamEvents calls. This flag can be toggled at any time using BASS_ChannelFlags.
| | BASS_MIDI_DECAYEND | Let the sound decay naturally (including reverb) instead of stopping abruptly at the end of the file, including when looping. This flag can be toggled at any time using BASS_ChannelFlags.
| | BASS_MIDI_DECAYSEEK | Let the old sound decay naturally (including reverb) when changing the position, including looping. This flag can be toggled at any time using BASS_ChannelFlags, but it should generally only be used in BASS_ChannelSetPosition calls to have it applied to particular position changes, eg. custom loops.
| | BASS_MIDI_NOCROP | Do not remove empty space (containing no events) from the end of the file.
| | BASS_MIDI_NODRUMPARAM | Do not apply default per-drum reverb/chorus/userfx levels and instead set them all to full. The default is to set different levels for different types of drum, eg. lower levels on kick drums. The userfx levels default to 127 in XG mode and 0 in all other modes. The levels can subsequently be changed via the MIDI_EVENT_DRUM_REVERB and MIDI_EVENT_DRUM_CHORUS and MIDI_EVENT_DRUM_USERFX events. This flag can be toggled at any time using BASS_ChannelFlags, but will only take effect upon a program change or system reset.
| | BASS_MIDI_NODRUMPARAMUSER | Do not apply default per-drum userfx levels and instead set them all to full. This flag is like BASS_MIDI_NODRUMPARAM but only affecting userfx levels.
| | 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_NOSYSRESET | Ignore system reset events (MIDI_EVENT_SYSTEM) when the system mode is unchanged. This flag can be toggled at any time using BASS_ChannelFlags.
| | BASS_MIDI_NOTEOFF1 | Only release the oldest instance upon a note off event (MIDI_EVENT_NOTE with velocity=0) when there are overlapping instances of the note. Otherwise all instances are released. This flag can be toggled at any time using BASS_ChannelFlags.
| | BASS_UNICODE | file is in UTF-16 form. Otherwise it is ANSI on Windows and UTF-8 on other platforms. This flag is ignored when file is not a filename.
|
|
| 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).
|
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 | The BASS_STREAM_AUTOFREE flag cannot be combined with the BASS_STREAM_DECODE flag.
|
| BASS_ERROR_ILLPARAM | filetype and/or length is invalid. length cannot be 0 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!
|
Remarks
BASSMIDI supports standard MIDI format 0/1/2 files. In the case of format 2, the tracks are rendered/played one after another. RIFF MIDI (RMID) files are also supported. The General MIDI standard events are supported, as are several Roland GS and Yamaha XG NRPN and SysEx events. A full list of supported MIDI events can be found in the BASS_MIDI_StreamEvent documentation.
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, which means the file can be deleted or moved after calling this function.
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.
Example
Create a stream of a MIDI file, with a sample rate of 44100hz.
HSTREAM stream = BASS_MIDI_StreamCreateFile(FALSE, "afile.mid", 0, 0, 0, 44100);
See also
BASS_MIDI_StreamCreate, BASS_MIDI_StreamCreateEvents, BASS_MIDI_StreamCreateFileUser, BASS_MIDI_StreamCreateURL, BASS_MIDI_StreamGetChannel, BASS_MIDI_StreamGetEvents, BASS_MIDI_StreamGetMark, BASS_MIDI_StreamLoadSamples, BASS_MIDI_StreamSetFonts, BASS_ATTRIB_MIDI_CPU, BASS_ATTRIB_MIDI_SRC, BASS_CONFIG_MIDI_AUTOFONT, BASS_CONFIG_MIDI_DEFFONT, BASS_CONFIG_MIDI_VOICES
BASS_ChannelGetInfo, BASS_ChannelGetLength, BASS_ChannelGetTags, BASS_ChannelPlay, BASS_ChannelSetAttribute, BASS_ChannelSetDSP, BASS_ChannelSetFX, BASS_ChannelSetLink, BASS_StreamFree