Get ticks of selected elements

• Aug 6, 2019 - 01:21

I have been working on the development of a plugin recently that generates a part of the score. For the moment I have only been using the range selection with the (quite weird to me as I don't understand this choice of implementation) cursor rewind method.

However MuseScore also has a Ctrl+click mechanic that enables to select notes individually, but I haven't found any way to access these notes... Does someone has the solution?

Also if someone could explain me the logic behind the cursor rewind, I would be grateful ^^

Thanks in advance!


Comments

This post only addresses this question:

> However MuseScore also has a Ctrl+click mechanic that enables to select notes
> individually, but I haven't found any way to access these notes... Does someone has the solution?

Soon...The ability to access selected elements will be available in v3.3. It was added as part of this request:

https://github.com/musescore/MuseScore/pull/5243

or in the nightly builds if you're so inclined.

In current development builds, toward 3.3, curScore.selection retrieves a list of the element(s) clicked on.:
function find_usable_note() {
var selection = curScore.selection;
var elements = selection.elements
console.log(elements.length, "selections"
for (var idx = 0; idx < elements.length; idx++) {
var element = elements[idx]
console.log("element.type=" + element.type)

Plugins using it effectively start here: https://musescore.org/en/project/articulation-and-ornamentation-control

In reply to by BSG

I downloaded MuseScore 3.3. beta and tried your plug-in for red notes. It worked good no mater how I selected the notes (a range selection or a collection selection). I consider this as a great improvement over the old way which really does not work good for me in version 3.2.
Finally a simple and logical way to code MuseScore plugin which walks over the selected elements! Now I might try to code some plugin.
Thank you

meanwhile the rewind (to score beginning, selection start or selection end) is explained in the manual of the plugin creator (hit ? button in the creator).

some code to use the rewind to treat just a portion of the Score: (careful, the two < signs have been turned into html entities :/

  //work on active selection or full score
  var cursor = curScore.newCursor();
  var startStaff;
  var endStaff;
  var endTick = curScore.lastSegment.tick + 1;
  var fullScore = false;

  cursor.rewind(1); // beginning of selection
  if (!cursor.segment) { // no selection
     fullScore = true;
     startStaff = 0; // start with 1st staff
     endStaff  = curScore.nstaves - 1; // and end with last
  } else {
     startStaff = cursor.staffIdx;
     cursor.rewind(2); // end of selection
     if (cursor.tick != 0) // selection does not include last measure 
        endTick = cursor.tick;
     endStaff = cursor.staffIdx;
  }
  console.log("range is staves " + startStaff + " to " + endStaff + " - end tick: " + endTick)
  for (var staff = startStaff; staff &lt;= endStaff; staff++) {
        cursor.rewind(1); // beginning of selection
        cursor.staffIdx = staff;
        if (fullScore)  // no selection
           cursor.rewind(0); // beginning of score
        while (cursor.segment &amp;&amp; (fullScore || cursor.tick &lt; endTick)) {
               var elt = cursor.element;
               // do what you need on the element
        } //end while element
  } //end for staff

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