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

Class able to read a MIDI file. More...

Collaboration diagram for NAudio.Midi.MidiFile:

Public Member Functions

 MidiFile (string filename)
 Opens a MIDI file for reading.
 
 MidiFile (string filename, bool strictChecking)
 Opens a MIDI file for reading.
 
 MidiFile (Stream inputStream, bool strictChecking)
 Opens a MIDI file stream for reading.
 
override string ToString ()
 Returns a string representation of the MIDI file.
 

Static Public Member Functions

static void Export (string filename, MidiEventCollection events)
 Exports the MIDI events to a file with the specified filename.
 

Properties

int FileFormat [get]
 MIDI File format.
 
MidiEventCollection Events [get]
 The collection of events in this MIDI file.
 
int Tracks [get]
 Number of tracks in this MIDI file.
 
int DeltaTicksPerQuarterNote [get]
 Delta Ticks Per Quarter Note.
 

Private Member Functions

 MidiFile (Stream inputStream, bool strictChecking, bool ownInputStream)
 
void FindNoteOn (NoteEvent offEvent, List< NoteOnEvent > outstandingNoteOns)
 Finds and updates the corresponding NoteOnEvent in the list of outstandingNoteOns with the provided NoteOffEvent.
 

Static Private Member Functions

static uint SwapUInt32 (uint i)
 Swaps the bytes of a 32-bit unsigned integer and returns the result.
 
static ushort SwapUInt16 (ushort i)
 Swaps the high and low bytes of the input unsigned 16-bit integer and returns the result.
 

Private Attributes

readonly MidiEventCollection events
 
readonly ushort fileFormat
 
readonly ushort deltaTicksPerQuarterNote
 
readonly bool strictChecking
 

Detailed Description

Class able to read a MIDI file.

Constructor & Destructor Documentation

◆ MidiFile() [1/4]

NAudio.Midi.MidiFile.MidiFile ( string filename)
inline

Opens a MIDI file for reading.

Parameters
filenameName of MIDI file

◆ MidiFile() [2/4]

NAudio.Midi.MidiFile.MidiFile ( string filename,
bool strictChecking )
inline

Opens a MIDI file for reading.

Parameters
filenameName of MIDI file
strictCheckingIf true will error on non-paired note events

◆ MidiFile() [3/4]

NAudio.Midi.MidiFile.MidiFile ( Stream inputStream,
bool strictChecking )
inline

Opens a MIDI file stream for reading.

Parameters
inputStreamThe input stream containing a MIDI file
strictCheckingIf true will error on non-paired note events

◆ MidiFile() [4/4]

NAudio.Midi.MidiFile.MidiFile ( Stream inputStream,
bool strictChecking,
bool ownInputStream )
inlineprivate
Here is the call graph for this function:

Member Function Documentation

◆ Export()

static void NAudio.Midi.MidiFile.Export ( string filename,
MidiEventCollection events )
inlinestatic

Exports the MIDI events to a file with the specified filename.

Parameters
filenameThe name of the file to which the MIDI events will be exported.
eventsThe collection of MIDI events to be exported.
Exceptions
ArgumentExceptionThrown when attempting to export more than one track to a type 0 file.

This method exports the MIDI events to a file with the specified filename. If the MIDI file type is 0 and there are more than one track, an ArgumentException is thrown. The method writes the MIDI events to the file in the specified format, including the header and track information.

Here is the call graph for this function:

◆ FindNoteOn()

void NAudio.Midi.MidiFile.FindNoteOn ( NoteEvent offEvent,
List< NoteOnEvent > outstandingNoteOns )
inlineprivate

Finds and updates the corresponding NoteOnEvent in the list of outstandingNoteOns with the provided NoteOffEvent.

Parameters
offEventThe NoteOffEvent to find a corresponding NoteOnEvent for.
outstandingNoteOnsThe list of outstanding NoteOnEvents to search for a matching NoteOnEvent.
Exceptions
FormatExceptionThrown when a NoteOffEvent is received without a corresponding NoteOnEvent, and strictChecking is enabled.

This method iterates through the list of outstandingNoteOns to find a matching NoteOnEvent based on the channel and note number. If a matching NoteOnEvent is found, it updates the OffEvent property of the NoteOnEvent with the provided offEvent, removes the NoteOnEvent from the list of outstandingNoteOns, and sets the found flag to true. If no matching NoteOnEvent is found and strictChecking is enabled, it throws a FormatException with a message indicating that an off without an on was received.

Here is the caller graph for this function:

◆ SwapUInt16()

static ushort NAudio.Midi.MidiFile.SwapUInt16 ( ushort i)
inlinestaticprivate

Swaps the high and low bytes of the input unsigned 16-bit integer and returns the result.

Parameters
iThe unsigned 16-bit integer to be swapped.
Returns
The result of swapping the high and low bytes of the input i .

This method takes an unsigned 16-bit integer i and swaps its high and low bytes. It does this by first masking the high and low bytes using bitwise AND operations, shifting the high byte to the low byte position, and shifting the low byte to the high byte position using bitwise OR operations. The result is then returned as the swapped unsigned 16-bit integer.

Here is the caller graph for this function:

◆ SwapUInt32()

static uint NAudio.Midi.MidiFile.SwapUInt32 ( uint i)
inlinestaticprivate

Swaps the bytes of a 32-bit unsigned integer and returns the result.

Parameters
iThe 32-bit unsigned integer to swap the bytes of.
Returns
The 32-bit unsigned integer with its bytes swapped.

This method swaps the bytes of the input 32-bit unsigned integer i such that the most significant byte becomes the least significant byte and vice versa.

Here is the caller graph for this function:

◆ ToString()

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

Returns a string representation of the MIDI file.

Returns
A string containing the format, number of tracks, and delta ticks per quarter note, followed by a list of MIDI events for each track.

Member Data Documentation

◆ deltaTicksPerQuarterNote

readonly ushort NAudio.Midi.MidiFile.deltaTicksPerQuarterNote
private

◆ events

readonly MidiEventCollection NAudio.Midi.MidiFile.events
private

◆ fileFormat

readonly ushort NAudio.Midi.MidiFile.fileFormat
private

◆ strictChecking

readonly bool NAudio.Midi.MidiFile.strictChecking
private

Property Documentation

◆ DeltaTicksPerQuarterNote

int NAudio.Midi.MidiFile.DeltaTicksPerQuarterNote
get

Delta Ticks Per Quarter Note.

◆ Events

MidiEventCollection NAudio.Midi.MidiFile.Events
get

The collection of events in this MIDI file.

◆ FileFormat

int NAudio.Midi.MidiFile.FileFormat
get

MIDI File format.

◆ Tracks

int NAudio.Midi.MidiFile.Tracks
get

Number of tracks in this MIDI file.


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