Note value data type
MNX encodes note values in a microsyntax. Some examples:
Note value | Encoding |
---|---|
A whole note | /1 |
A half note | /2 |
A quarter note | /4 |
An eighth note | /8 |
A dotted eighth note | /8d |
A double-dotted eighth note | /8dd |
A breve (double whole note) | *2 |
A dotted breve | *2d |
Syntax definition
Note values less than or equal to a whole note consist of the following, in order:
- The character U+002F SLASH.
- One or more ASCII digits encoding the rhythmic duration as a power-of-two fractional denominator.
- Zero or more occurrences of U+0064 LOWERCASE D characters — one for each augmentation dot.
Note values greater than a whole note consist of the following, in order:
- The character U+002A ASTERISK.
- One or more ASCII digits encoding the base note value as a power-of-two multiplying factor.
- Zero or more occurrences of U+0064 LOWERCASE D characters — one for each augmentation dot.
Algorithm for parsing
To parse a note value, use the following procedure:
- Let input be the string being parsed.
- Let position be a pointer into input, initially pointing at the start of the string.
- Let number of dots be
0
. - If the character indicated by position is a U+002A ASTERISK character (
*
), let fractional befalse
and advance position by1
. - Else, if the character indicated by position is a U+002E SLASH character (
/
), let fractional betrue
and advance position by1
. - Else, return an error.
- Collect a sequence of characters that are ASCII digits only and let unparsed number be the result.
- Let base value be the result of parsing unparsed number using the rules for parsing integers.
- Collect a sequence of characters that are U+0064 LOWERCASE D characters. Set number of dots to the length of this sequence.
- If position is not at the end of the string, return an error.
- If base value is not equal to a power of 2, return an error.
- If base value is equal to
1
and fractional isfalse
, return an error. - If fractional is
true
, set base value to (1
/ base value). - Return base value and number of dots.