This overload implements Unicode filenames. The BASS_UNICODE flag will be added automatically.
Namespace: Un4seen.Bass.AddOn.Midi
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.2
public static int BASS_MIDI_StreamCreateFile( string file, long offset, long length, BASSFlag flags, int freq )
Parameters
- file
- Type: SystemString
Filename for which a stream should be created. - offset
- Type: SystemInt64
File offset to begin streaming from. - length
- Type: SystemInt64
Data length... 0 = use all data up to the end of the file. - flags
- Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):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. WDM drivers or the BASS_STREAM_DECODE flag are required to use this flag in Windows. See Floating-point channels for more info. BASS_SAMPLE_MONO Decode/play the stream (MP3/MP2/MP1 only) in mono, reducing the CPU usage (if it was originally stereo). This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr). BASS_SAMPLE_3D Use 3D functionality. This is ignored if BASS_DEVICE_3D wasn't specified when calling BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr). 3D streams must be mono. The SPEAKER flags can not be used together with this flag. BASS_SAMPLE_LOOP Loop the events. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag). BASS_STREAM_AUTOFREE Automatically free the stream when it ends. This allows you to stream a file and forget about it, as BASS will automatically free the stream's resources when it has reached the end or when BASS_ChannelStop(Int32) (or BASS_Stop) is called. BASS_STREAM_DECODE Decode the sample data, without outputting it. Use BASS_ChannelGetData(Int32, IntPtr, Int32) to retrieve decoded sample data. The BASS_SAMPLE_SOFTWARE, BASS_SAMPLE_3D, BASS_SAMPLE_FX, BASS_STREAM_AUTOFREE and SPEAKER flags can not be used together with this flag. BASS_SPEAKER_xxx Speaker assignment flags. BASS_MIDI_ASYNC Process events asynchronously in BASS_MIDI_StreamEvent(Int32, Int32, BASSMIDIEvent, Int32) and BASS_MIDI_StreamEvents(Int32, BASSMIDIEventMode, BASS_MIDI_EVENT, Int32) calls. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag). BASS_MIDI_DECAYEND Let the sound decay naturally (including reverb) instead of stopping abruptly at the end of the events, including when looping. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag). 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(Int32, BASSFlag, BASSFlag), but it should generally only be used in BASS_ChannelSetPosition(Int32, Int64, BASSMode) 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 and chorus 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 levels can subsequently be changed via the MIDI_EVENT_DRUM_REVERB and MIDI_EVENT_DRUM_CHORUS events. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag), but will only take effect upon a program change or system reset. BASS_MIDI_NOFX Disable reverb and chorus processing, saving some CPU time. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag). 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(Int32, BASSFlag, BASSFlag). 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(Int32, BASSFlag, BASSFlag). - freq
- Type: SystemInt32
Sample rate (in Hz) to render/play the MIDI at (0 = the rate specified in the BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr) call; 1 = the device's current output rate or the BASS_Init rate if that is not available).
Return Value
Type: Int32If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
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 port 0 (channels 1-16). Channel 10 in each port's block of 16 channels defaults to being a drum channel.
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 overriden using BASS_MIDI_StreamSetFonts(Int32, BASS_MIDI_FONT, Int32). By default, with the BASS_CONFIG_MIDI_AUTOFONT config option enabled, BASSMIDI will also look for a soundfont of the same name as the MIDI file. For example, if the MIDI is "afile.mid", then it will look for a "afile.sf2" (or "afile.mid.sf2"). Note that a MIDI stream can have multiple soundfonts stacked, each providing different presets, for example.
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(Int32, BASSMode), BASS_ChannelGetPosition(Int32, BASSMode) and BASS_ChannelSetPosition(Int32, Int64, BASSMode) to deal in ticks.
Marker, instrument name, cue and lyric events can be retrieved via the BASS_MIDI_StreamGetMark(Int32, BASSMIDIMarker, Int32, BASS_MIDI_MARK) function. Syncs (BASS_SYNC_MIDI_MARKER, BASS_SYNC_MIDI_CUE, BASS_SYNC_MIDI_LYRIC, BASS_SYNC_MIDI_EVENT, BASS_SYNC_MIDI_TICK) can also be used to be notified of their occurrence.
The texts of each track in the MIDI file 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. In addition you might also use the BASS_ChannelGetMidiTrackText(Int32, Int32) method to retrieve the track text.
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.
As well as providing dedicated stream creation functions, BASSMIDI supports the BASS plugin system, adding MIDI file support to the standard BASS stream creation functions - BASS_StreamCreateFile(String, Int64, Int64, BASSFlag), BASS_StreamCreateURL(String, Int32, BASSFlag, DOWNLOADPROC, IntPtr), BASS_StreamCreateFileUser(BASSStreamSystem, BASSFlag, BASS_FILEPROCS, IntPtr). This is enabled using the BASS_PluginLoad function.
MIDI streams created via the plugin system use the sample rate specified in the BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr) call.
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. Sinc interpolation is not available on Windows CE.
ERROR CODE | Description |
---|---|
BASS_ERROR_INIT | BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr) 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 | file is not a valid URL. |
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 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, they are attempting to assign a stereo stream to a mono speaker 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! |