In this post we’re going to talk about the algorithm we chose for the accidentals positioning.

Simple accidental: E/4 flat:

Accidentals are placed inside columns, on the left of the note. We specify the distance between 2 columns as a quarter of the distance between two lines of the staff. The minimal distance between two accidentals in the same column is 2,5 lines, regardless of the accidental type.

Two non colliding accidentals: E/5 sharp, F/4 flat:

If the distance between two accidental is lower than 2,5 lines, one has to shift to an other column.

Two colliding accidentals: D/5 flat, F/4 sharp:

There are some rules about which one has to shift. The highest accidental has the priority to be on the right.
The last accidental has to be aligned with the first whenever possible:

Three colliding accidentals: D/5 sharp, F/4 flat, A/3 natural:

For the others accidentals, we haven’t set priority rules. We try to place them from the top to the bottom.

Here are some samples of potential renderings:

Four accidentals: E/5 flat, C/5 sharp, A/4 flat, F/4 natural:

Five accidentals: G/5 sharp, E/5 sharp, B/4 flat, F/4 flat, D/4 natural:

We are open to any suggestions to improve our algorithm of accidentals positioning. So far, we are following the rules as described by the book Music Notation, Theory and Technique for Music Notation.

The next post on accidentals will describe the behaviour we set when we have second notes (the notes that are so close, that one of the head must shift).

Second notes: E/5, D/5:

We know that we have an issue to draw leger lines, this is due to a regression, we will fix them soon…