Beginner struggling with creating plugins
I've never created plugins before and I'm trying to make a simple plugin to start myself off. I just want to create a C major triad on the cursor. MuseScore recognizes the plugin and I can enable it, but when I use it nothing happens. All of my knowledge comes from reverse engineering other plugins, so I'm sure there's a simple fix I'm missing.
I've attached the file below. I'm using the latest version of musescore, and VScode. I've also tried using the plugin creator in MuseScore 3, with no luck. Thanks.
Attachment | Size |
---|---|
triad.qml | 1.03 KB |
Comments
No idea whether this is a problem or absolutely required (I struggle with plugins even more than you do :-), but i noticed something odd in yours.
import QtQuick 2.2
import MuseScore 3.0
MuseScore {
version: "4.0"
Line 2 says to import MuseScore 3.0, but line 5 says that the MuseScore version is 4.0. Is that a problem?
In reply to No idea whether this is a… by TheHutch
Again, I have little experience so I'm totally unsure. I looked at the code for one of the default plugins in musescore 4, the one for interval mirroring, and it does the same thing. It's not a problem for the other one, so I figured I would copy it over.
In reply to Again, I have little… by Wreckfish319
I tried changing the import line to
Import MuseScore 4.0
but it made no difference. *shrug* As I should have said, it's a WAG anyway :-)
Someone will come along who knows more than us. (Almost anyone knows more than me :-)
In reply to No idea whether this is a… by TheHutch
No, that version mismatch is none really, it is library version vs. plugin version, one is entirely unrelated to the other.
And as of MuseScore Studio 4.4 you can drop the version on the import statements completely.
Check the logs for output from the plugin
In reply to Check the logs for output… by Jojo-Schmitz
I launched MuseScore, opened a small file, ran the plugin, and exited MuseScore. The entire log file is attached below, but it looks like the important part is ...
2025-05-12T14:19:40.545 | INFO | main_thread | ActionsDispatcher::doDispatch | try call action: action://extensions/v1/triad/triad.qml?action=main
2025-05-12T14:19:40.552 | ERROR | main_thread | ExtPluginRunner::run | Failed to load QML file: C:/Users/Owner/Documents/MuseScore4/Plugins/Triad/triad.qml
2025-05-12T14:19:40.552 | ERROR | main_thread | ExtPluginRunner::run | "file:///C:/Users/Owner/Documents/MuseScore4/Plugins/Triad/triad.qml:2 module \"MuseScore\" version 4.0 is not installed\n"
Obviously it failed to load the plugin file. Why? and how does one respond?
In reply to I launched MuseScore, opened… by TheHutch
I'm not sure what part of the error message you don't understand... to me it is 100% clear and really can't get clearer.
As mentioned before: that
Import MuseScore 4.0
is just plain wrong, useImport MuseScore 3.0
or (as of 4.4)Import MuseScore
, that number is not related to the MuseScore Studio version, but to the Plugin API versionIn reply to I launched MuseScore, opened… by TheHutch
So, I removed both version numbers. The beginning of the code now goes ...
Repeated the same thing as before: Opened MuseScore, opened a file, selected a position in the score, ran the plugin, closed MuseScore. New logfile attached but the operative lines of the log say:
In the code, the pitches are defined at line 22 by ...
I take it that's wrong. How do you define them?
In reply to So, I removed both version… by TheHutch
I don't think there's an Enum
Pitch
with those members C4, E4, G4. More likely you'd need integer valies 0 - 127 or 1 - 128, MIDI pitches. Or TPCs, Tonal Pitch Classes. Just check how other plugins do this kind of thingIn reply to I don#t tnhink there's an… by Jojo-Schmitz
I haven't been able to find any other plugins that "do this kind of thing" (and I've looked and asked before). Is there a table of MIDI pitches? and what are "TPC"s?
Well, I advance. I found a table of MIDI pitches and tried ...
... and got ...
So I tried ...
... and this time I got ...
... which refers to these lines in the code.
What's wrong with this one? How do you add a note to the score file?
In reply to I haven't been able to find… by TheHutch
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/tpc.h…
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/pitch…
In reply to I haven't been able to find… by TheHutch
Well, I figured out what was wrong with the last. It should have been
I figured out that several of the names I was using for variables were existing class names, so I changed them. So, now it doesn't give me any errors. It just doesn't DO anything. It says ...
... and nothing more. Obviously, I'm still missing something. I'm guessing that I have to give the chord a duration in order for it to be added, but I haven't found how to do that.
I would really appreciate it if someone could give me a hint here. (Code attached)
In reply to Well, I figured out what was… by TheHutch
In MS3 the duration is set with setDuration before using addNote
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
Watch out for possible infinite loop:
https://musescore.org/en/node/320206
In reply to Well, I figured out what was… by TheHutch
That's how it works, but I don't know how much you can use it. The best strategy, having at least an idea of how programming works, I think is to download the simplest plugins and try to understand how they work.
In reply to That's how it works, but I… by ILPEPITO
Not trying to make something that has any "utility". I'm not that far along. This is just a "Hello world" sort of program. I have tried to "download the simplest plugins and try to understand how they work." There aren't any "simplest plugins", as far as I can see. Or perhaps, this is the "simplest plugin" :-)
Question: exactly what do these three lines mean at the beginning?
1) import QtQuick 2.2
2) import MuseScore 3.0, and
3) version: "4.0"
Someone (Jojo?) said that one or another of them needed to be not present?
In reply to Not trying to make something… by TheHutch
'import' refers to the libraries, i.e. properties, methods, objects, controls, etc. that will be used to create the program. For this plugin you only need 'MuseScore 3.0', since it has no window (so no buttons, no checkboxes, etc.). I just changed the code, without worrying about these details. 'version' is simply the version number of the plugin, such as MU 3.6.2 or MU 4.5.2, and is optional. The simplest plugins perhaps (but not necessarily) are the 'shorter' ones, such as those that simply change the color of the note head.
In reply to Not trying to make something… by TheHutch
That
version: xx.yy
is something you'd see in the plugin manager, along with the name and description. Other than that it is pretty meaninglessThe version number after the import statements refer to a certain version of the library to import (and that is is 3.0 for Mu3 and Mu4). As of MuseScore Studio 4.4 (or rather as of Qt 6) you can drop them and always get the latest available version automagically (so need to specify it only if you want an older one).
In reply to That `version: xx.yy' is… by Jojo-Schmitz
So, then what version of QTQuick do I need to import? (I'm using MuS 4.5.2) The "2.2" in the original? Or the "6" you mention here? Or something else entirely?
In reply to So, then what version of… by TheHutch
As said, as of MuseScore 4.4 you don't need to specify the number. And here too that version is not the same as the Qt version.
In reply to As said, as of MuseScore 4.4… by Jojo-Schmitz
Does this mean that newer versions guarantee backward compatability with older versions?
In reply to Does this mean that newer… by yonah_ag
Not with pre 4.4, that still needs those version numbers
In reply to Not with pre 4.4, that still… by Jojo-Schmitz
I'm on 4.5.1, (after the demise of my MS3 uploads 🙁), but I'm pleasantly surprised to hear that possible Qt library updates couldn't create compatibility problems. I'll drop versions numbers on my includes.
In reply to I'm on 4.5.1, (after the… by yonah_ag
(Update to 4.5.2)
The plugins then won't run in 4.0.-4.3 though
In reply to (Update to 4.5.2) The… by Jojo-Schmitz
I'm not bothered about older versions and I'll update to 4.5.2 soon.
My priority is getting an emulation of the MS3 TAB Ring plugin running in MS4 because of the crippling effect MS4 has on guitar scores without TAB Ring.
I also need my user velocities copied from MS3 scores to their MS4 counterparts since opening an MS3 score in MS4 flattens all velocities to 64. (Why does it do this?) The plugin for this is 50% complete.
In reply to I'm not bothered about older… by yonah_ag
> My priority is getting an emulation of the MS3 TAB Ring plugin running in MS4 because of the crippling effect MS4 has on guitar scores without TAB Ring.
MS4 imparts a crippling effect by ignoring Len values, but at least it doesn't "flatten them" as it does with velocity.
> I also need my user velocities copied from MS3 scores to their MS4 counterparts since opening an MS3 score in MS4 flattens all velocities to 64. (Why does it do this?)
https://musescore.org/en/node/368932
I find this behavior patently unjustifiable. MS4 is FAR too willing to discard user data.
For further examples, look that the mixer settings after opening a MS3 score in MS4: the instrument is likely changes and the channel volume and pan are discarded.
I'd like to direct further comment on this point to the following post:
https://musescore.org/en/node/373626
In reply to > My priority is getting an… by scorster
— deleted —
Okay, so I just wrote very large post with a bunch of questions. However, I decided to dig a little and found half of the answers, so I deleted the post. I think I'm over the hump.
I'll still have lots of questions, but I'm starting to figure out some of the answers on my own.
Definitely struggling less, but still struggling :-)
Three questions:
1) How do I get the plugin to "see"/"know" what the current selection is in the score? The user clicks on THIS. How does the plugin identify that selection? It seems like it should be cursor.rewind(Cursor.Selection_Start) but that doesn't seem to work for me?? (which means I'm probably doing it wrong :-)
B) I can see how to read the key signature. How can I write one?
III) So far I have managed to do stuff in an open score. Can I run a plugin from the Home tab that creates a score? How?
In reply to Definitely struggling less,… by TheHutch
which means I'm probably doing it wrong
Very probabable. Color notes does this: