How to Remove a Clef Using the Plugin API

• Feb 6, 2025 - 00:30

Hi, this is my first post.
Apologies if this topic is misplaced.

How can I remove a clef that appears in the middle of a measure using the Plugin API?
I can access the Clef element using a Cursor, but I cannot find an API method to delete it.

Could someone help me understand how to remove a Clef?

  • Motivation:
    When opening a MIDI file, clefs sometimes appear in the middle of measures.
    I have been manually deleting them with the Delete key, but I would like to create a plugin that removes them automatically.

  • Environment:
    MuseScore 3.6.2.548021803
    Qt 5.9.9
    Windows 11 24H2

  • Source Code:

var cursor = curScore.newCursor();
cursor.rewind(Cursor.SCORE_START);
cursor.voice = 0;
cursor.staffIdx = 0;
 
var staffEnd = curScore.nstaves;
var tickEnd = 0;
var toEOF = true;
 
for (var s = 0; s < staffEnd; s++) {
    cursor.rewind(Cursor.SCORE_START);
    cursor.staffIdx = s;
    cursor.voice = 0;
 
    for (var v = 0; v < 4; v++) {
        cursor.rewind(Cursor.SCORE_START);
        cursor.staffIdx = s;
        cursor.voice = v;
        cursor.filter = Segment.ChordRest | Segment.Clef; 
 
        while (cursor.segment && (toEOF || cursor.tick < tickEnd)) {
            if (cursor.element) {
                if (cursor.element.type == Element.CLEF) {
                    var clef = cursor.element;
                    // this point
                }
            }
            cursor.next();
        }
    }
}

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