Plugin: Accessing rest dots
How do I access rests dots in a plugin to change their colour? I can change the colour of the rests themselves but, even though there are dotted rests in my score, I can't seem to get a handle on the dots.
This console.log line never triggers:
Comments
They're not available :'(
While dots internally can be accessed for a ChordRest, for some reason the Plugin API defined them directly and solely on a Note: https://github.com/musescore/MuseScore/blob/3.x/mscore/plugin/api/eleme…
In reply to They're not available :'(… by jeetee
Thanks. I'll use 2 rests instead of a dotted rest.
You can assess this by the duration:
Remark: "dotted" elements have always a length >= 1.5* the "non-dotted" element length.
This code also deals where one have to achieve a length between in [1,1.5[ of the the "non-dotted" element.
In reply to You can assess this by the… by parkingb
Good guessing. Not sure how it holds up if inside a tuplet?
But it doesn't help at all in getting the dot element to be able to change it's color property ;-)
In reply to Good guessing. Not sure how… by jeetee
Actually, it does because the duration of an element within a tuplet is not affected by the tuplet. It is the duration "as-if-there-were-no-tupelt" (should retest it to be sure at 100%).
In reply to You can assess this by the… by parkingb
If I can't get a JavaScript object to access the rest dot then I don't see any way of changing the dot's properties, e.g. colour. Am I missing something?
(I can do this easily enough via my Excel plugout framework but that means working with the MSCX file rather than the MSCZ file which, in this case, is just not an efficient way to work.)
In reply to If I can't get a JavaScript… by yonah_ag
I'm now wondering whether the dot would be included in
selection.elements
if you select that chord as a range.In reply to I'm now wondering whether… by jeetee
Maybe, but this code already runs against the whole score which I guess is already a range.
https://github.com/yonah-ag/musescore-tidy-tab-score/blob/main/TidyTabS…
In reply to Maybe, but this code already… by yonah_ag
That's a private repo, so 404 for me.
My line of thinking was that if the dot is included in
selection.elements
then you could use the Selection API to range select your rest, which should also select the dot.In reply to That's a private repo, so… by jeetee
Oops! It's public now.
Selection.elements sounds like it would not be useable unless I actually selected a range. This plugin processes the whole score as it has no benefit in applying only to selections, but I'll check out your suggestion as a possible workaround.
In reply to Oops! It's public now… by yonah_ag
You can force a selection with the selectRange method. Sometimes with the API you don't have any other choices than making an explicit selection in order to access some elements or functions you would normally expect to be exposed by the API as object properties or object methods but that are not.
In reply to You can force a selection… by parkingb
Thanks, I'll have a go with that idea.
In reply to You can assess this by the… by parkingb
@parkingb
This doesn't work for whole rests that span a non 4/4 measure. What we really need is access to the nominal duration e.durationType. This returns an QVariant(Ms::TDuration) which unfortunately is completely empty and unreadable. It has 0 properties and both
console.log(toString(selection.elements[0].durationType));
console.log(JSON.stringify(selection.elements[0].durationType));
don't give meaningful results. Has anyone found a workaround for that?
In reply to This doesn't work for whole… by harmony8
> whole rests that span a non 4/4 measure
Can you post an example (screenshot) of this ? I'm not sure to understand...
Indeed, the
durationType
is alwaysundefined
. However you have aduration
property at the CHORD level that returns a Duration object.E.g. for a dotted quarter:
In reply to > whole rests that span a… by parkingb
I mean that these two cases (see attached image) can not be differentiated. Both have a duration of 3/4. If you use duration related logic you will always derive this to be a dotted half rest, but there might be a whole rest displayed instead. I don't think this case can be identified without durationType. Has anyone found a solution for this?
In reply to I mean that these two cases… by harmony8
By the way, does anyone know whether durationType is exposed in Musescore 4.x plugin API?
In reply to By the way, does anyone know… by harmony8
If your goal is to differentiate both cases (the "duration" rest and the "empty measure" rest), indeed using the duration property doesn't work.
But I wonder. In which would you to differentiate both cases ?
In MU4, I tested at the rest level
durationType
is defined:In reply to If your goal is to… by parkingb
I build tokens for a Optical Music Recognition model. Because of that I need the displayed symbol types as well.
Great to hear that it works in MU4. I will look into it
In reply to I build tokens for a Optical… by harmony8
Building around the MuseScore internal format (or the limitations of what is available via the plugin framework) might not be the most sustainable approach for this use case.
It might be worth looking into the MusicXML format instead (which MuseScore can export).
In reply to Building around the… by jeetee
What you could do is create a plugin exporting the file to MusicXML, launch this plugin from an external app and the analyse the MusicXML file.
I've done this with success, from a java application of mine. This is a kind of score index. The application launch a MU plugin that extracts info from MU file selected by the user and save this in a json file that the application parses in order to store the file properties.
In your case, instead of exporting the file in a json format you could export it in the MusicXML format.
The limit of this approach is that it requires MU3.6-7 as the API of MU4.x does not support exporting files for the time being.
The same limitation would apply if you would proceed the other way around : write a plugin launched from MU that would export the file to MusicXML and then have the plugin launching an external application/script.