Note value quantity data type

A note value quantity is an integer multiple of a note value. Some examples:

Note value quantityEncoding
A single eighth note/8
Six eighth notes6/8
Six dotted eighth notes6/8d
Five whole notes5/1

Syntax definition

A note value quantity consists of the following, in order:

  1. Zero or more ASCII digits encoding the multiplier.
  2. A note value.

Algorithm for parsing

To parse a note value quantity, use the following procedure:

  1. Let input be the string being parsed.
  2. Let position be a pointer into input, initially pointing at the start of the string.
  3. Let multiplier be 1.
  4. Collect a sequence of characters that are ASCII digits only, and let unparsed number be the result.
  5. If unparsed number is not empty, assign unparsed number to multiplier using the rules for parsing integers.
  6. Let note value be the result of parsing the remainder of the string beginning at position according to the algorithm for parsing a note value.
  7. Return multiplier and note value.