-
Notifications
You must be signed in to change notification settings - Fork 0
/
crescendo or diminuendo.js
126 lines (109 loc) · 4.13 KB
/
crescendo or diminuendo.js
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
//=============================================================================
// MuseScore
// Music Score Editor
//
// Crescendo and Diminuendo plugin
//
// Creates note velocities for crescendos and diminuendos
// Version 0.9 - 2014
//
// By Tory Gaurnier, 2011
// By Joachim Schmitz, 2012-2014
//
// MuseScore: Copyright (C)2008 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
// Set to true, if you want this plugin to color all notes blue it changed
// velocity on. Use the blacknotes plugin to turn them black as needed
var colorit = false;
function init() {
};
function run() {
// no score open (MuseScore 2.0+, can't happen earlier)
if (typeof curScore === 'undefined')
return;
// MuseScore version too old
else if (mscoreVersion < 10100) {
messageBox = new QMessageBox();
messageBox.setWindowTitle("Message Box");
messageBox.text = "Sorry, but you need MuseScore version 1.1 or higher to use this plugin, please update.";
messageBox.exec();
return;
}
// real work can start...
var cursor = new Cursor(curScore);
var selectionEnd = new Cursor(curScore);
cursor.goToSelectionStart();
selectionEnd.goToSelectionEnd();
var startStaff = cursor.staff;
var endStaff = selectionEnd.staff;
curScore.startUndo();
// for all staves in selection
for (var staff = startStaff; staff < endStaff; staff++) {
// and all voices in staff
for (var voice = 0; voice < 4; voice++) {
var numberOfChords = 0;
var startingVelocity = 0;
var endingVelocity = 0;
// Find how many notes/chords are in the selection
cursor.goToSelectionStart();
cursor.voice = voice; // voice has to be set after goTo
cursor.staff = staff; // staff has to be set after goTo
while (cursor.tick() < selectionEnd.tick()) {
if (cursor.isChord()) {
numberOfChords++;
// Get starting and ending velocities
if (startingVelocity == 0)
startingVelocity = cursor.chord().note(0).velocity;
endingVelocity = cursor.chord().note(0).velocity;
}
cursor.next();
}
// Nothing to do for this voice
if (numberOfChords <= 2)
continue; // Over to next voice
// Calculate increment/decrement value
var inc = (endingVelocity - startingVelocity) / (numberOfChords - 1);
// Set velocity to all notes of all chords
cursor.goToSelectionStart();
cursor.voice = voice; // voice has to be set after goTo
cursor.staff = staff; // staff has to be set after goTo
for (var c = 1; c < numberOfChords; c++) { // End before last chord
while (!cursor.isChord())
cursor.next();
if (c != 1 ) { // Skip 1st chord
for (var n = 0; n < cursor.chord().notes; n++) {
cursor.chord().note(n).velocity = startingVelocity
+ Math.round(inc * (c-1));
if (colorit)
cursor.chord().note(n).color= new QColor(26,12,255); // blue
} // note loop
}
cursor.next();
} // chord loop
} // voice loop
} // staff loop
curScore.endUndo();
};
function close() {
};
mscorePlugin = {
majorVersion: 1,
minorVersion: 1,
menu: 'Plugins.Create Crescendo or Diminuendo',
init: init,
run: run,
onClose: close
};
mscorePlugin;