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 signatureEncoding
Four-four time4/4
Three quarters time3/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:

  1. Let input be the string being parsed.
  2. Let tokens be the result of strictly splitting the string input using U+002B PLUS as a delimiter.
  3. If tokens is empty, return an error.
  4. Let shared denominator be true.
  5. Let fractions be an empty list.
  6. While tokens is not empty,
    1. Remove the first element of tokens and assign it to t after stripping leading and trailing whitespace.
    2. If t contains the characters U+002F SLASH or U+002A ASTERISK,<
      1. Let nv be the result of parsing t as a note value quantity.
      2. If nv has a number of dots greater than zero, return an error.
      3. If shared denominator is true,
        1. Replace the denominator in each element of fractions with the denominator of nv.
        2. If more elements remain in tokens, set shared denominator to false.
        3. Append nv to fractions.
      4. Else,
        1. If tokens is empty, return an error.
        2. If shared denominator is false, return an error.
        3. Let numerator be the result of parsing t as a valid integer.
        4. Append the fraction composed of numerator and the denominator 1 to fractions.
  7. Return fractions and shared denominator as the result.