-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCus428State.cc
876 lines (805 loc) · 20.3 KB
/
Cus428State.cc
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
/* -*- mode:C++; indent-tabs-mode:t; tab-width:8; c-basic-offset: 8 -*- */
/*
* Controller for Tascam US-X2Y
*
* Copyright (c) 2003 by Karsten Wiese <[email protected]>
* Copyright (c) 2004-2013 by Rui Nuno Capela <[email protected]>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include <alsa/asoundlib.h>
#include "Cus428Midi.h"
extern int verbose;
// Differential wheel tracking constants.
#define W_DELTA_MAX 0xff
#define W_DELTA_MIN (W_DELTA_MAX >> 1)
// Shuttle speed wheel constants.
#define W_SPEED_MAX 0x3f
void us428_lights::init_us428_lights()
{
int i = 0;
memset(this, 0, sizeof(*this));
for (i = 0; i < 7; ++i)
Light[ i].Offset = i + 0x19;
}
void Cus428State::InitDevice(void)
{
if (us428ctls_sharedmem->CtlSnapShotLast >= 0)
SliderChangedTo(eFaderM, ((unsigned char*)(us428ctls_sharedmem->CtlSnapShot + us428ctls_sharedmem->CtlSnapShotLast))[eFaderM]);
// Reset the LEDs to the state known by us428control
LightSend();
}
int Cus428State::LightSend()
{
int Next = us428ctls_sharedmem->p4outLast + 1;
if(Next < 0 || Next >= N_us428_p4out_BUFS)
Next = 0;
memcpy(&us428ctls_sharedmem->p4out[Next].lights, Light, sizeof(us428_lights));
us428ctls_sharedmem->p4out[Next].type = eLT_Light;
return us428ctls_sharedmem->p4outLast = Next;
}
void Cus428State::SliderSend(int S)
{
Midi.SendMidiControl(15, 0x40 + S, ((unsigned char*)us428_ctls)[S] / 2);
}
void Cus428State::SendVolume(usX2Y_volume &V)
{
int Next = us428ctls_sharedmem->p4outLast + 1;
if (Next < 0 || Next >= N_us428_p4out_BUFS)
Next = 0;
memcpy(&us428ctls_sharedmem->p4out[Next].vol, &V, sizeof(V));
us428ctls_sharedmem->p4out[Next].type = eLT_Volume;
us428ctls_sharedmem->p4outLast = Next;
}
void Cus428State::UserSliderChangedTo(int S, unsigned char New)
{
SliderSend(S);
}
void Cus428State::SliderChangedTo(int S, unsigned char New)
{
if (StateInputMonitor() && S <= eFader3 || S == eFaderM) {
usX2Y_volume &V = Volume[S >= eFader4 ? eFader4 : S];
V.SetTo(S, New);
if (S == eFaderM || !LightIs(eL_Mute0 + S))
SendVolume(V);
} else {
UserSliderChangedTo(S, New);
}
}
void Cus428State::UserKnobChangedTo(eKnobs K, bool V)
{
switch (K) {
case eK_STOP:
if (verbose > 1)
printf("Knob STOP now %i\n", V);
if (V) TransportToggle(T_STOP);
Midi.SendMidiControl(15, K, V);
break;
case eK_PLAY:
if (verbose > 1)
printf("Knob PLAY now %i", V);
if (V) TransportToggle(T_PLAY);
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_Play));
Midi.SendMidiControl(15, K, V);
break;
case eK_REW:
if (verbose > 1)
printf("Knob REW now %i", V);
if (V) TransportToggle(T_REW);
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_Rew));
Midi.SendMidiControl(15, K, V);
break;
case eK_FFWD:
if (verbose > 1)
printf("Knob FFWD now %i", V);
if (V) TransportToggle(T_F_FWD);
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_FFwd));
Midi.SendMidiControl(15, K, V);
break;
case eK_RECORD:
if (verbose > 1)
printf("Knob RECORD now %i", V);
if (V) TransportToggle(T_RECORD);
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_Record));
Midi.SendMidiControl(15, K, V);
break;
case eK_SET:
if (verbose > 1)
printf("Knob SET now %i\n", V);
bSetLocate = V;
break;
case eK_LOCATE_L:
if (verbose > 1)
printf("Knob LOCATE_L now %i\n", V);
if (V) {
if (bSetLocate)
aWheel_L = aWheel;
else {
aWheel = aWheel_L;
LocateSend();
}
}
break;
case eK_LOCATE_R:
if (verbose > 1)
printf("Knob LOCATE_R now %i\n", V);
if (V) {
if (bSetLocate)
aWheel_R = aWheel;
else {
aWheel = aWheel_R;
LocateSend();
}
}
break;
case eK_REC:
if (verbose > 1)
printf("Knob REC now %i\n", V);
bSetRecord = V;
break;
case eK_SOLO:
if (verbose > 1)
printf("Knob SOLO now %i", V);
if (V) {
bool bSolo = ! LightIs(eL_Solo);
if (StateInputMonitor()) {
if (bSolo) {
MuteInputMonitor = Light[2].Value;
Light[2].Value = SoloInputMonitor;
} else {
SoloInputMonitor = Light[2].Value;
Light[2].Value = MuteInputMonitor;
}
} else {
if (bSolo) {
Mute[aBank] = Light[2].Value;
Light[2].Value = Solo[aBank];
} else {
Solo[aBank] = Light[2].Value;
Light[2].Value = Mute[aBank];
}
}
LightSet(eL_Solo, bSolo);
LightSend();
}
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_Solo));
break;
case eK_NULL:
if (verbose > 1)
printf("Knob NULL now %i", V);
if (V) {
bool bNull = ! LightIs(eL_Null);
LightSet(eL_Null, bNull);
LightSend();
}
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_Null));
break;
case eK_BANK_L:
if (verbose > 1)
printf("Knob BANK_L now %i", V);
if (V) BankSet(aBank - 1);
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_BankL));
break;
case eK_BANK_R:
if (verbose > 1)
printf("Knob BANK_R now %i", V);
if (V) BankSet(aBank + 1);
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_BankR));
break;
default:
if (verbose > 1)
printf("Knob %i now %i\n", K, V);
// Midi.SendMidiControl(15, K, V);
}
}
void Cus428State::KnobChangedTo(eKnobs K, bool V)
{
// switch (K & ~(StateInputMonitor() ? 3 : -1)) {
switch (K & ~3) {
case eK_Select0:
if (V) {
int S = eL_Select0 + (K & 7);
Light[eL_Select0 / 8].Value = 0;
LightSet(S, !LightIs(S));
if (bSetRecord) {
int R = eL_Rec0 + (K & 7);
LightSet(R, !LightIs(R));
if (!StateInputMonitor()) {
SendMaskedWrite(MMC_CIF_TRACK_RECORD,
Y * aBank + (K & 7), LightIs(R));
}
}
LightSend();
}
break;
case eK_Mute0:
if (V) {
int M = eL_Mute0 + (K & 7);
LightSet(M, !LightIs(M));
LightSend();
if (StateInputMonitor()) {
if (LightIs(eL_Solo)) {
for (int i = 0; i < 8; ++i) {
usX2Y_volume V = Volume[i];
if (!LightIs(eL_Mute0 + i) || (MuteInputMonitor & (1 << i)))
V.LH = V.LL = V.RL = V.RH = 0;
SendVolume(V);
}
} else {
usX2Y_volume V = Volume[M - eL_Mute0];
if (LightIs(M))
V.LH = V.LL = V.RL = V.RH = 0;
SendVolume(V);
}
} else {
if (LightIs(eL_Solo)) {
SendMaskedWrite(MMC_CIF_TRACK_SOLO,
Y * aBank + (K & 7), LightIs(M));
} else {
SendMaskedWrite(MMC_CIF_TRACK_MUTE,
Y * aBank + (K & 7), LightIs(M));
}
}
}
break;
default:
if (K == eK_InputMonitor) {
if (verbose > 1)
printf("Knob InputMonitor now %i", V);
if (V) {
bool bInputMonitor = ! StateInputMonitor();
if (bInputMonitor) {
Select[aBank] = Light[0].Value;
Rec[aBank] = Light[1].Value;
Light[0].Value = SelectInputMonitor;
Light[1].Value = RecInputMonitor;
if (LightIs(eL_Solo)) {
Solo[aBank] = Light[2].Value;
Light[2].Value = SoloInputMonitor;
} else {
Mute[aBank] = Light[2].Value;
Light[2].Value = MuteInputMonitor;
}
} else {
SelectInputMonitor = Light[0].Value;
RecInputMonitor = Light[1].Value;
Light[0].Value = Select[aBank];
Light[1].Value = Rec[aBank];
if (LightIs(eL_Solo)) {
SoloInputMonitor = Light[2].Value;
Light[2].Value = Solo[aBank];
} else {
MuteInputMonitor = Light[2].Value;
Light[2].Value = Mute[aBank];
}
}
LightSet(eL_InputMonitor, bInputMonitor);
LightSend();
}
if (verbose > 1)
printf(" Light is %i\n", LightIs(eL_InputMonitor));
} else
UserKnobChangedTo(K, V);
}
}
void Cus428State::UserWheelChangedTo(E_In84 W, char Diff)
{
char Param;
switch (W) {
case eWheelPan:
Param = 0x4D;
break;
case eWheelGain:
Param = 0x48;
break;
case eWheelFreq:
Param = 0x49;
break;
case eWheelQ:
Param = 0x4A;
break;
case eWheel:
Param = 0x60;
// Update the absolute wheel position.
WheelDelta((int) ((unsigned char *) us428_ctls)[W]);
break;
}
Midi.SendMidiControl(15, Param, ((unsigned char *) us428_ctls)[W]);
}
void Cus428State::WheelChangedTo(E_In84 W, char Diff)
{
if (W == eWheelPan && StateInputMonitor() && Light[0].Value) {
int index = 0;
while( index < 4 && (1 << index) != Light[0].Value)
index++;
if (index >= 4)
return;
// The pan encoder has 24 detents. A multiple of 13 allows
// the pan to go from full-left to full-right in 20 clicks
// instead of 255 clicks (over 10 full turns!).
Volume[index].PanTo(Diff * 13, us428_ctls->Knob(eK_SET));
if (!LightIs(eL_Mute0 + index))
SendVolume(Volume[index]);
return;
}
UserWheelChangedTo(W, Diff);
}
// Convert time-code (hh:mm:ss:ff:fr) into absolute wheel position.
void Cus428State::LocateWheel ( unsigned char *tc )
{
aWheel = (60 * 60 * 30) * (int) tc[0] // hh - hours [0..23]
+ ( 60 * 30) * (int) tc[1] // mm - minutes [0..59]
+ ( 30) * (int) tc[2] // ss - seconds [0..59]
+ (int) tc[3]; // ff - frames [0..29]
}
// Convert absolute wheel position into time-code (hh:mm:ss:ff:fr)
void Cus428State::LocateTimecode ( unsigned char *tc )
{
int W = aWheel;
tc[0] = W / (60 * 60 * 30); W -= (60 * 60 * 30) * (int) tc[0];
tc[1] = W / ( 60 * 30); W -= ( 60 * 30) * (int) tc[1];
tc[2] = W / ( 30); W -= ( 30) * (int) tc[2];
tc[3] = W;
tc[4] = 0;
}
// Get the wheel differential.
void Cus428State::WheelDelta ( int W )
{
// Compute the wheel differential.
int dW = W - W0;
if (dW > 0 && dW > +W_DELTA_MIN)
dW -= W_DELTA_MAX;
else
if (dW < 0 && dW < -W_DELTA_MIN)
dW += W_DELTA_MAX;
W0 = W;
aWheel += dW;
// Can't be less than zero.
if (aWheel < 0)
aWheel = 0;
// Now it's whether we're running transport already...
if (aWheelSpeed)
WheelShuttle(dW);
else
WheelStep(dW);
}
// Get the wheel step.
void Cus428State::WheelStep ( int dW )
{
unsigned char step;
if (dW < 0)
step = (unsigned char) (((-dW & 0x3f) << 1) | 0x40);
else
step = (unsigned char) ((dW << 1) & 0x3f);
Midi.SendMmcCommand(MMC_CMD_STEP, &step, sizeof(step));
}
// Set the wheel shuttle speed.
void Cus428State::WheelShuttle ( int dW )
{
unsigned char shuttle[3];
int V, forward;
// Update the current absolute wheel shuttle speed.
aWheelSpeed += dW;
// Don't make it pass some limits...
if (aWheelSpeed < -W_SPEED_MAX) aWheelSpeed = -W_SPEED_MAX;
if (aWheelSpeed > +W_SPEED_MAX) aWheelSpeed = +W_SPEED_MAX;
// Build the MMC-Shuttle command...
V = aWheelSpeed;
forward = (V >= 0);
if (!forward)
V = -(V);
shuttle[0] = (unsigned char) ((V >> 3) & 0x07); // sh
shuttle[1] = (unsigned char) ((V & 0x07) << 4); // sm
shuttle[2] = (unsigned char) 0; // sl
if (!forward)
shuttle[0] |= (unsigned char) 0x40;
Midi.SendMmcCommand(MMC_CMD_SHUTTLE, &shuttle[0], sizeof(shuttle));
}
// Send the MMC wheel locate command...
void Cus428State::LocateSend ()
{
unsigned char MmcData[6];
// Timecode's embedded on MMC command.
MmcData[0] = 0x01;
LocateTimecode(&MmcData[1]);
// Send the MMC locate command...
Midi.SendMmcCommand(MMC_CMD_LOCATE, MmcData, sizeof(MmcData));
}
// Toggle application transport state.
void Cus428State::TransportToggle ( unsigned char T )
{
switch (T) {
case T_PLAY:
if (uTransport & T_PLAY) {
uTransport = T_STOP;
Midi.SendMmcCommand(MMC_CMD_STOP);
} else {
uTransport &= T_RECORD;
uTransport |= T_PLAY;
Midi.SendMmcCommand(MMC_CMD_PLAY);
}
break;
case T_RECORD:
if (uTransport & T_RECORD) {
uTransport &= ~T_RECORD;
Midi.SendMmcCommand(MMC_CMD_RECORD_EXIT);
} else {
uTransport &= T_PLAY;
uTransport |= T_RECORD;
Midi.SendMmcCommand(uTransport & T_PLAY ? MMC_CMD_RECORD_STROBE : MMC_CMD_RECORD_PAUSE);
}
break;
default:
if (uTransport & T) {
uTransport = T_STOP;
} else {
uTransport = T;
}
if (uTransport & T_STOP)
Midi.SendMmcCommand(MMC_CMD_STOP);
if (uTransport & T_REW)
Midi.SendMmcCommand(MMC_CMD_REWIND);
if (uTransport & T_F_FWD)
Midi.SendMmcCommand(MMC_CMD_FAST_FORWARD);
break;
}
TransportSend();
}
// Set application transport state.
void Cus428State::TransportSet ( unsigned char T, bool V )
{
if (V) {
if (T == T_RECORD) {
uTransport |= T_RECORD;
} else {
uTransport = T;
}
} else {
if (T == T_RECORD) {
uTransport &= ~T_RECORD;
} else {
uTransport = T_STOP;
}
}
TransportSend();
}
// Update transport status lights.
void Cus428State::TransportSend()
{
// Common ground for shuttle speed set.
if (uTransport & T_PLAY)
aWheelSpeed = ((W_SPEED_MAX + 1) >> 3);
else if (uTransport & T_REW)
aWheelSpeed = -(W_SPEED_MAX + 1);
else if (uTransport & T_F_FWD)
aWheelSpeed = +(W_SPEED_MAX + 1);
else
aWheelSpeed = 0;
// Lightning feedback :)
LightSet(eL_Play, (uTransport & T_PLAY));
LightSet(eL_Record, (uTransport & T_RECORD));
LightSet(eL_Rew, (uTransport & T_REW));
LightSet(eL_FFwd, (uTransport & T_F_FWD));
LightSend();
}
// Set new bank layer state.
void Cus428State::BankSet( int B )
{
if (B >= 0 && B < cBanks) {
if (!StateInputMonitor()) {
bool bSolo = LightIs(eL_Solo);
Select[aBank] = Light[0].Value;
Rec[aBank] = Light[1].Value;
if (bSolo) {
Solo[aBank] = Light[2].Value;
} else {
Mute[aBank] = Light[2].Value;
}
Light[0].Value = Select[B];
Light[1].Value = Rec[B];
if (bSolo) {
Light[2].Value = Solo[B];
} else {
Light[2].Value = Mute[B];
}
}
aBank = B;
}
BankSend();
}
// Update bank status lights.
void Cus428State::BankSend()
{
LightSet(eL_BankL, (aBank == 0));
LightSet(eL_BankR, (aBank == cBanks - 1));
LightSend();
}
// Reset MMC state.
void Cus428State::MmcReset()
{
W0 = 0;
aBank = 0;
aWheel = aWheel_L = aWheel_R = 0;
aWheelSpeed = 0;
bSetLocate = false;
bSetRecord = false;
uTransport = 0;
BankSend();
TransportSend();
LocateSend();
BankSend();
}
// Process MMC maked-write sub-command.
void Cus428State::MaskedWrite ( unsigned char *data )
{
// data[0] - sub-command / information field.
// data[1] - target track bitmap byte address.
// data[2] - bitmap changed mask.
// data[3] - bitmap changed value.
int track = (data[1] > 0 ? (data[1] * 7) : 0) - 5;
for (int i = 0; i < 7; ++i) {
int mask = (1 << i);
if (data[2] & mask) {
// Only touch tracks that have the "mask" bit set.
int enable = (data[3] & mask);
int bank = (track / Y);
int N = (track % Y);
switch (data[0]) {
case MMC_CIF_TRACK_RECORD:
if (verbose > 1)
fprintf(stderr, "TRACK RECORD(%d, %d).\n", track, enable);
if (!StateInputMonitor() && bank >= 0 && bank < cBanks) {
if (bank == aBank) {
LightSet(eL_Rec0 + N, enable);
LightSend();
} else if (enable) {
Rec[bank] |= (1 << N);
} else {
Rec[bank] &= ~(1 << N);
}
}
break;
case MMC_CIF_TRACK_MUTE:
if (verbose > 1)
fprintf(stderr, "TRACK MUTE(%d, %d).\n", track, enable);
if (!StateInputMonitor() && bank >= 0 && bank < cBanks) {
if (bank == aBank && !LightIs(eL_Solo)) {
LightSet(eL_Mute0 + N, enable);
LightSend();
} else if (enable) {
Mute[bank] |= (1 << N);
} else {
Mute[bank] &= ~(1 << N);
}
}
break;
case MMC_CIF_TRACK_SOLO:
if (verbose > 1)
fprintf(stderr, "TRACK SOLO(%d, %d).\n", track, enable);
if (!StateInputMonitor() && bank >= 0 && bank < cBanks) {
if (bank == aBank && LightIs(eL_Solo)) {
LightSet(eL_Mute0 + N, enable);
LightSend();
} else if (enable) {
Solo[bank] |= (1 << N);
} else {
Solo[bank] &= ~(1 << N);
}
}
break;
default:
break;
}
}
track++;
}
}
// Send own MMC masked-write subcommand.
void Cus428State::SendMaskedWrite ( unsigned char scmd, int track, bool V )
{
unsigned char data[4];
int mask = (1 << (track < 2 ? track + 5 : (track - 2) % 7));
data[0] = scmd;
data[1] = (unsigned char) (track < 2 ? 0 : 1 + (track - 2) / 7);
data[2] = (unsigned char) mask;
data[3] = (unsigned char) (V ? mask : 0);
Midi.SendMmcCommand(MMC_CMD_MASKED_WRITE, &data[0], sizeof(data));
}
Cus428StateMixxx::Cus428StateMixxx(
struct us428ctls_sharedmem* Pus428ctls_sharedmem, int y)
: Cus428State(Pus428ctls_sharedmem, y)
{
focus = 0;
eq = 0;
LightSet(eL_Low, 1);
LightSet(eL_LowMid, 0);
LightSet(eL_HiMid, 0);
LightSet(eL_High, 0);
LightSend();
}
void Cus428StateMixxx::UserKnobChangedTo(eKnobs K, bool V)
{
switch (K) {
case eK_BANK_L:
if (verbose > 1)
printf("Knob BANK_L now %i\n", V);
if (V) LightSet(eL_BankL, !LightIs(eL_BankL));
LightSend();
Midi.SendMidiNote(0, 51, V ? 127 : 0);
break;
case eK_BANK_R:
if (verbose > 1)
printf("Knob BANK_R now %i\n", V);
if (V) LightSet(eL_BankR, !LightIs(eL_BankR));
LightSend();
Midi.SendMidiNote(1, 51, V ? 127 : 0);
break;
case eK_REW:
if (verbose > 1)
printf("Knob REW now %i\n", V);
Midi.SendMidiNote(focus, 60, V ? 127 : 0);
break;
case eK_FFWD:
if (verbose > 1)
printf("Knob FFWD now %i\n", V);
Midi.SendMidiNote(focus, 61, V ? 127 : 0);
break;
case eK_STOP:
if (verbose > 1)
printf("Knob STOP now %i\n", V);
Midi.SendMidiNote(focus, 62, V ? 127 : 0);
break;
case eK_PLAY:
if (verbose > 1)
printf("Knob PLAY now %i\n", V);
Midi.SendMidiNote(focus, 63, V ? 127 : 0);
break;
case eK_RECORD:
if (verbose > 1)
printf("Knob RECORD now %i\n", V);
Midi.SendMidiNote(focus, 64, V ? 127 : 0);
break;
case eK_LOW:
if (verbose > 1)
printf("Knob LOW now %i\n", V);
if (V)
{
eq = 0;
LightSet(eL_Low, 1);
LightSet(eL_LowMid, 0);
LightSet(eL_HiMid, 0);
LightSet(eL_High, 0);
LightSend();
}
break;
case eK_LOWMID:
if (verbose > 1)
printf("Knob LOWMID now %i\n", V);
if (V)
{
eq = 1;
LightSet(eL_Low, 0);
LightSet(eL_LowMid, 1);
LightSet(eL_HiMid, 0);
LightSet(eL_High, 0);
LightSend();
}
break;
case eK_HIMID:
if (verbose > 1)
printf("Knob HIMID now %i\n", V);
if (V)
{
eq = 2;
LightSet(eL_Low, 0);
LightSet(eL_LowMid, 0);
LightSet(eL_HiMid, 1);
LightSet(eL_High, 0);
LightSend();
}
break;
case eK_HIGH:
if (verbose > 1)
printf("Knob HIGH now %i\n", V);
if (V)
{
eq = 3;
LightSet(eL_Low, 0);
LightSet(eL_LowMid, 0);
LightSet(eL_HiMid, 0);
LightSet(eL_High, 1);
LightSend();
}
break;
case eK_SET:
if (verbose > 1)
printf("Knob SET now %i\n", V);
Midi.SendMidiNote(focus, 65, V ? 127 : 0);
break;
case eK_LOCATE_L:
if (verbose > 1)
printf("Knob LOCATE_L now %i\n", V);
if (V) {
focus = 0;
}
break;
case eK_LOCATE_R:
if (verbose > 1)
printf("Knob LOCATE_R now %i\n", V);
if (V) {
focus = 1;
}
break;
default:
if (verbose > 1)
printf("Knob %i now %i\n", K, V);
if (K >= eK_Select0 && K <= eK_Select0 + 7) {
if (V) LightSet(eL_Select0 + (K - eK_Select0), !LightIs(eL_Select0 + (K - eK_Select0)));
LightSend();
} else if (K >= eK_Mute0 && K <= eK_Mute0 + 7) {
if (V) LightSet(eL_Mute0 + (K - eK_Mute0), !LightIs(eL_Mute0 + (K - eK_Mute0)));
LightSend();
}
Midi.SendMidiNote(0, K, V);
}
}
void Cus428StateMixxx::UserSliderChangedTo(int S, unsigned char New)
{
// if (verbose > 1)
// printf("Slider : %d - %d - %d\n", S, New, ((unsigned char*)us428_ctls)[S]);
Midi.SendMidiControl(0, 0x40 + S, ((unsigned char*)us428_ctls)[S] / 2);
}
void Cus428StateMixxx::UserWheelChangedTo(E_In84 W, char Diff)
{
char Param;
char Value;
char Channel;
//if (verbose > 1)
// printf("Slider : %d - %d - %d\n", W, Diff, ((unsigned char *) us428_ctls)[W]);
Channel = 0;
switch (W) {
case eWheelGain:
Param = 0x48 + eq * 4;
break;
case eWheelFreq:
Param = 0x49 + eq * 4;
break;
case eWheelQ:
Param = 0x4A + eq * 4;
break;
case eWheelPan:
Param = 0x4B + eq * 4;
break;
case eWheel:
Param = 0x60;
Channel = focus;
// Update the absolute wheel position.
//WheelDelta((int) ((unsigned char *) us428_ctls)[W]);
break;
}
Value = 64 + Diff;
Midi.SendMidiControl(Channel, Param, Value);
//Midi.SendMidiControl(0, Param, ((unsigned char *) us428_ctls)[W]);
}