-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey_Signature.pde
More file actions
60 lines (51 loc) · 1.42 KB
/
Copy pathKey_Signature.pde
File metadata and controls
60 lines (51 loc) · 1.42 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
class KeySignature {
// Fields
boolean sharp; //Whether the key is with sharps
int accidentalCount; //0-7
// Constructor
KeySignature(boolean sharp, int accidentalCount) {
this.sharp = sharp;
this.accidentalCount = accidentalCount;
}
String getKeyName() {
if (sharp){
return sharpMajorKeys[accidentalCount] + " Major";
}else{
return flatMajorKeys[accidentalCount] + " Major";
}
}
//Returns which midi pitch classes (0–11) are sharpened/flattened in this key
int[] getAccidentalPitchClasses(){
int res[] = new int[this.accidentalCount];
for (int i=0;i<this.accidentalCount;i++){
res[i] = sharp ? sharpMidi[i]: flatMidi[i];
}
return res;
}
//Given a raw midi note, apply this key signature and return the adjusted note
int modifyPitch(int midiNote){
int pitchClass = midiNote%12;
for (int i=0;i<this.accidentalCount;i++){
if (sharp){
if (pitchClass==sharpMidi[i]){
return midiNote+1;
}
}else{
if (pitchClass==flatMidi[i]){
return midiNote-1;
}
}
}
return midiNote; //Not affected
}
//Methods
void display(float x, float y) {
textSize(24);
text(getKeyName(), x, y);
text("Accidentals: " + accidentalCount, x, y + 30);
}
void changeKey(boolean newSharp, int newCount) {
this.sharp = newSharp;
this.accidentalCount = newCount;
}
}