lenmus / lomse

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

Problem with colors in chord #393

Closed denisgottardello closed 3 months ago

denisgottardello commented 3 months ago

Hi, as you can see in the attached image the color attribute does not be applied correctly. My lpd code is

(chord (n b3 q p2 (color #ff0000))(n +d4 q p2 (color #ff0000))(n +f4 q p2 (color #ff0000)))

Screenshot_20240524_100211

cecilios commented 3 months ago

Thanks for reporting. I understand that the problem is that you expected the stem to also be drawn in red.

I'm very busy today and won't have time to look at this. Throughout the weekend I'll look at it and tell you something.

cecilios commented 3 months ago

By the way, if you write the LDP code by hand, you can save keystrokes since it is not necessary to put the staff (e.g. p2) on each note, since the LDP compiler always assumes the last entered staff.

cecilios commented 3 months ago

I have checkd this issue and I can confirm that there is a problem: in single notes stem color is always inherited from notehead's color. But in chords, no inheritance is applied. This was done in this way to facilitate highlighting only one of the chord noteheads and, thus, stem color must be specified in the stem.

But this decision must be reviewed because in some applications it could be necessary for single notes to have the notehead color different from that of the stem. So properties inheritance must be clearly defined and elements to control it have to be defined.

Currently, for LDP, there is no way to specify stem color and thus new properties/elements must be introduced in LDP (e.g. the possibility to specify color in the stem element or a new property in the chord element to specifý that notehead properties must be propagated to children elements).

I had no idea of adding more functionality to the LDP language as, to my knowledge it is not used in any project except in LenMus app. You are the first one reporting something related to LDP so, in order to find the most convenient way to solve this issue, I would appreciate if you could share some information about your project using Lomse and and why you have decided to use LDP. You can reply to me by PM if you prefer to keep this information confidential.

denisgottardello commented 3 months ago

Hi, I have written a free software (you can download it fro my website) to manage piano scores and other. Now I'm implementing the "solfeggio" (I don't know how to translate "solfeggio" in english. It is a read exercise.). After having choose the scale, the software dislays some notes. The note in red (can be more than one if it is a chord) is the note to play by a midi piano. If the playd note is correct the software will display the playd note in black and the next one in red. In other words I need to diplay in red the note to play. Please have a look at the picture. Screenshot_20240524_214752

cecilios commented 3 months ago

Thank you very much for sharing the information about your application. I see that it is a teaching application, like was mine, LenMus, which gave rise to this project. Feel free to ask me anything that you could need about Lomse, LDP or approaches and algorithms implemented in my LenMus application.

I understand that this issue is not critical for your application and it is more an aesthetic issue. I have been thinking about a simple and coherent way to solve it and I think the best approach would be to change Lomse to propagate the color of the noteheads to the stem, as it is currently done in simple notes. But for chors, this propagation will take place only when all the noteheads have the same colour; otherwise, the stem would be displayed in black unless the stem color was explicitly specified. With this change, the behavior of the chords will be consistent with that of the simple notes, and easily understandable and intuitive by Lomse users.

It would then remain pending how to specify the stem color. This can be done in MusicXML but not in LDP since, currently, the 'stem' element does not accept the 'color' sub-element and my intention is not to continue developing LDP unless a really important need arises.

Is this solution acceptable? Any observations or alternative solutions that may be better?

denisgottardello commented 3 months ago

Hi, and many thank for you reply. Yes, it not so important. I can complete my software without any problem. I have reported the issue only to improve Lomse. Best regards.

In data lunedì 27 maggio 2024 14:06:49 CEST, Cecilio Salmeron ha scritto:

Thank you very much for sharing the information about your application. I see that it is a teaching application, like was mine, LenMus, which gave rise to this project. Feel free to ask me anything that you could need about Lomse, LDP or approaches and algorithms implemented in my LenMus application.

I understand that this issue is not critical for your application and it is more an aesthetic issue. I have been thinking about a simple and coherent way to solve it and I think the best approach would be to change Lomse to propagate the color of the noteheads to the stem, as it is currently done in simple notes. But for chors, this propagation will take place only when all the noteheads have the same colour; otherwise, the stem would be displayed in black unless the stem color was explicitly specified. With this change, the behavior of the chords will be consistent with that of the simple notes, and easily understandable and intuitive by Lomse users.

It would then remain pending how to specify the stem color. This can be done in MusicXML but not in LDP since, currently, the 'stem' element does not accept the 'color' sub-element and my intention is not to continue developing LDP unless a really important need arises.

Is this solution acceptable? Any observations or alternative solutions that may be better? -- +39.347.4070897 http://www.labcsp.com[1] http://www.denisgottardello.it[2] GMT+1 Skype: mrdebug


[1] http://www.labcsp.com [2] http://www.denisgottardello.it

cecilios commented 3 months ago

The issue of chord's stem is now fixed (in my branch). The new rules for chords and single notes are:

Stems and flags are always rendered in the default color (black) unless the source file specifies a color. When the stem color has not been explicitly specified, the stem and the flag are rendered in the same color as the notehead. For a chord, stem and flag when color has not been explicitly defined in the source file, they are rendered in the same color as all the noteheads, but if the noteheads do not all have the same color, stem and flag are rendered in the default color (black).

image

But before creating a PR it is necessary to apply a similar solution to beams:

For the beam that joins a group of notes or chords, the rule is similar: if the beam color has not been specified in the source file, it will be drawn in the same color as all the noteheads only if they all have the same color; otherwise, in the default color (black).

If anyone feels that the new criteria for color inheritance are not correct or that there is a better solution, please comment on it. Otherwise I hope to be able to find time to fix this for beams and send a PR in a few days.