-
Notifications
You must be signed in to change notification settings - Fork 2
/
justintonationHE.qml
284 lines (267 loc) · 12.3 KB
/
justintonationHE.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
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2016 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.0
import MuseScore 1.0
MuseScore {
version: "1.0"
description: "Modify playback for Extended Helmholtz-Ellis"
menuPath: "Plugins.Notes.Just Intonation (Extended HE)"
// 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++)
func(notes[j]);
}
var notes = cursor.element.notes;
for (var i = 0; i < notes.length; i++) {
var note = notes[i];
func(note);
}
}
cursor.next();
}
}
}
}
function adjustTuning(note) {
var rootTpc = 12 // Bb, the first degree of the scale. it needs to be change if the scale starts on another degree.
// needs to be a parameter in the UI
var tpc = note.tpc
var t = 0
if (note.accidental) {
console.log(note.accidental.accType)
switch (note.accidental.accType) {
case Accidental.DOUBLE_FLAT_ONE_ARROW_DOWN:
tpc = tpc - 14
t = -21.5
break;
case Accidental.FLAT_ONE_ARROW_DOWN:
tpc = tpc - 7
t = -21.5
break;
case Accidental.NATURAL_ONE_ARROW_DOWN:
t = -21.5
break;
case Accidental.SHARP_ONE_ARROW_DOWN:
tpc = tpc + 7
t = -21.5
break;
case Accidental.DOUBLE_SHARP_ONE_ARROW_DOWN:
tpc = tpc + 14
t = -21.5
break;
case Accidental.DOUBLE_FLAT_ONE_ARROW_UP:
tpc = tpc - 14
t = 21.5
break;
case Accidental.FLAT_ONE_ARROW_UP:
tpc = tpc - 7
t = 21.5
break;
case Accidental.NATURAL_ONE_ARROW_UP:
t = 21.5
break;
case Accidental.SHARP_ONE_ARROW_UP:
tpc = tpc + 7
t = 21.5
break;
case Accidental.DOUBLE_SHARP_ONE_ARROW_UP:
tpc = tpc + 14
t = 21.5
break;
case Accidental.DOUBLE_FLAT_TWO_ARROWS_DOWN:
tpc = tpc - 14
t = -43
break;
case Accidental.FLAT_TWO_ARROWS_DOWN:
tpc = tpc - 7
t = -43
break;
case Accidental.NATURAL_TWO_ARROWS_DOWN:
t = -43
break;
case Accidental.SHARP_TWO_ARROWS_DOWN:
tpc = tpc + 7
t = -43
break;
case Accidental.DOUBLE_SHARP_TWO_ARROWS_DOWN:
tpc = tpc + 14
t = -43
break;
case Accidental.DOUBLE_FLAT_TWO_ARROWS_UP:
tpc = tpc - 14
t = 43
break;
case Accidental.FLAT_TWO_ARROWS_UP:
tpc = tpc - 7
t = 43
break;
case Accidental.NATURAL_TWO_ARROWS_UP:
t = 43
break;
case Accidental.SHARP_TWO_ARROWS_UP:
tpc = tpc + 7
t = 43
break;
case Accidental.DOUBLE_SHARP_TWO_ARROWS_UP:
tpc = tpc + 14
t = 43
break;
case Accidental.DOUBLE_FLAT_THREE_ARROWS_DOWN:
tpc = tpc - 14
t = -64.5
break;
case Accidental.FLAT_THREE_ARROWS_DOWN:
tpc = tpc - 7
t = -64.5
break;
case Accidental.NATURAL_THREE_ARROWS_DOWN:
t = -64.5
break;
case Accidental.SHARP_THREE_ARROWS_DOWN:
tpc = tpc + 7
t = -64.5
break;
case Accidental.DOUBLE_SHARP_THREE_ARROWS_DOWN:
tpc = tpc + 14
t = -64.5
break;
case Accidental.DOUBLE_FLAT_THREE_ARROWS_UP:
tpc = tpc - 14
t = 64.5
break;
case Accidental.FLAT_THREE_ARROWS_UP:
tpc = tpc - 7
t = 64.5
break;
case Accidental.NATURAL_THREE_ARROWS_UP:
t = 64.5
break;
case Accidental.SHARP_THREE_ARROWS_UP:
tpc = tpc + 7
t = 64.5
break;
case Accidental.DOUBLE_SHARP_THREE_ARROWS_UP:
tpc = tpc + 14
t = 64.5
break;
case Accidental.DOUBLE_FLAT_EQUAL_TEMPERED:
tpc = tpc - 14
break;
case Accidental.FLAT_EQUAL_TEMPERED:
tpc = tpc - 7
break;
case Accidental.NATURAL_EQUAL_TEMPERED:
tpc = tpc
break;
case Accidental.SHARP_EQUAL_TEMPERED:
tpc = tpc + 7
break;
case Accidental.DOUBLE_SHARP_EQUAL_TEMPERED:
tpc = tpc + 14
break;
case Accidental.LOWER_ONE_SEPTIMAL_COMMA:
t += -27.3
break;
case Accidental.RAISE_ONE_SEPTIMAL_COMMA:
t += 27.3
break;
case Accidental.LOWER_TWO_SEPTIMAL_COMMAS:
t += -54.5
break;
case Accidental.RAISE_TWO_SEPTIMAL_COMMAS:
t += 54.5
break;
case Accidental.LOWER_ONE_UNDECIMAL_QUARTERTONE:
t += -53.3
break;
case Accidental.RAISE_ONE_UNDECIMAL_QUARTERTONE:
t += 53.3
break;
case Accidental.LOWER_ONE_TRIDECIMAL_QUARTERTONE:
t += -65.3
break;
case Accidental.RAISE_ONE_TRIDECIMAL_QUARTERTONE:
t += 65.3
break;
}
} // accidental null
for (var i = 0; i < note.elements.length; i++) {
if (note.elements[i].type == Element.SYMBOL) {
var sym = note.elements[i].symbol
if (sym === "accidentalLowerOneSeptimalComma")
t += -27.3
else if (sym === "accidentalRaiseOneSeptimalComma")
t += 27.3
else if (sym === "accidentalLowerTwoSeptimalCommas")
t += -54.5
else if (sym === "accidentalRaiseTwoSeptimalCommas")
t += 54.5
else if (sym === "accidentalLowerOneUndecimalQuartertone")
t += - 53.3
else if (sym === "accidentalRaiseOneUndecimalQuartertone")
t += 53.3
else if (sym === "accidentalLowerOneTridecimalQuartertone")
t += - 65.3
else if (sym === "accidentalRaiseOneTridecimalQuartertone")
t += 65.3
}
}
var tuning = (tpc - rootTpc) * 2 + t
note.tuning = tuning
}
onRun: {
console.log("hello JI HE");
if (typeof curScore === 'undefined')
Qt.quit();
applyToNotesInSelection(adjustTuning)
Qt.quit();
}
}