lenmus / lomse

A C++ library for rendering, editing and playing back music scores.
MIT License
120 stars 28 forks source link

Fix overlaps when two voices in the same staff #318

Closed cecilios closed 3 years ago

cecilios commented 3 years ago

This PR fixes layout errors due to overlaps in notes, chords and rests when there are two voices in the same staff (e.g. test score 00633):

Lomse (before this PR): image

Lomse (after this PR): image

The solution has been to create a NoterestsCollisionsFixer object that will receive all note/rest shapes at a given staff and timepos, to check for overlaps and solve any detected issue by moving sideways the conflicting objects. The NoterestsCollisionsFixer object is created in the spacing algorithm in the TimeSliceNoterest objects.

When this task was started, the collision scenarios I had in mind were very simple, just unisons, notes a second apart and rests and notes collisions. But as I started to work and studied collision scenarios and engraving rules in these situations, it resulted that there are many engraving rules involved and the number of collision scenarios is overwhelming, requiring in practice near a case by case solution.

Therefore, this PR is a first step, fixing most collision cases between chords, notes, rests and accidentals. But not cases involving dots and collisions with flags, that introduce an extra level of complexity. So I prefer to take a rest on this issue for a while.

Limitations

Current implementation has some limitations:

I preferred not to deal with these two cases until having real scores displaying these types of problems, to confirm the need and to have more knowledge about the specific problems and the possible solutions.

Also, as commented, this PR does not deal with dots and with cases involving collisions with flags.

cecilios commented 3 years ago

Thank you. Merged