//============================================================================= // Bagpape Note Names Plugin //============================================================================= import QtQuick 2.0 import MuseScore 3.0 MuseScore { version: "3.0" description: qsTr("This plugin names notes as per your language setting") menuPath: "Plugins.Notes." + qsTr("Bagpipe Note Names (regular)") // this does not work, why? onRun: { function forEach(items, callback) { var i = 0; if (items && typeof items === 'object') { var keys = Object.keys(items); for (i = 0; i < keys.length; i++) { callback(keys[i], items[keys[i]]); } } } var transposeOffset = 0; var mapping = { 0: {note: "C♭♭"}, 1: {note: "G♭♭"}, 2: {note: "D♭♭"}, 3: {note: "A♭♭"}, 4: {note: "E♭♭"}, 5: {note: "B♭♭"}, 6: {note: "F♭"}, 7: {note: "C♭"}, 8: {note: "G♭"}, 9: {note: "D♭"}, 10: {note: "A♭"}, 11: {note: "E♭"}, 12: {note: "B♭"}, 13: {note: "F"}, 14: {note: "C"}, 15: {note: "G"}, 16: {note: "D"}, 17: {note: "A"}, 18: {note: "E"}, 19: {note: "B"}, 20: {note: "F♯", offset: -1}, 21: {note: "C♯"}, 22: {note: "G♯"}, 23: {note: "D♯"}, 24: {note: "A♯"}, 25: {note: "E♯"}, 26: {note: "B♯"}, 27: {note: "F♯♯"}, 28: {note: "C♯♯"}, 29: {note: "G♯♯"}, 30: {note: "D♯♯"}, 31: {note: "A♯♯"}, 32: {note: "E♯♯"}, 33: {note: "B♯♯"} }; function getNoteText(note) { return qsTranslate("InspectorAmbitus", mapping[note.tpc + transposeOffset].note).toLowerCase(); } function getSuffix(note) { // g : note.pitch > 79 // c : note.pitch > 76 if (note.offset.y <= 0) { return "'"; } return ""; } function renderNote(voice, notes, element, chord) { element.color = "#777"; element.fontFace = "Segoe Script"; var text = "", fontSize = notes.length > 1 ? 12 : 13, vOff = 0; switch (voice) { case 0: vOff = 6; break; case 1: vOff = 15; break; case 2: vOff = 4; break; case 3: vOff = 17; break; } for (var i = 0; i < notes.length; i++) { var note = notes[i], noteName = getNoteText(note), sep = ","; // change to "\n" if you want them vertically, then // you may need to decrease the text.offset.y values for // case 0 an 2 (voice 1 and 3) further down (twice) if (i > 0) { text = text + sep; // any but top note } if (typeof note.tpc === "undefined") { // like for grace notes ?!? return; } if (chord.duration.ticks <= 960) { fontSize = 12; } if (chord.duration.ticks <= 480) { fontSize = 11; vOff -= 0.1; } if (chord.duration.ticks <= 240) { fontSize = 10; vOff -= 0.1; } if (chord.duration.ticks <= 120) { fontSize = 9; vOff -= 0.1; } if (chord.duration.ticks <= 60) { fontSize = 8; vOff -= 0.1; } console.log("Adding note: ", noteName); text += qsTr(noteName + getSuffix(note)); } // end for note element.text = text; element.autoplace = false; element.placement = Placement.BELOW; element.fontSize = fontSize; element.offsetY = vOff; element.fixed = true; // forEach(note, function (key, value) { // console.log(key, ": ", value) // }); } if (typeof curScore === 'undefined') { Qt.quit(); } var cursor = curScore.newCursor(); var startStaff; var endStaff; var endTick; var fullScore = false; cursor.rewind(1); if (!cursor.segment) { // no selection fullScore = true; startStaff = 0; // start with 1st staff endStaff = curScore.nstaves - 1; // and end with last } else { 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 = curScore.lastSegment.tick + 1; } else { endTick = cursor.tick; } endStaff = cursor.staffIdx; } // console.log(startStaff + " - " + endStaff + " - " + endTick) for (var staff = startStaff; staff <= endStaff; staff++) { for (var voice = 0; voice < 4; voice++) { cursor.rewind(1); // beginning of selection cursor.voice = voice; cursor.staffIdx = staff; if (fullScore) { // no selection cursor.rewind(0); // beginning of score } while (cursor.segment && (fullScore || cursor.tick < endTick)) { if (cursor.element && cursor.element.type === Element.CHORD) { var element = newElement(Element.STAFF_TEXT), notes = cursor.element.notes; renderNote(voice, notes, element, cursor.element); cursor.add(element); } // end if CHORD cursor.next(); } // end while segment } // end for voice } // end for staff Qt.quit(); } // end onRun }