Struct TimeSignature
Time signature / meter.
public readonly struct TimeSignature : IEquatable<TimeSignature>
- Implements
- Inherited Members
Remarks
Both parts must be positive. BeatUnit is a denominator: at zero, BeatDuration and
MeasureDuration are undefined, and the meter still prints and compares as if it were a
real one ("4/0"). Note this only covers explicit construction — default(TimeSignature)
bypasses these initializers and is 0/0, as it is for every C# struct.
Whether a denominator is writable to a MIDI file is a stricter question, and belongs to the
export path rather than here: MIDI stores log2 of the denominator, so it can only encode powers
of two, while a meter like 4/3 is representable in this type and meaningful on paper.
Constructors
TimeSignature(int, int)
Time signature / meter.
public TimeSignature(int beatsPerMeasure, int beatUnit)
Parameters
beatsPerMeasureintBeats per measure (numerator); must be positive.
beatUnitintBeat unit note value (denominator: 4 = quarter, 8 = eighth); must be positive.
Remarks
Both parts must be positive. BeatUnit is a denominator: at zero, BeatDuration and
MeasureDuration are undefined, and the meter still prints and compares as if it were a
real one ("4/0"). Note this only covers explicit construction — default(TimeSignature)
bypasses these initializers and is 0/0, as it is for every C# struct.
Whether a denominator is writable to a MIDI file is a stricter question, and belongs to the
export path rather than here: MIDI stores log2 of the denominator, so it can only encode powers
of two, while a meter like 4/3 is representable in this type and meaningful on paper.
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Properties
BeatDuration
Duration of one beat as a Rational.
public Rational BeatDuration { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
BeatUnit
Beat unit as note value (4 = quarter, 8 = eighth, etc).
public int BeatUnit { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
BeatsPerMeasure
Beats per measure (numerator).
public int BeatsPerMeasure { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Common
Common time, 4/4.
public static TimeSignature Common { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Compound12
Compound quadruple, 12/8.
public static TimeSignature Compound12 { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Compound6
Compound duple, 6/8.
public static TimeSignature Compound6 { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Compound9
Compound triple, 9/8.
public static TimeSignature Compound9 { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
CutTime
Cut time, 2/2.
public static TimeSignature CutTime { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
IsCompound
Is this a compound meter (beats subdivide into 3)?
public bool IsCompound { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
IsSimple
Is this a simple meter (beats subdivide into 2)?
public bool IsSimple { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
MeasureDuration
Duration of one measure.
public Rational MeasureDuration { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
StrongBeats
Number of strong beats per measure.
public int StrongBeats { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Waltz
Waltz meter, 3/4.
public static TimeSignature Waltz { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Methods
Equals(TimeSignature)
Indicates whether this meter equals other (same numerator and denominator).
public bool Equals(TimeSignature other)
Parameters
otherTimeSignature
Returns
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Equals(object?)
Indicates whether obj is an equal TimeSignature.
public override bool Equals(object? obj)
Parameters
objobject
Returns
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
GetHashCode()
Returns a hash code combining numerator and denominator.
public override int GetHashCode()
Returns
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
ToString()
Returns the meter as "beats/unit" (e.g. "4/4").
public override string ToString()
Returns
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
Operators
operator ==(TimeSignature, TimeSignature)
Indicates whether two time signatures are equal.
public static bool operator ==(TimeSignature left, TimeSignature right)
Parameters
leftTimeSignaturerightTimeSignature
Returns
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.
operator !=(TimeSignature, TimeSignature)
Indicates whether two time signatures differ.
public static bool operator !=(TimeSignature left, TimeSignature right)
Parameters
leftTimeSignaturerightTimeSignature
Returns
Exceptions
- ArgumentOutOfRangeException
beatsPerMeasureorbeatUnitis not positive.