Class MidiReader
Reader of the MIDI data types.
Implements
Inherited Members
Namespace: Melanchall.DryWetMidi.Core
Assembly: Melanchall.DryWetMidi.dll
Syntax
public sealed class MidiReader : IDisposable
Constructors
MidiReader(Stream, ReaderSettings)
Initializes a new instance of the MidiReader with the specified stream.
Declaration
public MidiReader(Stream stream, ReaderSettings settings)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | Stream to read MIDI file from. |
ReaderSettings | settings | Settings according to which MIDI data should be read. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
One of the following errors occurred:
|
InvalidOperationException | Buffer of settings
is null in case of BufferingPolicy set to
UseCustomBuffer. |
Properties
EndReached
Gets a value indicating whether end of the underlying stream is reached.
Declaration
public bool EndReached { get; }
Property Value
Type | Description |
---|---|
Boolean |
Exceptions
Type | Condition |
---|---|
IOException | An I/O error occurred on the underlying stream. |
ObjectDisposedException | Property was called after the reader was disposed. |
Length
Gets length of the underlying stream.
Declaration
public long Length { get; }
Property Value
Type | Description |
---|---|
Int64 |
Position
Gets or sets the position within the underlying stream.
Declaration
public long Position { get; set; }
Property Value
Type | Description |
---|---|
Int64 |
Exceptions
Type | Condition |
---|---|
IOException | An I/O error occurred on the underlying stream. |
ObjectDisposedException | Property was called after the reader was disposed. |
Methods
Dispose()
Releases all resources used by the current instance of the MidiReader class.
Declaration
public void Dispose()
Read3ByteDword()
Reads a DWORD value (32-bit unsigned integer) presented by 3 bytes from the underlying
stream and advances the current position by three bytes.
Declaration
public uint Read3ByteDword()
Returns
Type | Description |
---|---|
UInt32 | A 32-bit unsigned integer read from the underlying stream. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
NotEnoughBytesException | Not enough bytes in the stream to read a 3-byte DWORD. |
ReadByte()
Reads a byte from the underlying stream and advances the current position by one byte.
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
Byte | The next byte read from the underlying stream. |
Exceptions
Type | Condition |
---|---|
EndOfStreamException | The end of the underlying stream is reached. |
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
ReadBytes(Int32)
Reads the specified number of bytes from the underlying stream into a byte array
and advances the current position by that number of bytes.
Declaration
public byte[] ReadBytes(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The number of bytes to read. This value must be 0 or a non-negative number or an exception will occur. |
Returns
Type | Description |
---|---|
Byte[] | A byte array containing data read from the underlying stream. This might be less than the number of bytes requested if the end of the stream is reached. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | count is negative. |
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
ReadDword()
Reads a DWORD value (32-bit unsigned integer) from the underlying stream and
advances the current position by four bytes.
Declaration
public uint ReadDword()
Returns
Type | Description |
---|---|
UInt32 | A 32-bit unsigned integer read from the underlying stream. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
NotEnoughBytesException | Not enough bytes in the stream to read a DWORD. |
ReadInt16()
Reads an INT16 value (16-bit signed integer) from the underlying stream and
advances the current position by two bytes.
Declaration
public short ReadInt16()
Returns
Type | Description |
---|---|
Int16 | A 16-bit signed integer read from the underlying stream. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
NotEnoughBytesException | Not enough bytes in the stream to read a INT16. |
ReadSByte()
Reads a signed byte from the underlying stream and advances the current position by one byte.
Declaration
public sbyte ReadSByte()
Returns
Type | Description |
---|---|
SByte | A signed byte read from the underlying stream. |
Exceptions
Type | Condition |
---|---|
EndOfStreamException | The end of the underlying stream is reached. |
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
ReadString(Int32)
Reads the specified number of characters from the underlying stream, returns the
data as string, and advances the current position by that number of characters.
Declaration
public string ReadString(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The length of string to read. |
Returns
Type | Description |
---|---|
String | The string being read. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | count is negative. |
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
ReadVlqLongNumber()
Reads a 64-bit signed integer presented in compressed format called variable-length quantity (VLQ)
to the underlying stream.
Declaration
public long ReadVlqLongNumber()
Returns
Type | Description |
---|---|
Int64 | A 64-bit signed integer read from the underlying stream. |
Remarks
Numbers in VLQ format are represented 7 bits per byte, most significant bits first.
All bytes except the last have bit 7 set, and the last byte has bit 7 clear. If the
number is between 0 and 127, it is thus represented exactly as one byte.
Exceptions
Type | Condition |
---|---|
NotEnoughBytesException | Not enough bytes in the stream to read a variable-length quantity number. |
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
ReadVlqNumber()
Reads a 32-bit signed integer presented in compressed format called variable-length quantity (VLQ)
to the underlying stream.
Declaration
public int ReadVlqNumber()
Returns
Type | Description |
---|---|
Int32 | A 32-bit signed integer read from the underlying stream. |
Remarks
Numbers in VLQ format are represented 7 bits per byte, most significant bits first.
All bytes except the last have bit 7 set, and the last byte has bit 7 clear. If the
number is between 0 and 127, it is thus represented exactly as one byte.
Exceptions
Type | Condition |
---|---|
NotEnoughBytesException | Not enough bytes in the stream to read a variable-length quantity number. |
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
ReadWord()
Reads a WORD value (16-bit unsigned integer) from the underlying stream and
advances the current position by two bytes.
Declaration
public ushort ReadWord()
Returns
Type | Description |
---|---|
UInt16 | A 16-bit unsigned integer read from the underlying stream. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Method was called after the reader was disposed. |
IOException | An I/O error occurred on the underlying stream. |
NotEnoughBytesException | Not enough bytes in the stream to read a WORD. |