Repository navigation
Expand file tree
/
Copy pathfImageViewer.cpp
More file actions
399 lines (330 loc) · 10.2 KB
/
Copy pathfImageViewer.cpp
File metadata and controls
399 lines (330 loc) · 10.2 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#include "imageViewer.h"
#include <stdio.h>
#include <string.h>
#include "mtPadBoard.h"
#include "mtPadsBacklight.h"
#include "core/interfaceMenuPopup.h"
#include "imageViewerDefs.h"
#include "core/songTimer.h"
#include "TrackerImpl.h"
#include "cr_section_macros.h"
cImageViewer imageViewer;
static cImageViewer* IV = &imageViewer;
static void functPlayAction();
static void functRecAction();
static void functLeft();
static void functRight();
static void functEncoder(int16_t value);
static void functSwitchModule(uint8_t button);
static void functActionButton(uint8_t button, uint8_t state);
static void functPads(uint8_t pad, uint8_t state, int16_t velo);
static void functMenu(uint8_t state);
__NOINIT(EXTERNAL_RAM) static char s_infoText[220];
static void functMiniMiddle();
void cImageViewer::update()
{
if (refreshImageState == 1)
{
if (display.getImgLoadState() == 0 || display.getImgLoadState() == 3)
{
char path[64];
snprintf(path, sizeof(path), "Images/%s/%d", actualFolderName, imageNumber);
if (display.readImgFromSd(path, ImageViewerJpegAddress, 800, 390))
{
refreshImageState = 0;
display.setControlHide(image);
}
else
{
refreshImageState = 2;
}
}
}
else if (refreshImageState == 2)
{
if (display.isImgLoaded())
{
display.setControlShow(image);
display.refreshControl(image);
refreshImageState = 0;
}
}
}
void cImageViewer::start(uint32_t options)
{
moduleRefresh = 1;
if (options >= MANUAL_CHAPTERS_COUNT)
{
options = 0;
}
strcpy(actualFolderName, &manualFolderNames[options][0]);
songTimer.hide();
ip->setButtonObj(interfaceButtonPerformance, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonParams, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonFile, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonConfig, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonMaster, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonSamplePlay, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonSampleEdit, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonSampleRec, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonSampleLoad, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonSong, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonPattern, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonGame, buttonPress, functSwitchModule);
ip->setButtonObj(interfaceButtonMiniMenu, functMenu);
showDefaultScreen();
setDefaultScreenFunct();
countImages();
refreshImage();
}
void cImageViewer::stop()
{
moduleRefresh = 0;
display.setControlHide(image);
display.setControlHide(infoTextBox);
mtPadBoard.releaseAllInstruments();
padsBacklight.clearGlobalPads(1, 1, 1);
songTimer.show();
}
void cImageViewer::setDefaultScreenFunct()
{
ip->clearButtonsRange(interfaceButton0, interfaceButton7);
ip->clearAllPots();
ip->setButtonObj(interfaceButtonPlay, buttonPress, functPlayAction);
ip->setButtonObj(interfaceButtonRec, buttonPress, functRecAction);
ip->setButtonObj(interfaceButtonRight, buttonPress, functRight);
ip->setButtonObj(interfaceButtonLeft, buttonPress, functLeft);
ip->setButtonObj(interfaceButtonMiniMiddle, buttonPress, functMiniMiddle);
ip->setButtonObj(interfaceButton0, functActionButton);
ip->setButtonObj(interfaceButton1, functActionButton);
ip->setButtonObj(interfaceButton2, functActionButton);
ip->setButtonObj(interfaceButton3, functActionButton);
ip->setButtonObj(interfaceButton4, functActionButton);
ip->setButtonObj(interfaceButton5, functActionButton);
ip->setButtonObj(interfaceButton6, functActionButton);
ip->setButtonObj(interfaceButton7, functActionButton);
ip->setPotObj(interfacePot0, functEncoder);
ip->setPadsGlobal(functPads);
}
bool cImageViewer::imageExists(uint8_t number)
{
FileSystem* fileSystem = TrackerImpl::getInstance()->getPlatform()->getFileSystem();
char path[64];
snprintf(path, sizeof(path), "Images/%s/%d.jpg", actualFolderName, number);
if (fileSystem->exists(path))
{
return true;
}
snprintf(path, sizeof(path), "Images/%s/%d.jpeg", actualFolderName, number);
return fileSystem->exists(path);
}
void cImageViewer::refreshImage()
{
if (imagesCount == 0)
{
snprintf(titleText, sizeof(titleText), "%s", actualFolderName);
display.setControlHide(image);
refreshImageState = 0;
display.setRemoveControlStyle(label[0], controlStyleShowBitmap);
display.setRemoveControlStyle(label[7], controlStyleShowBitmap);
display.setControlText(label[6], "");
display.setControlText(label[7], "Close");
display.refreshControl(label[0]);
display.refreshControl(label[6]);
display.refreshControl(label[7]);
snprintf(s_infoText,
sizeof(s_infoText),
"No images found in /Images/%s/"
"\n\nPlace up to 48 baseline JPEG images (max 800 x 390 px) in:"
"\n/Images/%s/1.jpg ... /Images/%s/48.jpg"
"\n\nUse Left/Right, the Jog-wheel, or Pads 1-48 to switch images.",
actualFolderName,
actualFolderName,
actualFolderName);
display.setControlShow(infoTextBox);
display.setControlText(infoTextBox, s_infoText);
display.refreshControl(infoTextBox);
}
else
{
snprintf(titleText, sizeof(titleText), "%s %d/%d", actualFolderName, imageNumber, imagesCount);
display.setControlHide(infoTextBox);
display.setControlHide(image);
display.setControlText(label[6], "Close");
display.setControlText(label[7], "");
display.setAddControlStyle(label[0], controlStyleShowBitmap);
display.setAddControlStyle(label[7], controlStyleShowBitmap);
display.refreshControl(label[0]);
display.refreshControl(label[6]);
display.refreshControl(label[7]);
refreshImageState = 1;
display.processDisplayUpdateImmediate();
}
titleBar->show();
titleBar->setTitle(titleText);
display.synchronizeRefresh();
}
void cImageViewer::nextImage()
{
if (imagesCount <= 1)
{
return;
}
uint8_t loop_start = imageNumber;
do
{
imageNumber++;
if (imageNumber > 48)
{
imageNumber = 1;
}
if (imageExists(imageNumber))
{
break;
}
} while (imageNumber != loop_start);
}
void cImageViewer::previouseImage()
{
if (imagesCount <= 1)
{
return;
}
uint8_t loop_start = imageNumber;
do
{
imageNumber--;
if (imageNumber < 1)
{
imageNumber = 48;
}
if (imageExists(imageNumber))
{
break;
}
} while (imageNumber != loop_start);
}
void cImageViewer::countImages()
{
imagesCount = 0;
int firstFound = 1;
for (uint8_t i = 1; i <= 48; i++)
{
if (imageExists(i))
{
if (imagesCount == 0)
{
firstFound = i;
}
imagesCount++;
}
}
imageNumber = firstFound;
}
void cImageViewer::setImage(uint8_t number)
{
if (imagesCount == 0)
{
return;
}
if (imageExists(number))
{
imageNumber = number;
}
}
//==============================================================================================================
static void functEncoder(int16_t value)
{
value = interfaceGlobals.invertValForList ? -value : value;
if (value > 0)
{
IV->nextImage();
IV->refreshImage();
}
else
{
IV->previouseImage();
IV->refreshImage();
}
}
//=========================================================================================================
static void functLeft()
{
IV->previouseImage();
IV->refreshImage();
}
static void functRight()
{
IV->nextImage();
IV->refreshImage();
}
//=========================================================================================================
static void functPlayAction()
{
}
static void functRecAction()
{
}
static void functSwitchModule(uint8_t button)
{
IV->eventFunct(eventSwitchModule, IV, &button, 0);
}
//##############################################################################################
//############################### ACTION BUTTONS #################################
//##############################################################################################
static void functActionButton(uint8_t button, uint8_t state)
{
if (state == buttonPress)
{
if (button == 0)
{
IV->previouseImage();
IV->refreshImage();
}
else if (button == 6)
{
IV->eventFunct(eventSwitchToPreviousModule, IV, 0, 0);
}
else if (button == 7)
{
if (IV->imagesCount == 0)
{
IV->eventFunct(eventSwitchToPreviousModule, IV, 0, 0);
}
else
{
IV->nextImage();
IV->refreshImage();
}
}
}
}
//##############################################################################################
//############################### PAD BOARD #################################
//##############################################################################################
static void functPads(uint8_t pad, uint8_t state, [[maybe_unused]] int16_t velo)
{
if (state == 1)
{
IV->setImage(pad + 1);
IV->refreshImage();
}
}
static void functMenu(uint8_t state)
{
if (state == buttonPress)
{
mtMenuPopup.showModulePopup(IV);
}
else if (state == buttonRelease)
{
mtMenuPopup.hideModulePopup(IV);
}
}
static void functMiniMiddle()
{
if (IV->imagesCount == 0)
{
IV->eventFunct(eventSwitchToPreviousModule, IV, 0, 0);
}
}