-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmovable-do.qml
373 lines (348 loc) · 13.3 KB
/
movable-do.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
//=============================================================================
// MuseScore Movable Do Plugin
//
// Copyright (C) 2022 Nozomu Yamazaki
// based on the following code by MuseScore
// https://github.com/musescore/MuseScore/blob/master/share/plugins/note_names/notenames.qml
//
// License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
//=============================================================================
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import MuseScore 3.0
import MuseScore.UiComponents 1.0
MuseScore {
id: root
version: "2.0"
description: "This plugin inserts movable do texts derived from the given tonality"
menuPath: "Plugins.MovableDo"
Component.onCompleted: {
if (mscoreMajorVersion >= 4) {
title = "Movable Do";
}
}
property int tonalityIndex: -1
property int notationIndex: -1
// Small note name size is fraction of the full font size.
property real fontSizeMini: 0.7
function nameChord(notes, text, small, movableDoOffset, notationIndex) {
var tpcToTonalPitch= {
"31": "A##",
"19": "B",
"7": "Cb",
"24": "A#",
"12": "Bb",
"0": "Cbb",
"29": "G##",
"17": "A",
"5": "Bbb",
"22": "G#",
"10": "Ab",
"27": "F##",
"15": "G",
"3": "Abb",
"32": "E##",
"20": "F#",
"8": "Gb",
"25": "E#",
"13": "F",
"1": "Gbb",
"30": "D##",
"18": "E",
"6": "Fb",
"23": "D#",
"11": "Eb",
"-1": "Fbb",
"28": "C##",
"16": "D",
"4": "Ebb",
"33": "B##",
"21": "C#",
"9": "Db",
"26": "B#",
"14": "C",
"2": "Dbb"
}
var tonalPitchToMovableDo = {
'A##': ['t', 'シ'],
'A#': ['li', 'ラ♯'],
'G##': ['l', 'ラ'],
'G#': ['si', 'ソ♯'],
'F##': ['s', 'ソ'],
'E##': ['fi', 'ファ♯'],
'E#': ['f', 'ファ'],
'D##': ['m', 'ミ'],
'D#': ['ri', 'レ♯'],
'C##': ['r', 'レ'],
'B##': ['di', 'ド♯'],
'B#': ['d', 'ド'],
'B': ['t', 'シ'],
'Bb': ['ta', 'シ♭'],
'A': ['l', 'ラ'],
'G': ['s', 'ソ'],
'F#': ['fi', 'ファ♯'],
'F': ['f', 'ファ'],
'E': ['m', 'ミ'],
'Eb': ['ma', 'ミ♭'],
'D': ['r', 'レ'],
'C#': ['di', 'ド♯'],
'C': ['d', 'ド'],
'Cb': ['t', 'シ'],
'Cbb': ['ta', 'シ♭'],
'Bbb': ['l', 'ラ'],
'Ab': ['lo', 'ラ♭'],
'Abb': ['s', 'ソ'],
'Gb': ['se', 'ソ♭'],
'Gbb': ['f', 'ファ'],
'Fb': ['m', 'ミ'],
'Ebb': ['r', 'レ'],
'Fbb': ['ma', 'ミ♭'],
'Db': ['ro', 'レ♭'],
'Dbb': ['d', 'ド'],
}
var sep = "\n"
// change to "," if you want them horizontally (anybody?)
var oct = ""
var name
for (var i = 0; i < notes.length; i++) {
if (!notes[i].visible)
continue
// skip invisible notes
if (text.text)
// only if text isn't empty
text.text = sep + text.text
if (small)
text.fontSize *= fontSizeMini
if (typeof notes[i].tpc === "undefined")
// like for grace notes ?!?
return
var tonalPitch = tpcToTonalPitch[String((parseInt(notes[i].tpc) - movableDoOffset + 35 + 1) % 35 - 1)]
name = tonalPitchToMovableDo[tonalPitch][notationIndex]
if (notes[i].tieBack !== null)
// skip if the note is tied
continue
text.text = name + oct + text.text
}
}
function renderGraceNoteNames(cursor, list, text, small, movableDoOffset, notationIndex) {
if (list.length > 0) {
// Check for existence.
// Now render grace note's names...
for (var chordNum = 0; chordNum < list.length; chordNum++) {
// iterate through all grace chords
var chord = list[chordNum]
// Set note text, grace notes are shown a bit smaller
nameChord(chord.notes, text, small, movableDoOffset, notationIndex)
if (text.text)
cursor.add(text)
// X position the note name over the grace chord
text.offsetX = chord.posX
switch (cursor.voice) {
case 1:
case 3:
text.placement = Placement.BELOW
break
}
// If we consume a STAFF_TEXT we must manufacture a new one.
if (text.text)
text = newElement(
Element.STAFF_TEXT) // Make another STAFF_TEXT
}
}
return text
}
function nameNotesMovableDo(tonalityText, notationIndex) {
var tonalityToMovableDoOffset = {
"C-Dur": 0,
"G-Dur": 1,
"D-Dur": 2,
"A-Dur": 3,
"E-Dur": 4,
"H-Dur": 5,
"Fis-Dur": 6,
"Cis-Dur": 7,
"F-Dur": -1,
"B-Dur": -2,
"Es-Dur": -3,
"As-Dur": -4,
"Des-Dur": -5,
"Ges-Dur": -6,
"Ces-Dur": -7,
"a-moll": 0,
"e-moll": 1,
"h-moll": 2,
"fis-moll": 3,
"cis-moll": 4,
"gis-moll": 5,
"dis-moll": 6,
"ais-moll": 7,
"d-moll": -1,
"g-moll": -2,
"c-moll": -3,
"f-moll": -4,
"b-moll": -5,
"es-moll": -6,
"as-moll": -7
}
var movableDoOffset = tonalityToMovableDoOffset[tonalityText]
var cursor = curScore.newCursor()
var startStaff
var endStaff
var endTick
var fullScore = false
cursor.rewind(1)
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) // beginning of selection
cursor.voice = voice
cursor.staffIdx = staff
if (fullScore)
// no selection
cursor.rewind(0) // beginning of score
while (cursor.segment && (fullScore || cursor.tick < endTick)) {
if (cursor.element
&& cursor.element.type === Element.CHORD) {
var text = newElement(Element.STAFF_TEXT)
// Make a STAFF_TEXT
// First...we need to scan grace notes for existence and break them
// into their appropriate lists with the correct ordering of notes.
var leadingLifo = Array()
// List for leading grace notes
var trailingFifo = Array()
// List for trailing grace notes
var graceChords = cursor.element.graceNotes
// Build separate lists of leading and trailing grace note chords.
if (graceChords.length > 0) {
for (var chordNum = 0; chordNum < graceChords.length; chordNum++) {
var noteType = graceChords[chordNum].notes[0].noteType
if (noteType === NoteType.GRACE8_AFTER
|| noteType === NoteType.GRACE16_AFTER
|| noteType === NoteType.GRACE32_AFTER) {
trailingFifo.unshift(graceChords[chordNum])
} else {
leadingLifo.push(graceChords[chordNum])
}
}
}
// Next process the leading grace notes, should they exist...
text = renderGraceNoteNames(cursor, leadingLifo,
text, true, movableDoOffset, notationIndex)
// Now handle the note names on the main chord...
var notes = cursor.element.notes
nameChord(notes, text, false, movableDoOffset,
notationIndex)
if (text.text)
cursor.add(text)
switch (cursor.voice) {
case 1:
case 3:
text.placement = Placement.BELOW
break
}
if (text.text)
text = newElement(
Element.STAFF_TEXT) // Make another STAFF_TEXT object
// Finally process trailing grace notes if they exist...
text = renderGraceNoteNames(cursor, trailingFifo,
text, true, movableDoOffset, notationIndex)
} // end if CHORD
cursor.next()
} // end while segment
} // end for voice
} // end for staff
cursor.rewind(1)
cursor.voice = 0
cursor.staffIdx = startStaff
if (fullScore)
cursor.rewind(0)
var text = newElement(Element.SYSTEM_TEXT)
text.text = tonalityText
text.fontSize *= 1.5
cursor.add(text)
}
onRun: {
console.log("Running Movable Do")
} // end onRun
Dialog {
id: tonalityDialog
visible: true
title: qsTr("Movable Do")
width: form.width
height: form.height
contentItem: Rectangle {
id: form
width: exporterColumn.width + 30
height: exporterColumn.height + 30
color: (mscoreMajorVersion < 4 ? "lightgray" : "#F5F5F6")
ColumnLayout {
id: exporterColumn
GridLayout {
id: grid
columns: 1
anchors.fill: parent
anchors.margins: 10
Label {
text: qsTr('調性')
}
StyledDropdown {
id: tonality
model: [
"C-Dur", "G-Dur", "D-Dur", "A-Dur", "E-Dur", "H-Dur", "Fis-Dur", "Cis-Dur", "F-Dur", "B-Dur", "Es-Dur", "As-Dur", "Des-Dur", "Ges-Dur", "Ces-Dur",
"a-moll", "e-moll", "h-moll", "fis-moll", "cis-moll", "gis-moll", "dis-moll", "ais-moll", "d-moll", "g-moll", "c-moll", "f-moll", "b-moll", "es-moll", "as-moll"
]
currentIndex: root.tonalityIndex
onActivated: function(index) {
root.tonalityIndex = index
}
}
Label {
text: qsTr('表記')
}
StyledDropdown {
id: notation
model: ["d r m", "ド レ ミ"]
currentIndex: root.notationIndex
onActivated: function(index) {
root.notationIndex = index
}
}
FlatButton {
id: button
text: qsTr("決定")
onClicked: {
curScore.startCmd()
console.log(notation.currentIndex)
nameNotesMovableDo(tonality.currentText,
notation.currentIndex)
curScore.endCmd()
tonalityDialog.visible = false
quit()
}
}
}
}
}
}
}