Measurable

Measurable()

A TemporalElement that reduces to a single rational length, in its system’s own unit (fractions of a whole note in WSMN, microseconds in clock time).

Measurables compare (and hash) by their rational_length, so a dotted quarter == 3 eighths == TemporalUnit(3, eighth), and can be compared against an iterable of Measurables, which is measured as the sum of its members.

>>> from openmusickit.systems.wsmn.temporal.symbols import quarter, eighth, dotted_quarter
>>> dotted_quarter.rational_length
Fraction(3, 8)
>>> dotted_quarter == [eighth, eighth, eighth] == TemporalUnit(3, eighth)
True
>>> quarter < dotted_quarter, quarter.scale(3)
(True, MetricalDuration(1, 2, dots=1))

Comparison is only defined within a temporal system (or with a universal element such as ZeroDuration); elements of incompatible systems are never equal, and ordering them raises TypeError. To relate them, convert first with a TemporalRatio.

>>> from openmusickit.values.time.clock_time import ClockDuration
>>> quarter == ClockDuration(250_000)
False
>>> quarter < ClockDuration(250_000)
Traceback (most recent call last):
...
TypeError: ...

Attributes

Name Description
temporal_system The TemporalSystem this element belongs to (for introspection and compatibility checks).
__slots__
rational_length Returns a fraction value representing the length of the element,

Methods

Name Description
scale Return this element scaled by a positive scalar, according to its TemporalSystem.
__eq__
__lt__ Shorter than other, by rational length, within compatible systems.
__hash__

scale

scale(scalar: int | Fraction)

Return this element scaled by a positive scalar, according to its TemporalSystem.

The result’s rational_length must equal self.rational_length * scalar. Implementations should return an element of the same type where the system allows it, and otherwise the closest thing the system offers: WSMN’s MetricalDuration returns a MetricalDuration for powers of two and may return a tuplet member or a TiedDuration for other scalars.

Raises

Name Type Description
ScalingError If scalar is not a positive rational, or if the scaled value cannot be represented in this TemporalSystem at all. Callers may catch this and fall back to an alternate strategy.

__eq__

__eq__(other)

__lt__

__lt__(other)

Shorter than other, by rational length, within compatible systems.

>>> from openmusickit.systems.wsmn.temporal.symbols import quarter, dotted_quarter
>>> quarter < dotted_quarter, dotted_quarter < quarter
(True, False)

__hash__

__hash__()