Match musicxml code with MuseScore objects
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
See e. g. https://musescore.org/nl/project/note-names
To traverse all segments in a score have a look at existing plugins like walk.qml
https://github.com/musescore/MuseScore/blob/3.x/share/plugins/walk.qml
In the seqment you can access all notes in all staves at this position.
The note has properties "staff" and "voice" inherited from the class "element".
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
In reply to To traverse all segments in… 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 Thanks. I think that the… 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"
In reply to Apparently not working in… by M.Thum
This won't work in Mu4, it'd crash, due to the
Qt.quit()
In reply to This won't work in Mu4, it'd… by Jojo-Schmitz
I know - I just put this together as an example how to access the data. I am currently not using Mu4 and don't know how to test plugins there.
In reply to Thanks. I think that the… by lucvdv
Works fine in Mu3, which it where it stems from
In reply to Works fine in Mu3, which it… by Jojo-Schmitz
I get the same errors as lucvdv with this walk.qml in MU3.6
walk.qml
In reply to I get the same errors as… by elsewhere
Using the one linked to above? Apparently not! It is different from the one that comes with 3.6.2, but is the one that comes with MuseScore 3.7 Evolution
In reply to Using the one linked to… by Jojo-Schmitz
What I posted is the built-in plugin from Program Files\MuseScore3\plugins I'm on Wndows 10
In reply to What I posted is the built… by elsewhere
Ok, so take the one from the link above instead
In reply to I get the same errors as… 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 If you want a closer idea of… by yonah_ag
Good idea to get attributes not exposed in the plugin API. I am already parsing MSCX in a browser web app using DomParser. This ist not available in Musescore plugin javascript. Which XML parser are you using?
In reply to Good idea to get attributes… 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.