MessageDialog code stops plugin from loading
I am using Windows 8.1 (6.3), Arch.: x86_64, MuseScore version (64-bit): 3.6.2.548021803, revision: 3224f34
This program uses Qt version 5.9.9.
I am trying to output some data after my plugin runs.
But as soon as I add the following code, the plugin no longer reloads.
What am I missing?
var debugDialog = MessageDialog {
title: qsTr("NOBREAK Plugin Results")
text: qsTr(messageText)
standardButtons: StandardButton.Ok
onAccepted: Qt.quit // Exit after the user clicks OK.
}
debugDialog.open()
If MessageDialog is not supported, is there another way to output information on the screen?
Here is the rest of the code:
/*
NOBREAK Plugin for MuseScore
Plugin Name: NOBREAK
Description: Searches measures for a staff text equal to "_nb".
If found, the text is hidden, the measure is marked as non-breakable (NOBREAK),
and a MessageDialog lists all affected measure numbers.
Author: [Your Name]
Version: 1.0
*/
import QtQuick 2.0
import QtQuick.Dialogs 1.2
import MuseScore 3.0
MuseScore {
// Marker text to search for
property string markerText: "_nb"
// The name displayed in the plugin menu.
menuPath: "Plugins.NOBREAK"
// Entry point of the plugin.
onRun: {
if (!curScore) {
console.log("No score is open.");
Qt.quit();
return;
}
// Array to store measure numbers with the marker.
var measuresWithMarker = [];
// Create a cursor and rewind to start processing by measures.
var cursor = curScore.newCursor();
cursor.rewind(Cursor.REWIND_MEASURE);
// Loop through each measure.
while (!cursor.eos()) {
var measure = cursor.measure;
var foundMarkerInMeasure = false;
// Iterate over all elements in the measure.
for (var i = 0; i < measure.elements.length; ++i) {
var el = measure.elements[i];
// Check if the element is a StaffText and its text exactly matches the marker.
if (el && el.type === ElementType.StaffText && el.text === markerText) {
el.visible = false; // Hide the marker text.
foundMarkerInMeasure = true;
}
}
// If we found the marker in the current measure, mark it as NOBREAK.
if (foundMarkerInMeasure) {
// Assuming MuseScore supports 'nobreak' property on measures.
measure.nobreak = true;
// Record the measure number.
// (If your MuseScore version uses a different property, adjust accordingly.)
measuresWithMarker.push(measure.no);
}
cursor.nextMeasure();
}
// Prepare the message text.
var messageText = (measuresWithMarker.length > 0) ?
"Measures with '_nb' marker found:\n" + measuresWithMarker.join(", ") :
"No measures found";
// Create a MessageDialog to display the results.
/*
var debugDialog = MessageDialog {
title: qsTr("NOBREAK Plugin Results")
text: qsTr(messageText)
standardButtons: StandardButton.Ok
onAccepted: Qt.quit // Exit after the user clicks OK.
}
debugDialog.open()
*/
}
}
Comments
What's the output in the plugin editor's console?
In reply to What's the output in the… by Jojo-Schmitz
This is part of the problem. I couldn't figure out how to see the console output, so I was trying to build my own way of displaying the variables in some message box. Somebody below recommended I try some built in plugin editor instead. Hopefully it'll work.
In reply to This is part of the problem… by a1s2d3f4
I confirm that I can see console.log messages when I use the Plugin Creator GUI in MuseScore 3 instead of my IDE to code.
But when I try to do the same in MuseScore 4, I don't see Plugin Creator there.
Do you know how I can output messages to console (or whatever it would be) when I test under MuseScore 4?
In reply to I confirm that I can see… by a1s2d3f4
Mu4 has no plugin editor and so no console either, the messages end up in the logs though
In reply to Mu4 has no plugin editor and… by Jojo-Schmitz
Oh, please do let me know where the log files are! I can load it into my Notepad++ and have it refresh every time the file changes. I guess I still have to go back to my manual "Reload" of the script code to test the plugin. Also, in case you know, is there a way to insert a "NO-BREAK" layout object into a measure in Mu4? Because after trying everything, I gave up in Mu3.
In reply to Oh, please do let me know… by a1s2d3f4
They should be here:
C:\Users(username)\AppData\Local\MuseScore\MuseScore4\logs\
but it doesn't seem like a good idea to start writing plugins with Musescore 4.
In reply to Oh, please do let me know… by a1s2d3f4
There's non no-break in Mu3
In reply to There's non no-break in Mu3 by Jojo-Schmitz
Thanks. I know there is no break in the user-interface "Palette". I was hoping that I could insert it through an API call because I read somewhere that the programmers "left the code in", but removed the palette item.
In reply to Thanks. I know there is no… by a1s2d3f4
Hmm, good one, not sure, but IIRC the cost de code got disabled too
I can't quite tell exactly what's wrong with your code (should it be Qt.quit()? Is MessageDialog supported?), but feel free to adapt the code below which works well for me:
In reply to I can't quite tell exactly… by michaelnorris
Thank you. Yes, this works well.
Qt.quit() is known to cause crashes in Mu4
It shouldn't in Mu3 though
it's a bit difficult to fix this code, there are too many points with improper use of the qml language and Musescore conventions. It should be corrected by examining other plugins to learn, correcting from time to time any error shown by the console.
cursor.eos()
is very nice, but unfortunately it doesn't exist... except in Greek mythology
In reply to it's a bit difficult to fix… by ILPEPITO
To be more precise, your code is probably conceptually correct, but the Musescore API doesn't have several properties that you assigned. And this will involve not only fixing these properties, but also writing the code differently.
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/index…
In reply to To be more precise, your… by ILPEPITO
Thanks. I'll try the plugin editor method. So far I have been editing the QML file in Notepad++ and hitting Reload to try my changes in MuseScore
In reply to Thanks. I'll try the plugin… by a1s2d3f4
Correct procedure. Beware that the 'Plugin Creator' does not notify you that a property does not exist: when something is wrong you will have to create a message like this:
console.log(cursor.eos);
(eos without the brackets, to transform it into a property) to see (in the 'Plugin Creator' window) if a certain value returns or 'undefined'. In this case you will see 'undefined'.