Search Results for

    Show / Hide Table of Contents

    Class MidiChunk

    Represents a chunk of Standard MIDI file.
    Inheritance
    object
    MidiChunk
    TrackChunk
    UnknownChunk
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Melanchall.DryWetMidi.Core
    Assembly: Melanchall.DryWetMidi.dll
    Syntax
    public abstract class MidiChunk
    Remarks

    MIDI files are made up of chunks. Each chunk has a 4-character type ID and a 32-bit length, which is the number of bytes in the chunk. You manage chunks via Chunks property of the MidiFile.

    There are two standard types of MIDI chunks: header chunk and track chunk. The first one will not be presented in the Chunks. Its data is used by the reading engine to set properties of the MidiFile such as TimeDivision and OriginalFormat. You cannot add header chunks in the chunks collection of the file since an appropriate one will be written by writing engine automatically on Write(string, bool, MidiFileFormat, WritingSettings) or Write(Stream, MidiFileFormat, WritingSettings).

    The structure of a MIDI chunk allows any custom chunks be placed in a MIDI file along with the standard ones described above. You can implement custom chunks that can be read from and written to a MIDI file. See Custom chunks article to learn more. If you doesn't specify information about your custom chunk types the reading engine will read them as instances of the UnknownChunk class where Data property will hold chunk's data and ChunkId will hold the ID of a chunk.

    See https://midi.org/standard-midi-files-specification for detailed MIDI file specification.

    Constructors

    MidiChunk(string)

    Initializes a new instance of the MidiChunk with the specified ID.
    Declaration
    protected MidiChunk(string id)
    Parameters
    Type Name Description
    string id The type of the chunk.
    Exceptions
    Type Condition
    ArgumentNullException id is null.
    ArgumentException id is empty, or consists only of white-space characters; or length of id doesn't equal 4.

    Fields

    IdLength

    The length of a chunk's ID. This field is constant.
    Declaration
    public const int IdLength = 4
    Field Value
    Type Description
    int

    Properties

    ChunkId

    Gets 4-character ID of the chunk which specifies its type.
    Declaration
    public string ChunkId { get; }
    Property Value
    Type Description
    string

    Methods

    Clone()

    Clones chunk by creating a copy of it.
    Declaration
    public abstract MidiChunk Clone()
    Returns
    Type Description
    MidiChunk Copy of the chunk.

    Equals(MidiChunk, MidiChunk)

    Determines whether two specified MidiChunk objects have the same content.
    Declaration
    public static bool Equals(MidiChunk chunk1, MidiChunk chunk2)
    Parameters
    Type Name Description
    MidiChunk chunk1 The first chunk to compare, or null.
    MidiChunk chunk2 The second chunk to compare, or null.
    Returns
    Type Description
    bool true if the chunk1 is equal to the chunk2; otherwise, false.

    Equals(MidiChunk, MidiChunk, MidiChunkEqualityCheckSettings)

    Determines whether two specified MidiChunk objects have the same content.
    Declaration
    public static bool Equals(MidiChunk chunk1, MidiChunk chunk2, MidiChunkEqualityCheckSettings settings)
    Parameters
    Type Name Description
    MidiChunk chunk1 The first chunk to compare, or null.
    MidiChunk chunk2 The second chunk to compare, or null.
    MidiChunkEqualityCheckSettings settings Settings according to which chunks should be compared.
    Returns
    Type Description
    bool true if the chunk1 is equal to the chunk2; otherwise, false.

    Equals(MidiChunk, MidiChunk, MidiChunkEqualityCheckSettings, out string)

    Determines whether two specified MidiChunk objects have the same content using the specified comparison settings.
    Declaration
    public static bool Equals(MidiChunk chunk1, MidiChunk chunk2, MidiChunkEqualityCheckSettings settings, out string message)
    Parameters
    Type Name Description
    MidiChunk chunk1 The first chunk to compare, or null.
    MidiChunk chunk2 The second chunk to compare, or null.
    MidiChunkEqualityCheckSettings settings Settings according to which chunks should be compared.
    string message Message containing information about what exactly is different in chunk1 and chunk2.
    Returns
    Type Description
    bool true if the chunk1 is equal to the chunk2; otherwise, false.

    Equals(MidiChunk, MidiChunk, out string)

    Determines whether two specified MidiChunk objects have the same content.
    Declaration
    public static bool Equals(MidiChunk chunk1, MidiChunk chunk2, out string message)
    Parameters
    Type Name Description
    MidiChunk chunk1 The first chunk to compare, or null.
    MidiChunk chunk2 The second chunk to compare, or null.
    string message Message containing information about what exactly is different in chunk1 and chunk2.
    Returns
    Type Description
    bool true if the chunk1 is equal to the chunk2; otherwise, false.

    GetContentSize(WritingSettings)

    Gets size of chunk's content as number of bytes required to write it according to specified WritingSettings.
    Declaration
    protected abstract uint GetContentSize(WritingSettings settings)
    Parameters
    Type Name Description
    WritingSettings settings Settings according to which the chunk's content will be written.
    Returns
    Type Description
    uint Number of bytes required to write chunk's content.

    GetStandardChunkIds()

    Returns array of IDs of standard chunks.
    Declaration
    public static string[] GetStandardChunkIds()
    Returns
    Type Description
    string[] Array of IDs of standard chunks.
    Remarks
    Standard chunks are header chunk (ID is MThd) and track chunk (ID is MTrk).

    ReadContent(MidiReader, ReadingSettings, uint)

    Reads content of a chunk. Content is a part of chunk's data without its header (ID and size).
    Declaration
    protected abstract void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
    Parameters
    Type Name Description
    MidiReader reader Reader to read the chunk's content with.
    ReadingSettings settings Settings according to which the chunk's content must be read.
    uint size Expected size of the content taken from the chunk's header.

    WriteContent(MidiWriter, WritingSettings)

    Writes content of a chunk. Content is a part of chunk's data without its header (ID and size).
    Declaration
    protected abstract void WriteContent(MidiWriter writer, WritingSettings settings)
    Parameters
    Type Name Description
    MidiWriter writer Writer to write the chunk's content with.
    WritingSettings settings Settings according to which the chunk's content must be written.

    Extension Methods

    CsvSerializer.SerializeToCsv(MidiChunk, Stream, TempoMap, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)
    CsvSerializer.SerializeToCsv(MidiChunk, string, bool, TempoMap, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)
    In this article
    Back to top 2024 / Generated by DocFX