/* Copyright © 2022, 2023 yonah_ag * * This program is free software; you can redistribute it or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation and appearing in the accompanying LICENSE file. * * Description * ----------- * */ import MuseScore 3.0 import QtQuick 2.2 import QtQuick.Controls 1.5 import QtQuick.Controls.Styles 1.3 import QtQuick.Layouts 1.3 import QtQuick.Dialogs 1.2 import Qt.labs.settings 1.0 import FileIO 3.0 MuseScore { description: "Map Score"; requiresScore: true; version: "0.0.5"; menuPath: "Plugins.Map Score"; pluginType: "dialog"; // "dock"; property var noteName : [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] property var iMap : 0 property var mIX : [] property var mTick : [] property var mType : [] property var mArtic : [] property var tinfo : "" function mapScore() { iMap = inpMapType.currentIndex; console.log("iMap="+iMap) mIX.length = 0; mTick.length = 0; mType.length = 0; mArtic.length = 0; var ix=0; var tick; var info; var elm; var etyp; var zelm var zall = (iMap==0); tinfo = "

Score Map : "; if (zall) tinfo += "All"; else tinfo += "Bowing"; tinfo += "

"; tinfo += ""; tinfo += ""; cmd('select-all') var selected = curScore.selection.elements; // console.log("check: "+selected.length); for (var ee in selected) { elm = selected[ee]; etyp = elm.type; switch (etyp) { case 21: // note zelm = true; tick = elm.parent.parent.tick; info = noteName[(elm.pitch % 12)]; break; case 26: // rest zelm = true; tick = elm.parent.tick; info = elm.duration.str; break; case 30: // articulation info = elm.symbol; if (info==2652) { info = "down"; zelm = true; } else if (info==2677) { info = "up" zelm = true; } tick = elm.parent.parent.tick; break; case 42: // stave text zelm = true; tick = elm.parent.tick; info = elm.text; break; case 27: // breath zelm = true; tick = elm.parent.tick; info = ""; break; default: zelm = zall; tick = ""; info = ""; } if (zelm) { ++ix; tinfo += ""; } } curScore.selection.clear(); tinfo += "
 index  Element Type - Name  Segment Tick " tinfo += " Details  Parent Element  Parent^ Element 
 " + ix + " "; tinfo += " " + elm.type + " - " + elm.name + " "; tinfo += " " + tick + " "; tinfo += " " + info + " "; tinfo += " " + elm.parent.type + " - " + elm.parent.name + " "; tinfo += " " + elm.parent.parent.type + " - " + elm.parent.parent.name + " "; tinfo += "
"; popInfo.text = tinfo; tinfo = ""; infoWin.visible = true; } function findNote() { var selected = curScore.selection; var elements = selected.elements; console.log("elms: "+elements.length); if (elements.length == 1) { var element = elements[0]; if (element.type == 20) { var note = element; return note; } } return false; } function viewNote() { var note = findNote(); if (!note) return; var seg = note.parent.parent; var tick = seg.tick; var tock = seg.next.tick; console.log(tick + " - " + tock); var anno = ""; if (seg.annotations && seg.annotations.length) { anno = seg.annotations[0].text.substring(0,12); } lblNote.text = "" + noteName[(note.pitch % 12)]; lblDyna.text = "" + note.veloOffset; lblOnTime.text = "" + note.playEvents[0].ontime; lblRing.text = "" + note.playEvents[0].len; lblTick.text = "" + tick; lblText.text = "" + anno; lblParent.text = "" + note.parent.type; lblPname.text = note.parent.name; lblSegment.text = "" + seg.type; lblSegname.text = seg.segmentType; var pick = curScore.selection.selectRange(tick,tock,0,1); // cmd('select-all') console.log("check: "+curScore.selection.elements.length); for (var ee in curScore.selection.elements) { console.log(curScore.selection.elements[ee].name); } // curScore.selection.clear(); } // cur.inputStateMode=Cursor.INPUT_STATE_SYNC_WITH_SCORE; onRun: {} // ================== // # USER INTERFACE # // ================== width: 250; height: 80; RowLayout { id: 'uiRow1' x:15; y:15 Label { id: lblRow1; text: "Map Score"; color:"#000000"; Layout.preferredWidth:70; Layout.topMargin: 0} Button { id: btnMapIt Layout.preferredWidth: 40 Layout.preferredHeight: 24 text: "Go" onClicked: mapScore(); } } RowLayout { id: uiRow2 x: 15; y: uiRow1.y+30 Label { id: lblRow2 Layout.preferredWidth: 70 color: "#000000" text: "Map Type" } ComboBox { id: inpMapType model: ["Full Map", "Bowing Map"] Layout.leftMargin: 0 Layout.preferredWidth: 120 currentIndex: 0 } } ApplicationWindow { id: infoWin x: 20; y: 70 width: 600; height: 900 title: "Score Map" visible: false TextArea { id: popInfo width: infoWin.width; height: infoWin.height textMargin: 15 textFormat: TextEdit.RichText readOnly: true wrapMode: TextEdit.Wrap text: "Processing..." } } }