DurationValue¶
duration_value ¶
Note duration values (whole, half, quarter, ... + dotted variations).
The DurationValue namespace converts between named durations
("quarter", "q", "q.") and their fractional values relative to a
whole note. Useful for music notation tooling.
Each duration entry has a denominator (whole = 1, quarter = 4, ...), a
shorthand string (q, e, s, ...), and a list of full names. Dotted
variations (q., q..) are computed on the fly.
Example
from tonal_py import DurationValue DurationValue.value("q") # quarter note 0.25 DurationValue.value("q.") # dotted quarter 0.375 DurationValue.fraction("q.") (3, 8)
Source parity: @tonaljs/duration-value
names ¶
Return every full duration name across all entries.
Each entry contributes multiple names (e.g. quarter has ["quarter",
"crotchet"]).
Example
from tonal_py import DurationValue "quarter" in DurationValue.names() True "whole" in DurationValue.names() True
Source code in src/tonal_py/duration_value.py
shorthands ¶
Return the shorthand strings (w, h, q, e, ...).
Example
from tonal_py import DurationValue DurationValue.shorthands()[:5]['dl', 'l', 'd', 'w', 'h']
Source code in src/tonal_py/duration_value.py
get ¶
Get a duration by name or shorthand, including dotted variations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A duration name or shorthand. Trailing dots add half the
previous value each (e.g. |
required |
Returns:
| Type | Description |
|---|---|
DurationValue
|
A |
Example
from tonal_py import DurationValue DurationValue.get("quarter").value 0.25 DurationValue.get("q").value 0.25 DurationValue.get("q.").fraction (3, 8)
Source code in src/tonal_py/duration_value.py
value ¶
Get a duration as a float (1.0 = whole note).
Example
from tonal_py import DurationValue DurationValue.value("q") 0.25 DurationValue.value("h.") # dotted half 0.75
Source code in src/tonal_py/duration_value.py
fraction ¶
Get a duration as a (numerator, denominator) reduced fraction.
Example
from tonal_py import DurationValue DurationValue.fraction("q") (1, 4) DurationValue.fraction("q.") (3, 8)