Time signature data type
A time signature in MNX is defined as a sum of ordered, undotted note value quantities that define the meter of a measure. Some examples:
Time signature | Encoding |
---|---|
Four-four time | 4/4 |
Three quarters time | 3/4 |
A compound time signature of 2/8, 3/8 and 2/8, with 2+3+2 over the shared denominator 8. | 2+3+2/8 |
A compound time signature of 2/8, 3/4 and 2/8 as separate fractions (note that the spaces are ignored). | 2/8 + 3/4 + 2/8 |
Algorithm for parsing
To parse a time signature, use the following procedure:
- Let input be the string being parsed.
- Let tokens be the result of strictly splitting the string input using U+002B PLUS as a delimiter.
- If tokens is empty, return an error.
- Let shared denominator be true.
- Let fractions be an empty list.
- While tokens is not empty,
- Remove the first element of tokens and assign it to t after stripping leading and trailing whitespace.
- If t contains the characters U+002F SLASH or U+002A ASTERISK,<
- Let nv be the result of parsing t as a note value quantity.
- If nv has a number of dots greater than zero, return an error.
- If shared denominator is
true
,- Replace the denominator in each element of fractions with the denominator of nv.
- If more elements remain in tokens, set shared denominator to
false
. - Append nv to fractions.
- Else,
- If tokens is empty, return an error.
- If shared denominator is false, return an error.
- Let numerator be the result of parsing t as a valid integer.
- Append the fraction composed of numerator and the denominator
1
to fractions.
- Return fractions and shared denominator as the result.