Plugin: Accessing rest dots

• Apr 9, 2022 - 18:00

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:

finddots.png


Comments

You can assess this by the duration:

var current = durationTo64(element.duration);
var analyze = analyzeDuration(current);
 
console.log(current + " => " + analyze.base + "/" + analyze.ratio)
 
function analyzeDuration(target) {
    var base = Math.log(target) / Math.log(2);
    var remaining = base - (base | 0); // base - trunc(base);
    base = base | 0; // = trunc
    base = Math.pow(2, base);
    var ratio = ((Math.pow(2, remaining) * 10000) | 0) / 10000;
 
    var half = null; ;
 
    // Gestion des arrondis
    // Gestion des arrondis
    if (Math.abs(ratio - 1.125) <= 0.01) {
        ratio = 1.125;
        half = 1.25;
    } else if (Math.abs(ratio - 1.25) <= 0.01) {
        ratio = 1.25;
        half = 1.5;
    } else if (Math.abs(ratio - 1.375) <= 0.01) {
        ratio = 1.375;
        half = 1.75;
    } else if (Math.abs(ratio - 1.4375) <= 0.01) {
        ratio = 1.4375;
        half = 1.875;
    } else if (Math.abs(ratio - 1.46875) <= 0.01) {
        ratio = 1.46875;
        half = 1.9375;
    } else if (Math.abs(ratio - 1.5) <= 0.01)
        ratio = 1.5;
    else if (Math.abs(ratio - 1.75) <= 0.01)
        ratio = 1.75;
    else if (Math.abs(ratio - 1.875) <= 0.01)
        ratio = 1.875;
    else if (Math.abs(ratio - 1.9375) <= 0.01)
        ratio = 1.9375;
 
    return {
        "base": base,
        "ratio": ratio,
        "half": half
    };
 
}
 
 
function durationTo64(duration) {
    return 64 * duration.numerator / duration.denominator;
    }

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 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 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 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.

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