Here is another way to reproduce this error.
1. Start with “My First Score”.
2. Select the clef in measure 1, and press the delete key.
(The clef is deleted, but a new clef is added before you can realize it is gone.)
3. Undo.
(The clef that was deleted in step 2 is inserted after the clef that replaced it.)
This issue is not limited to clefs. It applies to key signatures as well.
1. Start with “My First Score”.
2. Add a key signature in measure 1.
3. Select the key signature in measure 5, and press the delete key.
4. Undo.
The reason for this is simple enough. After an element is deleted, if its parent segment is empty, then the segment is deleted also, and the deletion of the segment is pushed to the undo stack. If the element happens to be a required clef or key signature, it is recreated, and a new segment is added to the measure, but the addition of the segment is not pushed to the undo stack. When this action is undone, the addition of the new segment is not undone, and the old segment is added back, resulting in duplication.
Pushing the addition of the new segment to the undo stack fixes the issue.
@ABL pointed out that this is only noticeable after a line break. If there is no explicit system break, duplicate clefs and key signatures may be created, but the parent segment is not enabled, and thus goes undetected until viewed in the debugger.
Comments
I cannot reproduce on mac. Jojo, could you please check on Windows?
Yes, I can still reproduce.
OS: Windows 7 SP 1 (6.1), Arch.: x86_64, MuseScore version (32-bit): 3.0.0, revision: 08a3f1b
In reply to Yes, I can still reproduce by Jojo-Schmitz
I can reproduce both on Windows 10 and on Linux Mint 18.3.
The double key happens only for systems after a line break.
See fix #210116: Delete all and Undo duplicates the clef #3700.
Here is another way to reproduce this error.
1. Start with “My First Score”.
2. Select the clef in measure 1, and press the delete key.
(The clef is deleted, but a new clef is added before you can realize it is gone.)
3. Undo.
(The clef that was deleted in step 2 is inserted after the clef that replaced it.)
This issue is not limited to clefs. It applies to key signatures as well.
1. Start with “My First Score”.
2. Add a key signature in measure 1.
3. Select the key signature in measure 5, and press the delete key.
4. Undo.
The reason for this is simple enough. After an element is deleted, if its parent segment is empty, then the segment is deleted also, and the deletion of the segment is pushed to the undo stack. If the element happens to be a required clef or key signature, it is recreated, and a new segment is added to the measure, but the addition of the segment is not pushed to the undo stack. When this action is undone, the addition of the new segment is not undone, and the old segment is added back, resulting in duplication.
Pushing the addition of the new segment to the undo stack fixes the issue.
@ABL pointed out that this is only noticeable after a line break. If there is no explicit system break, duplicate clefs and key signatures may be created, but the parent segment is not enabled, and thus goes undetected until viewed in the debugger.
Fixed in branch master, commit 2c012a23d4
fix #210116 Delete all and Undo duplicates the clef
Automatically closed -- issue fixed for 2 weeks with no activity.