Created
May 17, 2011 04:47
-
-
Save lasconic/975969 to your computer and use it in GitHub Desktop.
Applying a function to each note in a selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apply the given function to all notes in selection | |
function applyToNotesInSelection(func) | |
{ | |
var cursor = new Cursor(curScore); | |
var selectionEnd = new Cursor(curScore); | |
cursor.goToSelectionStart(); | |
selectionEnd.goToSelectionEnd(); | |
var startStaff = cursor.staff; | |
var endStaff = selectionEnd.staff; | |
for (var staff = startStaff; staff < endStaff; ++staff) { | |
cursor.goToSelectionStart(); | |
for (var v = 0; v < 4; v++) { | |
cursor.goToSelectionStart(); // set voice to 0 | |
cursor.voice = v; //voice has to be set after goTo | |
cursor.staff = staff; | |
while (cursor.tick() < selectionEnd.tick()) { | |
if (cursor.isChord()) { | |
var chord = cursor.chord(); | |
var n = chord.notes; | |
for (var i = 0; i < n; i++) { | |
var note = chord.note(i); | |
func(note); | |
} | |
} | |
cursor.next(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment