Xeno-rat
Loading...
Searching...
No Matches
NAudio.Midi.MidiEvent Class Reference

Represents an individual MIDI event. More...

Inheritance diagram for NAudio.Midi.MidiEvent:
Collaboration diagram for NAudio.Midi.MidiEvent:

Public Member Functions

virtual int GetAsShortMessage ()
 Returns the short message value calculated based on the channel and command code.
 
 MidiEvent (long absoluteTime, int channel, MidiCommandCode commandCode)
 Creates a MIDI event with specified parameters.
 
virtual MidiEvent Clone ()
 Creates a new object that is a copy of the current instance.
 
override string ToString ()
 Returns a string representation of the current Midi event.
 
virtual void Export (ref long absoluteTime, BinaryWriter writer)
 Exports the MIDI event and updates the absolute time.
 

Static Public Member Functions

static MidiEvent FromRawMessage (int rawMessage)
 Converts a raw MIDI message to a MidiEvent object.
 
static MidiEvent ReadNextEvent (BinaryReader br, MidiEvent previous)
 Reads the next MIDI event from the BinaryReader and returns the corresponding MidiEvent.
 
static bool IsNoteOff (MidiEvent midiEvent)
 Checks if the given MIDI event represents a Note Off message.
 
static bool IsNoteOn (MidiEvent midiEvent)
 Checks if the provided MIDI event is a Note On event and returns true if the velocity is greater than 0.
 
static bool IsEndTrack (MidiEvent midiEvent)
 Checks if the provided MIDI event is an end track event.
 
static int ReadVarInt (BinaryReader br)
 Reads a variable-length encoded integer from the provided BinaryReader and returns the result.
 
static void WriteVarInt (BinaryWriter writer, int value)
 Writes a variable-length encoded integer to the specified BinaryWriter.
 

Protected Member Functions

 MidiEvent ()
 Default constructor.
 

Properties

virtual int Channel [get, set]
 The MIDI Channel Number for this event (1-16)
 
int DeltaTime [get]
 The Delta time for this event.
 
long AbsoluteTime [get, set]
 The absolute time for this event.
 
MidiCommandCode CommandCode [get]
 The command code for this event.
 

Private Member Functions

object ICloneable. Clone ()
 

Private Attributes

MidiCommandCode commandCode
 The MIDI command code.
 
int channel
 
int deltaTime
 
long absoluteTime
 

Detailed Description

Represents an individual MIDI event.

Constructor & Destructor Documentation

◆ MidiEvent() [1/2]

NAudio.Midi.MidiEvent.MidiEvent ( )
inlineprotected

Default constructor.

Here is the caller graph for this function:

◆ MidiEvent() [2/2]

NAudio.Midi.MidiEvent.MidiEvent ( long absoluteTime,
int channel,
MidiCommandCode commandCode )
inline

Creates a MIDI event with specified parameters.

Parameters
absoluteTimeAbsolute time of this event
channelMIDI channel number
commandCodeMIDI command code

Member Function Documentation

◆ Clone() [1/2]

virtual MidiEvent NAudio.Midi.MidiEvent.Clone ( )
virtual

◆ Clone() [2/2]

object ICloneable. NAudio.Midi.MidiEvent.Clone ( )
private

◆ Export()

virtual void NAudio.Midi.MidiEvent.Export ( ref long absoluteTime,
BinaryWriter writer )
inlinevirtual

Exports the MIDI event and updates the absolute time.

Parameters
absoluteTimeThe absolute time of the event.
writerThe BinaryWriter to write the event to.
Exceptions
FormatExceptionThrown when the event is unsorted.

This method exports the MIDI event to the specified BinaryWriter and updates the absolute time. If the event's absolute time is less than the specified absolute time, a FormatException is thrown with the message "Can't export unsorted MIDI events". The method then writes the variable-length quantity representing the time difference to the writer, updates the absolute time, and writes the event data to the writer.

Reimplemented in NAudio.Midi.ChannelAfterTouchEvent, NAudio.Midi.ControlChangeEvent, NAudio.Midi.KeySignatureEvent, NAudio.Midi.MetaEvent, NAudio.Midi.NoteEvent, NAudio.Midi.PatchChangeEvent, NAudio.Midi.PitchWheelChangeEvent, NAudio.Midi.RawMetaEvent, NAudio.Midi.SequencerSpecificEvent, NAudio.Midi.SmpteOffsetEvent, NAudio.Midi.SysexEvent, NAudio.Midi.TempoEvent, NAudio.Midi.TextEvent, NAudio.Midi.TimeSignatureEvent, and NAudio.Midi.TrackSequenceNumberEvent.

Here is the call graph for this function:

◆ FromRawMessage()

static MidiEvent NAudio.Midi.MidiEvent.FromRawMessage ( int rawMessage)
inlinestatic

Converts a raw MIDI message to a MidiEvent object.

Parameters
rawMessageThe raw MIDI message to be converted.
Returns
A MidiEvent object representing the raw MIDI message.

This method parses the raw MIDI message and constructs a corresponding MidiEvent object. It extracts the command code, channel, and data bytes from the raw message and creates the appropriate MidiEvent based on the command code. If the command code is NoteOn, NoteOff, or KeyAfterTouch and the data2 value is greater than 0, it creates a NoteOnEvent; otherwise, it creates a NoteEvent. For ControlChange, PatchChange, ChannelAfterTouch, and PitchWheelChange command codes, it creates the corresponding events with the extracted data values. For other command codes, it throws a FormatException indicating an unsupported MIDI Command Code for the raw message.

Exceptions
FormatExceptionThrown when the raw message contains an unsupported MIDI Command Code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAsShortMessage()

virtual int NAudio.Midi.MidiEvent.GetAsShortMessage ( )
inlinevirtual

Returns the short message value calculated based on the channel and command code.

Returns
The short message value calculated as (channel - 1) + (int)commandCode.

Reimplemented in NAudio.Midi.ChannelAfterTouchEvent, NAudio.Midi.ControlChangeEvent, NAudio.Midi.NoteEvent, NAudio.Midi.PatchChangeEvent, and NAudio.Midi.PitchWheelChangeEvent.

◆ IsEndTrack()

static bool NAudio.Midi.MidiEvent.IsEndTrack ( MidiEvent midiEvent)
inlinestatic

Checks if the provided MIDI event is an end track event.

Parameters
midiEventThe MIDI event to be checked.
Returns
True if the MIDI event is an end track event; otherwise, false.

This method checks if the provided MIDI event is a meta event and if so, it further checks if the meta event type is EndTrack. If the provided MIDI event is null or not a meta event, the method returns false.

Here is the caller graph for this function:

◆ IsNoteOff()

static bool NAudio.Midi.MidiEvent.IsNoteOff ( MidiEvent midiEvent)
inlinestatic

Checks if the given MIDI event represents a Note Off message.

Parameters
midiEventThe MIDI event to be checked.
Returns
True if the MIDI event represents a Note Off message; otherwise, false.

This method checks if the provided midiEvent is not null and if its command code is NoteOn. If the command code is NoteOn, it further checks if the velocity of the NoteEvent is 0 and returns true. If the command code is not NoteOn, it directly checks if the command code is NoteOff and returns the result. If the provided midiEvent is null, it returns false.

◆ IsNoteOn()

static bool NAudio.Midi.MidiEvent.IsNoteOn ( MidiEvent midiEvent)
inlinestatic

Checks if the provided MIDI event is a Note On event and returns true if the velocity is greater than 0.

Parameters
midiEventThe MIDI event to be checked.
Returns
True if the provided midiEvent is a Note On event with velocity greater than 0; otherwise, false.

◆ ReadNextEvent()

static MidiEvent NAudio.Midi.MidiEvent.ReadNextEvent ( BinaryReader br,
MidiEvent previous )
inlinestatic

Reads the next MIDI event from the BinaryReader and returns the corresponding MidiEvent.

Parameters
brThe BinaryReader used to read the MIDI data.
previousThe previous MidiEvent, used to determine running status.
Returns
The MidiEvent read from the BinaryReader.

This method reads the next MIDI event from the BinaryReader and returns the corresponding MidiEvent. It first reads the delta time using the ReadVarInt method, then determines the command code and channel based on the MIDI data. Depending on the command code, it creates a specific type of MidiEvent (e.g., NoteOnEvent, NoteOffEvent, ControlChangeEvent) using the BinaryReader. If the command code is not supported, it throws a FormatException with a message indicating the unsupported MIDI Command Code. The created MidiEvent is then populated with the channel, delta time, and command code before being returned.

Exceptions
FormatExceptionThrown when the MIDI Command Code is not supported.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadVarInt()

static int NAudio.Midi.MidiEvent.ReadVarInt ( BinaryReader br)
inlinestatic

Reads a variable-length encoded integer from the provided BinaryReader and returns the result.

Parameters
brThe BinaryReader from which to read the variable-length encoded integer.
Returns
The variable-length encoded integer read from the BinaryReader.

This method reads a variable-length encoded integer from the provided BinaryReader by reading up to 4 bytes and decoding the value based on the MSB (Most Significant Bit) of each byte. The method shifts the value by 7 bits for each byte read and adds the lower 7 bits of the byte to the value until a byte with the MSB set to 0 is encountered, indicating the end of the encoded integer. If the method does not encounter a valid end byte after reading 4 bytes, it throws a FormatException with the message "Invalid Var Int".

Exceptions
FormatExceptionThrown when the method encounters an invalid variable-length encoded integer format.
Here is the caller graph for this function:

◆ ToString()

override string NAudio.Midi.MidiEvent.ToString ( )
inline

Returns a string representation of the current Midi event.

Returns
A string representing the Midi event. If the commandCode is greater than or equal to MidiCommandCode.Sysex, the string contains the absoluteTime and the commandCode. Otherwise, the string contains the absoluteTime, the commandCode, and the channel.

This method returns a string representation of the current Midi event. If the commandCode is greater than or equal to MidiCommandCode.Sysex, the string contains the absoluteTime and the commandCode. Otherwise, the string contains the absoluteTime, the commandCode, and the channel.

◆ WriteVarInt()

static void NAudio.Midi.MidiEvent.WriteVarInt ( BinaryWriter writer,
int value )
inlinestatic

Writes a variable-length encoded integer to the specified BinaryWriter.

Parameters
writerThe BinaryWriter to write the integer to.
valueThe integer value to be written.
Exceptions
ArgumentOutOfRangeExceptionThrown when the value is negative or exceeds the maximum allowed value (0x0FFFFFFF).

This method writes a variable-length encoded integer to the specified BinaryWriter. The integer value is encoded using a variable-length format, where each byte contains 7 bits of the original value and a continuation bit. The process continues until all bits of the original value have been encoded.

Here is the caller graph for this function:

Member Data Documentation

◆ absoluteTime

long NAudio.Midi.MidiEvent.absoluteTime
private

◆ channel

int NAudio.Midi.MidiEvent.channel
private

◆ commandCode

MidiCommandCode NAudio.Midi.MidiEvent.commandCode
private

The MIDI command code.

◆ deltaTime

int NAudio.Midi.MidiEvent.deltaTime
private

Property Documentation

◆ AbsoluteTime

long NAudio.Midi.MidiEvent.AbsoluteTime
getset

The absolute time for this event.

◆ Channel

virtual int NAudio.Midi.MidiEvent.Channel
getset

The MIDI Channel Number for this event (1-16)

◆ CommandCode

MidiCommandCode NAudio.Midi.MidiEvent.CommandCode
get

The command code for this event.

◆ DeltaTime

int NAudio.Midi.MidiEvent.DeltaTime
get

The Delta time for this event.


The documentation for this class was generated from the following file: