0xfe/vexflow — pull request #52 by incompleteopus (2012-04-04 04:45:59+00:00)
Title: More generic note duration handling

I created a pull request out of my code to get this finally merged, so I can move on with the ABC notation parser implementation.

Please tell me if there is anything that still needs to be changed.

Here's the full explanation for all changes:

This pull request contains changes to the way note durations are expressed to make it easier to dynamically generate notes and to express an arbitrary number of dots for the duration in conjunction with note type, which can be regular note, rest, harmonic or muted note.

To preserve backwards-compatibility there are two ways to express note duration:

1. The extended old way: The code parses durations in format [base-duration][dots][type], such as "8dddr", "2dm". There can be an arbitrary number of dots in the duration. Also, numbers 1, 2 and 4 can be used for durations w, h and q, to make the API more consistent. The old identifiers are still supported as aliases.

NOTE: I removed alias "b" for 32nd note, because I couldn't see that alias being used anywhere, but that broke one of the VexTab tests. I couldn't find the code that generates "b" as note duration:

VexTab Parser module: Notation Only Test (2, 1, 3)
1. tabstave notation and tablature
2. Died on test #2: Invalid note initialization object: "b"

2. The new way:

For example:
{
duration: "2", // duration is still a string to keep it extensible
dots: 3,
type: "r"
}

Where type can be one of "n" (default for regular note), "r" (rest), "h" (harmonic), or "m" (muted).
Parameters dots and type are optional.

To fully support the new API for note duration, GhostNote constructor now accepts both a string or an object containing the properties described above.

I added tests for both the old and new API.

I also fixed a small bug, where line_shift for tenor clef was incorrect (zero).

Since I couldn't find any tests for that, I refactored StaveNote draw tests, so that the same tests are run for all four clefs: treble, alto, tenor and bass.

In addition, I added separate tests for harmonic and muted note types.