Search Results for

    Show / Hide Table of Contents

    Struct SevenBitNumber

    Type that is used to represent a seven-bit number (0-127; or in binary format 0000000-1111111).
    Implements
    IComparable<SevenBitNumber>
    IConvertible
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Melanchall.DryWetMidi.Common
    Assembly: Melanchall.DryWetMidi.dll
    Syntax
    public struct SevenBitNumber : IComparable<SevenBitNumber>, IConvertible
    Remarks

    Seven-bit numbers widely used by MIDI protocol as parameters of MIDI events (note number or velocity). Instead of manipulating built-in .NET numeric types (like byte or int) and checking for out-of-range errors all validation of numbers in the [0; 127] range happens on data type level via casting .NET integer values to the SevenBitNumber (see explicit operator SevenBitNumber(byte)).

    Examples

    For example, to set a note's number:

    var noteOnEvent = new NoteOnEvent();
    noteOnEvent.NoteNumber = (SevenBitNumber)100;

    or velocity:

    var noteOffEvent = new NoteOffEvent(SevenBitNumber.MinValue, (SevenBitNumber)70);

    where SevenBitNumber.MinValue passed to the noteNumber parameter and (SevenBitNumber)70 passed to the velocity one.

    Constructors

    SevenBitNumber(byte)

    Initializes a new instance of the SevenBitNumber with the specified value.
    Declaration
    public SevenBitNumber(byte value)
    Parameters
    Type Name Description
    byte value Value representing seven-bit number.
    Exceptions
    Type Condition
    ArgumentOutOfRangeException value is out of [MinValue; MaxValue] range.

    Fields

    MaxValue

    The largest possible value of a SevenBitNumber.
    Declaration
    public static readonly SevenBitNumber MaxValue
    Field Value
    Type Description
    SevenBitNumber

    MinValue

    The smallest possible value of a SevenBitNumber.
    Declaration
    public static readonly SevenBitNumber MinValue
    Field Value
    Type Description
    SevenBitNumber

    Values

    All possible values of SevenBitNumber.
    Declaration
    public static readonly SevenBitNumber[] Values
    Field Value
    Type Description
    SevenBitNumber[]

    Methods

    CompareTo(SevenBitNumber)

    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(SevenBitNumber other)
    Parameters
    Type Name Description
    SevenBitNumber 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.

    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
    ValueType.Equals(object)

    GetHashCode()

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

    GetTypeCode()

    Returns the TypeCode for value type SevenBitNumber.
    Declaration
    public TypeCode GetTypeCode()
    Returns
    Type Description
    TypeCode The enumerated constant, Byte.

    Parse(string)

    Converts the string representation of a seven-bit number to its SevenBitNumber equivalent.
    Declaration
    public static SevenBitNumber Parse(string input)
    Parameters
    Type Name Description
    string input A string containing a number to convert.
    Returns
    Type Description
    SevenBitNumber A SevenBitNumber equivalent to the seven-bit number 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
    ValueType.ToString()

    TryParse(string, out SevenBitNumber)

    Converts the string representation of a seven-bit number to its SevenBitNumber equivalent. A return value indicates whether the conversion succeeded.
    Declaration
    public static bool TryParse(string input, out SevenBitNumber sevenBitNumber)
    Parameters
    Type Name Description
    string input A string containing a number to convert.
    SevenBitNumber sevenBitNumber When this method returns, contains the SevenBitNumber equivalent of the seven-bit number contained in input, if the conversion succeeded, or zero 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.

    Operators

    explicit operator SevenBitNumber(byte)

    Converts the value of a byte to a SevenBitNumber.
    Declaration
    public static explicit operator SevenBitNumber(byte number)
    Parameters
    Type Name Description
    byte number Byte value to convert to a SevenBitNumber object.
    Returns
    Type Description
    SevenBitNumber number represented as SevenBitNumber.
    Exceptions
    Type Condition
    ArgumentOutOfRangeException number is out of [0; 127] range.

    implicit operator byte(SevenBitNumber)

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

    Implements

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