Plugin API: merge changes from onScoreStateChanged with user action in undo stack #5626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After having tried some of the suggestions in dmitrio95/fretboard-plugin#1 (comment) it turned out that the experimental score changes notification API does not play well with the concept of undoable actions. As a part of handling score state change a plugin may want to make some adjustment to a score (for example, update some elements or their properties). In order to make it undoable it must call
startCmd()
/endCmd()
. However this creates a separate entry in undo stack with the changes made by a plugin. When user tries to undo this action, only plugin-originated action will be undone and not the one made by user. Moreover, as plugin-originated changes are likely to depend on score state it will likely try to redo this change again. In this case his will lead to inability to undo anything at all while such plugin is running.In order to make this situation better it is proposed to merge plugin-originated changes made in response to user action with the user action itself, so invoking "Undo" command would undo both plugin-originated and user-originated changes. This should enable creating plugins which modify score editing process in certain way. An example of such plugin could be a "Note Names" plugin which updates note names for the relevant range on each score change without requiring explicit invocation by user. It might be useful for plugin developers to have such an example plugin bundled with MuseScore so I will probably create a modified version of this plugin shortly.