-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow-ticks_mu͒3.qml
130 lines (122 loc) · 3.73 KB
/
show-ticks_mu͒3.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*-
* Copyright © 2021
* mirabilos <[email protected]>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un‐
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person’s immediate fault when using the work as intended.
*-
* Show ticks of selection, to aid in debugging some messages such as
* “in measure underrun”.
*/
import MuseScore 3.0
import QtQuick 2.0
import QtQuick.Dialogs 1.2
MuseScore {
description: "This mu͒3/mu͒4 plugin shows the ticks of the current selection";
requiresScore: true;
version: "3";
menuPath: "Plugins.Show ticks";
id: showTicks
//4.4 title: "Show ticks"
Component.onCompleted: {
// runs once before console.log is ready
if (mscoreMajorVersion == 4 && mscoreMinorVersion <= 3) {
showTicks.title = "Show ticks";
}
}
MessageDialog {
id: alert;
title: "Ticks position in score";
icon: StandardIcon.Information;
}
onRun: {
var minpos = 2147483647;
var maxpos = 0;
var seen = 0;
var end = "";
if (curScore.selection && curScore.selection.elements &&
curScore.selection.elements.length) {
var elts = curScore.selection.elements;
console.log("operating on selection: " + elts.length);
for (var idx = 0; idx < elts.length; ++idx) {
var e = elts[idx];
while (e) {
if (e.type == Element.SCORE) {
console.log("child of score");
} else if (e.type == Element.PAGE) {
console.log("child of page");
} else if (e.type == Element.SYSTEM) {
console.log("child of system");
} else if (e.type == Element.MEASURE) {
console.log("child of measure");
} else if (e.type != Element.SEGMENT) {
e = e.parent;
continue;
}
break;
}
if (!e || e.type != Element.SEGMENT) {
console.log("#" + idx + " skipped, " +
"no segment as parent");
continue;
}
console.log("#" + idx + " at " + e.tick);
if (e.tick < seen) {
console.log("below " + seen + ", ignoring");
continue;
}
seen = e.tick ? 1 : 0;
if (e.tick < minpos)
minpos = e.tick;
if (e.tick > maxpos)
maxpos = e.tick;
}
}
var cursor = curScore.newCursor();
cursor.rewind(Cursor.SELECTION_START);
if (cursor.segment) {
console.log("operating on cursor at " + cursor.tick);
seen = cursor.tick ? 1 : 0;
if (cursor.tick < minpos)
minpos = cursor.tick;
if (cursor.tick > maxpos)
maxpos = cursor.tick;
cursor.rewind(Cursor.SELECTION_END);
if (!cursor.tick) {
/* until end of the score */
cursor.rewind(Cursor.SELECTION_START);
while (cursor.next())
/* nothing */;
end = " (end of score)";
console.log("EOS at " + cursor.tick);
} else
console.log("cursor until " + cursor.tick);
var csrmax = cursor.tick - 1;
if (csrmax > seen) {
if (csrmax < minpos)
minpos = csrmax;
if (csrmax > maxpos)
maxpos = csrmax;
}
}
if (minpos == 2147483647)
alert.text = "could not find position";
else if (maxpos <= minpos)
alert.text = "at " + minpos + end;
else
alert.text = "from " + minpos + " to " + maxpos + end;
alert.open();
}
}