Rewind problem

• Nov 19, 2022 - 13:14

Hi guys I want to rewind to previous note but when I use line cursor.prev(); it rewinds to previous segment and it happens to be a rest. I want some line which skips the rests and rewinds to a previous note.

Thank you.


Comments

Cursor's purpose is to move by segments; you can .filter on segment types, but ChordRest is the combining type for rests and chords.
So you'll need to loop it:

while (cursor.prev() && (cursor.element.type != Element.CHORD)) {
    // Nothing to do here, just continue rewinding
}
// Do check for a valid element as you might've rewinded all the way to the start of the score.

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