import QtQuick 2.0 import MuseScore 3.0 MuseScore { version: "3.0" description: "This test plugin walks through all PlayEvents in a score" menuPath: "Plugins.Walk PlayEvents" // Set this to "true" to have the walker also test modify NoteEvent values. property var doWriteTest: false; onRun: { console.log("Hello PlayEvent Walker"); if (!curScore) Qt.quit(); console.log("Score name=" + curScore.scoreName); // IMPORTANT: Call creatPlayEvents to populate the Note.playEvents with ornamentations. curScore.createPlayEvents() for (var curStaff = 0; curStaff < curScore.nstaves; curStaff++) { walkOneStaff(curStaff, doWriteTest); } Qt.quit(); } // onRun function walkOneStaff(staffIdx, doWriteTest) { var cursor = curScore.newCursor(); cursor.voice = 0; cursor.staffIdx = staffIdx; cursor.rewind(Cursor.SCORE_START); console.log("###### START STAFF " + cursor.staffIdx + " ######"); var chordNum = 0; // Current chord number on staff while (cursor.segment) { var e = cursor.element; if (e) { if (e.type == Element.CHORD) { var chord = e; var notes = e.notes; console.log("Chord[" + chordNum + "].notes.length=" + notes.length) for (var idx = 0; idx < notes.length; idx++) { var note = notes[idx]; console.log("===notes[" + idx + "].pitch=" + note.pitch) console.log("===note.playEvents.length=" + note.playEvents.length); var playEvents = note.playEvents; for (var eidx = 0; eidx < playEvents.length; eidx++) { var playEvent = playEvents[eidx]; printPlayEvent(playEvent, eidx, "------") if (doWriteTest) { console.log("------ Write PlayEvent Test: sets pitch=2, len=500, and ontime=200.") playEvent.pitch = 2 // Actually offset applied to parent pitch. playEvent.len = 500 playEvent.ontime = 200 printPlayEvent(playEvent, eidx, "------") } } // NoteEvent loop } // Note loop chordNum++ } // Chord processing } cursor.next(); } // Segment walk loop console.log("^^^^^^ END STAFF " + cursor.staffIdx + " ^^^^^^"); } function printPlayEvent(playEvent, eventIdx, prefixString) { console.log("------playEvents[" + eventIdx + "].pitch=" + playEvent.pitch) console.log("------playEvents[" + eventIdx + "].ontime=" + playEvent.ontime) console.log("------playEvents[" + eventIdx + "].offtime=" + playEvent.offtime) console.log("------playEvents[" + eventIdx + "].len=" + playEvent.len) } }