Can a plugin use features of the QT graphics engine beyond what's supported in the plugin API?

• May 9, 2020 - 15:45

I would like to draw semi-transparent, filled rectangles in various colors over noteheads in a score, similar to what you would get with a highlighter. I understand that this isn't a feature of musescore itself and wouldn't exist in the plugin API. Is it possible to use the API for the underlying QT graphics engine to render such rectangles, and the plugin API to help determine the positioning and size?

If such a solution is possible, can any of the folks here offer a hint to get started? Is there another plugin that uses features of the graphic engine does this that I can study?


Comments

As you can't get access to the ScoreView object, I don't see this being possible from a plugin.

But then again, highlighting is entirely possible within MuseScore itself. Use any Staff Text and give it a semi-transparent background. Or use a note-anchored line. You can play both with the alpha setting for it, as well as with the stacking order to place it above/below other objects depth-wise.

In reply to by splainer975

Extensions aren't really documented, I had to reverse engineer this by looking at the source for the drumline extension on GitHub. But basically, it's just a ZIP file contains a collection of things that are supported and document - templates, soundfonts, workspaces, palettes, etc. My education extension adds a couple of workspaces that contain some new palettes (and in one case also change font settings for use with younger musicians), also some useful templates. but all of these things can be done individually without packaging it as an extension, which is kind of a lot of trouble frankly.

In reply to by jeetee

I have run aground trying to add note-anchored lines to the score. I'd be grateful for ideas on where I might be going wrong.

I presume that a note-anchored line is the "Line" that I can insert from the Lines palette when I have a note or chord selected. That object is identified as a "Text Line" in the status bar of the UI, and I'm able to fiddle with it in the Inspector to get the result I want.

I'm taking baby steps with the code but failing fast:
While iterating the notes of a chord, I create what I think is a "Text Line" for each note, and then try to add it to the score. I'm starting by trying this out on a single chord.

var highlight = newElement(Element.TEXTLINE); // No problem so far
cursor.add(highlight); // Once this code is present, MuseScore crashes when I run the plugin


To clarify, I want to be able to highlight each and every note of a selection or the entire score, according to the SpectraTone color scheme. (See https://musescore.org/en/node/304072). That's why Marc's nifty highlighter annotation won't work for me.

I'm modifying with the colornotes plugin as the basis for my own plugin, because it already does much of what I want. I know that I could just change the colors used in colornotes, but the effect is too subtle. I need these colors to be quite visible, hence the highlighting.

In reply to by splainer975

No, a note-anchored line is something special, it can only be added via the Add menu. Unlike the standard text line, it is designed to connect two notes specifically.

But I can't see that either would be useful for your goal. Instead, it sounds like you just want to change the note color itself. I'm not quite understanding how tweaking the note color wouldn't do the job, unless you're saying you want the color to extend beyond the border of the notehead? In which case the textline is probably closer to what you want, except that positioning it directly on the notehead is probably not so straightforward because it wasn't designed to be used that way. Instead I'd look into adding a fingering element with a text of " " and a custom text style, so the default position would be right on the notehead. All you'd have to do is figure out the exact frame size etc you need. And figure out if the plugin framework actually supports any of this.

In reply to by Marc Sabatella

Thanks so much for all the info and advice. I've had a breakthrough.

I find the note color alone too subtle for notes with whole or half head type. I have to peer really close to distinguish, for example, red from orange. I would prefer to keep the head type for metric readability.

I wasn't having much luck with fingering text regarding the positioning. However, staff text seems to work OK, if I use "\u2584" (a rectangle) as the text, set its autoplace property to false, and set its offsetY property to the 0.5 * the note's line property value.

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