Search Results for

    Show / Hide Table of Contents

    Class MidiFileUtilities

    Utility methods for MidiFile.
    Inheritance
    object
    MidiFileUtilities
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Melanchall.DryWetMidi.Interaction
    Assembly: Melanchall.DryWetMidi.dll
    Syntax
    public static class MidiFileUtilities

    Methods

    GetDuration(MidiFile, TimeSpanType)

    Gets the duration of the specified MidiFile. Duration is defined by the time of last MIDI event of the file.
    Declaration
    public static ITimeSpan GetDuration(this MidiFile midiFile, TimeSpanType durationType)
    Parameters
    Type Name Description
    MidiFile midiFile MidiFile to get duration of.
    TimeSpanType durationType The type of time span representing the duration of midiFile.
    Returns
    Type Description
    ITimeSpan An implementation of ITimeSpan representing duration of midiFile.
    Exceptions
    Type Condition
    ArgumentNullException midiFile is null.
    InvalidEnumArgumentException durationType specified an invalid value.

    GetDuration(TrackChunk, TimeSpanType, TempoMap)

    Gets the duration of the specified TrackChunk. Duration is defined by the time of last MIDI event of the track chunk.
    Declaration
    public static ITimeSpan GetDuration(this TrackChunk trackChunk, TimeSpanType durationType, TempoMap tempoMap)
    Parameters
    Type Name Description
    TrackChunk trackChunk TrackChunk to get duration of.
    TimeSpanType durationType The type of time span representing the duration of trackChunk.
    TempoMap tempoMap Tempo map to calculate duration.
    Returns
    Type Description
    ITimeSpan An implementation of ITimeSpan representing duration of trackChunk.
    Exceptions
    Type Condition
    ArgumentNullException

    One of the following errors occurred:

    • trackChunk is null.
    • tempoMap is null.
    InvalidEnumArgumentException durationType specified an invalid value.

    GetDuration(IEnumerable<TrackChunk>, TimeSpanType, TempoMap)

    Gets the duration of the specified collection of TrackChunk. Duration is defined by the time of last MIDI event of the track chunks.
    Declaration
    public static ITimeSpan GetDuration(this IEnumerable<TrackChunk> trackChunks, TimeSpanType durationType, TempoMap tempoMap)
    Parameters
    Type Name Description
    IEnumerable<TrackChunk> trackChunks Collection TrackChunk to get duration of.
    TimeSpanType durationType The type of time span representing the duration of trackChunks.
    TempoMap tempoMap Tempo map to calculate duration.
    Returns
    Type Description
    ITimeSpan An implementation of ITimeSpan representing duration of trackChunks.
    Exceptions
    Type Condition
    ArgumentNullException

    One of the following errors occurred:

    • trackChunks is null.
    • tempoMap is null.
    InvalidEnumArgumentException durationType specified an invalid value.

    GetDuration<TTimeSpan>(MidiFile)

    Gets the duration of the specified MidiFile. Duration is defined by the time of last MIDI event of the file.
    Declaration
    public static TTimeSpan GetDuration<TTimeSpan>(this MidiFile midiFile) where TTimeSpan : class, ITimeSpan
    Parameters
    Type Name Description
    MidiFile midiFile MidiFile to get duration of.
    Returns
    Type Description
    TTimeSpan An instance of TTimeSpan representing duration of midiFile.
    Type Parameters
    Name Description
    TTimeSpan The type of time span representing the duration of midiFile.
    Exceptions
    Type Condition
    ArgumentNullException midiFile is null.
    NotSupportedException TTimeSpan is not supported.

    GetDuration<TTimeSpan>(TrackChunk, TempoMap)

    Gets the duration of the specified TrackChunk. Duration is defined by the time of last MIDI event of the track chunk.
    Declaration
    public static TTimeSpan GetDuration<TTimeSpan>(this TrackChunk trackChunk, TempoMap tempoMap) where TTimeSpan : class, ITimeSpan
    Parameters
    Type Name Description
    TrackChunk trackChunk TrackChunk to get duration of.
    TempoMap tempoMap Tempo map to calculate duration.
    Returns
    Type Description
    TTimeSpan An instance of TTimeSpan representing duration of trackChunk.
    Type Parameters
    Name Description
    TTimeSpan The type of time span representing the duration of trackChunk.
    Exceptions
    Type Condition
    ArgumentNullException

    One of the following errors occurred:

    • trackChunk is null.
    • tempoMap is null.
    NotSupportedException TTimeSpan is not supported.

    GetDuration<TTimeSpan>(IEnumerable<TrackChunk>, TempoMap)

    Gets the duration of the specified collection of TrackChunk. Duration is defined by the time of last MIDI event of the track chunks.
    Declaration
    public static TTimeSpan GetDuration<TTimeSpan>(this IEnumerable<TrackChunk> trackChunks, TempoMap tempoMap) where TTimeSpan : class, ITimeSpan
    Parameters
    Type Name Description
    IEnumerable<TrackChunk> trackChunks Collection of TrackChunk to get duration of.
    TempoMap tempoMap Tempo map to calculate duration.
    Returns
    Type Description
    TTimeSpan An instance of TTimeSpan representing duration of trackChunks.
    Type Parameters
    Name Description
    TTimeSpan The type of time span representing the duration of trackChunks.
    Exceptions
    Type Condition
    ArgumentNullException

    One of the following errors occurred:

    • trackChunks is null.
    • tempoMap is null.
    NotSupportedException TTimeSpan is not supported.

    IsEmpty(MidiFile)

    Checks whether the specified MidiFile is empty or not. MidiFile is empty when it doesn't contain MIDI events.
    Declaration
    public static bool IsEmpty(this MidiFile midiFile)
    Parameters
    Type Name Description
    MidiFile midiFile MidiFile to check emptiness of.
    Returns
    Type Description
    bool A value indicating whether midiFile is empty or not.
    Exceptions
    Type Condition
    ArgumentNullException midiFile is null.

    ShiftEvents(MidiFile, ITimeSpan)

    Shifts events forward inside MidiFile by the specified distance.
    Declaration
    public static void ShiftEvents(this MidiFile midiFile, ITimeSpan distance)
    Parameters
    Type Name Description
    MidiFile midiFile MidiFile containing events to shift.
    ITimeSpan distance Distance to shift events by.
    Exceptions
    Type Condition
    ArgumentNullException

    One of the following errors occurred:

    • midiFile is null.
    • distance is null.
    In this article
    Back to top 2025 / Generated by DocFX