-
Notifications
You must be signed in to change notification settings - Fork 1
/
encoders.h
149 lines (109 loc) · 3.62 KB
/
encoders.h
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
void encoderChange( int encoder,int value){
updateLCD = 1;
updateMatrix = 1;
switch(encoder){
case 0: // current channel
if ( value == 0 && currentChannel != 0){
currentChannel--;
}
if (value == 1 && currentChannel != channels){
currentChannel++;
}
break;
case 1: // step
if( value == 0 && currentStep != 0){
currentStep--;
}
if(value == 1 && currentStep != 32){
currentStep++;
}
break;
case 2: // mode
if ( value == 0 && editMode != 0){ // Edit Mode
editMode--;
}
if ( value == 1 && editMode != 2){ // Edit Mode
editMode++;
}
break;
case 3: // Patch
if ( value == 0 && patternData[currentChannel][3][0] != 0){
patternData[currentChannel][3][0]--;
MIDI.sendProgramChange(patternData[currentChannel][3][0], currentChannel+1);
}
if ( value == 1 && patternData[currentChannel][3][0] != 255){
patternData[currentChannel][3][0]++;
MIDI.sendProgramChange(patternData[currentChannel][3][0], currentChannel+1);
}
break;
case 4: // Note on / off
if ( value == 0 && patternData[currentChannel][0][currentStep] != 0){
patternData[currentChannel][0][currentStep]--;
}
if ( value == 1 && patternData[currentChannel][0][currentStep] != 2){
patternData[currentChannel][0][currentStep]++;
}
break;
case 5: // Note Number
if( value == 0 && patternData[currentChannel][1][currentStep] != 0){
patternData[currentChannel][1][currentStep]--;
}
if( value == 1 && patternData[currentChannel][1][currentStep] != 255){
patternData[currentChannel][1][currentStep]++;
}
break;
case 6: // Velocity
if ( value == 0 && patternData[currentChannel][2][currentStep] != 0){
patternData[currentChannel][2][currentStep]--;
}
if ( value == 1 && patternData[currentChannel][2][currentStep] != 127){
patternData[currentChannel][2][currentStep]++;
}
break;
}
}
void handleEncoders(){
if (newNavKeyValues != oldNavKeyValues){
for ( int i = 0; i < 10; i++){
int row = encoderMapping[i][0];
int key1 = encoderMapping[i][1];
int key2 = encoderMapping[i][2];
byte value1 = (~newNavKeyValues[row] >> key1) & B00000001;
byte value1_old = (~oldNavKeyValues[row] >> key1) & B00000001;
byte value2 = (~newNavKeyValues[row] >> key2) & B00000001;
byte value2_old = (~oldNavKeyValues[row] >> key2) & B00000001;
if (value1 != value1_old || value2 != value2_old){
/* if (value1_old == 0 && value1 == 0 && value2_old ==1 && value2 == 0 ) {
encoderChange(i,0);
}*/
if (value1_old == 0 && value1 == 1 && value2_old ==0 && value2 == 0 ) {
encoderChange(i,0);
}
/*
if (value1_old == 1 && value1 == 0 && value2_old ==1 && value2 == 1 ) {
encoderChange(i,0);
}*/
if (value1_old == 1 && value1 == 1 && value2_old ==0 && value2 == 1 ) {
encoderChange(i,0);
}
/*
if (value1_old == 0 && value1 == 0 && value2_old ==0 && value2 == 1 ) {
encoderChange(i,1);
} */
if (value1_old == 0 && value1 == 1 && value2_old ==1 && value2 == 1 ) {
encoderChange(i,1);
}
/*
if (value1_old == 1 && value1 == 0 && value2_old ==0 && value2 == 0 ) {
encoderChange(i,1);
}
*/
if (value1_old == 1 && value1 == 1 && value2_old ==1 && value2 == 0 ) {
encoderChange(i,1);
}
oldNavKeyValues[row] = newNavKeyValues[row];
}
MIDI.read();
}
}
}