//============================================================================= // MuseScore // Music Composition & Notation // // Copyright (C) 2012 Werner Schweer // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 // as published by the Free Software Foundation and appearing in // the file LICENCE.GPL // https://musescore.org/en/node/273379 //============================================================================= import QtQuick 2.2 import MuseScore 3.0 MuseScore { menuPath: "Plugins.Examples.SegmentWalk" version: "0.0.1" description: qsTr("Walks over all segments of a score") pluginType: "dialog" //requiresScore: true //not supported before 2.1.0, manual checking onRun function setCursorToTime(cursor, time){ cursor.rewind(0); while (cursor.segment) { var current_time = cursor.tick; if(current_time>=time){ return true; } cursor.next(); } cursor.rewind(0); return false; }// end setcursor To Time onRun: { if (!curScore) { console.log(qsTranslate("QMessageBox", "No score open.\nThis plugin requires an open score to run.\n")); Qt.quit(); } var cursor = curScore.newCursor(); cursor.rewind(0); //fixed the running to just voice 1 of staff 1 now, as the console.log only keeps last 1000 messages anyway for (var track = 0; track < /*curScore.ntracks*/ 1; ++track) { //console.log('===== Track ' + track + ' ====='); var segment = curScore.firstSegment(); while (segment) { var aCount = 0; var annotation = segment.annotations[aCount]; while (annotation) { //console.log('aCount = ' + aCount); if (annotation.type == Element.STAFF_TEXT) { var stafftext = annotation; console.log('stafftext.text = ' + stafftext.text); console.log('time = ' + segment.tick); var lyric = newElement(Element.LYRICS); lyric.text = stafftext.text; //stafftext.remove(); removeElement(stafftext); setCursorToTime(cursor, segment.tick); cursor.add(lyric); annotation = segment.annotations[++aCount]; } } segment = segment.next; } } Qt.quit(); } }