cursor segment transversing

• Feb 21, 2023 - 09:30

Do you know why the outer cursor transverses fine, but the inner copycursor does not? (expect 2160 but jump to 2400)

qml helpcursorsegment.qml

import MuseScore 3.0
MuseScore {
onRun: {
  function closestNextElement(cursor, elemType) {
    var seg = cursor.segment;
    console.log('seg.tick '+seg.tick)
    if (!seg) return false;
    while(seg = seg.next) {
      var tr;
      for (tr = 0; tr < curScore.ntracks; tr++) {
        var el = seg.elementAt(tr);
        if (el && el.type == elemType)  break;
      }
      if (tr < curScore.ntracks) {
        cursor.track = tr;
        while (cursor.tick < seg.tick)  cursor.next();
        return true;
      }
    }
    return false;
  }
 
  var cursor = curScore.newCursor()
  cursor.rewind(Cursor.SCORE_START)
  var t=true
  while( t && cursor.tick<=curScore.lastSegment.tick ){
    console.log('')
    console.log('t '+t)
    console.log('cursor.tick '+cursor.tick)
    copyc(cursor)
    t=closestNextElement(cursor, Element.CHORD)
    console.log('cursor.tick after closestNextElement '+cursor.tick)
  }
 
  function copyc(c){
    var copycursor=curScore.newCursor()
      copycursor.rewind(Cursor.SCORE_START)
    copycursor.rewindToTick(c.tick)
    console.log('copycursor.tick '+copycursor.tick)
    var copyseg = copycursor.segment;
    console.log('copyseg.tick '+copyseg.tick)
  }
}
}

output

...
Debug: t true
Debug: cursor.tick 2160
Debug: copycursor.tick 2400
Debug: copyseg.tick 2400
Debug: seg.tick 2160
Debug: cursor.tick after closestNextElement 2400
...

test mscz cursorsegment.mscz


Comments

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