-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidicode.txt
115 lines (109 loc) · 3.24 KB
/
midicode.txt
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
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
resetMIDI();
}
void loop() {
// Plays through all programmed chords
for (int note = 0; note < 12; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
playChord(note,0x69);
delay(5000);
playChord(note,0);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
}
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
void resetMIDI(){ //Turns off all notes on channel 1.
for (int note = 0x05; note < 0x6D; note ++)
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
}
void playChord(int chordNumber, int loudness){ //Loudness is an int from 0 (off) to 127
int root = 0;
switch (chordNumber){
case 0: //Tonic, I chord
root = 0x30;
noteOn(0x90, root, loudness); //Channel 1, C3, volume
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
break;
case 1: //Tonic, I chord, first Inversion
root = 0x30;
noteOn(0x90, root+12, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
break;
case 2: //Tonic, vi6 chord, first Inversion
root = 0x30;
noteOn(0x90, root, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+9, loudness);
break;
case 3: //Tonic, vi chord, root position
root = 0x30;
noteOn(0x90, root, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root-3, loudness);
break;
case 4: //Predominant, IV chord, root position
root = 0x30+5;
noteOn(0x90, root, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
break;
case 5: //Predominant, ii65 chord, 1st inversion 7th chord
root = 0x30+2;
noteOn(0x90, root+3, loudness);
noteOn(0x90, root+7, loudness);
noteOn(0x90, root+12, loudness);
noteOn(0x90, root+10, loudness);
break;
case 6: //Predominant, IV7 chord, root position
root = 0x30+5;
noteOn(0x90, root, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
noteOn(0x90, root+11, loudness);
break;
case 7: //Predominant, IV65 chord, 1st inversion 7th chord
root = 0x30+5;
noteOn(0x90, root+12, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
noteOn(0x90, root+11, loudness);
break;
case 8: //Dominant, V chord, Root Position
root = 0x30+7;
noteOn(0x90, root, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
break;
case 9: //Dominant, V7 chord, Root Position
root = 0x30+7;
noteOn(0x90, root, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
noteOn(0x90, root+10, loudness);
break;
case 10: //Dominant, V6 chord, 1st inversion
root = 0x30+7;
noteOn(0x90, root+12, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
break;
case 11: //Dominant, V65 chord, 7th chord 1st inversion
root = 0x30+7;
noteOn(0x90, root+12, loudness);
noteOn(0x90, root+4, loudness);
noteOn(0x90, root+7, loudness);
noteOn(0x90, root+10, loudness);
break;
}
}