-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathIntervals.ino
80 lines (66 loc) · 2 KB
/
Intervals.ino
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
// "Intervals" - Builds and plays major and minor chords from root notes
//
// Running this sketch will show you how easily you can use musical intervals
// to generate and play patterns of notes like major and minor chords.
//
// Setup needed to run the examples: https://github.com/razrotenberg/Midier#setup
// No additional setup is required for this sketch
//
#include <Midier.h>
void setup()
{
// if you are connecting using USB, set the baud rate that is configured in the serial-to-MIDI software
// if you are connecting using a physical MIDI connector and cable, set it to 31250
// if you're not sure what this is, or which baud rate to use: https://github.com/razrotenberg/Midier#baud-rate
Serial.begin(9600);
}
void loop()
{
// have a list of the basic notes as the root notes
const midier::Note notes[] = {
midier::Note::C,
midier::Note::D,
midier::Note::E,
midier::Note::F,
midier::Note::G,
midier::Note::A,
midier::Note::B,
};
// iterate over all root notes
for (auto note : notes)
{
// play the major chord
playMajorChord(note);
// sleep for a short time
delay(600);
// play the minor chord
playMinorChord(note);
// sleep for a bit longer time
delay(1500);
}
}
void playNote(midier::Note note)
{
// play the note
midier::midi::play(note);
// sleep for a very short time
delay(400);
}
void playMajorChord(midier::Note root)
{
// a major chord has a root, major third, and perfect fifth
midier::Note third = root + midier::Interval::M3;
midier::Note fifth = root + midier::Interval::P5;
playNote(root);
playNote(third);
playNote(fifth);
}
void playMinorChord(midier::Note root)
{
// a minor chord has a root, minor third, and perfect fifth
midier::Note third = root + midier::Interval::m3;
midier::Note fifth = root + midier::Interval::P5;
playNote(root);
playNote(third);
playNote(fifth);
}