-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLayerConfiguration.ino
82 lines (68 loc) · 2.76 KB
/
LayerConfiguration.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
81
82
// "Sequencer/Advanced/LayerConfiguration" - Detaching and re-attaching a layer from the common configuration
//
// This example shows how layers can detach from the common configuration and have a
// different configuration and can be re-attached to the common configuration at any time.
//
// 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()
{
// create the common configuration
const midier::Config config =
{
.note = midier::Note::G,
.accidental = midier::Accidental::Natural,
.octave = 3,
.mode = midier::Mode::Ionian,
.rhythm = midier::Rhythm::Swung_Sextuplet,
.steps = 4,
};
// create a container for a single layer
midier::Layers<1> layers;
// create a sequencer and specify the initial common configuration
midier::Sequencer sequencer(layers, config);
// start playing an arpeggio
midier::Sequencer::Handle handle = sequencer.start(1);
// run for four bars
sequencer.run(4);
// change the common configuration
sequencer.config = config.octave(4);
// run for another four bars and hear that the layer was affected by the
// change of the common configuration and is played an octave higher
sequencer.run(4);
// detach from the common configuration
*handle.config = midier::Config
{
.note = midier::Note::D,
.accidental = midier::Accidental::Sharp,
.octave = 3,
.mode = midier::Mode::Aeolian,
.rhythm = midier::Rhythm::Sixteenth,
.steps = 4,
};
// run for two bars and hear the new layer configuration
sequencer.run(2);
// change the common configuration once again
sequencer.config = midier::Config
{
.note = midier::Note::F,
.accidental = midier::Accidental::Natural,
.octave = 5,
};
// run for another two bars and hear that the layer was not affected by the
// change of the common configuration this time, as it was detached before
sequencer.run(2);
// re-attach to the common configuration
*handle.config = &sequencer.config;
// run for four bars and hear that the layer is played in the new common configuration
sequencer.run(4);
}