Search Results for

    Show / Hide Table of Contents

    Class Interval

    Represents a musical interval in terms of half steps number.
    Inheritance
    object
    Interval
    Implements
    IComparable<Interval>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Melanchall.DryWetMidi.MusicTheory
    Assembly: Melanchall.DryWetMidi.dll
    Syntax
    public sealed class Interval : IComparable<Interval>

    Fields

    Eight

    Interval of eight half steps up.
    Declaration
    public static readonly Interval Eight
    Field Value
    Type Description
    Interval

    Eleven

    Interval of eleven half steps up.
    Declaration
    public static readonly Interval Eleven
    Field Value
    Type Description
    Interval

    Five

    Interval of five half steps up.
    Declaration
    public static readonly Interval Five
    Field Value
    Type Description
    Interval

    Four

    Interval of four half steps up.
    Declaration
    public static readonly Interval Four
    Field Value
    Type Description
    Interval

    Nine

    Interval of nine half steps up.
    Declaration
    public static readonly Interval Nine
    Field Value
    Type Description
    Interval

    One

    Interval of one half step up.
    Declaration
    public static readonly Interval One
    Field Value
    Type Description
    Interval

    Seven

    Interval of seven half steps up.
    Declaration
    public static readonly Interval Seven
    Field Value
    Type Description
    Interval

    Six

    Interval of six half steps up.
    Declaration
    public static readonly Interval Six
    Field Value
    Type Description
    Interval

    Ten

    Interval of ten half steps up.
    Declaration
    public static readonly Interval Ten
    Field Value
    Type Description
    Interval

    Three

    Interval of three half steps up.
    Declaration
    public static readonly Interval Three
    Field Value
    Type Description
    Interval

    Twelve

    Interval of twelve half steps up (one octave up).
    Declaration
    public static readonly Interval Twelve
    Field Value
    Type Description
    Interval

    Two

    Interval of two half steps up.
    Declaration
    public static readonly Interval Two
    Field Value
    Type Description
    Interval

    Zero

    Interval of zero half steps up.
    Declaration
    public static readonly Interval Zero
    Field Value
    Type Description
    Interval

    Properties

    Direction

    Gets the direction of the interval represented by the current Interval.
    Declaration
    public IntervalDirection Direction { get; }
    Property Value
    Type Description
    IntervalDirection

    HalfSteps

    Gets signed half steps number which represents an interval of the current Interval.
    Declaration
    public int HalfSteps { get; }
    Property Value
    Type Description
    int

    Size

    Gets the size of interval represented by the current Interval as a number of half steps away.
    Declaration
    public SevenBitNumber Size { get; }
    Property Value
    Type Description
    SevenBitNumber

    Methods

    CompareTo(Interval)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
    Declaration
    public int CompareTo(Interval other)
    Parameters
    Type Name Description
    Interval other An object to compare with this instance.
    Returns
    Type Description
    int

    A value that indicates the relative order of the objects being compared. The return value has these meanings:

    ValueMeaning
    Less than zeroThis instance precedes other in the sort order.
    ZeroThis instance occurs in the same position in the sort order as other.
    Greater than zeroThis instance follows other in the sort order.

    Down()

    Returns downward version of the current Interval.
    Declaration
    public Interval Down()
    Returns
    Type Description
    Interval A downward version of the current Interval.

    Equals(object)

    Determines whether the specified object is equal to the current object.
    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj The object to compare with the current object.
    Returns
    Type Description
    bool true if the specified object is equal to the current object; otherwise, false.
    Overrides
    object.Equals(object)

    FromDefinition(IntervalDefinition)

    Creates an instance of the Interval from IntervalDefinition.
    Declaration
    public static Interval FromDefinition(IntervalDefinition intervalDefinition)
    Parameters
    Type Name Description
    IntervalDefinition intervalDefinition Interval definition to create interval from.
    Returns
    Type Description
    Interval Interval created from intervalDefinition.
    Exceptions
    Type Condition
    ArgumentNullException intervalDefinition is null.

    FromHalfSteps(int)

    Returns an Interval by the specified signed number of half steps where negative one means downward interval.
    Declaration
    public static Interval FromHalfSteps(int halfSteps)
    Parameters
    Type Name Description
    int halfSteps The number of half steps.
    Returns
    Type Description
    Interval An Interval represented by the halfSteps.
    Exceptions
    Type Condition
    ArgumentOutOfRangeException halfSteps is out of range (result interval is out of the [-127,127] range).

    Get(SevenBitNumber, IntervalDirection)

    Returns an Interval by the specified half steps number and interval's direction.
    Declaration
    public static Interval Get(SevenBitNumber intervalSize, IntervalDirection direction)
    Parameters
    Type Name Description
    SevenBitNumber intervalSize The size of an interval as a number of half steps away.
    IntervalDirection direction The direction of an interval (up or down).
    Returns
    Type Description
    Interval An Interval with the specified interval and direction.
    Exceptions
    Type Condition
    InvalidEnumArgumentException direction specified an invalid value.

    Get(IntervalQuality, int)

    Gets an instance of the Interval by the specified interval quality and number.
    Declaration
    public static Interval Get(IntervalQuality intervalQuality, int intervalNumber)
    Parameters
    Type Name Description
    IntervalQuality intervalQuality Interval quality.
    int intervalNumber Interval number.
    Returns
    Type Description
    Interval An instance of the Interval which represents intervalNumber along with intervalQuality.
    Exceptions
    Type Condition
    InvalidEnumArgumentException intervalQuality specified an invalid value.
    ArgumentOutOfRangeException intervalNumber is less than 1.
    ArgumentException intervalQuality is not applicable to intervalNumber.

    GetDown(SevenBitNumber)

    Returns a downward Interval by the specified half steps number.
    Declaration
    public static Interval GetDown(SevenBitNumber intervalSize)
    Parameters
    Type Name Description
    SevenBitNumber intervalSize The size of an interval as a number of half steps away.
    Returns
    Type Description
    Interval A downward Interval with the specified interval.

    GetHashCode()

    Serves as the default hash function.
    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int A hash code for the current object.
    Overrides
    object.GetHashCode()

    GetIntervalDefinitions()

    Returns collection of definitions of the current Interval.
    Declaration
    public IReadOnlyCollection<IntervalDefinition> GetIntervalDefinitions()
    Returns
    Type Description
    IReadOnlyCollection<IntervalDefinition> Collection of definitions of the current Interval.

    GetUp(SevenBitNumber)

    Returns an upward Interval by the specified half steps number.
    Declaration
    public static Interval GetUp(SevenBitNumber intervalSize)
    Parameters
    Type Name Description
    SevenBitNumber intervalSize The size of an interval as a number of half steps away.
    Returns
    Type Description
    Interval An upward Interval with the specified interval.

    IsPerfect(int)

    Gets a value indicating whether the specified interval number (1 and greater) is perfect or not.
    Declaration
    public static bool IsPerfect(int intervalNumber)
    Parameters
    Type Name Description
    int intervalNumber Interval number to determine whether it's perfect or not.
    Returns
    Type Description
    bool true if intervalNumber is perfect; otherwise, false.
    Exceptions
    Type Condition
    ArgumentOutOfRangeException intervalNumber is less than 1.

    IsQualityApplicable(IntervalQuality, int)

    Gets a value indicating whether quality is applicable to the specified interval number (1 and greater) or not.
    Declaration
    public static bool IsQualityApplicable(IntervalQuality intervalQuality, int intervalNumber)
    Parameters
    Type Name Description
    IntervalQuality intervalQuality Interval quality to check whether it's applicable to intervalNumber or not.
    int intervalNumber Interval number to check whether intervalQuality is applicable to it or not.
    Returns
    Type Description
    bool true if intervalQuality is applicable to intervalNumber; otherwise, false.
    Exceptions
    Type Condition
    InvalidEnumArgumentException intervalQuality specified an invalid value.
    ArgumentOutOfRangeException intervalNumber is less than 1.

    Parse(string)

    Converts the string representation of a musical interval to its Scale equivalent.
    Declaration
    public static Interval Parse(string input)
    Parameters
    Type Name Description
    string input A string containing an interval to convert.
    Returns
    Type Description
    Interval A Scale equivalent to the musical interval contained in input.
    Exceptions
    Type Condition
    ArgumentException input is null or contains white-spaces only.
    FormatException input has invalid format.

    ToString()

    Returns a string that represents the current object.
    Declaration
    public override string ToString()
    Returns
    Type Description
    string A string that represents the current object.
    Overrides
    object.ToString()

    TryParse(string, out Interval)

    Converts the string representation of a musical interval to its Interval equivalent. A return value indicates whether the conversion succeeded.
    Declaration
    public static bool TryParse(string input, out Interval interval)
    Parameters
    Type Name Description
    string input A string containing an interval to convert.
    Interval interval When this method returns, contains the Interval equivalent of the musical interval contained in input, if the conversion succeeded, or null if the conversion failed. The conversion fails if the input is null or Empty, or is not of the correct format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
    Returns
    Type Description
    bool true if input was converted successfully; otherwise, false.

    Up()

    Returns upward version of the current Interval.
    Declaration
    public Interval Up()
    Returns
    Type Description
    Interval An upward version of the current Interval.

    Operators

    operator +(Interval, int)

    Adds the specified number of half steps to an Interval.
    Declaration
    public static Interval operator +(Interval interval, int halfSteps)
    Parameters
    Type Name Description
    Interval interval The interval to add half steps to.
    int halfSteps The number of half steps to add to the interval.
    Returns
    Type Description
    Interval The Interval which is the interval shifted by the halfSteps.
    Exceptions
    Type Condition
    ArgumentNullException interval is null.
    ArgumentOutOfRangeException halfSteps is out of range (result interval is out of the [-127,127] range).

    operator /(Interval, int)

    Shrinks the specified Interval by dividing it by an integer number.
    Declaration
    public static Interval operator /(Interval interval, int divisor)
    Parameters
    Type Name Description
    Interval interval The interval to shrink.
    int divisor The number to divide the interval by.
    Returns
    Type Description
    Interval The Interval which is the interval shrunk by the divisor.
    Exceptions
    Type Condition
    ArgumentNullException interval is null.
    ArgumentOutOfRangeException divisor is zero.

    operator ==(Interval, Interval)

    Determines if two Interval objects are equal.
    Declaration
    public static bool operator ==(Interval interval1, Interval interval2)
    Parameters
    Type Name Description
    Interval interval1 The first Interval to compare.
    Interval interval2 The second Interval to compare.
    Returns
    Type Description
    bool true if the intervals are equal, false otherwise.

    implicit operator Interval(SevenBitNumber)

    Converts the value of a SevenBitNumber to a Interval.
    Declaration
    public static implicit operator Interval(SevenBitNumber interval)
    Parameters
    Type Name Description
    SevenBitNumber interval SevenBitNumber object to convert to an Interval.
    Returns
    Type Description
    Interval interval represented as Interval.

    implicit operator int(Interval)

    Converts the value of a Interval to a int.
    Declaration
    public static implicit operator int(Interval interval)
    Parameters
    Type Name Description
    Interval interval Interval object to convert to an int.
    Returns
    Type Description
    int interval represented as int.

    operator !=(Interval, Interval)

    Determines if two Interval objects are not equal.
    Declaration
    public static bool operator !=(Interval interval1, Interval interval2)
    Parameters
    Type Name Description
    Interval interval1 The first Interval to compare.
    Interval interval2 The second Interval to compare.
    Returns
    Type Description
    bool false if the intervals are equal, true otherwise.

    operator *(Interval, int)

    Stretches the specified Interval by multiplying it by an integer number.
    Declaration
    public static Interval operator *(Interval interval, int multiplier)
    Parameters
    Type Name Description
    Interval interval The interval to stretch.
    int multiplier The number to multiply the interval by.
    Returns
    Type Description
    Interval The Interval which is the interval stretched by the multiplier.
    Exceptions
    Type Condition
    ArgumentNullException interval is null.
    ArgumentOutOfRangeException multiplier is out of range (result interval is out of the [-127,127] range).

    operator -(Interval, int)

    Subtracts the specified number of half steps from an Interval.
    Declaration
    public static Interval operator -(Interval interval, int halfSteps)
    Parameters
    Type Name Description
    Interval interval The interval to subtract half steps from.
    int halfSteps The number of half steps to subtract from the interval.
    Returns
    Type Description
    Interval The Interval which is the interval shifted by the halfSteps.
    Exceptions
    Type Condition
    ArgumentNullException interval is null.
    ArgumentOutOfRangeException halfSteps is out of range (result interval is out of the [-127,127] range).

    operator -(Interval)

    Returns downward version of the specified Interval.
    Declaration
    public static Interval operator -(Interval interval)
    Parameters
    Type Name Description
    Interval interval The Interval to get downward version of.
    Returns
    Type Description
    Interval A downward version of the interval.
    Remarks
    This operator produces the same result as the Down() method.
    Exceptions
    Type Condition
    ArgumentNullException interval is null.

    operator +(Interval)

    Returns upward version of the specified Interval.
    Declaration
    public static Interval operator +(Interval interval)
    Parameters
    Type Name Description
    Interval interval The Interval to get upward version of.
    Returns
    Type Description
    Interval An upward version of the interval.
    Remarks
    This operator produces the same result as the Up() method.
    Exceptions
    Type Condition
    ArgumentNullException interval is null.

    Implements

    IComparable<T>
    In this article
    Back to top 2024 / Generated by DocFX