Staff.clefList()

• May 19, 2018 - 22:12

Here it is in libmscore/staff.h: https://github.com/musescore/MuseScore/blob/1d27005a2d6dc381bf6e16ab3f4…

Here is the ClefList class: https://github.com/musescore/MuseScore/blob/1d27005a2d6dc381bf6e16ab3f4…

Here is the ClefTypeList struct: https://github.com/musescore/MuseScore/blob/1d27005a2d6dc381bf6e16ab3f4…

First I want to clarify that this ClefList is only for SegmentType::Clef, not SegmentType::HeaderClef. Staff.clefList() returns an empty map if there are no clef changes in the score, only initial clefs, which are the HeaderClefs. Please correct me if that is not the case.

I setup a 4/4 score with a clef change from G clef to F clef in the 4th measure. I iterate over the ClefList in this way:

        ClefList& clefs = staff->clefList();
        ClefList::iterator c;
        for (c = clefs.begin(); c != clefs.end(); ++c)
            whatever();

This problem can be seen in Staff::setClef(): https://github.com/musescore/MuseScore/blob/1d27005a2d6dc381bf6e16ab3f4…

If I'm debugging, and I put a breakpoint anywhere in setClef(), the clef types are correct for the newly added clef.
If I do not break in that function when I add the clef, it uses ClefType::INVALID, the default type for new Clef(). After adding the clef, when I iterate over the ClefList in my for loop, the ClefType is INVALID for concert and transposed struct members.

The crazy thing is: If I break inside setClef() the first time I add the clef, I don't have to break again during this debugging session, it just works after that. But if I don't break the first time I add the clef, the breakpoint does not fix the problem, and even inside setClef(), the ClefType is INVALID.

The new clef isn't being initialized properly without the breakpoint. Why is this happening? What can I do to correct it? Right now I'm stuck with a permanent breakpoint inside setClef().

This behavior is identical if I save the file with the clef change and reopen it. If I break in setClef(), all is good. If I don't, the clef looks fine on the screen, but the staff's CleffList has this clef as ClefType::INVALID. I haven't tested by setting console or log output and running from the debug.exe. I'm having other oddities occur when running from the debug.exe, so I'm always running inside the debugger now.

I'm running Windows 10.


Comments

An added wrinkle: In an attempt to avoid using ClefList, I tried iterating over all segments of SegmentType::Clef, then iterating by staff inside that loop. But there are no segments of type Clef in my score, even though I have a clef change at measure 4.

Segment* seg;
SegmentType st = SegmentType::Clef;
for (seg = score->firstMeasureMM()->first(st); seg; seg = seg->next1MM(st)) {

The for loop exits immediately, it does not iterate even once.

Am I misinterpreting SegmentType::Clef? Or is this another issue?

Do you still have an unanswered question? Please log in first to post your question.