forked from Pomax/arduino-midi-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
30-rendering.ino
212 lines (173 loc) · 5.51 KB
/
30-rendering.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
uint8_t itemRectWidth = 0;
uint8_t itemRectHeight = 0;
uint8_t itemRectOffsetLeft = 0;
uint8_t itemRectOffsetTop = 0;
unsigned long lastNoteSignal = 0;
bool noteIndicatorVisible = false;
String previousFilename;
unsigned long lastCCSignal = 0;
bool ccIndicatorVisible = false;
unsigned long lastRenderedSeconds = 1000;
bool displayShowsWaiting = false;
bool sdErrorVisible = false;
void updateDisplay() {
if (sdCardError == true && sdErrorVisible == false) {
sdErrorVisible = true;
drawSdCardError();
return;
}
if (sdCardError == true && sdErrorVisible == true) {
delay(1000);
initSd();
return;
}
if (sdCardError == false && sdErrorVisible == true) {
tft.fillRect(0, 65, lcdWidth, lcdHeight, BLACK);
sdErrorVisible = false;
displayShowsWaiting == false;
isRecording == false;
startTime = 0;
}
updateNoteIndicator();
updateCCIndicator();
updateFilename();
updateRecTime();
}
void drawSdCardError() {
itemRectWidth = 155;
itemRectHeight = 42;
itemRectOffsetLeft = lcdWidth/2 - itemRectWidth/2;
itemRectOffsetTop = 90;
tft.fillRect(0, 65, lcdWidth, lcdHeight, DARK_GRAY);
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, RED);
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, RED);
tft.setCursor(itemRectOffsetLeft + 6, itemRectOffsetTop + 11);
tft.setTextColor(WHITE );
tft.setTextSize(3);
tft.println("SD Error");
}
void hello() {
tft.fillRect(0, 0, lcdWidth, 65, DARK_GRAY);
tft.setCursor(35, 20);
tft.setTextColor(WHITE );
tft.setTextSize(3);
tft.println("MIDI RECORDER");
tft.setTextSize(2);
tft.setTextColor(GRAY);
tft.println(" by Pomax");
}
String zeroPadLeft(int number) {
return String((number >= 10) ? number : "0" + String(number));
}
void updateFilename() {
if(previousFilename == filename) {
return;
}
itemRectWidth = 230;
itemRectHeight = 28;
itemRectOffsetLeft = lcdWidth/2 -itemRectWidth/2;
itemRectOffsetTop = 166;
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, BLACK);
tft.setCursor(itemRectOffsetLeft + 5, itemRectOffsetTop + 3);
tft.setTextColor(GRAY);
tft.setTextSize(3);
tft.println(filename);
previousFilename = filename;
}
void drawText(String text) {
tft.fillRect(0, 0, lcdWidth, lcdHeight, DARK_GRAY);
tft.setCursor(0, 100);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.println(text);
}
void updateRecTime() {
itemRectWidth = 155;
itemRectHeight = 42;
itemRectOffsetLeft = lcdWidth/2 - itemRectWidth/2;
itemRectOffsetTop = 90;
if (isRecording == false && displayShowsWaiting == false) {
//tft.setCursor(0,0);
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, DARK_GRAY);
tft.setCursor(itemRectOffsetLeft + 12, itemRectOffsetTop + 3);
tft.setTextColor(WHITE);
tft.setTextSize(2);
displayShowsWaiting = true;
tft.println("waiting for");
tft.setCursor(itemRectOffsetLeft + 60, itemRectOffsetTop + 23);
tft.println("MIDI");
return;
}
if (isRecording == false && displayShowsWaiting == true) {
return;
}
displayShowsWaiting = false;
unsigned long deltaSecondsSinceStart = (currentMillis - startTime)/1000;
if(isRecording == false) {
deltaSecondsSinceStart = 0;
}
if(lastRenderedSeconds == deltaSecondsSinceStart) {
return;
}
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, RED);
tft.setCursor(itemRectOffsetLeft + 6, itemRectOffsetTop + 11);
tft.setTextColor(WHITE );
tft.setTextSize(3);
uint16_t h;
uint8_t m;
uint8_t s;
secondsToHMS(deltaSecondsSinceStart, h, m, s);
tft.println(zeroPadLeft(h) + ":" + zeroPadLeft(m) + ":" + zeroPadLeft(s));
lastRenderedSeconds = deltaSecondsSinceStart;
}
void updateNoteIndicator() {
itemRectWidth = 48;
itemRectHeight = 14;
itemRectOffsetLeft = 10;
itemRectOffsetTop = 104;
if (currentMillis - lastNoteSignal > 300 && noteIndicatorVisible == true) {
// remove note indicator
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, BLACK);
noteIndicatorVisible = false;
return;
}
if (currentMillis - lastNoteSignal < 300 && noteIndicatorVisible == false) {
// show note indicator
noteIndicatorVisible = true;
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.fillRect(itemRectOffsetLeft, itemRectOffsetTop, itemRectWidth, itemRectHeight, BLACK);
tft.setCursor(itemRectOffsetLeft, itemRectOffsetTop);
tft.println("NOTE");
}
}
void updateCCIndicator() {
itemRectWidth = 23;
itemRectHeight = 14;
//itemRectOffsetLeft = lcdWidth - 10 - itemRectWidth;
itemRectOffsetTop = 104;
if (currentMillis - lastCCSignal > 300 && ccIndicatorVisible == true) {
// remove note indicator
tft.fillRect(lcdWidth - 10 - itemRectWidth, itemRectOffsetTop, itemRectWidth, itemRectHeight, BLACK);
ccIndicatorVisible = false;
return;
}
if (currentMillis - lastCCSignal < 300 && ccIndicatorVisible == false) {
// show note indicator
ccIndicatorVisible = true;
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.fillRect(lcdWidth - 10 - itemRectWidth, itemRectOffsetTop, itemRectWidth, itemRectHeight, BLACK);
tft.setCursor(lcdWidth - 10 - itemRectWidth, itemRectOffsetTop);
tft.println("CC");
}
}
void secondsToHMS( const uint32_t seconds, uint16_t &h, uint8_t &m, uint8_t &s )
{
uint32_t t = seconds;
s = t % 60;
t = (t - s)/60;
m = t % 60;
t = (t - m)/60;
h = t;
}