Search Results for

    Show / Hide Table of Contents

    Class CsvSerializer

    Provides methods to serialize MIDI data to CSV and deserialize it back. More info in the CSV serializer article.
    Inheritance
    object
    CsvSerializer
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Melanchall.DryWetMidi.Tools
    Assembly: Melanchall.DryWetMidi.dll
    Syntax
    public static class CsvSerializer

    Methods

    DeserializeChunkFromCsv(Stream, TempoMap, CsvSerializationSettings)

    Reads a MidiChunk represented as CSV from the specified stream.
    Declaration
    public static MidiChunk DeserializeChunkFromCsv(Stream stream, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    Stream stream Stream to read a chunk from.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which MidiChunk should be deserialized.
    Returns
    Type Description
    MidiChunk An instance of the MidiChunk read from CSV representation from stream.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support reading.
    ArgumentNullException

    One of the following errors occurred:

    • stream is null.
    • tempoMap is null.
    FormatException Invalid CSV representation.

    DeserializeChunkFromCsv(string, TempoMap, CsvSerializationSettings)

    Reads a MidiChunk represented as CSV from the specified file.
    Declaration
    public static MidiChunk DeserializeChunkFromCsv(string filePath, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    string filePath Path to the file to read a chunk from.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which MidiChunk should be deserialized.
    Returns
    Type Description
    MidiChunk An instance of the MidiChunk read from CSV representation from filePath.
    Exceptions
    Type Condition
    ArgumentException filePath is null, a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException tempoMap is null.
    FormatException Invalid CSV representation.

    DeserializeChunksFromCsv(Stream, TempoMap, CsvSerializationSettings)

    Reads a collection of MidiChunk represented as CSV from the specified stream.
    Declaration
    public static ICollection<MidiChunk> DeserializeChunksFromCsv(Stream stream, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    Stream stream Stream to read chunks from.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which collection of MidiChunk should be deserialized.
    Returns
    Type Description
    ICollection<MidiChunk> Collection of MidiChunk read from CSV representation from stream.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support reading.
    ArgumentNullException

    One of the following errors occurred:

    • stream is null.
    • tempoMap is null.
    FormatException Invalid CSV representation.

    DeserializeChunksFromCsv(string, TempoMap, CsvSerializationSettings)

    Reads a collection of MidiChunk represented as CSV from the specified file.
    Declaration
    public static ICollection<MidiChunk> DeserializeChunksFromCsv(string filePath, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    string filePath Path to the file to read chunks from.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which collection of MidiChunk should be deserialized.
    Returns
    Type Description
    ICollection<MidiChunk> Collection of MidiChunk read from CSV representation from filePath.
    Exceptions
    Type Condition
    ArgumentException filePath is null, a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException tempoMap is null.
    FormatException Invalid CSV representation.

    DeserializeFileFromCsv(Stream, CsvSerializationSettings)

    Reads a MidiFile represented as CSV from the specified stream.
    Declaration
    public static MidiFile DeserializeFileFromCsv(Stream stream, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    Stream stream Stream to read the file from.
    CsvSerializationSettings settings Settings according to which MidiFile should be deserialized.
    Returns
    Type Description
    MidiFile An instance of the MidiFile read from CSV representation from stream.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support reading.
    ArgumentNullException stream is null.
    FormatException Invalid CSV representation.

    DeserializeFileFromCsv(string, CsvSerializationSettings)

    Reads a MidiFile represented as CSV from the specified file.
    Declaration
    public static MidiFile DeserializeFileFromCsv(string filePath, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    string filePath Path to the file to read the file from.
    CsvSerializationSettings settings Settings according to which MidiFile should be deserialized.
    Returns
    Type Description
    MidiFile An instance of the MidiFile read from CSV representation from filePath.
    Exceptions
    Type Condition
    ArgumentException filePath is null, a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    FormatException Invalid CSV representation.

    DeserializeObjectsFromCsv(Stream, TempoMap, CsvSerializationSettings)

    Reads collection of ITimedObject represented as CSV from the specified stream.
    Declaration
    public static ICollection<ITimedObject> DeserializeObjectsFromCsv(Stream stream, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    Stream stream Stream to read objects from.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which collection of ITimedObject should be deserialized.
    Returns
    Type Description
    ICollection<ITimedObject> Collection of ITimedObject read from CSV representation from stream.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support reading.
    ArgumentNullException

    One of the following errors occurred:

    • stream is null.
    • tempoMap is null.
    FormatException Invalid CSV representation.

    DeserializeObjectsFromCsv(string, TempoMap, CsvSerializationSettings)

    Reads collection of ITimedObject represented as CSV from the specified file.
    Declaration
    public static ICollection<ITimedObject> DeserializeObjectsFromCsv(string filePath, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    string filePath Path to the file to read objects from.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which collection of ITimedObject should be deserialized.
    Returns
    Type Description
    ICollection<ITimedObject> Collection of ITimedObject read from CSV representation from filePath.
    Exceptions
    Type Condition
    ArgumentException filePath is null, a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException tempoMap is null.
    FormatException Invalid CSV representation.

    SerializeToCsv(MidiChunk, Stream, TempoMap, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)

    Writes the specified MidiChunk to a stream in CSV format.
    Declaration
    public static void SerializeToCsv(this MidiChunk midiChunk, Stream stream, TempoMap tempoMap, CsvSerializationSettings settings = null, ObjectType objectType = ObjectType.TimedEvent, ObjectDetectionSettings objectDetectionSettings = null)
    Parameters
    Type Name Description
    MidiChunk midiChunk MidiChunk to serialize to CSV representation.
    Stream stream Stream to write the midiChunk to.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which midiChunk should be serialized.
    ObjectType objectType Types of objects within midiChunk to serialize if it's a track chunk (see Remarks section).
    ObjectDetectionSettings objectDetectionSettings Settings according to which objects within a track chunk should be detected and built.
    Remarks
    objectType defines what kind of objects to put to the objectType as CSV. For example, if you specify TimedEvent, all events within midiChunk will be written to the stream if it's a track chunk. If you specify Note, only notes will be written. If you specify Note | TimedEvent, events and notes will be written. Please see Getting objects: GetObjects article to learn more.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support writing.
    ArgumentNullException

    One of the following errors occurred:

    • midiChunk is null.
    • stream is null.
    • tempoMap is null.

    SerializeToCsv(MidiChunk, string, bool, TempoMap, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)

    Writes the specified MidiChunk to a file in CSV format.
    Declaration
    public static void SerializeToCsv(this MidiChunk midiChunk, string filePath, bool overwriteFile, TempoMap tempoMap, CsvSerializationSettings settings = null, ObjectType objectType = ObjectType.TimedEvent, ObjectDetectionSettings objectDetectionSettings = null)
    Parameters
    Type Name Description
    MidiChunk midiChunk MidiChunk to serialize to CSV representation.
    string filePath Path to the file to write the midiChunk to.
    bool overwriteFile If true and file specified by filePath already exists it will be overwritten; if false and the file exists exception will be thrown.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which midiChunk should be serialized.
    ObjectType objectType Types of objects within midiChunk to serialize if it's a track chunk (see Remarks section).
    ObjectDetectionSettings objectDetectionSettings Settings according to which objects within a track chunk should be detected and built.
    Remarks
    objectType defines what kind of objects to put to the objectType as CSV. For example, if you specify TimedEvent, all events within midiChunk will be written to the stream if it's a track chunk. If you specify Note, only notes will be written. If you specify Note | TimedEvent, events and notes will be written. Please see Getting objects: GetObjects article to learn more.
    Exceptions
    Type Condition
    ArgumentException filePath is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException

    One of the following errors occurred:

    • midiChunk is null.
    • tempoMap is null.

    SerializeToCsv(MidiFile, Stream, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)

    Writes the specified MidiFile to a stream in CSV format.
    Declaration
    public static void SerializeToCsv(this MidiFile midiFile, Stream stream, CsvSerializationSettings settings = null, ObjectType objectType = ObjectType.TimedEvent, ObjectDetectionSettings objectDetectionSettings = null)
    Parameters
    Type Name Description
    MidiFile midiFile MidiFile to serialize to CSV representation.
    Stream stream Stream to write the midiFile to.
    CsvSerializationSettings settings Settings according to which midiFile should be serialized.
    ObjectType objectType Types of objects within track chunks of the midiFile to serialize (see Remarks section).
    ObjectDetectionSettings objectDetectionSettings Settings according to which objects within track chunks should be detected and built.
    Remarks
    objectType defines what kind of objects to put to the objectType as CSV. For example, if you specify TimedEvent, all events within track chunks of the midiFile will be written to the stream. If you specify Note, only notes will be written. If you specify Note | TimedEvent, events and notes will be written. Please see Getting objects: GetObjects article to learn more.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support writing.
    ArgumentNullException

    One of the following errors occurred:

    • midiFile is null.
    • stream is null.

    SerializeToCsv(MidiFile, string, bool, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)

    Writes the specified MidiFile to a file in CSV format.
    Declaration
    public static void SerializeToCsv(this MidiFile midiFile, string filePath, bool overwriteFile, CsvSerializationSettings settings = null, ObjectType objectType = ObjectType.TimedEvent, ObjectDetectionSettings objectDetectionSettings = null)
    Parameters
    Type Name Description
    MidiFile midiFile MidiFile to serialize to CSV representation.
    string filePath Path to the file to write the midiFile to.
    bool overwriteFile If true and file specified by filePath already exists it will be overwritten; if false and the file exists exception will be thrown.
    CsvSerializationSettings settings Settings according to which midiFile should be serialized.
    ObjectType objectType Types of objects within track chunks of the midiFile to serialize (see Remarks section).
    ObjectDetectionSettings objectDetectionSettings Settings according to which objects within track chunks should be detected and built.
    Remarks
    objectType defines what kind of objects to put to the objectType as CSV. For example, if you specify TimedEvent, all events within track chunks of the midiFile will be written to the stream. If you specify Note, only notes will be written. If you specify Note | TimedEvent, events and notes will be written. Please see Getting objects: GetObjects article to learn more.
    Exceptions
    Type Condition
    ArgumentException filePath is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException midiFile is null.

    SerializeToCsv(IEnumerable<MidiChunk>, Stream, TempoMap, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)

    Writes the specified collection of MidiChunk to a stream in CSV format.
    Declaration
    public static void SerializeToCsv(this IEnumerable<MidiChunk> midiChunks, Stream stream, TempoMap tempoMap, CsvSerializationSettings settings = null, ObjectType objectType = ObjectType.TimedEvent, ObjectDetectionSettings objectDetectionSettings = null)
    Parameters
    Type Name Description
    IEnumerable<MidiChunk> midiChunks Collection of MidiChunk to serialize to CSV representation.
    Stream stream Stream to write the midiChunks to.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which midiChunks should be serialized.
    ObjectType objectType Types of objects within track chunks of the midiChunks to serialize (see Remarks section).
    ObjectDetectionSettings objectDetectionSettings Settings according to which objects within track chunks should be detected and built.
    Remarks
    objectType defines what kind of objects to put to the objectType as CSV. For example, if you specify TimedEvent, all events within track chunks of the midiChunks will be written to the stream. If you specify Note, only notes will be written. If you specify Note | TimedEvent, events and notes will be written. Please see Getting objects: GetObjects article to learn more.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support writing.
    ArgumentNullException

    One of the following errors occurred:

    • midiChunks is null.
    • stream is null.
    • tempoMap is null.

    SerializeToCsv(IEnumerable<MidiChunk>, string, bool, TempoMap, CsvSerializationSettings, ObjectType, ObjectDetectionSettings)

    Writes the specified collection of MidiChunk to a file in CSV format.
    Declaration
    public static void SerializeToCsv(this IEnumerable<MidiChunk> midiChunks, string filePath, bool overwriteFile, TempoMap tempoMap, CsvSerializationSettings settings = null, ObjectType objectType = ObjectType.TimedEvent, ObjectDetectionSettings objectDetectionSettings = null)
    Parameters
    Type Name Description
    IEnumerable<MidiChunk> midiChunks Collection of MidiChunk to serialize to CSV representation.
    string filePath Path to the file to write the midiChunks to.
    bool overwriteFile If true and file specified by filePath already exists it will be overwritten; if false and the file exists exception will be thrown.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which midiChunks should be serialized.
    ObjectType objectType Types of objects within track chunks of the midiChunks to serialize (see Remarks section).
    ObjectDetectionSettings objectDetectionSettings Settings according to which objects within track chunks should be detected and built.
    Remarks
    objectType defines what kind of objects to put to the objectType as CSV. For example, if you specify TimedEvent, all events within track chunks of the midiChunks will be written to the stream. If you specify Note, only notes will be written. If you specify Note | TimedEvent, events and notes will be written. Please see Getting objects: GetObjects article to learn more.
    Exceptions
    Type Condition
    ArgumentException filePath is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException

    One of the following errors occurred:

    • midiChunks is null.
    • tempoMap is null.

    SerializeToCsv(IEnumerable<ITimedObject>, Stream, TempoMap, CsvSerializationSettings)

    Writes the specified objects to a stream in CSV format.
    Declaration
    public static void SerializeToCsv(this IEnumerable<ITimedObject> timedObjects, Stream stream, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    IEnumerable<ITimedObject> timedObjects Collection of ITimedObject to serialize to CSV representation.
    Stream stream Stream to write the timedObjects to.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which timedObjects should be serialized.
    Exceptions
    Type Condition
    ArgumentException stream doesn't support writing.
    ArgumentNullException

    One of the following errors occurred:

    • timedObjects is null.
    • stream is null.
    • tempoMap is null.

    SerializeToCsv(IEnumerable<ITimedObject>, string, bool, TempoMap, CsvSerializationSettings)

    Writes the specified objects to a file in CSV format.
    Declaration
    public static void SerializeToCsv(this IEnumerable<ITimedObject> timedObjects, string filePath, bool overwriteFile, TempoMap tempoMap, CsvSerializationSettings settings = null)
    Parameters
    Type Name Description
    IEnumerable<ITimedObject> timedObjects Collection of ITimedObject to serialize to CSV representation.
    string filePath Path to the file to write the timedObjects to.
    bool overwriteFile If true and file specified by filePath already exists it will be overwritten; if false and the file exists exception will be thrown.
    TempoMap tempoMap TempoMap to use for time/length conversions.
    CsvSerializationSettings settings Settings according to which timedObjects should be serialized.
    Exceptions
    Type Condition
    ArgumentException filePath is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
    ArgumentNullException

    One of the following errors occurred:

    • timedObjects is null.
    • tempoMap is null.

    See Also

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