/
FMDisplay.cpp
1559 lines (1439 loc) · 45.4 KB
/
FMDisplay.cpp
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Author: Xavier Hosxe (xavier . hosxe (at) gmail . com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FMDisplay.h"
#define NULL 0
extern const char* lfoSeqMidiClock[];
extern const char* lfoOscMidiClock[];
const char* stepChars = "_123456789ABCDEF";
#define CUSTOM_CHAR_NOTE (char)7
unsigned int screenSaverGoal[4];
const char* enveloppeRandomizer [] = { "keep", "perc", "pad ", "rand" };
const char* otherRandomizer [] = { "keep", "soft", "medi", "high" };
FMDisplay::FMDisplay() {
}
FMDisplay::~FMDisplay() {
}
void FMDisplay::init(LiquidCrystal* lcd, Storage* storage, float ticksPerMinute) {
refreshStatus = 0;
this->lcd = lcd;
this->storage = storage;
for (int k=0; k<4; k++) {
presetModifed[k] = false;
noteOnCounter[k] = 0;
}
algoCounter = 0;
currentTimbre = 0;
customCharsInit();
screenSaveTimer = 0;
screenSaverMode = false;
screenSaverGoal[0] = 2 * ticksPerMinute;
screenSaverGoal[1] = 5 * ticksPerMinute;
screenSaverGoal[2] = 10 * ticksPerMinute;
screenSaverGoal[3] = 60 * ticksPerMinute;
algoCounterForIMInformation = false;
lcd->clear();
}
void FMDisplay::customCharsInit() {
unsigned char midiIn[8] = {
0b00000,
0b00000,
0b00000,
0b01110,
0b00000,
0b00000,
0b00000,
0b00000
};
unsigned char backslash[8] = {
0b00000,
0b10000,
0b01000,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000
};
unsigned char minusPoint[8] = {
0b00000,
0b00000,
0b00000,
0b00011,
0b00000,
0b00000,
0b00000,
0b00000
};
unsigned char stepCursor[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b10001,
0b01110,
0b00100,
0b00100,
};
unsigned char stepPos[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00100,
0b00100,
0b00000,
};
unsigned char firstSteps[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b10000,
0b10000,
};
unsigned char thirdStep[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b10100,
0b10100,
};
unsigned char note[8] = {
0b00100,
0b00110,
0b00101,
0b00101,
0b00100,
0b11100,
0b11100,
0b00000,
};
lcd->createChar(0, midiIn);
lcd->createChar(1, backslash);
lcd->createChar(2, minusPoint);
lcd->createChar(3, stepCursor);
lcd->createChar(4, stepPos);
lcd->createChar(5, firstSteps);
lcd->createChar(6, thirdStep);
lcd->createChar(CUSTOM_CHAR_NOTE, note);
}
void FMDisplay::printValueWithSpace(int value) {
lcd->print(value);
if (value>99) {
lcd->print(' ');
} else if (value>9) {
lcd->print(" ");
} else if (value>-1) {
lcd->print(" ");
} else if (value>-10) {
lcd->print(" ");
} else if (value>-100) {
lcd->print(' ');
}
}
void FMDisplay::printFloatWithSpace(float value) {
if (value < 0.0) {
lcd->print((char)2);
value = - value;
} else {
lcd->print(' ');
}
if (value < 10.0f) {
int integer = (int) (value + .0005f);
lcd->print(integer);
lcd->print('.');
value -= integer;
int valueTimes100 = (int)(value*100.0f+.0005f);
if (valueTimes100 < 10) {
lcd->print("0");
lcd->print(valueTimes100);
} else {
lcd->print(valueTimes100);
}
} else {
int integer = (int) (value + .0005f);
lcd->print(integer);
lcd->print('.');
value -= integer;
lcd->print((int)(value*10 + .0005f ));
}
}
void FMDisplay::printScalaFrequency(float value) {
int integer = (int) (value + .0005f);
lcd->print(integer);
lcd->print('.');
value -= integer;
lcd->print((int)(value*10 + .0005f ));
}
bool FMDisplay::shouldThisValueShowUp(int row, int encoder) {
int algo = this->synthState->params->engine1.algo;
switch (row) {
case ROW_MODULATION1:
if (unlikely(encoder >= 2 && algoInformation[algo].im == 1)) {
return false;
}
break;
case ROW_MODULATION2:
if (unlikely(encoder >= 2 && algoInformation[algo].im == 3)) {
return false;
}
break;
case ROW_MODULATION3:
if (unlikely(encoder >= 2 && algoInformation[algo].im == 5)) {
return false;
}
break;
case ROW_OSC_MIX1:
if (unlikely(encoder >= 2 && algoInformation[algo].mix == 1)) {
return false;
}
break;
case ROW_OSC_MIX2:
if (unlikely(encoder >= 2 && algoInformation[algo].mix == 3)) {
return false;
}
break;
case ROW_OSC_MIX3:
if (unlikely(encoder >= 2 && algoInformation[algo].mix == 5)) {
return false;
}
break;
case ROW_ENGINE:
if (encoder == ENCODER_ENGINE_GLIDE && this->synthState->params->engine1.numberOfVoice != 1
&& this->synthState->params->engine2.playMode != 2.0f)
{
return false;
}
break;
case ROW_ENGINE2:
if (unlikely(this->synthState->params->engine2.playMode == 1.0f && encoder >= 1)) {
return false;
}
break;
case ROW_EFFECT:
{
if (unlikely(encoder == 0)) {
return true;
}
int effect = this->synthState->params->effect.type;
if (filterRowDisplay[effect].paramName[encoder -1] == NULL) {
return false;
}
}
break;
case ROW_ARPEGGIATOR1:
if (encoder >= 1 && this->synthState->params->engineArp1.clock == 0.0f) {
return false;
}
break;
default:
break;
}
return true;
}
void FMDisplay::updateEncoderValue(int row, int encoder, ParameterDisplay* param, float newFloatValue) {
int newValue = (int)newFloatValue;
if (!shouldThisValueShowUp(row, encoder)) {
lcd->setCursor(encoder*5, 3);
lcd->print(" ");
return;
}
switch (param->displayType) {
case DISPLAY_TYPE_STRINGS :
lcd->setCursor(encoder*5, 3);
lcd->print(param->valueName[newValue]);
break;
case DISPLAY_TYPE_FLOAT_LFO_FREQUENCY:
if (newFloatValue * 10.0f > LFO_FREQ_MAX_TIMES_10) {
int stringIndex = newFloatValue * 10.0f + .005f;
lcd->setCursor(encoder*5, 3);
#ifdef DEBUG
if (likely(stringIndex <= LFO_MIDICLOCK_MC_TIME_8)) {
#endif
lcd->print(lfoOscMidiClock[stringIndex-LFO_FREQ_MAX_TIMES_10-1]);
#ifdef DEBUG
} else {
lcd->print("#ER#");
}
#endif
break;
}
lcd->setCursor(encoder*5 - 1, 3);
printFloatWithSpace(newFloatValue);
break;
case DISPLAY_TYPE_STEP_SEQ_BPM:
lcd->setCursor(encoder*5, 3);
#ifdef DEBUG
if (unlikely(newValue > LFO_SEQ_MIDICLOCK_TIME_4)) {
lcd->print("#ER#");
break;
}
#endif
if (newValue > 240) {
lcd->print(lfoSeqMidiClock[newValue-241]);
break;
}
printValueWithSpace(newValue);
break;
case DISPLAY_TYPE_LFO_KSYN:
if (unlikely(newFloatValue < 0.0f)) {
lcd->setCursor(encoder*5, 3);
lcd->print("Off ");
break;
}
lcd->setCursor(encoder*5 - 1, 3);
printFloatWithSpace(newFloatValue);
break;
case DISPLAY_TYPE_FLOAT:
if (unlikely(row == ROW_PERFORMANCE1)) {
lcd->setCursor(encoder*5, 3);
} else {
lcd->setCursor(encoder*5 - 1, 3);
}
printFloatWithSpace(newFloatValue);
break;
// else what follows
case DISPLAY_TYPE_INT:
lcd->setCursor(encoder*5, 3);
printValueWithSpace(newValue);
break;
case DISPLAY_TYPE_FLOAT_OSC_FREQUENCY:
{
// Hack... to deal with the special case of the fixed frequency.....
int oRow = row - ROW_OSC_FIRST;
OscillatorParams* oParam = (OscillatorParams*)&this->synthState->params->osc1;
OscFrequencyType ft = (OscFrequencyType)oParam[oRow].frequencyType;
if (ft == OSC_FT_FIXE) {
lcd->setCursor(10, 3);
newValue = oParam[oRow].frequencyMul * 1000.0 + oParam[oRow].detune * 100;
if (newValue < 0) {
newValue = 0;
}
printValueWithSpace(newValue);
// Ftune
lcd->setCursor(15, 3);
lcd->print(" ");
} else {
lcd->setCursor(encoder*5 - 1, 3);
printFloatWithSpace(newFloatValue);
}
break;
}
case DISPLAY_TYPE_NONE:
lcd->setCursor(encoder*5, 3);
lcd->print(" ");
break;
case DISPLAY_TYPE_VOICES:
lcd->setCursor(encoder*5, 3);
printValueWithSpace(newValue);
if (newValue == 1 || this->synthState->params->engine2.playMode == 2.0f) {
// if voices = 1 or 0 let's refresh the glide info
updateEncoderValue(ENCODER_ENGINE_GLIDE+1);
updateEncoderName(row, ENCODER_ENGINE_GLIDE);
} else {
// erase glide
lcd->setCursor(ENCODER_ENGINE_GLIDE * 5, 2);
lcd->print(" ");
lcd->setCursor(ENCODER_ENGINE_GLIDE * 5, 3);
lcd->print(" ");
}
break;
case DISPLAY_TYPE_STEP_SEQ1:
{
int whichStepSeq = row - ROW_LFOSEQ1;
StepSequencerSteps * seqSteps = &((StepSequencerSteps * )(&this->synthState->params->lfoSteps1))[whichStepSeq];
int decal = (this->synthState->stepSelect[whichStepSeq] >> 3 ) * 8;
lcd->setCursor(12, 3);
for (int k=0; k<4; k++) {
lcd->print(stepChars[seqSteps->steps[k + decal] ] );
}
lcd->setCursor(10, 2);
lcd->print(" ");
lcd->setCursor(10, 3);
lcd->print(' ');
if (decal == 0) {
lcd->print((char)5);
} else {
lcd->print((char)6);
}
lcd->setCursor(12 + this->synthState->stepSelect[whichStepSeq] - decal, 2);
lcd->print((char)3);
}
break;
case DISPLAY_TYPE_STEP_SEQ2:
{
int whichStepSeq = row - ROW_LFOSEQ1;
StepSequencerSteps * seqSteps = &((StepSequencerSteps * )(&this->synthState->params->lfoSteps1))[whichStepSeq];
int decal = (this->synthState->stepSelect[whichStepSeq] >> 3 ) * 8;
lcd->setCursor(16, 3);
for (int k=4; k<8; k++) {
lcd->print(stepChars[seqSteps->steps[k + decal]] );
}
lcd->setCursor(12, 2);
lcd->print((char)4);
lcd->setCursor(16, 2);
lcd->print((char)4);
}
break;
case DISPLAY_TYPE_ARP_PATTERN:
{
// Each encoder erase a left or right chars
char pos[] = {0, 1, 18, 19};
const int index = (int)this->synthState->params->engineArp2.pattern - ARPEGGIATOR_PRESET_PATTERN_COUNT;
const arp_pattern_t user_pattern = this->synthState->params->engineArpUserPatterns.patterns[ index ];
uint16_t nibble = ARP_MASK_GETNIBBLE( ARP_PATTERN_GETMASK(user_pattern), encoder );
lcd->setCursor(pos[encoder], 3);
lcd->print(' ');
lcd->setCursor(2 + encoder*4, 3);
char s[] = { '_', '_', '_', '_', 0 };
if ( nibble & 0x1 ) s[ 0 ] = CUSTOM_CHAR_NOTE;
if ( nibble & 0x2 ) s[ 1 ] = CUSTOM_CHAR_NOTE;
if ( nibble & 0x4 ) s[ 2 ] = CUSTOM_CHAR_NOTE;
if ( nibble & 0x8 ) s[ 3 ] = CUSTOM_CHAR_NOTE;
lcd->print( s );
if (unlikely(encoder == 3)) {
lcd->setCursor(2 + this->synthState->patternSelect, 2);
lcd->print((char)3);
}
}
break;
}
}
void FMDisplay::updateEncoderName(int row, int encoder) {
lcd->setCursor(encoder*5, 2);
if (!shouldThisValueShowUp(row, encoder)) {
lcd->print(" ");
return;
}
if (unlikely(row == ROW_ARPEGGIATOR3)) {
// Each encoder erase a left or right chars
char pos[] = {0, 1, 18, 19};
lcd->setCursor(pos[encoder], 2);
lcd->print(' ');
lcd->setCursor(2 + encoder * 4, 2);
lcd->print((char)4);
lcd->print(" ");
return;
}
if (unlikely(row == ROW_EFFECT && encoder > 0)) {
int effect = this->synthState->params->effect.type;
lcd->print(filterRowDisplay[effect].paramName[encoder -1]);
return;
}
const struct ParameterRowDisplay* paramRow = allParameterRows.row[row];
lcd->print(paramRow->paramName[encoder]);
}
void FMDisplay::refreshAllScreenByStep() {
switch (this->synthState->fullState.synthMode) {
case SYNTH_MODE_EDIT:
switch (refreshStatus) {
case 12:
lcd->setCursor(3,1);
lcd->print(" ");
break;
case 11:
// erase the caracters between
for (int k=0; k<4; k++) {
lcd->setCursor(4+k*5,2);
lcd->print(' ');
}
break;
case 10:
// erase the caracters between
for (int k=0; k<4; k++) {
lcd->setCursor(4+k*5,3);
lcd->print(' ');
}
break;
case 9:
{
int row = this->synthState->getCurrentRow();
if (this->synthState->fullState.midiConfigValue[MIDICONFIG_OP_OPTION] == 0) {
// New UI
if (row >= ROW_OSC_FIRST && row <= ROW_ENV_LAST) {
lcd->setCursor(0,1);
lcd->print("Op");
lcd->print(this->synthState->getOperatorNumber() + 1);
lcd->print(" ");
lcd->print(allParameterRows.row[row]->rowName);
} else {
lcd->setCursor(0,1);
lcd->print(allParameterRows.row[row]->rowName);
}
if (row >= ROW_MATRIX_FIRST && row != ROW_PERFORMANCE1 && row != ROW_LFOPHASES && row < ROW_MIDINOTE1CURVE) {
lcd->print(' ');
lcd->print(getRowNumberToDiplay(row));
}
} else {
lcd->setCursor(0,1);
lcd->print(allParameterRows.row[row]->rowName);
if (row > ROW_ENGINE_LAST && row != ROW_PERFORMANCE1 && row != ROW_LFOPHASES && row < ROW_MIDINOTE1CURVE) {
lcd->print(' ');
lcd->print(getRowNumberToDiplay(row));
}
}
if (unlikely(row == ROW_ARPEGGIATOR3)) {
lcd->setCursor(8,1);
lcd->print("Usr");
lcd->print(1+(int)this->synthState->params->engineArp2.pattern - ARPEGGIATOR_PRESET_PATTERN_COUNT);
}
break;
}
case 5:
case 6:
case 7:
case 8:
updateEncoderName(this->synthState->getCurrentRow(), refreshStatus -5);
break;
default :
updateEncoderValue(refreshStatus);
break;
}
break;
}
refreshStatus --;
}
void FMDisplay::updateEncoderValue(int refreshStatus) {
int row = this->synthState->getCurrentRow();
struct ParameterDisplay param = allParameterRows.row[row]->params[refreshStatus -1];
float newValue = ((float*)this->synthState->params)[row*NUMBER_OF_ENCODERS+refreshStatus -1];
updateEncoderValue(this->synthState->getCurrentRow(), refreshStatus -1, ¶m, newValue);
}
void FMDisplay::newPresetName(int timbre) {
if (currentTimbre == timbre && this->synthState->getSynthMode() == SYNTH_MODE_EDIT) {
int l = getLength(this->synthState->params->presetName);
lcd->setCursor(3,0);
lcd->print(this->synthState->params->presetName);
if (presetModifed[currentTimbre]) {
lcd->print('*');
l++;
}
for (int k=l; k< 13; k++) {
lcd->print(' ');
}
}
};
void FMDisplay::displayPreset() {
FullState* fullState = &this->synthState->fullState;
if (algoCounter > 0) {
// algoCounter will (should) be updated after
// so we don't erase useless part...
lcd->setCursor(11,0);
lcd->print(" ");
lcd->setCursor(11,1);
lcd->print(" ");
}
lcd->setCursor(0, 0);
if (this->synthState->getIsPlayingNote()) {
lcd->print((char)7);
} else {
lcd->print('I');
}
lcd->print((char)('0'+currentTimbre +1));
lcd->print(' ');
lcd->print(this->synthState->params->presetName);
if (presetModifed[currentTimbre]) {
lcd->print('*');
}
}
void FMDisplay::newTimbre(int timbre) {
currentTimbre = timbre;
if (unlikely(wakeUpFromScreenSaver())) {
return;
}
if (this->synthState->fullState.synthMode == SYNTH_MODE_EDIT) {
lcd->clearActions();
lcd->clear();
displayPreset();
refreshStatus = 12;
}
}
// Update FMDisplay regarding the callbacks from SynthState
void FMDisplay::newParamValueFromExternal(int timbre, int currentRow, int encoder, ParameterDisplay* param, float oldValue, float newValue) {
if (unlikely(screenSaverMode)) {
return;
}
checkPresetModified(timbre);
if (timbre == currentTimbre) {
if (this->synthState->getSynthMode() == SYNTH_MODE_EDIT && currentRow == this->displayedRow) {
if (unlikely((currentRow == ROW_LFOSEQ1 || currentRow == ROW_LFOSEQ2) && encoder>1)) {
updateStepSequencer(currentRow, encoder, oldValue, newValue);
return;
}
if (unlikely((currentRow == ROW_EFFECT || currentRow == ROW_ARPEGGIATOR1) && encoder == 0)) {
refreshStatus = 8;
} else {
if (shouldThisValueShowUp(currentRow, encoder)) {
updateEncoderValue(currentRow, encoder, param, newValue);
}
}
}
}
}
void FMDisplay::updateStepSequencer(int currentRow, int encoder, int oldValue, int newValue) {
int whichStepSeq = currentRow - ROW_LFOSEQ1 ;
int decal = (this->synthState->stepSelect[whichStepSeq] >> 3 ) * 8;
if (encoder == 3) {
// new value to display
lcd->setCursor(12 + this->synthState->stepSelect[whichStepSeq] - decal, 3);
lcd->print(stepChars[newValue]);
} else if (encoder == 2) {
int oldDecal = (oldValue >> 3 ) * 8;
// Change cursor
lcd->setCursor(12 + oldValue - oldDecal, 2);
if ((oldValue & 3) == 0) {
lcd->print((char)4);
} else {
lcd->print(' ');
}
// if new part 0-7 or 8-15 let's redraw all value
if (oldDecal != decal) {
refreshStatus = 4;
return;
}
lcd->setCursor(12 + newValue - decal, 2);
lcd->print((char)3);
}
}
void FMDisplay::updateArpPattern(int currentRow, int encoder, int oldValue, int newValue ) {
if ( 0 == encoder ) {
// Change cursor
lcd->setCursor(2 + oldValue, 2);
if ((oldValue & 3) == 0) {
lcd->print((char)4);
} else {
lcd->print(' ');
}
lcd->setCursor(2 + newValue, 2);
lcd->print((char)3);
} else {
// new value to display
int mask = 0x1;
for ( int i = 0; i < sizeof(uint16_t)*8; ++i ) {
if ( (oldValue & mask) != (newValue & mask ) ) {
lcd->setCursor(2 + i, 3);
lcd->print( newValue & mask ? CUSTOM_CHAR_NOTE : '_' );
}
mask <<= 1;
}
}
}
void FMDisplay::newParamValue(int timbre, int currentRow, int encoder, ParameterDisplay* param, float oldValue, float newValue) {
if (wakeUpFromScreenSaver()) {
return;
}
checkPresetModified(timbre);
if (this->synthState->getSynthMode() == SYNTH_MODE_EDIT) {
if (unlikely(currentRow != this->displayedRow)) {
// Octobre 2017 : Don't remember when it was usefull.
// What i'm sure is that we don't want it with the new 2.08 Copy firmware.
// newcurrentRow(timbre, currentRow);
return;
}
if (likely(currentRow != ROW_ENGINE || encoder != ENCODER_ENGINE_ALGO || algoCounterForIMInformation)) {
if (unlikely(algoCounter > 0 || algoCounterForIMInformation)) {
// New value with Algo on screen so we must redraw the full screen
algoCounter = 0;
algoCounterForIMInformation = false;
// Refresh
newTimbre(this->currentTimbre);
return;
}
}
// Special cases
switch (currentRow) {
case ROW_LFOSEQ1:
case ROW_LFOSEQ2:
if (encoder > ENCODER_STEPSEQ_GATE) {
updateStepSequencer(currentRow, encoder, oldValue, newValue);
return;
}
break;
case ROW_ARPEGGIATOR3:
// special case arpegiattor user pattern
updateArpPattern(currentRow, encoder, oldValue, newValue );
return;
break;
case ROW_OSC1 ... ROW_OSC_LAST:
if (encoder == ENCODER_OSC_FTYPE) {
if (newValue == OSC_FT_FIXE) {
lcd->setCursor(ENCODER_OSC_FREQ * 5 + 1, 3);
lcd->print(" ");
}
refreshStatus = 4;
return;
}
break;
case ROW_EFFECT:
if (unlikely(encoder == ENCODER_EFFECT_TYPE)) {
refreshStatus = 8;
return;
}
break;
case ROW_ENGINE:
if (encoder == ENCODER_ENGINE_ALGO) {
displayAlgo(newValue);
}
break;
case ROW_ENGINE2:
if (unlikely(encoder == ENCODER_ENGINE2_PLAY_MODE)) {
refreshStatus = 8;
return;
}
break;
case ROW_ARPEGGIATOR1:
if (unlikely(encoder == ENCODER_ARPEGGIATOR_CLOCK)) {
refreshStatus = 8;
return;
}
break;
}
updateEncoderValue(currentRow, encoder, param, newValue);
}
}
void FMDisplay::newcurrentRow(int timbre, int newcurrentRow) {
this->displayedRow = newcurrentRow;
if (unlikely(wakeUpFromScreenSaver())) {
return;
}
if (algoCounter > 0) {
displayPreset();
algoCounter = 0;
}
refreshStatus = 12;
}
/*
* Menu Listener
*/
void FMDisplay::newSynthMode(FullState* fullState) {
if (unlikely(screenSaverMode)) {
screenSaverMode = false;
screenSaveTimer = 0;
}
lcd->clearActions();
lcd->clear();
switch (fullState->synthMode) {
case SYNTH_MODE_EDIT:
displayPreset();
refreshStatus = 12;
break;
case SYNTH_MODE_MENU:
refreshStatus = 0;
menuRow = 0;
newMenuState(fullState);
break;
}
// just in case...
algoCounter = 0;
}
int FMDisplay::rowInc(MenuState menuState) {
switch (menuState) {
case MENU_SAVE_ENTER_COMBO_NAME:
case MAIN_MENU:
case MENU_RENAME_BANK:
case MENU_RENAME_COMBO:
case MENU_SAVE_ENTER_PRESET_NAME:
return 0;
}
return 1;
}
void FMDisplay::newMenuState(FullState* fullState) {
menuRow += rowInc(fullState->currentMenuItem->menuState);
if (fullState->currentMenuItem->hasSubMenu) {
int pos = 0;
for (int k=0; k<fullState->currentMenuItem->maxValue; k++) {
fullState->menuPosition[k] = pos;
lcd->setCursor(pos +1, menuRow);
const char* name = MenuItemUtil::getMenuItem(fullState->currentMenuItem->subMenu[k])->name;
pos = pos + (getLength(name) + 1);
lcd->print(name);
}
}
switch (fullState->currentMenuItem->menuState) {
case MENU_SAVE_ENTER_COMBO_NAME:
lcd->setCursor(6, menuRow);
for (int k=0;k<12; k++) {
lcd->print(allChars[(int)fullState->name[k]]);
}
break;
case MENU_SAVE_ENTER_PRESET_NAME:
lcd->setCursor(6, menuRow);
for (int k=0;k<12; k++) {
lcd->print(allChars[(int)fullState->name[k]]);
}
break;
case MENU_CREATE_COMBO:
case MENU_CREATE_BANK:
case MENU_RENAME_COMBO:
case MENU_RENAME_BANK:
lcd->setCursor(6, menuRow);
lcd->print(" ");
lcd->setCursor(6, menuRow);
for (int k=0;k<8; k++) {
lcd->print(allChars[(int)fullState->name[k]]);
}
break;
case MENU_RENAME_PATCH:
lcd->setCursor(6, menuRow);
for (int k=0;k<12; k++) {
lcd->print(allChars[(int)fullState->name[k]]);
}
break;
case MENU_DEFAULT_COMBO_SAVE:
lcd->setCursor(1, menuRow);
lcd->print("Save to default ?");
break;
case MENU_DEFAULT_COMBO_RESET:
lcd->setCursor(1, menuRow);
lcd->print("Reset default ?");
break;
case MENU_CONFIG_SETTINGS:
lcd->setCursor(1, menuRow);
lcd->print(midiConfig[fullState->menuSelect].title);
break;
case MENU_CONFIG_SETTINGS_SAVE:
lcd->setCursor(1, menuRow);
lcd->print("Save Config ? ");
break;
case MENU_SAVE_SYSEX_PATCH:
lcd->setCursor(1, menuRow);
lcd->print("Send Patch ?");
break;
case MENU_LOAD_RANDOMIZER:
lcd->setCursor(1, menuRow);
lcd->print("Oper Enve IMs Modu");
break;
}
newMenuSelect(fullState);
}
void FMDisplay::displayBankSelect(int bankNumber, bool usable, const char* name) {
eraseRow(menuRow);
lcd->setCursor(2, menuRow);
lcd->print(bankNumber);
if (usable) {
lcd->print(" - ");
} else {
lcd->print(" * ");
}
lcd->print(name);
}
void FMDisplay::displayPatchSelect(int presetNumber, const char* name) {
// Erase row except the note
lcd->setCursor(1, menuRow);
lcd->print(" ");
lcd->setCursor(2, menuRow);
lcd->print(presetNumber);
lcd->print(" - ");
lcd->print(name);
}
void FMDisplay::newMenuSelect(FullState* fullState) {
lcd->noCursor();
switch(fullState->currentMenuItem->menuState) {
case MAIN_MENU:
case MENU_LOAD:
case MENU_SAVE:
case MENU_TOOLS:
case MENU_MIDI_BANK:
case MENU_MIDI_PATCH:
case MENU_DEFAULT_COMBO:
case MENU_RENAME:
case MENU_CREATE:
case MENU_SCALA:
for (int k=0; k<fullState->currentMenuItem->maxValue; k++) {
lcd->setCursor(fullState->menuPosition[k], menuRow);
lcd->print(' ');
}
lcd->setCursor(fullState->menuPosition[fullState->menuSelect], menuRow);
lcd->print(">");
break;
case MENU_LOAD_SELECT_BANK_PRESET:
case MENU_LOAD_SELECT_DX7_PRESET:
displayPatchSelect(fullState->menuSelect, this->synthState->params->presetName);
break;
case MENU_SCALA_FILENAME:
displayBankSelect(fullState->menuSelect, (fullState->scalaScaleConfig.scalaFile->fileType != FILE_EMPTY), fullState->scalaScaleConfig.scalaFile->name);
break;
case MENU_SAVE_SELECT_BANK_PRESET:
displayPatchSelect(fullState->menuSelect, storage->getPatchBank()->loadPreenFMPatchName(fullState->preenFMBank, fullState->menuSelect));
break;
case MENU_LOAD_SELECT_COMBO_PRESET:
case MENU_SAVE_SELECT_COMBO_PRESET:
displayPatchSelect(fullState->menuSelect, storage->getComboBank()->loadPreenFMComboName(fullState->preenFMCombo, fullState->menuSelect));
break;
case MENU_LOAD_SELECT_DX7_BANK:
displayBankSelect(fullState->menuSelect, (fullState->dx7Bank->fileType != FILE_EMPTY), fullState->dx7Bank->name);
break;
case MENU_SAVE_SELECT_BANK:
displayBankSelect(fullState->menuSelect, (fullState->preenFMBank->fileType == FILE_OK), fullState->preenFMBank->name);
break;
case MENU_RENAME_SELECT_BANK:
displayBankSelect(fullState->menuSelect, (storage->getPatchBank()->getFile(fullState->menuSelect)->fileType != FILE_EMPTY), storage->getPatchBank()->getFile(fullState->menuSelect)->name);
break;
case MENU_LOAD_SELECT_BANK:
displayBankSelect(fullState->menuSelect, (fullState->preenFMBank->fileType != FILE_EMPTY), fullState->preenFMBank->name);
break;
case MENU_RENAME_SELECT_COMBO:
displayBankSelect(fullState->menuSelect, (storage->getComboBank()->getFile(fullState->menuSelect)->fileType != FILE_EMPTY), storage->getComboBank()->getFile(fullState->menuSelect)->name);
break;
case MENU_SAVE_SELECT_COMBO:
displayBankSelect(fullState->menuSelect, (fullState->preenFMCombo->fileType == FILE_OK), fullState->preenFMCombo->name);
break;
case MENU_LOAD_SELECT_COMBO: