-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshape_notes.qml
189 lines (173 loc) · 6.6 KB
/
shape_notes.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
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2015 Nicolas Froment
//
// 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.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import MuseScore 1.0
MuseScore {
version: "1.0"
description: "Change notehead according to pitch. Sacred harp, shape notes, Aikin."
menuPath: "Plugins.Notes.Shapes Notes"
pluginType: "dialog"
id: window
width: 220
height: 130
ExclusiveGroup { id: exclusiveGroup }
ColumnLayout {
id: column
anchors.margins : 10
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 60
CheckBox {
id: shape7CheckBox
text: "7 shape notes"
checked: true
exclusiveGroup: exclusiveGroup
}
CheckBox {
id: shape4CheckBox
text: "4 shape notes"
exclusiveGroup: exclusiveGroup
}
CheckBox {
id: normalCheckBox
text: "Normal notes"
exclusiveGroup: exclusiveGroup
}
}
RowLayout {
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: column.bottom
height: 70
Button {
id: okButton
text: "Ok"
onClicked: {
apply()
Qt.quit()
}
}
Button {
id: closeButton
text: "Close"
onClicked: { Qt.quit() }
}
}
// -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
property variant scales : ['C', 'G', 'D', 'A', 'E', 'B', 'F', 'C', 'G', 'D', 'A', 'E', 'B', 'F', 'C'];
// Apply the given function to all notes in selection
// or, if nothing is selected, in the entire score
function applyToNotesInSelection(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 && cursor.element.type == Element.CHORD) {
var graceChords = cursor.element.graceNotes;
for (var i = 0; i < graceChords.length; i++) {
// iterate through all grace chords
var notes = graceChords[i].notes;
for (var j = 0; j < notes.length; j++) {
// and go over all notes of this grace chord
func(notes[j], cursor.keySignature);
}
}
var notes = cursor.element.notes;
for (var i = 0; i < notes.length; i++) {
var note = notes[i];
func(note, cursor.keySignature);
}
}
cursor.next();
}
}
}
}
function shapeNotes(note, curKey) {
console.log("shapeNotes")
var tpcNames = "FCGDAEB"
var name = tpcNames[(note.tpc + 1) % 7]
var names = "CDEFGAB"
var scale = scales[curKey+7];
var degrees = [
NoteHead.HEAD_NORMAL,
NoteHead.HEAD_NORMAL,
NoteHead.HEAD_NORMAL,
NoteHead.HEAD_NORMAL,
NoteHead.HEAD_NORMAL,
NoteHead.HEAD_NORMAL,
NoteHead.HEAD_NORMAL
];
if (shape4CheckBox.checked)
degrees = [ // 4 notes
NoteHead.HEAD_FA,
NoteHead.HEAD_SOL,
NoteHead.HEAD_LA,
NoteHead.HEAD_FA,
NoteHead.HEAD_SOL,
NoteHead.HEAD_LA,
NoteHead.HEAD_MI
];
else if (shape7CheckBox.checked)
degrees = [ // 7 notes
NoteHead.HEAD_DO,
NoteHead.HEAD_RE,
NoteHead.HEAD_MI,
NoteHead.HEAD_FA,
NoteHead.HEAD_SOL,
NoteHead.HEAD_LA,
NoteHead.HEAD_TI
];
note.headGroup = degrees[(names.indexOf(name) - names.indexOf(scale) +28)%7];
}
function apply() {
console.log("hello shapeNotes");
curScore.startCmd();
applyToNotesInSelection(shapeNotes);
curScore.endCmd();
}
onRun: {
if (!curScore)
Qt.quit();
}
}