/* 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.1.2";
menuPath: "Plugins.Map Score";
pluginType: "dialog"; // "dock";
property var noteName : [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
property var mIX : []
property var mTick : []
property var mType : []
property var mArtic : []
property var tinfo : ""
function mapAll() {
mIX.length = 0;
mTick.length = 0;
mType.length = 0;
mArtic.length = 0;
var ix=0; var tick; var info;
var elm; var etyp
var zunk; // unknown element
var zsys; // parent is system
tinfo = "
Score Map : All
";
tinfo += "
";
tinfo += " index | Track | Element Name | Segment Tick "
tinfo += " | Details | Parent Element | ^Parent Element |
";
cmd('select-all')
var selected = curScore.selection.elements;
for (var ee in selected) {
elm = selected[ee];
// if (elm.track > 0) break;
zunk = false;
zsys = false;
etyp = elm.type;
switch (etyp) {
case Element.NOTE:
tick = elm.parent.parent.tick;
info = noteName[(elm.pitch % 12)];
break;
case Element.STEM:
case Element.HOOK:
case Element.ACCIDENTAL:
case Element.ARPEGGIO:
tick = "";
info = "";
break;
case Element.REST:
case Element.BAR_LINE:
case Element.DYNAMIC:
case Element.HARMONY:
case Element.TEMPO_TEXT:
case Element.CLEF:
tick = elm.parent.tick;
switch (etyp) {
case Element.REST:
info = elm.duration.str;
break;
case Element.DYNAMIC:
info = "v = " + elm.velocity;
break;
case Element.HARMONY:
info = elm.text;
break;
default:
info = "";
}
break;
case Element.ARTICULATION:
case Element.LYRICS:
if (etyp==Element.ARTICULATION) {
info = elm.symbol;
if (info==2652) {
info = "down";
}
else if (info==2677) {
info = "up";
}
}
else {
info = elm.text;
}
tick = elm.parent.parent.tick;
break;
case Element.STAFF_TEXT:
tick = elm.parent.tick;
info = elm.text;
break;
case Element.NOTEDOT:
tick = elm.parent.parent.parent.tick;
info = "";
break;
case Element.BREATH:
tick = elm.parent.tick;
info = elm.symbol;
break;
case Element.BEAM:
case Element.TIE:
case Element.SLUR:
case Element.TEXTLINE:
case Element.VIBRATO:
zsys = true;
tick = "";
info = "";
break;
default:
tick = "";
info = "";
zunk = true;
}
++ix;
tinfo += " " + ix + " ";
tinfo += " | " + elm.track + " "
tinfo += " | " + elm.name + " ";
tinfo += " | " + tick + " ";
tinfo += " | " + info + " ";
if (zunk)
tinfo += " | | ";
else if (zsys)
tinfo += " | System | ";
else {
tinfo += " | " + elm.parent.name + " ";
tinfo += " | " + elm.parent.parent.name + " ";
}
tinfo += " |
";
}
curScore.selection.clear();
tinfo += "
";
}
function mapBow() {
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 zunk; // unknown element
var zsys; // parent is system
tinfo = "Score Map : Bowing
";
tinfo += "
";
tinfo += " index | Track | Element Name | Segment Tick "
tinfo += " | Details | Parent Element | ^Parent Element |
";
cmd('select-all')
var selected = curScore.selection.elements;
for (var ee in selected) {
elm = selected[ee];
if (elm.track > 0) break;
zunk = false;
zsys = false;
etyp = elm.type;
switch (etyp) {
case Element.NOTE:
zelm = true;
tick = elm.parent.parent.tick;
info = noteName[(elm.pitch % 12)];
break;
case Element.REST:
zelm = true;
tick = elm.parent.tick;
info = elm.duration.str;
break;
case Element.ARTICULATION:
info = elm.symbol;
if (info==2652) {
info = "down";
tick = elm.parent.parent.tick;
zelm = true;
}
else if (info==2677) {
info = "up";
tick = elm.parent.parent.tick;
zelm = true;
}
break;
case Element.STAFF_TEXT:
info = elm.text;
zelm = (info == "pizz." || info == "arco");
if (zelm) tick = elm.parent.tick;
break;
case Element.BREATH:
zelm = true;
tick = elm.parent.tick;
info = elm.symbol;
break;
case Element.TIE:
case Element.SLUR:
zelm = true;
zsys = true;
tick = "";
info = "";
break;
default:
zelm = false;
}
if (zelm) {
++ix;
tinfo += " " + ix + " ";
tinfo += " | " + elm.track + " "
tinfo += " | " + elm.name + " ";
tinfo += " | " + tick + " ";
tinfo += " | " + info + " ";
if (zunk)
tinfo += " | | ";
else if (zsys)
tinfo += " | System | ";
else {
tinfo += " | " + elm.parent.name + " ";
tinfo += " | " + elm.parent.parent.name + " ";
}
tinfo += " |
";
}
}
curScore.selection.clear();
tinfo += "
";
}
function mapScore()
{
infoWin.visible = true;
console.time("Process");
switch (inpMapType.currentIndex) {
case 0:
mapAll();
break;
case 1:
mapBow();
break;
case 2:
tinfo = "Add Bowing Symbols is still in development";
}
popInfo.text = tinfo;
tinfo = "";
console.timeEnd("Process");
}
onRun: {}
// ==================
// # USER INTERFACE #
// ==================
width: 300;
height: 50;
RowLayout { id: uiRow1
x: 15; y:15
Label { id: lblRow2
Layout.preferredWidth: 50
color: "#000000"
text: "Process"
}
ComboBox {
id: inpMapType
model: ["All Elements", "Bowing Elements", "Add Bowing Symbols"]
Layout.leftMargin: 0
Layout.preferredWidth: 150
currentIndex: 0
}
Button { id: btnMapIt
Layout.leftMargin: 5
Layout.preferredWidth: 40
Layout.preferredHeight: 24
text: "Go"
onClicked: mapScore();
}
}
ApplicationWindow {
id: infoWin
x: 20; y: 70
width: 630; 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..."
}
}
}