-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi_framework.ino
127 lines (102 loc) · 3.08 KB
/
midi_framework.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
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
127
#include "Controller.hpp"
// === NUMBER OF CONTROLS USED
byte NUMBER_BUTTONS = 0;
byte NUMBER_ROTPOTS = 0;
byte NUMBER_SLDPOTS = 1;
byte NUMBER_NCODERS = 0;
// === DEFINE DIRECTLY CONNECTED BUTTONS
// - Button (Pin Number, Command, Note Number, Channel, Debounce Time)
// --> Command parameter 0=NOTE, 1=CC, 2=Toggle CC
Button BU0(0, CC, 50, 1, 5);
Button BU1(1, CC, 51, 1, 5);
Button BU2(2, CC, 52, 1, 5);
Button BU3(3, CC, 53, 1, 5);
// Array of pointers to buttons used
Button *BUTTONS[] { &BU0, &BU1, &BU2, &BU3 };
// === DEFINE DIRECTLY CONNECTED ROTARY POTENTIOMETERS
// - RotaryPot (Pin Number, Command, CC Control, Channel)
RotaryPot RP0(A0, 0, 1, 1);
// Array of pointers to buttons used
RotaryPot *ROTPOTS[] { &RP0 };
// === DEFINE DIRECTLY CONNECTED SLIDE POTENTIOMETERS
// - SlidePot (Pin Number, Command, CC Control, Channel)
SlidePot SP0(A0, 0, 1, 1);
// Array of pointers to buttons used
SlidePot *SLDPOTS[] { &SP0 };
static void updateButtons();
static void updateRotPots();
static void updateSldPots();
void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if (NUMBER_BUTTONS != 0) updateButtons();
if (NUMBER_ROTPOTS != 0) updateRotPots();
if (NUMBER_SLDPOTS != 0) updateSldPots();
/* if (NUMBER_NCODERS != 0) updateNcoders(); */
}
// === STATIC FUNCTIONS
// - Manipulating component values.
static void updateButtons()
{
for (int i = 0; i < NUMBER_BUTTONS; i++) {
button_state_t button_state = BUTTONS[i]->getCompValue();
if (button_state == PRESSED) {
switch (BUTTONS[i]->getCommand()) {
case NOTE:
break;
case CC:
digitalWrite(LED_BUILTIN, HIGH);
usbMIDI.sendControlChange(
BUTTONS[i]->getValue(),
CC_ON,
BUTTONS[i]->getChannel());
break;
case TOGGLE_CC:
break;
}
}
if (button_state == NOT_PRESSED) {
switch (BUTTONS[i]->getCommand()) {
case NOTE:
break;
case CC:
digitalWrite(LED_BUILTIN, LOW);
usbMIDI.sendControlChange(
BUTTONS[i]->getValue(),
CC_OFF,
BUTTONS[i]->getChannel());
break;
}
}
}
}
static void updateRotPots()
{
for (int i = 0; i < NUMBER_ROTPOTS; i++) {
int pot_value = ROTPOTS[i]->getCompValue();
if (pot_value != 255) {
usbMIDI.sendControlChange(
ROTPOTS[i]->getControl(),
pot_value,
ROTPOTS[i]->getChannel());
Serial.println(pot_value);
}
}
}
static void updateSldPots()
{
for (int i = 0; i < NUMBER_SLDPOTS; i++) {
int pot_value = SLDPOTS[i]->getCompValue();
if (pot_value != 255) {
usbMIDI.sendControlChange(
SLDPOTS[i]->getControl(),
pot_value,
SLDPOTS[i]->getChannel());
Serial.println(pot_value);
}
}
}