Issue: grace notes
Grace notes are musical ornaments, printed in a smaller font,
that take up no additional logical time in a measure.
The issue with grace notes is that as the quote above says, says take no additional logical time in a measure.
Let's take an example. On the following images
This means that:
- at the very beginning of the song, that is at \( t=0s \), a pianist must press the
la
key (akaa
). - at \( t=0.6s \), he must release the
la
key and immediately press it again - at \( t=1.2s \), he must release the
la
key. - and somewhen after pressing the
la
key the first and second, he must quickly press and release thesol
key.
However the pressing and release time for the grace key (here sol
) are not well defined.
Now let's look at the generated events:
music sheet | lilypond source | generated events |
---|---|---|
| la' \grace{sol'} la' |
Here we can easily see that the grace note has a starting time set to 0.25000000-0.25000000
. This means the grace note must have finished by the end of the first quarter note.
On the slightly more complicated sheet below, which contains two successive grace notes,
music sheet | lilypond source | generated events |
---|---|---|
| la' \grace{sol' sol'} la' |
we can see they have a starting time of respectively 0.25000000-0.50000000
and 0.25000000-0.25000000
.
The part before the dash is the time they have to finish. The part after can be used to know order them.
To decide when to play a grace note, and for how long, the algorithm used is quite simple, it will:
- Try to fit all successive grace note fairly distributed between the former and next "normal" notes, and use all the time in between these two notes
- prevent grace note from being played longer than (29 / 128) * (60 / 100) seconds to match the midi file produced by lylipond. If the former and next normal note are separated by a longer duration such that this maximum duration limit is hit, then grace notes are played at the end of the interval. That is, they are played right before the following next normal note.