-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chord-Level-Filter.qml
375 lines (329 loc) · 12.7 KB
/
Chord-Level-Filter.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
//=======================================================================================================
// Chord Level Filter for MuseScore 4.x
// This script was inspired by worldwideweary's "Chord Level Selector".
// Most portion of the main function were re-written (except for the get chords section),
// some bugs fixed (see below) and other funcionalities were added; specifically,
// the options "Copy levels", and "Crop to levels". The UI was also redesigned to contain the
// new functionalities and level boxes where regrouped into a single vertical column,
// now with the "bottom note" on the bottom.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=======================================================================================================
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Dialogs 1.1
import MuseScore 3.0
MuseScore {
title: "Filter Chord Levels"
version: "1.1"
description: "Choose the notes levels you wish to filter/select or apply other operations to within a range selection."
categoryCode: "Editing tools"
thumbnailName: ""
pluginType: "dialog"
width: 500
height: 225
function displayMessageDlg(msg) {
ctrlMessageDialog.text = qsTr(msg);
ctrlMessageDialog.visible = true;
}
function selectLevels(move, deleteDesired, copy, crop) {
////////////// GET SELECTION //////////////////
//////////////////////////////////////////////
var cursor = curScore.newCursor();
cursor.rewind(1);
var startTick = cursor.tick;
var startStaff;
var endStaff;
var endTick;
startStaff = cursor.staffIdx;
cursor.rewind(2);
if (cursor.tick == 0) {
endTick = curScore.lastSegment.tick + 1;
} else {
endTick = cursor.tick;
}
endStaff = cursor.staffIdx;
///////////////////////////////////////////
///////////////////////////////////////////
var operationPerformed = false;
curScore.startCmd(); // Start collecting undo info.
//////////////////// GET CHORDS //////////////////////////
//////////////////////////////////////////////////////////
var chords = new Array();
var maxChordLength=0
for (var staff = startStaff; staff <= endStaff; staff++) {
for (var voice = 0; voice < 4; voice++) {
cursor.rewind(1); // sets voice to 0
cursor.voice = voice; //voice has to be set after goTo
cursor.staffIdx = staff;
while (cursor.segment && (cursor.tick < endTick)) {
if (cursor.element && cursor.element.type == Element.CHORD) {
var graceChords = cursor.element.graceNotes;
for (var i = 0; i < graceChords.length; i++) {
chords.push(graceChords[i]);
}
// the chord of the notes...
chords.push(cursor.element);
if (cursor.element.notes.length > maxChordLength ){
maxChordLength=cursor.element.notes.length
}
}
cursor.next();
}
}
}
///////////////////////////////////////////
///////////////////////////////////////////
if (!chords.length) {
displayMessageDlg(qsTr("No valid range selection on current score! Tsk Tsk."));
return;
}
var levels = new Array();
if (ctrlCheckBoxLevel7.checked) { levels.push(7) }
if (ctrlCheckBoxLevel6.checked) { levels.push(6) }
if (ctrlCheckBoxLevel5.checked) { levels.push(5) }
if (ctrlCheckBoxLevel4.checked) { levels.push(4) }
if (ctrlCheckBoxLevel3.checked) { levels.push(3) }
if (ctrlCheckBoxLevel2.checked) { levels.push(2) }
if (ctrlCheckBoxLevel1.checked) { levels.push(1) }
if (!levels.length && !ctrlCheckBoxTopLevel.checked || levels[levels.length-1] > maxChordLength ) {
displayMessageDlg(qsTr("No levels(s) checked! Select the level(s) that match your chord stack sizes."));
return;
}
// Method: will clear the range selection and begin adding one at a time the notes that correlate with user-checked levels
curScore.selection.clear();
////////////// SELECT DESIRED NOTE LEVELS //////////////////////
////////////////////////////////////////////////////////////////
var emptyChordPotential = false;
for (var c = 0; c < chords.length; c++) {
var topNote= chords[c].notes[chords[c].notes.length - 1].pitch
for (var n = 0; n < chords[c].notes.length; n++) {
if ((crop || copy) && !levels.includes(n+1) ){
curScore.selection.select(chords[c].notes[n], true)
}
if (!crop & !copy && levels.includes(n+1) ){
curScore.selection.select(chords[c].notes[n], true);
}
}
if ((crop || copy) && ctrlCheckBoxTopLevel.checked ) {
curScore.selection.deselect(chords[c].notes[chords[c].notes.length - 1])
}
if (!crop && !copy && ctrlCheckBoxTopLevel.checked) {
curScore.selection.select(chords[c].notes[chords[c].notes.length - 1], true)
}
} /// end all chords iteration
if (deleteDesired || copy || crop) {
cmd("delete")
}
// Switch voice of remaining selection if Revoice
if (move) {
var cmdVoiceIndex = ctrlComboBoxVoice.currentIndex + 1;
cmd("voice-" + cmdVoiceIndex);
}
curScore.endCmd(); // Finish off the undo record.
if (copy) {
curScore.selection.selectRange(startTick, endTick, startStaff, endStaff+1);
cmd("copy")
cmd("undo")
}
operationPerformed = true;
return operationPerformed;
}
onRun: {
if (typeof curScore === 'undefined') {
var msg = "Chord Levels exiting without processing - no current score!";
displayMessageDlg(msg);
quit();
}
}
Rectangle {
property alias mouseArea: mouseArea
property alias btnCopy: btnCopy
property alias btnCrop: btnCrop
property alias btnDeleteLevels: btnDeleteLevels
property alias btnRevoiceLevels: btnRevoiceLevels
property alias btnClose: btnClose
property alias ctrlHintLabel: ctrlHintLabel
property alias ctrlMessageDialog: ctrlMessageDialog
width: 600 // added 200 (from 400)
height: 250
color: "grey"
MessageDialog {
id: ctrlMessageDialog
icon: StandardIcon.Information
title: "Chord Levels Message"
text: "Welcome to Chord Levels!"
visible: false
onAccepted: {
visible = false;
}
}
MouseArea {
id: mouseArea
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
Text {
id: ctrlStackRangeLabel
x: 180 // 25
y: 15
width: 100
text: "Levels:"
}
Column {
x: 180////80
y: 35
// Column {
// x: 175 // origin 125
// y: 15
CheckBox {
id: ctrlCheckBoxTopLevel
text: "Top" // 8
}
CheckBox {
id: ctrlCheckBoxLevel7
text: qsTr("7")
}
CheckBox {
id: ctrlCheckBoxLevel6
text: qsTr("6")
}
CheckBox {
id: ctrlCheckBoxLevel5
text: qsTr("5")
}
CheckBox {
id: ctrlCheckBoxLevel4
text: qsTr("4")
}
CheckBox {
id: ctrlCheckBoxLevel3
text: qsTr("3")
}
CheckBox {
id: ctrlCheckBoxLevel2
text: qsTr("2")
}
CheckBox {
id: ctrlCheckBoxLevel1
text: qsTr("Bottom") // 1
}
// }
}
Text {
id: ctrlVoicesLabel
x: 435 // orig 292
y: 40
width: 100
text: "Voice:"
}
ComboBox {
id: ctrlComboBoxVoice
width: 55
currentIndex: 1
x: 435
y: 60
model: ListModel {
id: cbVoiceItems
ListElement { text: "1"; color: "Blue" }
ListElement { text: "2"; color: "Green" }
ListElement { text: "3"; color: "Brown" }
ListElement { text: "4"; color: "Purple" }
}
}
Button {
id: btnCopy
x: 280
y: 175
width: 150
height: 35
text: qsTr("Copy")
onClicked: {
if (selectLevels(false, false, true, false)) {
quit();
}
}
}
Button {
id: btnCrop
x: 280
y: 135
width: 150
height: 35
text: qsTr("Crop To levels")
onClicked: {
if (selectLevels(false, false, false, true)) {
quit();
}
}
}
Button {
id: btnDeleteLevels
x: 280
y: 95
width: 150
height: 35
text: qsTr("Delete")
onClicked: {
if (selectLevels(false, true, false, false)) {
quit();
}
}
}
Button {
id: btnRevoiceLevels
x: 280
y: 55
width: 150
height: 35
text: qsTr("Change to voice:")
onClicked: {
if (selectLevels(true, false, false, false)) {
quit();
}
}
}
Button {
id: btnSelectLevels
x: 280
y: 15
width: 150
height: 35
text: qsTr("Select")
onClicked: {
if (selectLevels(false, false, false, false)) {
quit();
}
}
}
Button {
id: btnClose
x: 20 ////50
y: 170
width: 125
height: 35
text: qsTr("Close")
onClicked: {
console.log("Chord Levels closed.");
quit();
}
}
Text {
id: ctrlHintLabel
x: 20
y: 30 // 100
width: 100 //// 250
text: qsTr("Check the levels you want to delete, change voice, crop, copy, or select for further operations.")
font.italic: true
color: "white"
wrapMode: Text.WordWrap
font.pointSize: 9
}
}
}
}