How to get a "full score" object when curScore is one of the score excerpts ?

• Apr 14, 2022 - 15:05

If a score contains multiple "excerpts", the full score and its excerpts are considered as Score objects.
Depending on what is currently displayed, calling curScore will return either an excerpt's score or the full score.

That can be demonstrated with this little code, ran on a score with 2 excerpts (e.g. the one in annex):

var explore=["scoreName","parts.length","title","ntracks"];
 
var scores=[curScore,curScore.excerpts[0].partScore];
 
for(var e=0;e<explore.length;e++) {
    for(var s=0;s<scores.length;s++) {
          var score=scores[s];
          var prop=explore[e];
          var action="score."+prop;
          console.log(prop+": "+eval(action));
    }
}

When executed on the "full" score, it will return;

Debug: scoreName: mcveExcerpt
Debug: scoreName: mcveExcerpt
Debug: parts.length: 2
Debug: parts.length: 1
Debug: title:
Debug: title:
Debug: ntracks: 8
Debug: ntracks: 4

When executed on one excerpt, it will return;

Debug: scoreName: mcveExcerpt
Debug: scoreName: mcveExcerpt
Debug: parts.length: 1
Debug: parts.length: 1
Debug: title:
Debug: title:
Debug: ntracks: 4
Debug: ntracks: 4

The question is:
When curScore is an excerpt's score how can we access through the API the full/main score ?

PS: this question has started from this thread Get cursor to score from parts

Attachment Size
mcveExcerpt.mscz 5.37 KB

Comments

Probably this is not the cleanest solution, but it is possible to search through the global list of opened scores (see the scores property). Something like this code should find the correct score:

function findFullScore(curScore) {
    for (var i = 0; i < scores.length; ++i) {
        var score = scores[i];
 
        if (score.is(curScore)) {
            return score;
        }
 
        var excerpts = score.excerpts;
 
        for (var ei = 0; ei < excerpts.length; ++ei) {
            if (excerpts[ei].partScore.is(curScore)) {
                return score;
            }
        }
    }
}

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