-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStraightUpDeltaruningIt.qml
More file actions
197 lines (177 loc) · 8.22 KB
/
Copy pathStraightUpDeltaruningIt.qml
File metadata and controls
197 lines (177 loc) · 8.22 KB
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
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// "Straight Up Deltaruning It" Plugin
//
// Copyright (C) 2025 silvncr
//
// Based on the
// Note Names Plugin
//
// Copyright (C) 2012 Werner Schweer
// Copyright (C) 2013 - 2021 Joachim Schmitz
// Copyright (C) 2014 Jörn Eichler
// Copyright (C) 2020 Johan Temmerman
//
// Sourced from
// <https://github.com/musescore/MuseScore/blob/edf6004ecee4d0de89ad0cb7a3f0103efa9d7c42/share/plugins/note_names/notenames.qml>
//
// 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 MuseScore 3.0
MuseScore {
version: "4.0"
description: "Notates your piece to arrange for the DELTARUNE Ch.4 in-game piano"
title: "Straight Up Deltaruning It"
categoryCode: "composing-arranging-tools"
thumbnailName: "StraightUpDeltaruningIt.png"
// Small note name size is fraction of the full font size.
property real fontSizeMini: 0.7;
property int last_case: 95;
function nameChord (notes, text, small) {
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
switch (notes[i].pitch) {
case last_case: name = "."; break; // same as last
// B major, B4-B6
case 71: name = "○\n$O"; last_case = notes[i].pitch; break; // B4
case 73: name = "⇒\n$E"; last_case = notes[i].pitch; break; // C#5
case 75: name = "⇘\n$SE"; last_case = notes[i].pitch; break; // D#5
case 76: name = "⇓\n$S"; last_case = notes[i].pitch; break; // E5
case 78: name = "⇙\n$SW"; last_case = notes[i].pitch; break; // F#5
case 80: name = "⇐\n$W"; last_case = notes[i].pitch; break; // G#5
case 82: name = "⇖\n$NW"; last_case = notes[i].pitch; break; // A#5
case 83: if (last_case >= 83) {name = "●\nO"} else {name = "⇧\n$N"}; last_case = notes[i].pitch; break; // B5
case 85: name = "→\nE"; last_case = notes[i].pitch; break; // C#6
case 87: name = "↘\nSE"; last_case = notes[i].pitch; break; // D#6
case 88: name = "↓\nS"; last_case = notes[i].pitch; break; // E6
case 90: name = "↙\nSW"; last_case = notes[i].pitch; break; // F#6
case 92: name = "←\nW"; last_case = notes[i].pitch; break; // G#6
case 94: name = "↖\nNW"; last_case = notes[i].pitch; break; // A#6
case 95: name = "↑\nN"; last_case = notes[i].pitch; break; // B6
default: name = qsTr("?") + text.text; break;
} // end switch tpc
// octave, middle C being C4
//oct = (Math.floor(notes[i].pitch / 12) - 1)
// or
//oct = (Math.floor(notes[i].ppitch / 12) - 1)
// or even this, similar to the Helmholtz system but one octave up
//var octaveTextPostfix = [",,,,,", ",,,,", ",,,", ",,", ",", "", "'", "''", "'''", "''''", "'''''"];
//oct = octaveTextPostfix[Math.floor(notes[i].pitch / 12)];
text.text = name + oct + text.text
} // end for note
}
function renderGraceNoteNames (cursor, list, text, small) {
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)
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 text we must manufacture a new one.
if (text.text)
text = newElement(Element.LYRICS); // Make another text
}
}
return text
}
onRun: {
curScore.startCmd()
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.LYRICS); // Make a 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)
// Now handle the note names on the main chord...
var notes = cursor.element.notes;
nameChord(notes, text, false);
if (text.text)
cursor.add(text);
switch (cursor.voice) {
case 1: case 3: text.placement = Placement.BELOW; break;
}
if (text.text)
text = newElement(Element.LYRICS) // Make another text object
// Finally process trailing grace notes if they exist...
text = renderGraceNoteNames(cursor, trailingFifo, text, true)
} // end if CHORD
cursor.next();
} // end while segment
} // end for voice
} // end for staff
curScore.endCmd()
quit();
} // end onRun
}