-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsightreadingfactorybutfree.qml
398 lines (358 loc) · 13.3 KB
/
sightreadingfactorybutfree.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.1
import Qt.labs.settings 1.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.SightReadingFactoryButFree"
description: "Tired of paying Sight Reading Factory subscription fees? Download this plugin for Musescore 3.0.5 and above and start generating sight-reading music for free!"
version: "1.0.0"
pluginType: "dialog"
requiresScore: false
property int margin: 10
width: 360
height: 450
onRun: {
if((mscoreMajorVersion == 3) && (mscoreMinorVersion == 0) && (mscoreUpdateVersion < 5)) {
console.log(qsTr("Unsupported MuseScore version.\nSight Reading Factory, but Free needs v3.0.5 or above.\n"));
Qt.quit();
}
}
Settings {
id: settings
category: "Plugin-SightReadingFactoryButFree"
}
function createScore()
{
console.log("Creating Score");
if(getRandomInt(0, 1000) == 999) {
console.log("Rick Rolling");
var score = newScore("Never Gonna Give You Up.mscz", "violin", 4);
score.addText("title", "Never Gonna Give You Up");
score.addText("composer", "Rick Astley");
var cursor = score.newCursor();
cursor.track = 0;
cursor.rewind(0);
cursor.setDuration(3, 8);
cursor.addNote(60);
cursor.addNote(62);
cursor.setDuration(1, 4);
cursor.addNote(55);
cursor.setDuration(3, 8);
cursor.addNote(62);
cursor.addNote(64);
cursor.setDuration(1, 16);
cursor.addNote(67);
cursor.addNote(65);
cursor.addNote(64);
cursor.addNote(60);
cursor.setDuration(3,8);
cursor.addNote(60);
cursor.addNote(62);
cursor.setDuration(5,4);
cursor.addNote(55);
Qt.quit();
return;
}
var measures = numMeasures.text;
console.log(measures);
var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-';
var name = '';
for(var i=0; i<8; i++) {
name += characters.charAt(Math.floor(Math.random()*characters.length));
}
console.log(name);
console.log(instrumentBox.currentText.toLowerCase());
var score = newScore(name + '.mscz', ""+instrumentBox.currentText.toLowerCase(), measures);
var dif = difSlider.value;
console.log(dif);
var timeText = timeSig.currentText;
console.log(timeText);
var denominator = 1;
switch(timeText) {
case "4/4": var numerator = 4; var denominator = 4; break;
case "3/4": var numerator = 3; var denominator = 4; break;
case "2/4": var numerator = 2; var denominator = 4; break;
case "2/2": var numerator = 2; var denominator = 2; break;
case "6/8": var numerator = 6; var denominator = 8; break;
}//crashes with anything that isn't 4/4
var keyText = keyBox.currentText;
console.log(keyText);
switch(keyText) {
case "C": var key = 0; break;
case "C♯": var key = 1; break;
case "D": var key = 2; break;
case "E♭": var key = 3; break;
case "E": var key = 4; break;
case "F": var key = 5; break;
case "F♯": var key = 6; break;
case "G": var key = 7; break;
case "G♯": var key = 8; break;
case "A": var key = 9; break;
case "B♭": var key = 10; break;
case "B": var key = 11; break;
}
console.log(key);
score.addText("title", name);
score.addText("subtitle", "Generated by Sight Reading Factory, but Free");
score.addText("composer", "Sight Reading Factory, but Free");
var cursor = score.newCursor();
cursor.track = 0;
cursor.rewind(0);
var ts = newElement(Element.TIMESIG);
ts.timesig = fraction(numerator, denominator);
cursor.add(ts);
cursor.rewind(0);
var tempoElement = newElement(Element.TEMPO_TEXT);
cursor.add(tempoElement);
tempoElement.tempo = tempoBox.text / 64;
tempoElement.visible = true;
tempoElement.followText = true;
var tempoText = newElement(Element.SYSTEM_TEXT);
cursor.add(tempoText);
tempoText.text = " = " + tempoBox.text;
tempoText.visible = true;
// var ks = newElement(Element.KEYSIG);
// ks.keysig = key;
// ks.visible = true;
// ks.followText = true;
// cursor.add(ks);
cursor.rewind(0);
addNotes(cursor, key, measures, numerator, denominator, dif, ""+instrumentBox.currentText.toLowerCase());
}
function addNotes(cursor, key, measures, numerator, denominator, dif, instrument)
{
var rythms = [
[1],
[2],
[4],
[8],
[4, 4, 4, 4],
[2, 4, 4],
[4, 8, 8, 4, 4],
[4, 4, 4],
[4, 2, 4],
[4, 8, 8, 8, 8, 8, 8],
[4, 4, 4, 8, 8],
[4, 8, 8, 8, 8],
[4, 2],
[4, 8, 8, 4, 4],
[16],
[4, 8, 16, 16],
[8, 16, 16],
[16, 16, 16, 16],
[2, 16, 16, 16, 8, 16],
[16, 8, 16, 8, 8, 4, 4],
[16, 16, 16, 16, 8, 8, 8, 8, 4, 4, 2],
[16, 16, 16, 16, 8, 8, 8, 8],
[32, 32, 16, 8],
[4, 4, 4, 8, 8]
];
var nm3 = 55 + key;
var nm2 = 57 + key;
var nm1 = 59 + key;
var n1 = 60 + key;
var n2 = 62 + key;
var n3 = 64 + key;
var n4 = 65 + key;
var n5 = 67 + key;
var n6 = 69 + key;
var n7 = 71 + key;
var n8 = 72 + key;
var n9 = 74 + key;
var n10 = 76 + key;
var n11 = 77 + key;
var n12 = 79 + key;
var notes = [n1, -1, -1, -1, nm3, nm2, nm1, nm1, n1, n1, n2, n3, n3, n5, n5, n4, n4, n2, n6, n7, n8, n8, n9, n10, n11, n12]; // -1 == rest; more occurrances of note = higher probability
for(var i=0; i<notes.length; i++) {
notes[i] = ((instrument == "flute" && key < 6 || notes[i] < 60) && notes[i] != -1) ? notes[i] + 12 : notes[i];
notes[i] = (instrument == "trumpet" && key > 4 && notes[i] >= 63) ? notes[i] - 12 : notes[i];
notes[i] = ((instrument == "oboe" && notes[i] <= 57) && notes[i] != -1) ? notes[i] + 12 : notes[i];
}
console.log(notes);
var totalCounts = measures * (numerator / denominator);
var newRythms = [];
while(countSum(newRythms) < totalCounts) {
var randomRythm = rythms[getRandomInt(0, Math.min(rythms.length - 12 + (dif * 2), rythms.length))];
if(countSum(newRythms) + countSum(randomRythm) > totalCounts) {
continue;
}
// randomRythm.forEach(element => newRythm.push(element));
for(var i=0; i<randomRythm.length; i++) {
newRythms.push(randomRythm[i]);
}
}
var lastNote = notes[0];
for(var i=0; i<newRythms.length; i++) {
cursor.setDuration(1, newRythms[i]);
var randomNote = notes[getRandomInt(0, Math.max(rythms.length - 12 + (dif * 2), rythms.length))];
while((Math.abs(randomNote - lastNote) > 9 + dif || randomNote == lastNote) && randomNote != -1) {
randomNote = notes[getRandomInt(0, Math.max(rythms.length - 12 + (dif * 2), rythms.length))];
}
if(randomNote == -1) {
cursor.addRest();
}
else {
cursor.addNote(randomNote);
lastNote = randomNote;
}
}
}
function getRandomInt(lower, upper) //lower inclusive, upper exclusive
{
return Math.floor(Math.random() * (upper - lower) + lower);
}
function countSum(arr) {
var sum = 0;
// arr.forEach(element => sum += (1 / element));
for(var i=0; i<arr.length; i++) {
sum += (1 / arr[i]);
}
return sum;
}
Rectangle {
color: "lightgrey"
anchors.fill: parent
GridLayout {
columns: 2
anchors.fill: parent
anchors.margins: 10
Label {
text: "Key (Concert):"
}
ComboBox {
id: keyBox
model: ListModel {
id: keyList
ListElement { text: "C" }
ListElement { text: "C♯" }
ListElement { text: "D" }
ListElement { text: "E♭" }
ListElement { text: "E" }
ListElement { text: "F" }
ListElement { text: "F♯" }
ListElement { text: "G" }
ListElement { text: "G♯" }
ListElement { text: "A" }
ListElement { text: "B♭" }
ListElement { text: "B" }
}
currentIndex: 0
style: ComboBoxStyle {
font.family: 'MScore Text'
font.pointSize: 14
}
}
Label {
text: "Time Signature:"
}
ComboBox {
id: timeSig
model: ListModel {
id: timeSigList
ListElement { text: "4/4" }
//ListElement { text: "3/4" }
//ListElement { text: "2/4" }
//ListElement { text: "2/2" }
//ListElement { text: "6/8" }
}
currentIndex: 0
style: ComboBoxStyle {
font.family: 'MScore Text'
font.pointSize: 14
}
}
Label {
text: "Tempo:"
}
TextField{
id: tempoBox
text: '120'
validator: DoubleValidator { bottom: 1; top: 255; decimals: 0; notation: DoubleValidator.StandardNotation; }
implicitHeight: 20
}
Label {
text: "Difficulty:"
}
Slider {
id: difSlider
Layout.fillWidth: true
minimumValue: 1
maximumValue: 6
value: 1
stepSize: 1
style: SliderStyle {
groove: Rectangle {
id: grooveRect
implicitHeight: 6
color: '#555555'
radius: implicitHeight
border {
color: '#888888'
width: 1
}
Rectangle {
implicitHeight: grooveRect.implicitHeight
implicitWidth: styleData.handlePosition
color: '#f9f9f9'
radius: grooveRect.radius
border {
color: '#888888'
width: 1
}
}
}
handle: Rectangle {
anchors.centerIn: parent
color: control.pressed ? '#ffffff': '#d8d8d8'
border.color: '#666666'
border.width: 1
implicitWidth: 16
implicitHeight: 16
radius: 8
}
}
}
Label {
text: "Number of Measures:"
}
TextField{
id: numMeasures
text: '16'
validator: DoubleValidator { bottom: 1; top: 100; decimals: 0; notation: DoubleValidator.StandardNotation; }
implicitHeight: 20
}
Label {
text: "Instrument Voice:"
}
ComboBox {
id: instrumentBox
model: ListModel {
id: instrumentList
ListElement { text: "Clarinet" }
ListElement { text: "Trumpet" }
ListElement { text: "Alto-Saxophone" }
ListElement { text: "Flute" }
ListElement { text: "Violin" }
ListElement { text: "Oboe" }
}
currentIndex: 0
style: ComboBoxStyle {
font.family: 'MScore Text'
font.pointSize: 10
}
}
Button {
id: confirmButton
text: qsTranslate("PrefsDialogBase", "Create")
onClicked: {
createScore();
Qt.quit();
}
}
}
}
}