Class BassMidi
BassMidi is a BASS addon enabling the playback of MIDI files and real-time events, using SF2 soundfonts to provide the sounds.
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.Midi.dll
Syntax
public static class BassMidi : object
Remarks
Supports: .midi, .mid, .rmi, .kar
Fields
ChorusChannel
ReverbChannel
UserFXChannel
Properties
AutoFont
Automatically load matching soundfonts? If set to 1 (default), BASSMIDI will try to load a soundfont matching the MIDI file. If set to 2, the matching soundfont will also be used on all banks.
Declaration
public static int AutoFont { get; set; }
Property Value
Int32
|
Compact
Automatically compact all soundfonts following a configuration change? compact (bool): If true, all soundfonts are compacted following a MIDI stream being freed, or a StreamSetFonts(Int32, MidiFont[], Int32) call. The compacting isn't performed immediately upon a MIDI stream being freed or StreamSetFonts(Int32, MidiFont[], Int32) being called. It's actually done 2 seconds later (in another thread), so that if another MIDI stream starts using the soundfonts in the meantime, they aren't needlessly closed and reopened. Samples that have been preloaded by FontLoad(Int32, Int32, Int32) are not affected by automatic compacting. Other samples that have been preloaded by StreamLoadSamples(Int32) are affected though, so it is probably wise to disable this option when using that function. By default, this option is enabled.
Declaration
public static bool Compact { get; set; }
Property Value
Boolean
|
DefaultFont
Default soundfont usage filename (string): Filename of the default soundfont to use (null = no default soundfont). If the specified soundfont cannot be loaded, the default soundfont setting will remain as it is. On Windows, the default is to use one of the Creative soundfonts (28MBGM.SF2 or CT8MGM.SF2 or CT4MGM.SF2 or CT2MGM.SF2), if present in the windows system directory.
Declaration
public static string DefaultFont { get; set; }
Property Value
String
|
InputPorts
The number of MIDI Input ports to make available (Linux Only).
ports (int): Number of Input ports... 0 (min) - 10 (max).
MIDI Input ports allow MIDI data to be received from other software, not only MIDI devices.
Once a port has been initialized via
Declaration
public static int InputPorts { get; set; }
Property Value
Int32
|
Voices
The maximum number of samples to play at a time (polyphony). voices (int): Maximum number of samples to play at a time... 1 (min) - 1000 (max). This setting determines the maximum number of samples that can play together in a single MIDI stream. This isn't necessarily the same thing as the maximum number of notes, due to presets often layering multiple samples. When there are no voices available to play a new sample, the voice with the lowest volume will be killed to make way for it. The more voices that are used, the more CPU that is required. So this option can be used to restrict that, for example on a less powerful system. The CPU usage of a MIDI stream can also be restricted via the MidiCPU attribute. Changing this setting only affects subsequently created MIDI streams, not any that have already been created. The default setting is 128 voices. Platform-specific The default setting is 100, except on iOS, where it is 40.
Declaration
public static int Voices { get; set; }
Property Value
Int32
|
Methods
ConvertEvents(IntPtr, Int32, MidiEvent[], Int32, MidiEventsMode)
Convert raw MIDI data to MidiEvent structures.
Declaration
public static int ConvertEvents(IntPtr Data, int Length, MidiEvent[] Events, int Count, MidiEventsMode Flags)
Parameters
IntPtr
Data
The raw MIDI data. |
Int32
Length
The length of the data. |
MidiEvent[]
Events
Pointer to an array to receive the events... |
Int32
Count
The maximum number of events to convert. |
MidiEventsMode
Flags
A combination of NoRunningStatus and Time. |
Returns
Int32
If successful, the number of events processed is returned, else -1 is returned. Use LastError to get the error code. |
ConvertEvents(Byte[], Int32, MidiEvent[], Int32, MidiEventsMode)
Convert raw MIDI data to MidiEvent structures.
Declaration
public static int ConvertEvents(byte[] Data, int Length, MidiEvent[] Events, int Count, MidiEventsMode Flags)
Parameters
Byte[]
Data
The raw MIDI data. |
Int32
Length
The length of the data. |
MidiEvent[]
Events
An array to receive the events... null = get the number of events without getting the events themselves. |
Int32
Count
The maximum number of events to convert. |
MidiEventsMode
Flags
A combination of NoRunningStatus and Time. |
Returns
Int32
If successful, the number of events processed is returned, else -1 is returned. Use LastError to get the error code. |
CreateStream(IntPtr, Int64, Int64, BassFlags, Int32)
Create a stream from Memory (IntPtr).
Declaration
public static int CreateStream(IntPtr Memory, long Offset, long Length, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
IntPtr
Memory
|
Int64
Offset
|
Int64
Length
|
BassFlags
Flags
|
Int32
Frequency
|
Returns
Int32
|
CreateStream(MidiEvent[], Int32, BassFlags, Int32)
Creates a sample stream from a sequence of MIDI events.
Declaration
public static int CreateStream(MidiEvent[] Events, int PulsesPerQuarterNote, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
MidiEvent[]
Events
An array of MidiEvents containing the event sequence to play (the array should be terminated with a End event). |
Int32
PulsesPerQuarterNote
The number of pulses per quarter note (or ticks per beat) value of the MIDI stream to create. |
BassFlags
Flags
A combination of BassFlags. |
Int32
Frequency
Sample rate to render/play the MIDI at (0 = the rate specified in the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) call; 1 = the device's current output rate (or the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) BASS_Init rate if that is not available). |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
This function creates a 16 channel MIDI stream to play a predefined sequence of MIDI events. Any of the standard MIDI events can be used, but Level, Transpose, and SystemEx events are not available and will be ignored. The sequence should end with a End event. Multiple tracks are possible via the EndTrack event, which signals the end of a track; the next event will be in a new track. Any Tempo events should be in the first 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 StreamSetFonts(Int32, MidiFont[], Int32).
Platform-specific
On Android and iOS, sinc interpolation requires a NEON-supporting CPU; the SincInterpolation flag will otherwise be ignored. Sinc interpolation is not available on Windows CE.
CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr, Int32)
Create a stream using User File Procedures.
Declaration
public static int CreateStream(StreamSystem System, BassFlags Flags, FileProcedures Procedures, IntPtr User = null, int Frequency = 0)
Parameters
StreamSystem
System
|
BassFlags
Flags
|
FileProcedures
Procedures
|
IntPtr
User
|
Int32
Frequency
|
Returns
Int32
|
CreateStream(Byte[], Int64, Int64, BassFlags, Int32)
Create a stream from Memory (byte[]).
Declaration
public static int CreateStream(byte[] Memory, long Offset, long Length, BassFlags Flags, int Frequency = 0)
Parameters
Byte[]
Memory
|
Int64
Offset
|
Int64
Length
|
BassFlags
Flags
|
Int32
Frequency
|
Returns
Int32
|
CreateStream(Int32, BassFlags, Int32)
Creates a sample stream to render real-time MIDI events.
Declaration
public static int CreateStream(int Channels, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
Int32
Channels
The number of MIDI channels: 1 (min) - 128 (max). |
BassFlags
Flags
A combination of BassFlags. |
Int32
Frequency
Sample rate (in Hz) to render/play the MIDI at (0 = the rate specified in the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) call; 1 = the device's current output rate or the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) rate if that is not available). |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
This function creates a stream solely for real-time MIDI events. As it's not based on any file, the stream has no predetermined length and is never-ending. Seeking isn't possible, but it is possible to reset everything, including playback buffer, by calling ChannelPlay(Int32, Boolean) (Restart = true) or ChannelSetPosition(Int32, Int64, PositionFlags) (Position = 0).
MIDI events are applied using the StreamEvent(Int32, Int32, MidiEventType, Int32) function. If the stream is being played (it's not a decoding channel), then there will be some delay in the effect of the events being heard. This latency can be reduced by making use of the PlaybackBufferLength and UpdatePeriod options.
If a stream has 16 MIDI channels, then channel 10 defaults to percussion/drums and the rest melodic, otherwise they are all melodic. That can be changed using StreamEvent(Int32, Int32, MidiEventType, Int32) and Drums.
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 StreamSetFonts(Int32, MidiFont[], Int32).
To play a MIDI file, use CreateStream(String, Int64, Int64, BassFlags, Int32).
Platform-specific
On Android and iOS, sinc interpolation requires a NEON-supporting CPU; the SincInterpolation flag will otherwise be ignored. Sinc interpolation is not available on Windows CE.
CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr, Int32)
Create a stream from Url.
Declaration
public static int CreateStream(string Url, int Offset, BassFlags Flags, DownloadProcedure Procedure, IntPtr User = null, int Frequency = 0)
Parameters
String
Url
|
Int32
Offset
|
BassFlags
Flags
|
DownloadProcedure
Procedure
|
IntPtr
User
|
Int32
Frequency
|
Returns
Int32
|
CreateStream(String, Int64, Int64, BassFlags, Int32)
Create a stream from file.
Declaration
public static int CreateStream(string File, long Offset = null, long Length = null, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
String
File
|
Int64
Offset
|
Int64
Length
|
BassFlags
Flags
|
Int32
Frequency
|
Returns
Int32
|
FontCompact(Int32)
Compact a soundfont's memory usage.
Declaration
public static bool FontCompact(int Handle)
Parameters
Int32
Handle
The soundfont to get info on (e.g. as returned by FontInit(String, FontInitFlags))... 0 = all soundfonts. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Compacting involves freeing any samples that are currently loaded but unused. The amount of sample data currently loaded can be retrieved using FontGetInfo(Int32, out MidiFontInfo).
FontFree(Int32)
Frees a soundfont.
Declaration
public static bool FontFree(int Handle)
Parameters
Int32
Handle
The soundfont handle to free (e.g. as returned by FontInit(String, FontInitFlags)). |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When a soundfont is freed, it is automatically removed from any MIDI streams that are using it.
FontGetInfo(Int32)
Retrieves information on a soundfont.
Declaration
public static MidiFontInfo FontGetInfo(int Handle)
Parameters
Int32
Handle
The soundfont to get info on (e.g. as returned by FontInit(String, FontInitFlags)). |
Returns
MidiFontInfo
An instance of MidiFontInfo structure is returned. Throws BassException on Error. |
FontGetInfo(Int32, out MidiFontInfo)
Retrieves information on a soundfont.
Declaration
public static bool FontGetInfo(int Handle, out MidiFontInfo Info)
Parameters
Int32
Handle
The soundfont to get info on (e.g. as returned by FontInit(String, FontInitFlags)). |
MidiFontInfo
Info
An instance of MidiFontInfo structure to store the information into. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
FontGetPreset(Int32, Int32, Int32)
Retrieves the name of a preset in a soundfont.
Declaration
public static string FontGetPreset(int Handle, int Preset, int Bank)
Parameters
Int32
Handle
The soundfont handle to get the preset name from. |
Int32
Preset
Preset number to load... -1 = all presets (the first encountered). |
Int32
Bank
Bank number to load... -1 = all banks (the first encountered). |
Returns
String
If successful, the requested preset name is returned, else null is returned. Use LastError to get the error code. |
FontGetPresets(Int32)
Retrieves the presets in a soundfont.
Declaration
public static int[] FontGetPresets(int Handle)
Parameters
Int32
Handle
The soundfont handle to get the preset name from. |
Returns
Int32[]
If successful, an array of presets is returned, else null is returned. Use LastError to get the error code. |
Remarks
The presets are delivered with the preset number in the LOWORD and the bank number in the HIWORD, and in numerically ascending order.
FontGetPresets(Int32, Int32[])
Retrieves the presets in a soundfont.
Declaration
public static bool FontGetPresets(int Handle, int[] Presets)
Parameters
Int32
Handle
The soundfont handle to get the preset name from. |
Int32[]
Presets
The array to receive the presets. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The presets are delivered with the preset number in the LOWORD and the bank number in the HIWORD, and in numerically ascending order.
FontGetVolume(Int32)
Retrieves a soundfont's volume level.
Declaration
public static float FontGetVolume(int Handle)
Parameters
Int32
Handle
The soundfont to get the volume of. |
Returns
Single
If successful, the soundfont's volume level is returned, else -1 is returned. Use LastError to get the error code. |
FontInit(FileProcedures, IntPtr, FontInitFlags)
Initializes a soundfont via user callback functions.
Declaration
public static int FontInit(FileProcedures Procedures, IntPtr User, FontInitFlags Flags)
Parameters
FileProcedures
Procedures
The user defined file function (see FileProcedures). |
IntPtr
User
User instance data to pass to the callback functions. |
FontInitFlags
Flags
Unused. |
Returns
Int32
If successful, the soundfont's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
The unbuffered file system (NoBuffer) is always used by this function.
FontInit(String, FontInitFlags)
Initializes a soundfont from a file (unicode).
Declaration
public static int FontInit(string File, FontInitFlags Flags)
Parameters
String
File
The file name of the sound font (e.g. an .sf2 file). |
FontInitFlags
Flags
Any combination of FontInitFlags. |
Returns
Int32
If successful, the soundfont's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASSMIDI uses SF2 and/or SFZ soundfonts to provide the sounds to use in the rendering of MIDI files. Several soundfonts can be found on the internet, including a couple on the BASS website.
A soundfont needs to be initialized before it can be used to render MIDI streams. Once initialized, a soundfont can be assigned to MIDI streams using the StreamSetFonts(Int32, MidiFont[], Int32) function. A single soundfont can be shared by multiple MIDI streams.
Information on the initialized soundfont can be retrieved using FontGetInfo(Int32, out MidiFontInfo).
If a soundfont is initialized multiple times, each instance will have its own handle but share the same sample/etc data.
Soundfonts use PCM sample data as standard, but BASSMIDI can accept any format that is supported by BASS or its add-ons. The FontPack function can be used to compress the sample data in SF2 files. SFZ samples are in separate files and can be compressed using standard encoding tools.
Using soundfonts that are located somewhere other than the file system is possible via
SFZ support
The following SFZ opcodes are supported: ampeg_attack, ampeg_decay, ampeg_delay, ampeg_hold, ampeg_release, ampeg_sustain, ampeg_vel2attack, ampeg_vel2decay, amplfo_delay/fillfo_delay/pitchlfo_delay, amplfo_depth, amplfo_freq/fillfo_freq/pitchlfo_freq, amp_veltrack, cutoff, effect1, effect2, end, fileg_attack/pitcheg_attack, fileg_decay/pitcheg_decay, fileg_delay/pitcheg_delay, fileg_depth, fileg_hold/pitcheg_hold, fileg_release/pitcheg_release, fileg_sustain/pitcheg_sustain, fileg_vel2depth, fillfo_depth, fil_veltrack, group, hikey, hivel, key, lokey, loop_end, loop_mode, loop_start, lovel, offset, off_by, pan, pitcheg_depth, pitchlfo_depth, pitch_keycenter, pitch_keytrack, pitch_veltrack, resonance, sample, seq_length, seq_position, transpose, tune, volume. The fil_type opcode is also supported, but only to confirm that a low pass filter is wanted (the filter will be disabled otherwise). The combined EG and LFO entries in the opcode list reflect that there is a shared EG for pitch/filter and a shared LFO for amplitude/pitch/filter, as is the case in SF2. Information on these (and other) SFZ opcodes can be found at www.sfzformat.com.
Platform-specific
The MidiFontMemoryMap option is not available on big-endian systems (eg. PowerPC) as a soundfont's little-endian sample data cannot be played directly from a mapping; its byte order needs to be reversed.
FontLoad(Int32, Int32, Int32)
Preloads presets from a soundfont.
Declaration
public static bool FontLoad(int Handle, int Preset, int Bank)
Parameters
Int32
Handle
The soundfont handle. |
Int32
Preset
Preset number to load... -1 = all presets. |
Int32
Bank
Bank number to load... -1 = all banks. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Samples are normally loaded as they are needed while rendering a MIDI stream, which can result in CPU spikes, particularly with packed soundfonts. That generally won't cause any problems, but when smooth/constant performance is critical this function can be used to preload the samples before rendering, so avoiding the need to load them while rendering.
When preloading samples to render a particular MIDI stream, it is more efficient to use StreamLoadSamples(Int32) to preload the specific samples that the MIDI stream will use, rather than preloading the entire soundfont.
Samples that are preloaded by this function are not affected by automatic compacting via the Compact option, but can be compacted/unloaded manually with FontCompact(Int32).
A soundfont should not be preloaded while it's being used to render any MIDI streams, as that could delay the rendering.
FontSetVolume(Int32, Single)
Sets a soundfont's volume level.
Declaration
public static bool FontSetVolume(int Handle, float Volume)
Parameters
Int32
Handle
The soundfont to set the volume of. |
Single
Volume
The volume level... 0=silent, 1.0=normal/default. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
By default, some soundfonts may be louder than others, which could be a problem when mixing multiple soundfonts. This function can be used to compensate for any differences, by raising the level of the quieter soundfonts or lowering the louder ones.
Changes take immediate effect in any MIDI streams that are using the soundfont.
FontUnload(Int32, Int32, Int32)
Unloads presets from a soundfont.
Declaration
public static bool FontUnload(int Handle, int Preset, int Bank)
Parameters
Int32
Handle
The soundfont handle. |
Int32
Preset
Preset number to load... -1 = all presets. |
Int32
Bank
Bank number to load... -1 = all banks. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
An unloaded preset will be loaded again when needed by a MIDI stream. Any samples that are currently being used by a MIDI stream will not be unloaded.
FontUnpack(Int32, String)
Produces a decompressed version of a packed soundfont.
Declaration
public static bool FontUnpack(int Handle, string OutFile)
Parameters
Int32
Handle
The soundfont to unpack. |
String
OutFile
Filename for the unpacked soundfont. |
Returns
Boolean
If successful, the true is returned, else false is returned. Use LastError to get the error code. |
Remarks
To unpack a soundfont, the appropriate BASS add-on needs to be loaded (via PluginLoad(String)) to decode the samples. For example, if the samples are FLAC encoded, BASSFLAC would need to be loaded. BASS also needs to have been initialized, using Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr). For just unpacking a soundfont, the NoSoundDevice could be used.
A soundfont should not be unpacked while it is being used to render any MIDI streams, as that could delay the rendering. FontGetInfo(Int32, out MidiFontInfo) can be used to check if a soundfont is packed.
StreamEvent(Int32, Int32, MidiEventType, Byte, Byte)
Applies an event to a MIDI stream.
Declaration
public static bool StreamEvent(int Handle, int Channel, MidiEventType Event, byte LowParameter, byte HighParameter)
Parameters
Int32
Handle
The MIDI stream to apply the event to (as returned by CreateStream(Int32, BassFlags, Int32)). |
Int32
Channel
The MIDI channel to apply the event to... 0 = channel 1. |
MidiEventType
Event
The event to apply (see MidiEventType for details). |
Byte
LowParameter
The event parameter (LOBYTE), (see MidiEventType for details). |
Byte
HighParameter
The event parameter (HIBYTE), (see MidiEventType for details). |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
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 MidiChannels attribute.
Event syncs (see SyncFlags) are not triggered by this function. If sync triggering is wanted, StreamEvents(Int32, MidiEventsMode, MidiEvent[], Int32) can be used instead.
If the MIDI stream is being played (it's 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 PlaybackBufferLength and UpdatePeriod config options when creating the stream.
StreamEvent(Int32, Int32, MidiEventType, Int32)
Applies an event to a MIDI stream.
Declaration
public static bool StreamEvent(int Handle, int Channel, MidiEventType Event, int Parameter)
Parameters
Int32
Handle
The MIDI stream to apply the event to (as returned by CreateStream(Int32, BassFlags, Int32)). |
Int32
Channel
The MIDI channel to apply the event to... 0 = channel 1. |
MidiEventType
Event
The event to apply (see MidiEventType for details). |
Int32
Parameter
The event parameter (see MidiEventType for details). |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
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 MidiChannels attribute.
Event syncs (see SyncFlags) are not triggered by this function. If sync triggering is wanted, StreamEvents(Int32, MidiEventsMode, MidiEvent[], Int32) can be used instead.
If the MIDI stream is being played (it's 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 PlaybackBufferLength and UpdatePeriod config options when creating the stream.
StreamEvents(Int32, MidiEventsMode, IntPtr, Int32)
Applies any number of events to a MIDI stream.
Declaration
public static int StreamEvents(int Handle, MidiEventsMode Mode, IntPtr Events, int Length)
Parameters
Int32
Handle
The MIDI stream to apply the events to. |
MidiEventsMode
Mode
Midi Events Mode. |
IntPtr
Events
The event data (raw data - byte[]). |
Int32
Length
Length of Events data according to |
Returns
Int32
If successful, the number of events processed is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
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 MidiChannels attribute.
If the MIDI stream is being played (it's 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 PlaybackBufferLength and UpdatePeriod config options when creating the stream.
StreamEvents(Int32, MidiEventsMode, MidiEvent[], Int32)
Applies any number of events to a MIDI stream.
Declaration
public static int StreamEvents(int Handle, MidiEventsMode Mode, MidiEvent[] Events, int Length = 0)
Parameters
Int32
Handle
The MIDI stream to apply the events to. |
MidiEventsMode
Mode
Midi Events Mode. |
MidiEvent[]
Events
The event data (an array of MidiEvent structures). |
Int32
Length
No of MidiEvent items... 0 = No of items in |
Returns
Int32
If successful, the number of events processed is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
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 MidiChannels attribute.
If the MIDI stream is being played (it's 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 PlaybackBufferLength and UpdatePeriod config options when creating the stream.
StreamEvents(Int32, MidiEventsMode, Byte[], Int32)
Applies any number of events to a MIDI stream.
Declaration
public static int StreamEvents(int Handle, MidiEventsMode Mode, byte[] Raw, int Length = 0)
Parameters
Int32
Handle
The MIDI stream to apply the events to. |
MidiEventsMode
Mode
Midi Events Mode. |
Byte[]
Raw
The event data (raw data - byte[]). |
Int32
Length
No of |
Returns
Int32
If successful, the number of events processed is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
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 MidiChannels attribute.
If the MIDI stream is being played (it's 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 PlaybackBufferLength and UpdatePeriod config options when creating the stream.
StreamEvents(Int32, MidiEventsMode, Int32, Byte[], Int32)
Applies any number of events to a MIDI stream.
Declaration
public static int StreamEvents(int Handle, MidiEventsMode Mode, int Channel, byte[] Raw, int Length = 0)
Parameters
Int32
Handle
The MIDI stream to apply the events to. |
MidiEventsMode
Mode
Midi Events Mode. |
Int32
Channel
To overcome the 16 channel limit, the event data's channel information can optionally be overridden by adding the new channel number to this parameter, where 1 = the 1st channel - else leave to 0. |
Byte[]
Raw
The event data (raw data - byte[]). |
Int32
Length
No of |
Returns
Int32
If successful, the number of events processed is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
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 MidiChannels attribute.
If the MIDI stream is being played (it's 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 PlaybackBufferLength and UpdatePeriod config options when creating the stream.
StreamGetChannel(Int32, Int32)
Gets a HSTREAM handle for a MIDI channel (e.g. to set DSP/FX on individual MIDI channels).
Declaration
public static int StreamGetChannel(int Handle, int Channel)
Parameters
Int32
Handle
The midi stream to get a channel from. |
Int32
Channel
The MIDI channel... 0 = channel 1. Or one of the following special channels: ChorusChannel = Chorus mix channel. The default chorus processing is replaced by the stream's processing. ReverbChannel = Reverb mix channel. The default reverb processing is replaced by the stream's processing. UserFXChannel = User effect mix channel. |
Returns
Int32
If successful, the channel handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
By default, MIDI channels do not have streams assigned to them; a MIDI channel only gets a stream when this function is called, which it then keeps until the MIDI stream is freed. MIDI channel streams can also be freed before then via StreamFree(Int32). Each MIDI channel stream increases the CPU usage slightly, even if there are no DSP/FX set on them, so for optimal performance they should not be activated when unnecessary.
The MIDI channel streams have a different path to the final mix than the BASSMIDI reverb/chorus processing, which means that the reverb/chorus will not be present in the data received by any DSP/FX set on the streams and nor will the reverb/chorus be applied to the DSP/FX output; the reverb/chorus processing will use the channel's original data.
The MIDI channel streams can only be used to set DSP/FX on the channels.
They cannot be used with
StreamGetEvent(Int32, Int32, MidiEventType)
Retrieves the current value of an event in a MIDI stream channel.
Declaration
public static int StreamGetEvent(int Handle, int Channel, MidiEventType Event)
Parameters
Int32
Handle
The MIDI stream to retrieve the event from (as returned by CreateStream(Int32, BassFlags, Int32). |
Int32
Channel
The MIDI channel to get the event value from... 0 = channel 1. |
MidiEventType
Event
The event value to retrieve. With the drum key events (DrumCutOff/etc) and the Note and ScaleTuning events, the HIWORD can be used to specify which key/note to get the value from. |
Returns
Int32
The event parameter if successful - else -1 (use LastError to get the error code). |
Remarks
SYNCs can be used to be informed of when event values change.
StreamGetEvents(Int32, Int32, MidiEventType)
Retrieves the events in a MIDI file stream.
Declaration
public static MidiEvent[] StreamGetEvents(int Handle, int Track, MidiEventType Filter)
Parameters
Int32
Handle
The MIDI stream to get the events from. |
Int32
Track
The track to get the events from... 0 = 1st track. |
MidiEventType
Filter
The type of event to retrieve (use None to retrieve all events). |
Returns
MidiEvent[]
An array of MidiEvent configuration entries on success, null on error. |
StreamGetEvents(Int32, Int32, MidiEventType, MidiEvent[])
Retrieves the events in a MIDI file stream.
Declaration
public static int StreamGetEvents(int Handle, int Track, MidiEventType Filter, MidiEvent[] Events)
Parameters
Int32
Handle
The MIDI stream to get the events from. |
Int32
Track
The track to get the events from... 0 = 1st track. |
MidiEventType
Filter
The type of event to retrieve (use None to retrieve all events). |
MidiEvent[]
Events
An array of MidiEvents to retrieve the events (null = get the number of events without getting the events themselves). |
Returns
Int32
If successful, the number of events is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
This function should first be called with Events
= null to get the number of events, before allocating an array of the required size and retrieving the events.
StreamGetEvents(Int32, Int32, MidiEventType, MidiEvent[], Int32, Int32)
Retrieves a portion of the events in a MIDI stream.
Declaration
public static int StreamGetEvents(int Handle, int Track, MidiEventType Filter, MidiEvent[] Events, int Start, int Count)
Parameters
Int32
Handle
The MIDI stream to get the events from. |
Int32
Track
The track to get the events from... 0 = 1st track, -1 = all tracks. |
MidiEventType
Filter
The type of event to retrieve (use None to retrieve all events). |
MidiEvent[]
Events
An array of MidiEvents to retrieve the events (null = get the number of events without getting the events themselves). |
Int32
Start
The first event to retrieve. |
Int32
Count
The maximum number of events to retrieve. |
Returns
Int32
If successful, the number of events is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
This function should first be called with Events
= null to get the number of events, before allocating an array of the required size and retrieving the events.
This function is identical to StreamGetEvents(Int32, Int32, MidiEventType, MidiEvent[]) except that it can retrieve a portion of the events instead of all of them.
StreamGetFonts(Int32)
Retrieves the soundfont configuration of a MIDI stream, or the default soundfont configuration.
Declaration
public static MidiFont[] StreamGetFonts(int Handle)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
Returns
MidiFont[]
An array of MidiFont configuration entries if successfull - or null on error. |
StreamGetFonts(Int32, IntPtr, Int32)
Retrieves the soundfont configuration of a MIDI stream, or the default soundfont configuration.
Declaration
public static int StreamGetFonts(int Handle, IntPtr Fonts, int Count)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
IntPtr
Fonts
An |
Int32
Count
The maximum number of elements to retrieve. This and fonts can be 0, to get the number of elements in the soundfont configuration. |
Returns
Int32
If successful, the number of soundfonts in the configuration (which can be higher than count) is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
When a soundfont matching the MIDI file is loaded, it will be the first element in the returned configuration.
StreamGetFonts(Int32, MidiFont[], Int32)
Retrieves the soundfont configuration of a MIDI stream, or the default soundfont configuration.
Declaration
public static int StreamGetFonts(int Handle, MidiFont[] Fonts, int Count)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
MidiFont[]
Fonts
An array to retrieve the soundfont configuration. |
Int32
Count
The maximum number of elements to retrieve in the fonts array. This and fonts can be 0, to get the number of elements in the soundfont configuration. |
Returns
Int32
If successful, the number of soundfonts in the configuration (which can be higher than count) is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
When a soundfont matching the MIDI file is loaded, it will be the first element in the returned configuration.
StreamGetFonts(Int32, MidiFontEx[], Int32)
Retrieves the soundfont configuration of a MIDI stream, or the default soundfont configuration.
Declaration
public static int StreamGetFonts(int Handle, MidiFontEx[] Fonts, int Count)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
MidiFontEx[]
Fonts
An array to retrieve the soundfont configuration. |
Int32
Count
The maximum number of elements to retrieve in the fonts array. This and fonts can be 0, to get the number of elements in the soundfont configuration. |
Returns
Int32
If successful, the number of soundfonts in the configuration (which can be higher than count) is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
When a soundfont matching the MIDI file is loaded, it will be the first element in the returned configuration.
StreamGetFontsCount(Int32)
Retrieves the number of elements in the soundfont configuration.
Declaration
public static int StreamGetFontsCount(int Handle)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
Returns
Int32
If successful, the number of soundfonts in the configuration is returned, else -1 is returned. Use LastError to get the error code. |
StreamGetFontsEx(Int32)
Retrieves the soundfont configuration of a MIDI stream, or the default soundfont configuration.
Declaration
public static MidiFontEx[] StreamGetFontsEx(int Handle)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
Returns
MidiFontEx[]
An array of MidiFontEx configuration entries if successfull - or null on error. |
StreamGetMark(Int32, MidiMarkerType, Int32)
Retrieves a marker from a MIDI stream.
Declaration
public static MidiMarker StreamGetMark(int Handle, MidiMarkerType Type, int Index)
Parameters
Int32
Handle
The MIDI stream to retrieve the marker from. |
MidiMarkerType
Type
The type of marker to retrieve. |
Int32
Index
The marker to retrieve... 0 = the first. |
Returns
MidiMarker
On success, an instance of the MidiMarker structure is returned. Use LastError to get the error code. |
Remarks
The markers are ordered chronologically.
Syncs can be used to be informed of when markers are encountered during playback.
If a lyric marker text begins with a '/' (slash) character, that means a new line should be started. If the text begins with a '' (backslash) character, the display should be cleared. Lyrics can sometimes be found in Text instead of Lyric markers.
StreamGetMark(Int32, MidiMarkerType, Int32, out MidiMarker)
Retrieves a marker from a MIDI stream.
Declaration
public static bool StreamGetMark(int Handle, MidiMarkerType Type, int Index, out MidiMarker Mark)
Parameters
Int32
Handle
The MIDI stream to retrieve the marker from. |
MidiMarkerType
Type
The type of marker to retrieve. |
Int32
Index
The marker to retrieve... 0 = the first. |
MidiMarker
Mark
The MidiMarker structure to receive the marker details into. |
Returns
Boolean
true on success, else false is returned. Use LastError to get the error code. |
Remarks
The markers are ordered chronologically.
Syncs can be used to be informed of when markers are encountered during playback.
If a lyric marker text begins with a '/' (slash) character, that means a new line should be started. If the text begins with a '' (backslash) character, the display should be cleared. Lyrics can sometimes be found in Text instead of Lyric markers.
StreamGetMarks(Int32, Int32, MidiMarkerType)
Retrieves the markers in a MIDI file stream.
Declaration
public static MidiMarker[] StreamGetMarks(int Handle, int Track, MidiMarkerType Type)
Parameters
Int32
Handle
The MIDI stream to retrieve the markers from. |
Int32
Track
The track to get the markers from... 0 = 1st track, -1 = all tracks. |
MidiMarkerType
Type
The type of marker to retrieve. |
Returns
MidiMarker[]
On success, an array of MidiMarker instances is returned, else null is returned. Use LastError to get the error code. |
Remarks
The markers are ordered chronologically, and by track number (lowest first) if multiple markers have the same position.
SYNCs can be used to be informed of when markers are encountered during playback.
If a lyric marker text begins with a / (slash) character, that means a new line should be started. If the text begins with a \ (backslash) character, the display should be cleared. Lyrics can sometimes be found in Text instead of Lyric markers.
StreamGetMarks(Int32, Int32, MidiMarkerType, MidiMarker[])
Retrieves the markers in a MIDI file stream.
Declaration
public static int StreamGetMarks(int Handle, int Track, MidiMarkerType Type, MidiMarker[] Marks)
Parameters
Int32
Handle
The MIDI stream to retrieve the markers from. |
Int32
Track
The track to get the markers from... 0 = 1st track, -1 = all tracks. |
MidiMarkerType
Type
The type of marker to retrieve. |
MidiMarker[]
Marks
An array of MidiMarkers to receive the data into. Can be null to get the no of markers. |
Returns
Int32
No of markers in the array on success, -1 on failure. Use LastError to get the error code. |
Remarks
The markers are ordered chronologically, and by track number (lowest first) if multiple markers have the same position.
SYNCs can be used to be informed of when markers are encountered during playback.
If a lyric marker text begins with a / (slash) character, that means a new line should be started. If the text begins with a \ (backslash) character, the display should be cleared. Lyrics can sometimes be found in Text instead of Lyric markers.
StreamGetPreset(Int32, Int32, out MidiFont)
Retrieves the preset currently in use on a channel of a MIDI stream.
Declaration
public static bool StreamGetPreset(int Handle, int Channel, out MidiFont Font)
Parameters
Int32
Handle
The MIDI stream to retrieve the soundfont configuration of... 0 = get default soundfont configuration. |
Int32
Channel
The MIDI channel... 0 = channel 1. |
MidiFont
Font
The structure to receive font information. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function tells what preset from what soundfont is currently being used on a particular MIDI channel. That information can be used to get the preset's name from FontGetPreset(Int32, Int32, Int32). No preset information will be available for a MIDI channel until a note is played in that channel. The present and bank numbers will not necessarily match the channel's current Program and Bank event values, but rather what the MIDI stream's soundfont configuration maps those event values to.
StreamLoadSamples(Int32)
Preloads the samples required by a MIDI file stream.
Declaration
public static bool StreamLoadSamples(int Handle)
Parameters
Int32
Handle
The MIDI stream handle. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Samples are normally loaded as they are needed while rendering a MIDI stream, which can result in CPU spikes, particularly with packed soundfonts. That generally won't cause any problems, but when smooth/constant performance is critical this function can be used to preload the samples before rendering, so avoiding the need to load them while rendering.
Preloaded samples can be compacted/unloaded just like any other samples, so it is probably wise to disable the Compact option when preloading samples, to avoid any chance of the samples subsequently being automatically unloaded.
This function should not be used while the MIDI stream is being rendered, as that could interrupt the rendering.
StreamSetFilter(Int32, Boolean, MidiFilterProcedure, IntPtr)
Set an event filtering function on a MIDI stream.
Declaration
public static bool StreamSetFilter(int Handle, bool Seeking, MidiFilterProcedure Procedure, IntPtr User = null)
Parameters
Int32
Handle
The MIDI stream handle. |
Boolean
Seeking
Also filter events when seeking. |
MidiFilterProcedure
Procedure
The callback function... null = no filtering. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function allows a MIDI stream to have its events modified during playback via a callback function. The callback function will be called before an event is processed, and it can choose to keep the event as is, or it can modify or drop the event. The filtering can also be applied to events while seeking, so that playback begins in a filtered state after seeking. Filtering only applies to a MIDI stream's defined event sequence, not any events that are applied via StreamEvent(Int32, Int32, MidiEventType, Byte, Byte) or StreamEvents(Int32, MidiEventsMode, Byte[], Int32).
StreamSetFonts(Int32, MidiFont[], Int32)
Applies a soundfont configuration to a MIDI stream, or sets the default soundfont configuration.
Declaration
public static int StreamSetFonts(int Handle, MidiFont[] Fonts, int Count)
Parameters
Int32
Handle
The MIDI stream to apply the soundfonts to... 0 = set default soundfont configuration. |
MidiFont[]
Fonts
An array of MidiFont soundfonts to apply. |
Int32
Count
The number of elements in the fonts array. |
Returns
Int32
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Multiple soundfonts can be stacked, each providing different presets, for example. When a preset is present in multiple soundfonts, the earlier soundfont in the array has priority. When a soundfont matching the MIDI file is loaded, that remains loaded when calling this function, and has priority over all other soundfonts. When a preset is not available on a non-0 bank in any soundfont, BASSMIDI will try to fall back to bank 0; first the LSB and then the MSB if still unsuccessful.
Changing the default configuration only affects subsequently created MIDI streams. Existing streams that are using the previous default configuration will continue to use that previous configuration.
On Windows, the default default configuration will be to use the Creative 4MB (CT4MGM.SF2) or 2MB (CT2MGM.SF2) soundfont when present in the Windows system directory.
StreamSetFonts(Int32, MidiFontEx[], Int32)
Applies a soundfont configuration to a MIDI stream, or sets the default soundfont configuration.
Declaration
public static int StreamSetFonts(int Handle, MidiFontEx[] Fonts, int Count)
Parameters
Int32
Handle
The MIDI stream to apply the soundfonts to... 0 = set default soundfont configuration. |
MidiFontEx[]
Fonts
An array of MidiFontEx soundfonts to apply. |
Int32
Count
The number of elements in the fonts array. |
Returns
Int32
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Multiple soundfonts can be stacked, each providing different presets, for example. When a preset is present in multiple soundfonts, the earlier soundfont in the array has priority. When a soundfont matching the MIDI file is loaded, that remains loaded when calling this function, and has priority over all other soundfonts. When a preset is not available on a non-0 bank in any soundfont, BASSMIDI will try to fall back to bank 0; first the LSB and then the MSB if still unsuccessful.
Changing the default configuration only affects subsequently created MIDI streams. Existing streams that are using the previous default configuration will continue to use that previous configuration.
On Windows, the default default configuration will be to use the Creative 4MB (CT4MGM.SF2) or 2MB (CT2MGM.SF2) soundfont when present in the Windows system directory.