-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.ino
84 lines (77 loc) · 1.78 KB
/
editor.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
#include "editor.h"
// Editor constructors
Editor::Editor(){};
Editor::Editor(int a, int b, int p){
pinMode(p, INPUT_PULLUP);
bounce = new Bounce(p, 50);
encoder = new Encoder(a, b);
number = 3;
level = 0;
newInLo = 0;
newInHi = 0;
DP = 0;
};
// Editor destructor
Editor::~Editor(){
delete bounce;
delete encoder;
};
int Editor::send(){/////////////////////////////////////////////////////////////
int incdec = encoder->read();
if(incdec >= 1 && level < 127){ // If turned up but not already maxed
level += 1;
incdec = level;
usbMIDI.sendControlChange(number, level, MIDIchannel);
}
else if (incdec <= -1 && level > 0){ // If turned down but not bottomed out
level -= 1;
incdec = level;
usbMIDI.sendControlChange(number, level, MIDIchannel);
}
else{incdec = -1;}
encoder->write(0);
return incdec;
};
int Editor::quadOne(byte val, byte max){
int newValue = encoder->read();
if (newValue == 4){
if (val < max){
encoder->write(0);
newValue = val + 1;
}
else if (val == max){
encoder->write(0);
newValue = 0;
}
}
else if (newValue == -4){
if (val > 0){
encoder->write(0);
newValue = val - 1;
}
else if (val == 0){
encoder->write(0);
newValue = max;
}
}
else if (newValue > 4 || newValue < -4){
encoder->write(0);
newValue = -1;
}
else{newValue = -1;}
return newValue;
};
byte Editor::editChannel(){
int newValue = quadOne(MIDIchannel, 15);
if (newValue >= 0){
return newValue;
}
else{return MIDIchannel;}
};
byte Editor::setAnalog(int p){
int newValue = analogRead(p);
if (newValue > newInHi){newInHi = newValue;}
else if (newValue < newInLo){newInLo = newValue;}
if (newInHi - newInLo > 127){return true;}
else{return false;}
};