MusicTheory Docs API Toolbox GitHub NuGet
Contents

API / MusicTheory

Duration record

Represents a musical duration (note or rest length), exact to the fraction.

Constructors

Duration(DurationType type, int dots = 0)
Initializes a new instance of the Duration class.
type
The duration type.
dots
The number of dots (0-3).

Throws ArgumentOutOfRangeException An undefined type, or dots outside 0-3.

Properties

DurationType Type { get; }
Gets the base duration type.
int Dots { get; }
Gets the number of dots (0-3).
(int, int)? Tuplet { get; }
Gets the tuplet ratio (actual notes in the space of normal ones, e.g. 3:2 for a triplet), or null.
bool IsTuplet { get; }
Gets whether this is a tuplet duration.
Rational Value { get; }
Gets the exact value of this duration in whole notes.

Methods

static Duration CreateTuplet(DurationType type, int actual, int normal)
Creates a tuplet duration.
type
The base duration type.
actual
Number of notes in the tuplet.
normal
Number of normal notes it replaces.

Returns A new tuplet duration.

Throws ArgumentOutOfRangeException An undefined type, or a count below 1.

static IReadOnlyList<Duration> Decompose(Rational value)
Splits a value into notatable durations, greedily and largest first. Tuplets are never produced.
value
The value in whole notes.

Returns The durations, whose values sum to value.

Throws ArgumentException The value is not positive or is not a finite sum of binary durations down to a 64th.

string GetSymbol()
Gets the Unicode symbol for this duration.

Returns The Unicode music symbol.

double GetTimeInSeconds(double bpm, Duration? beat = null)
Gets the time of this duration in seconds at a given tempo.
bpm
The tempo in beats per minute.
beat
The duration that counts as one beat; a quarter note when null.

Returns The duration in seconds.

Throws ArgumentOutOfRangeException bpm is not a positive finite number.

string ToString()
Returns a string representation of the duration.

Returns A readable name for the duration.

static bool TryFromValue(Rational value, out Duration? duration)
Finds the plain or dotted (up to 3 dots) duration of exactly the given value. Tuplets are never returned.
value
The value in whole notes.
duration
The matching duration, or null.

Returns True when a notatable duration has this value.