How to add symbol to score?

• Apr 1, 2021 - 07:41

Please, how is it possible to add symbol to score via plugin?

I tried following, but it is not working.
What I am doing wrong please?
Thank You.

var sym = newElement(Element.SYMBOL);
sym.symbol = "noteheadSlashDiamondWhite";


In reply to by Jojo-Schmitz

Thanks, but it still doesnt work.
Here is comlete snippet.

import QtQuick 2.0
import MuseScore 3.0
MuseScore {
      version:  "3.0"
      description: "This demo plugin creates a new score."
      menuPath: "Plugins.createscore"
      requiresScore: false
      onRun: {
            var sel = curScore.selection;
            var cursor = curScore.newCursor();
            cursor.track = 0;
            var text = newElement(Element.SYSTEM_TEXT);
            text.text = "text";
            var sym = newElement(Element.SYMBOL);
            sym.symbol = "<sym>noteheadSlashDiamondWhite</sym>";
            cursor.add(text); // works
            cursor.add(sym); //doesnt work

I'm not sure you can add symbols that way.
You can add staff text however, and set the text property to the symbol you want enclosed in sym tags

In reply to by jeetee

Thanks, it seems to be usable workround at the moment.

Does it mean, it is not possible to create symbols via plugin?

Here are few examples (made in Musescore, not by plugin).
First symbol is assigned to staff (this can be probably hacked by staff text).
Scond is assigned to note. Can be this done somehow?


Attachment Size
add symbol with plugin?.mscx 6.45 KB

In reply to by sammik

The issue seems to be that you are trying to add a symbol to a rest while a cursor assumes that symbols should be added only to notes. So if you position a cursor to a note before adding the symbol then your code should work fine. In UI you can add a symbol to a rest so this is apparently something that was missed when adding that functionality to a cursor, but otherwise creating symbols is possible with plugins.

In reply to by dmitrio95

So this code change:

diff --git a/mscore/plugin/api/cursor.cpp b/mscore/plugin/api/cursor.cpp
index d09bc7389..46d66ed1f 100644
--- a/mscore/plugin/api/cursor.cpp
+++ b/mscore/plugin/api/cursor.cpp
@@ -310,8 +310,14 @@ void Cursor::add(Element* wrapped)
-                  // To be added to a note
-                  case ElementType::SYMBOL:
+                  // To be added to a note (and in case of SYMBOL also to a rest)
+                  case ElementType::SYMBOL: {
+                        Ms::Element* curElement = currentElement();
+                        if (curElement->isRest()) {
+                              s->setParent(curElement);
+                              _score->undoAddElement(s);
+                              }
+                        } // FALLTHROUGH
                   case ElementType::FINGERING:
                   case ElementType::BEND:
                   case ElementType::NOTEHEAD: {

should fix this, shoudn't it?

See (for 3.x, check the artifacts to test)
and (for master)

Edit: both have been merged, so should be found in the development builds at shortly

In reply to by dmitrio95

Thanks, for this.
But UI allows to add symbols to segment too (if it is not a bug), like staff text.

So, in case, it is not a bug, may be, question, if it wouldn't be better to cursor add it to segment.

And note.add(symbol) would add it to note (it does, in fact).

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