-
Notifications
You must be signed in to change notification settings - Fork 5
/
blacknotes.qml
140 lines (133 loc) · 5.08 KB
/
blacknotes.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
//=============================================================================
// Black notes : Paint all notes in black
// http://musescore.org/en/project/blacknotes
//
// Copyright (C)2010 Nicolas Froment (lasconic)
// Copyright (C)2014 Jörn Eichler (heuchi)
// Copyright (C)2012-2019 Joachim Schmitz (Jojo-Schmitz)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
import QtQuick 2.9
import QtQuick.Dialogs 1.2
import MuseScore 3.0
MuseScore {
version: "3.0"
description: "This plugin paints all chords and rests in black"
menuPath: "Plugins.Notes.Color Notes in Black"
MessageDialog {
id: versionError
visible: false
title: qsTr("Unsupported MuseScore Version")
text: qsTr("This plugin needs MuseScore 3.0.2 or later")
onAccepted: {
Qt.quit()
}
}
function blackenElement(element) {
if (element.type == Element.REST)
element.color = "black"
else if (element.type == Element.CHORD) {
if (element.stem)
element.stem.color = "black"
if (element.hook)
element.hook.color = "black"
if (element.beam)
element.beam.color = "black"
if (element.stemSlash)
element.stemSlash.color = "black"
}
else if (element.type == Element.NOTE) {
element.color = "black"
if (element.accidental)
element.accidental.color = "black"
for (var i = 0; i < element.dots.length; i++) {
if (element.dots[i])
element.dots[i].color = "black"
}
}
else
console.log("Unknown element type: " + element.type)
}
// Apply the given function to all chords and rests in selection
// or, if nothing is selected, in the entire score
function applyToChordsAndRestsInSelection(func) {
var cursor = curScore.newCursor()
cursor.rewind(1)
var startStaff
var endStaff
var endTick
var fullScore = false
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) // sets voice to 0
cursor.voice = voice //voice has to be set after goTo
cursor.staffIdx = staff
if (fullScore)
cursor.rewind(0) // if no selection, beginning of score
while (cursor.segment && (fullScore || cursor.tick < endTick)) {
if (cursor.element) {
if (cursor.element.type == Element.REST)
func(cursor.element)
else if (cursor.element.type == Element.CHORD) {
func(cursor.element)
var graceChords = cursor.element.graceNotes;
for (var i = 0; i < graceChords.length; i++) {
// iterate through all grace chords
func(graceChords[i])
var notes = graceChords[i].notes
for (var j = 0; j < graceChords[i].notes.length; j++)
func(graceChords[i].notes[j])
}
var notes = cursor.element.notes
for (var i = 0; i < notes.length; i++) {
var note = notes[i]
func(note)
}
}
cursor.next()
}
}
}
}
}
onRun: {
console.log("Hello, Black Notes")
// check MuseScore version
if (mscoreMajorVersion == 3 && mscoreMinorVersion == 0 && mscoreUpdateVersion <= 1)
versionError.open()
else
applyToChordsAndRestsInSelection(blackenElement)
Qt.quit();
}
}