Match musicxml code with MuseScore objects

• Aug 9, 2024 - 16:17

Hello,

If I export a musescore file to xml, one of the notes has the following description:

  <note default-x="101.91" default-y="-30.00">
        <pitch>
          <step>G</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <voice>5</voice>
        <type>half</type>
        <stem>down</stem>
        <staff>1</staff>
        </note>

So the note has voice 5 and exists on staff 1.

How do I get to this information in a plugin?

Thanks!
Luc.


Comments

In reply to by M.Thum

Thanks.

I think that the walk.qml plugin contains a bug.
The output says:
Debug: type: Chord at tick: undefined color #000000
Debug: type: Chord at tick: undefined color #000000
Debug: type: Chord at tick: undefined color #000000
Debug: type: Chord at tick: undefined color #000000
Debug: type: Chord at tick: undefined color #000000

The code says:
var e = cursor.element;
if (e) {
console.log("type:", e.name, "at tick:", e.tick, "color", e.color);

tick is a property of the cursor, not the element, so the log statment above should be:
console.log("type:", e.name, "at tick:", cursor.tick, "color", e.color);

That generates output:
Debug: type: Chord at tick: 0 color #000000
Debug: type: Chord at tick: 240 color #000000
Debug: type: Chord at tick: 720 color #000000
Debug: type: Chord at tick: 960 color #000000
Debug: type: Chord at tick: 1440 color #000000

Best Regards,
Luc.

In reply to by lucvdv

Apparently not working in newer version

I modified one of my plugins to walk through all notes;

import QtQuick 2.0
import MuseScore 3.0

MuseScore {
version: "3.0"
description: "This test plugin walks through all notes in a score"
menuPath: "Plugins.WalkNotes"

  onRun: {

        if (!curScore)
              Qt.quit();
        var segment = curScore.firstSegment();
        while (segment) {
            for (var ix = 0; ix &lt; curScore.parts.length; ix++) {    
                var part = curScore.parts[ix];
                if (!part.show)                   //skip hidden instruments
                    continue;   
                for (var track=part.startTrack; track

In reply to by elsewhere

Hello in the new example code above you find one qml that walks through all notes. To solve your problem you can start from there accessing the properties of the note element you need. You find all attributes in the plugin docu here,
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
You have to look at the note element and possible at element and scoreElement also.
Don't expect a ready made solution for a problem not even precisely specified

If you want a closer idea of the structure of a MuseScore score structure you could save in MSCX format which is MuseScore's own XML format, similar to MusicXML but closer to MuseScore's internal document object, (as referenced when walking through a score in a plugin). You will find that many of the chord/note properties are specified slightly differently.

All the properties shown in your snippet of code are avaiable via the plugin API in MS3. You will occasionally find that some score properties are not available via the plugin api. (I can't comment on MS4 because I don't use it yet).

As a last resort you can save (from plugin code) as MSCX or MusicXML then read and parse the resulting file in the same plugin.

In reply to by M.Thum

I write my own specific javascript parsing based on the plugin needs, starting with a regex reduction of the MusicXML and then using simple javascript arrays for mapping. I also have a separate Excel application for full parsing of MSCX files with decoding of various attributes.

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