Search Results for

    Show / Hide Table of Contents

    Class MidiReader

    Reader of the MIDI data types.
    Inheritance
    object
    MidiReader
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    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:

    • stream is null.
    • settings is null.
    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
    bool
    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
    long

    Position

    Gets or sets the position within the underlying stream.
    Declaration
    public long Position { get; set; }
    Property Value
    Type Description
    long
    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
    uint 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(int)

    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
    int 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
    uint 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
    short 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(int)

    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
    int 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
    long 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
    int 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
    ushort 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.

    Implements

    IDisposable
    In this article
    Back to top 2024 / Generated by DocFX