Redrawing/updating score view
In my plugin I'm planning a lot of tools, which would be opened in windows on top of main MuseScore's window. The windows uses Qt.WindowStaysOnTopHint flag.
First, I'm not sure if it's should work as I use it, but I've found, that simple code:
var cursor = curScore.newCursor() cursor.rewind(1) cursor.setDuration(1, 4) cursor.addNote(60)
does not shows any note as long as I don't update the score view manually (switching between page view and continuous view, for example). Then I found doLayout() method:
var cursor = curScore.newCursor() cursor.rewind(1) cursor.setDuration(1, 4) cursor.addNote(60) curScore.doLayout()
And now the generated note is visible, but only when I click on the score view (put the MuseScore's window on foreground).
Is it possible to make changes visible in place? For example, I push a button in my foreground window, the example code is evaluating and a generated note is appeared on the score in the selected measure without any other actions.
Comments
I've found. I should to use startCmd() and endCmd() methods of Score object. There is also no need for doLayout() in such case.
Still don't fully understand what is the purpose of doLayout().
In reply to I've found. I should to use by Ales Tsurko
I'm not familair with any special considerations for plugins, but I can answer regarding the similarly-named functions in the main code.
doLayout() does pretty much what it says - it performs a full layout of the score. However, it is normally called automatically by endCmd(). So assuming you are using startCmd() and endCmd() normally to make your plugin undoable, doLayout() does indeed take care of itself. As for why doLayout() doesn't fully work when called outside the context of startCmd() and endCmd(), it specifically produces an error if called outside the context of startCmd() / endCmd() if the undo stack is dirty (eg, if you made any modifications).
In reply to I'm not familair with any by Marc Sabatella
Thanks for the explanation!