Add comments to a score (Changelog, notes etc...)

• Nov 24, 2016 - 18:02

Last weekend I sat down with a french music teacher, composer, and MuseScore user @skunt. He asked me if it would be possible to have a dialog where he could write some text notes. He would use this dialog to write down the current state of the score, TODOs, things to be worked on. With his students, he would use it to add some comments about the state of learning process of the piece etc...

So I wrote a plugin: https://musescore.org/en/project/scorecomments

Once installed and activate, go to Plugins > Comments and a dialog will pop up. Enter some text, save your score, and next time you open it, this dialog will show the same text.


Comments

In reply to by skunt

Now working with this plugin :)

To launch it with a shortcut (ALT- works well), it's ok. But to close the window I must leave my keyboard and take the mouse, it's not very useful.

Is there a way to close by pressing ESC key e.g. ?

In reply to by skunt

It doesn't really harm, but doesn't do any good either, and should get prevenddt. Unfortunatly the requiresScore property is not available in 2.0, but what about `if (currentScore === 'undefined' ) Qt.quit()` Not sure this works with "pluginType: Dialog" though

In reply to by jeetee

OK, tried with `if (!curScore)` and it seems to work, sort of (the dialog shows up very briefly still),
it didn't work at all with `if (typeof curScore === 'undefined' )` though.

PR created and sent ;-)

BTW: the problem with the short flashing dialog exists with my Batch convert plugin too, here at MuseScore start and only visible if the computer is quite slow or pretty busy with some other stuff. And hints how to avoid that are appreciated...

In reply to by Jojo-Schmitz

With some minor changes the flashing dialog can be removed.

Use a window object and only display it if a score is open.

You need to import the window type with
{syntaxhighlighter class="brush: js"}
import QtQuick.Window 2.2
{/syntaxhighlighter}

The top of the code then should look like this:

{syntaxhighlighter class="brush: js"}
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.2
import MuseScore 1.0

MuseScore {
menuPath : "Plugins.Comments"
version : "2.0"
description : qsTr("This plugin adds comments to your score")
pluginType : "Dialog"
//requiresScore: true // needs MuseScore > 2.0.3

onRun : {
if (!curScore) {
Qt.quit();
} else {
window.visible = true;
}
}

Window {
id : window
width : 400;
height : 300;
visible : false

Label {
{/syntaxhighlighter}

And to save the text if the window is closed by clicking the windows X tool at the end of the Window object (still within it) add:
{syntaxhighlighter class="brush: js"}
onClosing : {
if (curScore)
curScore.setMetaTag("comments", abcText.text)
Qt.quit()
}
{/syntaxhighlighter}
I also like the plugins to remember where I left the window last time I used it, and by using window we can.

At the end of the window object (still within the window object) add :

{syntaxhighlighter class="brush: js"}
Component.onCompleted : {
if (curScore) {
var metrics = curScore.metaTag("metrics");
if (metrics) {
metrics = JSON.parse(metrics);
window.x = metrics.x;
window.y = metrics.y;
window.width = metrics.width;
window.height = metrics.height;
}
}
}
{/syntaxhighlighter}
And change the on closing to:
{syntaxhighlighter class="brush: js"}
onClosing : {
if (curScore) {
var metrics = {
x : window.x,
y : window.y,
width : window.width,
height : window.height
}
curScore.setMetaTag("comments", abcText.text)
curScore.setMetaTag("metrics", JSON.stringify(metrics));
}
Qt.quit()
}
{/syntaxhighlighter}

I initially missed the mod to close the window on escape, we need to modify the key handler to:
{syntaxhighlighter class="brush: js"}
Keys.onPressed : {
if (event.key == Qt.Key_Escape) {
if (curScore) {
curScore.setMetaTag("comments", text)
var metrics = {
x : window.x,
y : window.y,
width : window.width,
height : window.height
}
curScore.setMetaTag("metrics", JSON.stringify(metrics));
}
window.close();
Qt.quit()
}
}
{/syntaxhighlighter}

Full code with these mods is available here:

https://docs.google.com/document/d/1VsWhX7ThMM693D7e_tggjuDBndC8sIpqXWV…

Copy and paste it to a new plugin.

I can't find out what pluginType : "Dialog" actually does, but as it runs with it there, I left it in.

There is an awful lot of functionality in the QML environment, I'm just getting to grips with some of it.

Hope it helps.

In reply to by stevel05

Awesome ideas to improve this plugin ! Thanks guys !

@Stevel05: Your code works very well ! Thank you for the explanations and your contribution.

My question is : what happen if the user modify or delete metrics informations in Score Properties ? The window dialog seems to use its default centered position.

In reply to by stevel05

You could just as well wrap into another Dialog iso a Window, similar setup, slightly different visual effect.

As for saving settings for/from a plugin, you're better off using the actual settings provision rather than storing it in the score (what you're doing now). See https://github.com/jeetee/MuseScore_Plugin_Examples for an example using both techniques.

@steve: pluginType: "dialog" and "dock" results in a different wrapping structure when the plugin is loaded, see https://github.com/musescore/MuseScore/blob/522e84dfb196ac7a61830c4666f…

In reply to by stevel05

Pull requests welcome. https://github.com/lasconic/musescore_comments

I'm not a fan at all of saving the dialog metrics in the score properties... If you use different computers or share your files with others, the dialog might be completely out of screen.
Probably better to use Qt.labs.settings

Regarding requireScore in 2.0.4/2.1, I don't think it's a good idea either (sorry). It would mean that plugin made for this version would not work with 2.0.X, and that would be a pity.

In reply to by Jojo-Schmitz

@Jojo: No is the short answer.
The plugin code in the older/current released versions is very strict of which members/children appear at the 1st level of the plugin. Having requireScore in your plugin means the plugin itself can't get instantiated in 2.0.x
That's all water under the bridge unfortunately.

In reply to by [DELETED] 5

On my macOS Sierra and musescore 2.0.3.1 :

It works, but there is two problems :

1/ There are tow windows that appears when I launch le plugin : the second window is grey :
Capture d’écran 2016-11-27 à 20.49.16.png

2/ If the window is open : I type some text but I don't press esc key : I click on the save icon : the window plugin closes and the comments is not saved in the metaTag.

In reply to by stevel05

1/ the second window has disappeared. This bug is fixed.
2/ if save without quit the plugin dialog, the text is correctly saved. Bug fixed.
3/ I saw that the position of the dialog is saved too.
4/ Without current score opened, laughing the plugin does not do anything. So, ok.

Now, this plugin seems to have a great behavior. Thanks @stevel05, great work !

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