musescore / MuseScore

MuseScore is an open source and free music notation software. For support, contribution, bug reports, visit MuseScore.org. Fork and make pull requests!
https://musescore.org
Other
11.99k stars 2.58k forks source link

Plug-in can “corrupt” score #22889

Open TeeDeeY opened 3 months ago

TeeDeeY commented 3 months ago

Issue type

UX/Interaction bug (incorrect behaviour)

Bug description

Changing a measure’s time sig actual using a plug-in can lead to a “corrupt score”. I modified the Musescore test1.qml to demo the action. The plug-in and video will be attached.

This was tested in MS 4.4 but has been a problem in prior 4.x versions.

Steps to reproduce

Copy the plug-in into the plug-ins directory, manage plug ins, add it. It’s a modified MS 4.4 demo plugin, with the title changed to include “time signature”.

Open a brand new score, any instrument, with default 4/4 signature. Run plug-in. Notice the + sign on the measure. It is 5/4, but only allows 4 notes to be entered. Saving the file in the current state gives a corruption warning. Going to the measure and pressing the DEL key “fixes” it, and then the measure can accept five quarter notes, and be saved correctly.

Screenshots/Screen recordings

No response

MuseScore Version

4.4

Regression

No.

Operating system

Ubuntu 24.04

Additional context

No response

TeeDeeY commented 3 months ago

Screencast from 2024-05-18 01-43-01.webm

TeeDeeY commented 3 months ago

test1-ts.zip

TeeDeeY commented 3 months ago

When the measure's "actual" time signature is changed using a plug-in, it should be ready for correct input, like when using the GUI. In this case, it is not. Having to press the DEL key in the GUI to cure the corruption problem is not helpful for plugins, but does demonstrate the situation.

Please look at the plugin. It is very minimal but should demonstrate the point. It changes the first measure's Actual Time Signature to 5/4, so the score should originally start with a 4/4 time signature, so a change happens.

Thanks for checking on this.

jeetee commented 3 months ago

This was/is an issue in MS3 as well; where I couldn't get it to work out even with interaction tricks such as swapping voices twice etc.

It's why the TimeSig Enforcer plugin uses insert and delete commands rather than actual time signature duration manipulation. (See https://musescore.org/en/project/time-signature-enforcer for that one, not (yet?) ported to MS4)

TeeDeeY commented 3 months ago

My time signature copy/paste plugin copies the range of time signatures correctly but when changing a measure’s actual time signature (different than the nominal) to match the original, the measure is corrupted. I’ve tried workarounds but couldn’t get them to work.

A measure’s “actual” time signature copy was requested by a user who actually needs the function.

MarcSabatella commented 3 months ago

In theory, after changing the duration you would fill any gaps that result with one of the functions dedicated to that purpose. That's what would happen internally after changing a duration etc. But probably those functions aren't exposed to plugins, so you'd have to do it by doing the math and inserting appropriate rests yourself.

In the future, it would be nice indeed if the plugin API were defined in such a way that a user plugin would be incapable of corrupting a score - if changing a measure durations worked more like the measure properties dialog and did the rest fill automatically.

TeeDeeY commented 3 months ago

In theory, after changing the duration you would fill any gaps that result with one of the functions dedicated to that purpose. That's what would happen internally after changing a duration etc. But probably those functions aren't exposed to plugins, so you'd have to do it by doing the math and inserting appropriate rests yourself.

In the future, it would be nice indeed if the plugin API were defined in such a way that a user plugin would be incapable of corrupting a score - if changing a measure durations worked more like the measure properties dialog and did the rest fill automatically.

After the plug-in is run, the measure only allowed 4 notes to be entered, as shown in the video. I’ve tried adding notes to cause a “reset” but that didn’t work, so it’s not a “math” issue. Using DEL in the GUI fixes it, showing that the plug-in interface needs to take some “known” additional steps to accomplish the task.

Hopefully fixing the issue for plugins helps in other situations. Sometimes scores are corrupted and fixing it in one place may help prevent problems in other areas of the program that use the same function calls.

MarcSabatella commented 3 months ago

Yes, I get that four beats only were present, because as I said, normally would need to have the plugin then fill in the gap it just created. Except the function to do that probably my isn’t available in the API.

The math I mean is calculating how many additional beats you need and lengthening the last note to cover that duration, etc. presumably it’s possible but would just take work. Best to ask for help with things like that in the plugins forum at MuseScore.org

meanwhile, as a feature request, yes it would be good if changing measure duration did that for you so you don’t have to add that code yourself.

TeeDeeY commented 3 months ago

If the Plug-in API performed the same tasks as the “right-click, measure properties, change the ‘actual’ time signature numbers, save”, things would be OK as well. The process is already worked out. Hopefully this get scheduled for fixing.