function applyToNotesInSelection(func) { var cursor = curScore.newCursor(); //var selectionEnd = curScore.newCursor(); var startStaff; var endStaff; var endTick; var fullScore = false;// so that not the hole score(paper) get a mark. var s=false; cursor.rewind(1); if (!cursor.segment) { // no selection console.log("Nothing select!"); s=false; } else { // else if select somthing startStaff = cursor.staffIdx; cursor.rewind(2); if (cursor.tick == 0) { // this happens when the selection includes // the last measure of the score. // rewind(2) goes behind the last segment (where // there's none) and sets tick=0 endTick = cursor.lastSegment.tick + 1; } else { endTick = cursor.tick; } endStaff = cursor.staffIdx; console.log(startStaff + " - " + endStaff + " - " + endTick); s=true; } if(s==true) { for (var staff = startStaff; staff <= endStaff; staff++) { for (var voice = 0; voice < 4; voice++) { cursor.rewind(1); // sets voice to 0 cursor.voice = voice;//voice has to be set after goTo cursor.staffIdx = staff; while (cursor.segment && cursor.tick < endTick) { if (cursor.element && cursor.element.type == Element.CHORD) { var graceChords = cursor.element.graceNotes; for (var i = 0; i < graceChords.length; i++) { // iterate through all grace chords var notes = graceChords[i].notes; func(note); } var notes = cursor.element.notes; for (var i = 0; i < notes.length; i++) { var note = notes[i]; func(note); } } cursor.next(); } } } } //end if (s==true) } //end applyToNotesInSelection