import QtQuick 2.9 import QtQuick.Controls 1.5 import QtQuick.Layouts 1.3 import QtQuick.Dialogs 1.2 // FileDialog import QtQuick.Window 2.3 import Qt.labs.folderlistmodel 2.2 import Qt.labs.settings 1.0 import QtQml 2.8 import MuseScore 3.0 import FileIO 3.0 MuseScore { menuPath: "Plugins." + qsTr("transposer open document") description: "openes a document and transposes it from C to Bb" version: "1.0" requiresScore: false property var thisScore onRun: { console.log("Hello Transposer") if (mscoreMajorVersion < 3) { window.visible = false versionError.open() } else { //window.visible = true //This command fails } var fileName="C:/Users/Dirk/Documents/MuseScore3/Partituren/testin.mscz" thisScore = readScore(fileName,false) //This opens the file, but it is greyed out in Musescore if (thisScore) { console.log(thisScore) } else { console.log("thisScore object failed : Please close the greyed out file!!") } openFileTimer.running=true } Timer { id: openFileTimer interval: 1000 //long time interval helps seeing what happens running: false onTriggered: { console.log("Score name=" + thisScore.scoreName) thisScore.startCmd(); thisScore.visible = true // Is there another command, which will make the score visible, and above all the object model accessible? cmd("select-all"); //Unforturnatly only works when the file is opened manually. thisScore.endCmd(); for (var curStaff = 0; curStaff < thisScore.nstaves; curStaff++) { walkOneStaff(curStaff); } var TransUp=2 // transpose up a whole step for Bb instrument console.log("Original key: " + thisScore.keysig); /// Debug: Original key: 2 for (var i = TransUp; i-- > 0; ) { thisScore.startCmd(); cmd("select-all"); cmd("transpose-up"); thisScore.endCmd(); } console.log("Transposed key: " + thisScore.keysig); // Debug: Transposed key: 2 i.e. cmd("transpose-up") does not work. var targetFile ="C:/Users/Dirk/Documents/MuseScore3/Partituren/testout.mscz"; var res = writeScore(thisScore, targetFile, "mscz") console.log(" -> %1".arg(targetFile)) closeScore(thisScore) Qt.quit() } } function walkOneStaff(staffIdx) { var cursor = thisScore.newCursor(); cursor.filter = -1 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.KEYSIG) { console.log(e) ; console.log(e.accidental) } if (e.type == Element.CHORD) { var chord = e; var notes = e.notes; // Loop through notes. for (var idx = 0; idx < notes.length; idx++) { var note = notes[idx]; // e.notes[0].tpc=e.notes[0].tpc+2 //e.notes[0].pitch=e.notes[0].pitch+2; e.notes[0].pitch=e.notes[0].pitch; e.notes[0].tpc=e.notes[0].tpc ; console.log("tpc = ", e.notes[0].tpc) console.log("pitch = ", e.notes[0].pitch) //thisScore.selection.elements.push(note) //does not work anymore //e.notes[0].pitch=e.notes[0].pitch+2; /* e.notes[0].tpc = refNote.tpc; e.notes[0].tpc1 = refNote.tpc1; e.notes[0].tpc2 = refNote.tpc2; */ thisScore.selection.select(note, true) } // Loop through grace notes. for (var gc = 0; gc < chord.graceNotes.length; gc++) { var gchord = chord.graceNotes[gc]; for (var gn = 0; gn < gchord.notes.length; gn++) { var gnote = gchord.notes[gn]; thisScore.selection.select(gnote, true) // thisScore.selection.elements.push(gnote) } // Grace note loop } chordNum++ } // Chord processing else { // Non-chords } } cursor.next(); } // Segment walk loop console.log("^^^^^^ END STAFF " + cursor.staffIdx + " chordcount " +chordNum+ " ^^^^^^"); } }