Expand description
music21’s common.numberTools: quarter lengths kept exact, numbers
rounded and written the way music21 writes them, Roman numerals and
ordinals.
Structs§
- Nearest
Multiple - The multiple of a unit nearest a value, as
nearest_multiplefinds it.
Enums§
- IntOr
Float - A whole number or a float, which is what music21’s
numToIntOrFloatandroundToHalfIntegergive back. - OffsetQL
- A quarter length or an offset as music21 keeps one: a float where a float says it exactly, a fraction where none does.
Constants§
- DENOM_
LIMIT - music21’s
defaults.limitOffsetDenominator: the largest denominatorop_frackeeps a quarter length as a fraction over. - MUSIC_
ORDINAL_ NAMES - music21’s
musicOrdinals:ORDINAL_NAMESwith an interval’s own names for the first, the eighth, the fifteenth and the twenty-second. - ORDINAL_
NAMES - music21’s
ordinals: the names of the numbers from nought to twenty-two, in English.
Functions§
- add_
float_ precision - The third or sixth a value is within
grainof, asop_fracgives it, or nothing for a value near neither: music21’saddFloatPrecision, which leaves such a value alone. - approximate_
gcd - The greatest length that goes a whole number of times, to within
grain, into every one ofvalues: music21’sapproximateGCD, which tries the smallest value, then each value divided by one to sixteen. - contiguous_
list - Whether each value is one more than the one before: music21’s
contiguousList, which wants them sorted first. An empty list is contiguous here; music21 cannot look at its first value. - contiguous_
runs - The runs of sorted values each one more than the one before, as ranges
of their positions: what music21’s
groupContiguousIntegersgroups. - decimal_
to_ tuplet - The tuplet ratio, in lowest terms, that a simple decimal stands for:
music21’s
decimalToTuplet. Below one, the denominator is the larger. - dot_
multiplier - What
dotsdots multiply a note’s length by: music21’sdotMultiplier. It is always exact, since its denominator is a power of two. - float_
ratio - The exact fraction a float stands for, in lowest terms, as Python’s
float.as_integer_ratiogives it. - float_
repr - A float written as Python’s
reprwrites it: the shortest digits that read back as the same float,1.0for a whole number, and an exponent below a ten-thousandth or from 1e16 up. - from_
roman - A Roman numeral, upper or lower case, read as a number: music21’s
fromRoman. The medievalIIIIandICare read too, unlessstrict_modernrefuses a subtraction of less than a tenth. - is_
binary_ denominator - Whether
denominatoris a power of two, which is when music21’sopFracturns a fraction into a float. - is_
close - Python’s
math.isclose(a, b, abs_tol=abs_tol), with its relative tolerance of one in a billion. - limit_
denominator - The fraction nearest
numerator / denominatorwhose denominator is at mostlimit: Python’sFraction.limit_denominator, which music21’s_preFracLimitDenominatorcopies. A fraction already within the limit comes back as it is. - mixed_
numeral - A number as a whole number and a fraction,
1 1/3, with the fraction’s denominator limited tolimit: music21’smixedNumeralfor a float. - mixed_
numeral_ fraction mixed_numeralfor an exact fraction, whose denominator is not limited:-4 3/7for -31/7.- nearest_
multiple - The multiple of
unitnearest a value that is not negative, how far off it is and which way: music21’snearestMultiple. Half way rounds down. - num_
to_ int_ or_ float - A value close enough to a whole number, within a millionth, as that
whole number, and anything else as it is: music21’s
numToIntOrFloat. - op_frac
- music21’s
opFracfor a float: the float itself where its exact fraction has a denominator up toDENOM_LIMIT, and otherwise the nearest fraction within the limit, written as a float again where its denominator is a power of two. - ordinal_
abbreviation - The letters written after a number to make it an ordinal,
st,nd,rdorth, with ansafter all butstforplural: music21’sordinalAbbreviation. - ordinals_
to_ numbers - music21’s
ordinalsToNumbers, in the order it fills it: each ordinal name, lowered and not, and abbreviated,1st, and each interval name that differs from it, mapped to its number. - round_
to_ half_ integer - A number rounded to the nearest half, a quarter rounding up, as
music21’s
roundToHalfIntegerdoes: a whole number where it lands on one, and a float on a half. - str_
trim_ float - A float written with
max_digitsdecimals and its trailing zeros dropped, one decimal always kept: music21’sstrTrimFloat. - to_
roman - A number from 1 to 3999 as a Roman numeral: music21’s
toRoman. - unit_
boundary_ proportion - The span of the unit interval each value’s share of their sum takes,
one after another, the last ending at exactly one: music21’s
unitBoundaryProportion. - unit_
normalize_ proportion - Each value as its share of their sum: music21’s
unitNormalizeProportion. - weighted_
index - Which of the weighted choices a draw
drawfrom the unit interval lands on, as music21’sweightedSelectionpicks one: the last where it lands on none.