Class MidiUtils

Namespace
SpessaSharp.MIDI.Utils
Assembly
SpessaSharp.dll

A general purpose class for handling MIDI messages.

public static class MidiUtils
Inheritance
MidiUtils
Inherited Members

Fields

GsDataMinLen

public const int GsDataMinLen = 9

Field Value

int

XgDataMinLen

public const int XgDataMinLen = 7

Field Value

int

Methods

AnalyzeNRPN(int, int, int)

Analyzes a MIDI Non-Registered Parameter Number and returns an identification and data for it.

public static MidiUtils.AnalyzedParameter AnalyzeNRPN(int channel, int nrpn, int value)

Parameters

channel int

The MIDI channel number.

nrpn int

The 14-bit NRPN number.

value int

The 14-bit value for that number.

Returns

MidiUtils.AnalyzedParameter

AnalyzeRPN(int, int, int)

Analyzes a MIDI Registered Parameter Number and returns an identification and data for it.

public static MidiUtils.AnalyzedParameter AnalyzeRPN(int channel, int rpn, int value)

Parameters

channel int

The MIDI channel number.

rpn int

The 14-bit RPN number.

value int

The 14-bit value for that number.

Returns

MidiUtils.AnalyzedParameter

AnalyzeSysEx(MidiMessage)

Analyzes a MIDI System Exclusive message and returns an identification and data for it.

public static MidiUtils.AnalyzedMessage AnalyzeSysEx(MidiMessage e)

Parameters

e MidiMessage

The message to analyze

Returns

MidiUtils.AnalyzedMessage

AnalyzeSysEx(ReadOnlySpan<byte>)

Analyzes a MIDI System Exclusive message and returns an identification and data for it.

public static MidiUtils.AnalyzedMessage AnalyzeSysEx(ReadOnlySpan<byte> syx)

Parameters

syx ReadOnlySpan<byte>

The System Exclusive message, WITHOUT the first 0xF0 System Exclusive byte!

Returns

MidiUtils.AnalyzedMessage

ChannelToSyx(int)

Channel number to GS/XG "part number"

public static int ChannelToSyx(int chan)

Parameters

chan int

Returns

int

DeviceControl(int, ReadOnlySpan<byte>)

Gets a raw Device Control System Exclusive message bytes, without the 0xF0 status byte.

public static byte[] DeviceControl(int subID, ReadOnlySpan<byte> data)

Parameters

subID int

The sub ID.

data ReadOnlySpan<byte>

Data, can be multiple bytes.

Returns

byte[]

DeviceControlMessage(int, int, ReadOnlySpan<byte>)

Gets a Device Control System Exclusive MIDI message.

public static MidiMessage DeviceControlMessage(int ticks, int subID, ReadOnlySpan<byte> data)

Parameters

ticks int

The tick time of the message.

subID int

The sub ID.

data ReadOnlySpan<byte>

Data, can be multiple bytes.

Returns

MidiMessage

Gs(int, int, int, byte)

public static byte[] Gs(int a1, int a2, int a3, byte data)

Parameters

a1 int
a2 int
a3 int
data byte

Returns

byte[]

Gs(int, int, int, byte, byte)

public static byte[] Gs(int a1, int a2, int a3, byte data1, byte data2)

Parameters

a1 int
a2 int
a3 int
data1 byte
data2 byte

Returns

byte[]

Gs(int, int, int, ReadOnlySpan<byte>, Span<byte>)

Gets raw GS System Exclusive message, without the 0xF0 status byte.

public static ReadOnlySpan<byte> Gs(int a1, int a2, int a3, ReadOnlySpan<byte> data, Span<byte> result)

Parameters

a1 int

Address 1

a2 int

Address 2

a3 int

Address 3

data ReadOnlySpan<byte>

Data, can be multiple bytes.

result Span<byte>

The final output, whose len must be GsDataMinLen + data.Length

Returns

ReadOnlySpan<byte>

The same result provided for convenience

Exceptions

ArgumentException

GsMessage(int, int, int, int, ReadOnlySpan<byte>)

Sends a GS System Exclusive address

public static MidiMessage GsMessage(int ticks, int a1, int a2, int a3, ReadOnlySpan<byte> data)

Parameters

ticks int
a1 int

Address 1

a2 int

Address 2

a3 int

Address 3

data ReadOnlySpan<byte>

Data, can be multiple bytes

Returns

MidiMessage

Reset(int, System)

Gets a selected reset System Exclusive MIDI message.

public static MidiMessage Reset(int ticks, Midi.System system)

Parameters

ticks int
system Midi.System

The system to reset into.

Returns

MidiMessage

Set(int, System, GlobalMidiParameter)

Returns a list of MIDI events needed to set the given parameter.

public static MidiMessage[] Set(int ticks, Midi.System system, GlobalMidiParameter parameter)

Parameters

ticks int

The ticks for all events.

system Midi.System

If the message has multiple ways of setting it, this selects the preferred way. Otherwise, it prefers Universal (GM).

parameter GlobalMidiParameter

The parameter and value to set.

Returns

MidiMessage[]

The list of MIDIMessages that set the parameter.

Set(int, int, System, ChannelMidiParameter)

Returns a list of MIDI events needed to set the given parameter.

public static MidiMessage[] Set(int ticks, int channel, Midi.System system, ChannelMidiParameter parameter)

Parameters

ticks int

The ticks for all events.

channel int

The channel number.

system Midi.System

If the message has multiple ways of setting it, this selects the preferred way. Otherwise, it prefers Universal (GM).

parameter ChannelMidiParameter

The parameter and value to set.

Returns

MidiMessage[]

The list of MIDIMessages that set the parameter.

Syx(int, ReadOnlySpan<byte>)

Turns raw SysEx bytes (without the 0xF0 status byte) into a MIDIMessage.

public static MidiMessage Syx(int ticks, ReadOnlySpan<byte> data)

Parameters

ticks int

The tick time of the message.

data ReadOnlySpan<byte>

The data for the message, without the 0xF0 status byte.

Returns

MidiMessage

SyxToChannel(int)

GS/XG "part number" to channel number.

public static int SyxToChannel(int part)

Parameters

part int

Returns

int

Xg(int, int, int, ReadOnlySpan<byte>, Span<byte>)

Gets raw XG System Exclusive message bytes, without the 0xF0 status byte.

public static Span<byte> Xg(int a1, int a2, int a3, ReadOnlySpan<byte> data, Span<byte> result)

Parameters

a1 int

Address 1

a2 int

Address 2

a3 int

Address 3

data ReadOnlySpan<byte>

Data, can be multiple bytes.

result Span<byte>

Returns

Span<byte>

XgMessage(int, int, int, int, ReadOnlySpan<byte>)

Gets a XG System Exclusive MIDI message

public static MidiMessage XgMessage(int ticks, int a1, int a2, int a3, ReadOnlySpan<byte> data)

Parameters

ticks int

The tick time of the message.

a1 int

Address 1

a2 int

Address 2

a3 int

Address 3

data ReadOnlySpan<byte>

Data, can be multiple bytes

Returns

MidiMessage