forked from g0orx/pihpsdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi3.c
878 lines (873 loc) · 27.1 KB
/
midi3.c
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
/*
* Layer-3 of MIDI support
*
* (C) Christoph van Wullen, DL1YCF
*
*
* In most cases, a certain action only makes sense for a specific
* type. For example, changing the VFO frequency will only be implemeted
* for MIDI_WHEEL, and TUNE off/on only with MIDI_KNOB.
*
* However, changing the volume makes sense both with MIDI_KNOB and MIDI_WHEEL.
*/
#include <gtk/gtk.h>
#include "radio.h"
#include "vfo.h"
#include "filter.h"
#include "band.h"
#include "mode.h"
#include "new_menu.h"
#include "sliders.h"
#include "ext.h"
#include "agc.h"
#include "midi.h"
#ifdef LOCALCW
#include "iambic.h"
#endif
void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
int new;
double dnew;
double *dp;
int *ip;
//
// Handle cases in alphabetical order of the key words in midi.props
//
switch (action) {
/////////////////////////////////////////////////////////// "A2B"
case VFO_A2B: // only key supported
if (type == MIDI_KEY) {
g_idle_add(ext_vfo_a_to_b, NULL);
}
break;
/////////////////////////////////////////////////////////// "AFGAIN"
case MIDI_AF_GAIN: // knob or wheel supported
switch (type) {
case MIDI_KNOB:
active_receiver->volume = 0.01*val;
break;
case MIDI_WHEEL:
dnew=active_receiver->volume += 0.01*val;
if (dnew < 0.0) dnew=0.0; if (dnew > 1.0) dnew=1.0;
active_receiver->volume = dnew;
break;
default:
// do not change volume
// we should not come here anyway
break;
}
g_idle_add(ext_update_af_gain, NULL);
break;
/////////////////////////////////////////////////////////// "AGCATTACK"
case AGCATTACK: // only key supported
// cycle through fast/med/slow AGC attack
if (type == MIDI_KEY) {
new=active_receiver->agc + 1;
if (new > AGC_FAST) new=0;
active_receiver->agc=new;
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "AGCVAL"
case MIDI_AGC: // knob or wheel supported
switch (type) {
case MIDI_KNOB:
dnew = -20.0 + 1.4*val;
break;
case MIDI_WHEEL:
dnew=active_receiver->agc_gain + val;
if (dnew < -20.0) dnew=-20.0; if (dnew > 120.0) dnew=120.0;
break;
default:
// do not change value
// we should not come here anyway
dnew=active_receiver->agc_gain;
break;
}
dp=malloc(sizeof(double));
*dp=dnew;
g_idle_add(ext_set_agc_gain, (gpointer) dp);
break;
/////////////////////////////////////////////////////////// "ANF"
case ANF: // only key supported
if (type == MIDI_KEY) {
g_idle_add(ext_anf_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "ATT"
case ATT: // Key for ALEX attenuator, wheel or knob for slider
switch(type) {
case MIDI_KEY:
if (filter_board == ALEX && active_receiver->adc == 0) {
new=active_receiver->alex_attenuation + 1;
if (new > 3) new=0;
g_idle_add(ext_set_alex_attenuation, GINT_TO_POINTER(new));
g_idle_add(ext_update_att_preamp, NULL);
}
break;
case MIDI_WHEEL:
new=adc_attenuation[active_receiver->adc] + val;
dp=malloc(sizeof(double));
*dp=(double) new;
if(have_rx_gain) {
if(*dp<-12.0) {
*dp=-12.0;
} else if(*dp>48.0) {
*dp=48.0;
}
} else {
if(*dp<0.0) {
*dp=0.0;
} else if (*dp>31.0) {
*dp=31.0;
}
}
g_idle_add(ext_set_attenuation_value,(gpointer) dp);
break;
case MIDI_KNOB:
dp=malloc(sizeof(double));
if (have_rx_gain) {
*dp=-12.0 + 0.6*(double) val;
} else {
*dp = 0.31 * (double) val;
}
g_idle_add(ext_set_attenuation_value,(gpointer) dp);
break;
default:
// do nothing
// we should not come here anyway
break;
}
break;
/////////////////////////////////////////////////////////// "B2A"
case VFO_B2A: // only key supported
if (type == MIDI_KEY) {
g_idle_add(ext_vfo_b_to_a, NULL);
}
break;
/////////////////////////////////////////////////////////// "BANDDOWN"
/////////////////////////////////////////////////////////// "BANDUP"
case BAND_DOWN:
case BAND_UP:
switch (type) {
case MIDI_KEY:
new=(action == BAND_UP) ? 1 : -1;
break;
case MIDI_WHEEL:
new=val > 0 ? 1 : -1;
break;
case MIDI_KNOB:
// cycle through the bands
new = ((BANDS-1) * val) / 100 - vfo[active_receiver->id].band;
break;
default:
// do not change
// we should not come here anyway
new=0;
break;
}
//
// If the band has not changed, do nothing. Otherwise
// vfo.c will loop through the band stacks
//
if (new != 0) {
new+=vfo[active_receiver->id].band;
if (new >= BANDS) new=0;
if (new < 0) new=BANDS-1;
g_idle_add(ext_vfo_band_changed, GINT_TO_POINTER(new));
}
break;
/////////////////////////////////////////////////////////// "COMPRESS"
case COMPRESS: // wheel or knob
switch (type) {
case MIDI_WHEEL:
dnew=transmitter->compressor_level + val;
if (dnew > 20.0) dnew=20.0;
if (dnew < 0 ) dnew=0;
break;
case MIDI_KNOB:
dnew=(20.0*val)/100.0;
break;
default:
// do not change
// we should not come here anyway
dnew=transmitter->compressor_level;
break;
}
transmitter->compressor_level=dnew;
// automatically engange compressor if level > 0.5
if (dnew < 0.5) transmitter->compressor=0;
if (dnew > 0.5) transmitter->compressor=1;
g_idle_add(ext_set_compression, NULL);
break;
/////////////////////////////////////////////////////////// "CTUN"
case MIDI_CTUN: // only key supported
// toggle CTUN
if (type == MIDI_KEY) {
g_idle_add(ext_ctun_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "CURRVFO"
case VFO: // only wheel supported
if (type == MIDI_WHEEL && !locked) {
g_idle_add(ext_vfo_step, GINT_TO_POINTER(val));
}
break;
/////////////////////////////////////////////////////////// "CWL"
/////////////////////////////////////////////////////////// "CWR"
case CWL: // only key
case CWR: // only key
#ifdef LOCALCW
if (type == MIDI_KEY) {
new=(action == CWL);
keyer_event(new,val);
}
#endif
break;
/////////////////////////////////////////////////////////// "CWSPEED"
case CWSPEED: // knob or wheel
switch (type) {
case MIDI_KNOB:
// speed between 5 and 35 wpm
new= (int) (5.0 + (double) val * 0.3);
break;
case MIDI_WHEEL:
// here we allow from 1 to 60 wpm
new = cw_keyer_speed + val;
if (new < 1) new=1;
if (new > 60) new=60;
break;
default:
// do not change
// we should not come here anyway
new = cw_keyer_speed;
break;
}
cw_keyer_speed=new;
#ifdef LOCALCW
keyer_update();
#endif
g_idle_add(ext_vfo_update, NULL);
break;
/////////////////////////////////////////////////////////// "DIVCOARSEGAIN"
case DIV_COARSEGAIN: // knob or wheel supported
case DIV_FINEGAIN: // knob or wheel supported
case DIV_GAIN: // knob or wheel supported
switch (type) {
case MIDI_KNOB:
if (action == DIV_COARSEGAIN || action == DIV_GAIN) {
// -25 to +25 dB in steps of 0.5 dB
dnew = 10.0*(-25.0 + 0.5*val - div_gain);
} else {
// round gain to a multiple of 0.5 dB and apply a +/- 0.5 dB update
new = (int) (2*div_gain + 1.0) / 2;
dnew = 10.0*((double) new + 0.01*val - 0.5 - div_gain);
}
break;
case MIDI_WHEEL:
// coarse: increaments in steps of 0.25 dB, medium: steps of 0.1 dB fine: in steps of 0.01 dB
if (action == DIV_GAIN) {
dnew = val*0.5;
} else if (action == DIV_COARSEGAIN) {
dnew = val*2.5;
} else {
dnew = val * 0.1;
}
break;
default:
// do not change
// we should not come here anyway
dnew = 0.0;
break;
}
// dnew is the delta times 10
dp=malloc(sizeof(double));
*dp=dnew;
g_idle_add(ext_diversity_change_gain, dp);
break;
/////////////////////////////////////////////////////////// "DIVPHASE"
case DIV_COARSEPHASE: // knob or wheel supported
case DIV_FINEPHASE: // knob or wheel supported
case DIV_PHASE: // knob or wheel supported
switch (type) {
case MIDI_KNOB:
// coarse: change phase from -180 to 180
// fine: change from -5 to 5
if (action == DIV_COARSEPHASE || action == DIV_PHASE) {
// coarse: change phase from -180 to 180 in steps of 3.6 deg
dnew = (-180.0 + 3.6*val - div_phase);
} else {
// fine: round to multiple of 5 deg and apply a +/- 5 deg update
new = 5 * ((int) (div_phase+0.5) / 5);
dnew = (double) new + 0.1*val -5.0 -div_phase;
}
break;
case MIDI_WHEEL:
if (action == DIV_PHASE) {
dnew = val*0.5;
} else if (action == DIV_COARSEPHASE) {
dnew = val*2.5;
} else if (action == DIV_FINEPHASE) {
dnew = 0.1*val;
}
break;
default:
// do not change
// we should not come here anyway
dnew = 0.0;
break;
}
// dnew is the delta
dp=malloc(sizeof(double));
*dp=dnew;
g_idle_add(ext_diversity_change_phase, dp);
break;
/////////////////////////////////////////////////////////// "DIVTOGGLE"
case DIV_TOGGLE: // only key supported
if (type == MIDI_KEY) {
// enable/disable DIVERSITY
diversity_enabled = diversity_enabled ? 0 : 1;
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "DUP"
case MIDI_DUP:
if (can_transmit && !isTransmitting()) {
duplex=duplex==1?0:1;
g_idle_add(ext_set_duplex, NULL);
}
break;
/////////////////////////////////////////////////////////// "FILTERDOWN"
/////////////////////////////////////////////////////////// "FILTERUP"
case FILTER_DOWN:
case FILTER_UP:
//
// In filter.c, the filters are sorted such that the widest one comes first
// Therefore let FILTER_UP move down.
//
switch (type) {
case MIDI_KEY:
new=(action == FILTER_UP) ? -1 : 1;
break;
case MIDI_WHEEL:
new=val > 0 ? -1 : 1;
break;
case MIDI_KNOB:
// cycle through all the filters: val=100 maps to filter #0
new = ((FILTERS-1) * (val-100)) / 100 - vfo[active_receiver->id].filter;
break;
default:
// do not change filter setting
// we should not come here anyway
new=0;
break;
}
if (new != 0) {
new+=vfo[active_receiver->id].filter;
if (new >= FILTERS) new=0;
if (new <0) new=FILTERS-1;
g_idle_add(ext_vfo_filter_changed, GINT_TO_POINTER(new));
}
break;
/////////////////////////////////////////////////////////// "LOCK"
case MIDI_LOCK: // only key supported
if (type == MIDI_KEY) {
locked=!locked;
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "MICGAIN"
case MIC_VOLUME: // knob or wheel supported
// TODO: possibly adjust linein value if that is effective
switch (type) {
case MIDI_KNOB:
dnew=-10.0 + 0.6*val;
break;
case MIDI_WHEEL:
dnew = mic_gain + val;
if (dnew < -10.0) dnew=-10.0; if (dnew > 50.0) dnew=50.0;
break;
default:
// do not change mic gain
// we should not come here anyway
dnew = mic_gain;
break;
}
dp=malloc(sizeof(double));
*dp=dnew;
g_idle_add(ext_set_mic_gain, (gpointer) dp);
break;
/////////////////////////////////////////////////////////// "MODEDOWN"
/////////////////////////////////////////////////////////// "MODEUP"
case MODE_DOWN:
case MODE_UP:
switch (type) {
case MIDI_KEY:
new=(action == MODE_UP) ? 1 : -1;
break;
case MIDI_WHEEL:
new=val > 0 ? 1 : -1;
break;
case MIDI_KNOB:
// cycle through all the modes
new = ((MODES-1) * val) / 100 - vfo[active_receiver->id].mode;
break;
default:
// do not change
// we should not come here anyway
new=0;
break;
}
if (new != 0) {
new+=vfo[active_receiver->id].mode;
if (new >= MODES) new=0;
if (new <0) new=MODES-1;
g_idle_add(ext_vfo_mode_changed, GINT_TO_POINTER(new));
}
break;
/////////////////////////////////////////////////////////// "MOX"
case MIDI_MOX: // only key supported
if (type == MIDI_KEY && can_transmit) {
new = !mox;
g_idle_add(ext_mox_update, GINT_TO_POINTER(new));
}
break;
/////////////////////////////////////////////////////////// "MUTE"
case MIDI_MUTE:
if (type == MIDI_KEY) {
g_idle_add(ext_mute_update,NULL);
}
break;
/////////////////////////////////////////////////////////// "NOISEBLANKER"
case MIDI_NB: // only key supported
// cycle through NoiseBlanker settings: OFF, NB, NB2
if (type == MIDI_KEY) {
if (active_receiver->nb) {
active_receiver->nb = 0;
active_receiver->nb2= 1;
} else if (active_receiver->nb2) {
active_receiver->nb = 0;
active_receiver->nb2= 0;
} else {
active_receiver->nb = 1;
active_receiver->nb2= 0;
}
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "NOISEREDUCTION"
case MIDI_NR: // only key supported
// cycle through NoiseReduction settings: OFF, NR1, NR2
if (type == MIDI_KEY) {
if (active_receiver->nr) {
active_receiver->nr = 0;
active_receiver->nr2= 1;
} else if (active_receiver->nr2) {
active_receiver->nr = 0;
active_receiver->nr2= 0;
} else {
active_receiver->nr = 1;
active_receiver->nr2= 0;
}
g_idle_add(ext_update_noise, NULL);
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "PAN"
case MIDI_PAN: // wheel and knob
switch (type) {
case MIDI_WHEEL:
g_idle_add(ext_pan_update,GINT_TO_POINTER(val));
break;
case MIDI_KNOB:
g_idle_add(ext_pan_set,GINT_TO_POINTER(val));
break;
default:
// no action for keys (we should not come here anyway)
break;
}
break;
/////////////////////////////////////////////////////////// "PANHIGH"
case PAN_HIGH: // wheel or knob
switch (type) {
case MIDI_WHEEL:
if (mox) {
// TX panadapter affected
transmitter->panadapter_high += val;
} else {
active_receiver->panadapter_high += val;
}
break;
case MIDI_KNOB:
// Adjust "high water" in the range -50 ... 0 dBm
new = -50 + val/2;
if (mox) {
transmitter->panadapter_high = new;
} else {
active_receiver->panadapter_high = new;
}
break;
default:
// do nothing
// we should not come here anyway
break;
}
g_idle_add(ext_vfo_update, NULL);
break;
/////////////////////////////////////////////////////////// "PANLOW"
case PAN_LOW: // wheel and knob
switch (type) {
case MIDI_WHEEL:
if (isTransmitting()) {
// TX panadapter affected
transmitter->panadapter_low += val;
} else {
active_receiver->panadapter_low += val;
}
break;
case MIDI_KNOB:
if (isTransmitting()) {
// TX panadapter: use values -100 through -50
new = -100 + val/2;
transmitter->panadapter_low =new;
} else {
// RX panadapter: use values -140 through -90
new = -140 + val/2;
active_receiver->panadapter_low = new;
}
break;
default:
// do nothing
// we should not come here anyway
break;
}
g_idle_add(ext_vfo_update, NULL);
break;
/////////////////////////////////////////////////////////// "PREAMP"
case PRE: // only key supported
if (type == MIDI_KEY) {
//
// Normally on/off, but for CHARLY25, cycle through three
// possible states. Current HPSDR hardware does no have
// switch'able preamps.
//
int c25= (filter_board == CHARLY25);
new = active_receiver->preamp + active_receiver->dither;
new++;
if (c25) {
if (new >2) new=0;
} else {
if (new >1) new=0;
}
switch (new) {
case 0:
active_receiver->preamp=0;
if (c25) active_receiver->dither=0;
break;
case 1:
active_receiver->preamp=1;
if (c25) active_receiver->dither=0;
break;
case 2:
active_receiver->preamp=1;
if (c25) active_receiver->dither=1;
break;
}
g_idle_add(ext_update_att_preamp, NULL);
}
break;
/////////////////////////////////////////////////////////// "PURESIGNAL"
case MIDI_PS: // only key supported
#ifdef PURESIGNAL
// toggle PURESIGNAL
if (type == MIDI_KEY) {
new=!(transmitter->puresignal);
g_idle_add(ext_tx_set_ps,GINT_TO_POINTER(new));
}
#endif
break;
/////////////////////////////////////////////////////////// "RFGAIN"
case MIDI_RF_GAIN: // knob or wheel supported
if (type == MIDI_KNOB) {
new=val;
} else if (type == MIDI_WHEEL) {
new=(int)active_receiver->rf_gain+val;
}
g_idle_add(ext_set_rf_gain, GINT_TO_POINTER((int)new));
break;
/////////////////////////////////////////////////////////// "RFPOWER"
case TX_DRIVE: // knob or wheel supported
switch (type) {
case MIDI_KNOB:
dnew = val;
break;
case MIDI_WHEEL:
dnew=transmitter->drive + val;
if (dnew < 0.0) dnew=0.0; if (dnew > 100.0) dnew=100.0;
break;
default:
// do not change value
// we should not come here anyway
dnew=transmitter->drive;
break;
}
dp=malloc(sizeof(double));
*dp=dnew;
g_idle_add(ext_set_drive, (gpointer) dp);
break;
/////////////////////////////////////////////////////////// "RITCLEAR"
case MIDI_RIT_CLEAR: // only key supported
if (type == MIDI_KEY) {
// clear RIT value
vfo[active_receiver->id].rit = new;
g_idle_add(ext_vfo_update, NULL);
}
/////////////////////////////////////////////////////////// "RITSTEP"
case RIT_STEP: // key or wheel supported
// This cycles between RIT increments 1, 10, 100, 1, 10, 100, ...
switch (type) {
case MIDI_KEY:
// key cycles through in upward direction
val=1;
/* FALLTHROUGH */
case MIDI_WHEEL:
// wheel cycles upward or downward
if (val > 0) {
rit_increment=10*rit_increment;
} else {
rit_increment=rit_increment/10;
}
if (rit_increment < 1) rit_increment=100;
if (rit_increment > 100) rit_increment=1;
break;
default:
// do nothing
break;
}
g_idle_add(ext_vfo_update, NULL);
break;
/////////////////////////////////////////////////////////// "RITTOGGLE"
case RIT_TOGGLE: // only key supported
if (type == MIDI_KEY) {
// enable/disable RIT
new=vfo[active_receiver->id].rit_enabled;
vfo[active_receiver->id].rit_enabled = new ? 0 : 1;
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "RITVAL"
case RIT_VAL: // wheel or knob
switch (type) {
case MIDI_WHEEL:
// This changes the RIT value incrementally,
// but we restrict the change to +/ 9.999 kHz
new = vfo[active_receiver->id].rit + val*rit_increment;
if (new > 9999) new= 9999;
if (new < -9999) new=-9999;
vfo[active_receiver->id].rit = new;
break;
case MIDI_KNOB:
// knob: adjust in the range +/ 50*rit_increment
new = (val-50) * rit_increment;
vfo[active_receiver->id].rit = new;
break;
default:
// do nothing
// we should not come here anyway
break;
}
// enable/disable RIT according to RIT value
vfo[active_receiver->id].rit_enabled = (vfo[active_receiver->id].rit == 0) ? 0 : 1;
g_idle_add(ext_vfo_update, NULL);
break;
/////////////////////////////////////////////////////////// "SAT"
case MIDI_SAT:
switch (sat_mode) {
case SAT_NONE:
sat_mode=SAT_MODE;
break;
case SAT_MODE:
sat_mode=RSAT_MODE;
break;
case RSAT_MODE:
default:
sat_mode=SAT_NONE;
break;
}
g_idle_add(ext_vfo_update, NULL);
break;
/////////////////////////////////////////////////////////// "SNB"
case SNB: // only key supported
if (type == MIDI_KEY) {
g_idle_add(ext_snb_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "SPLIT"
case MIDI_SPLIT: // only key supported
// toggle split mode
if (type == MIDI_KEY) {
g_idle_add(ext_split_toggle, NULL);
}
break;
/////////////////////////////////////////////////////////// "SWAPRX"
case SWAP_RX: // only key supported
if (type == MIDI_KEY && receivers == 2) {
new=active_receiver->id; // 0 or 1
new= (new == 1) ? 0 : 1; // id of currently inactive receiver
active_receiver=receiver[new];
g_idle_add(menu_active_receiver_changed,NULL);
g_idle_add(ext_vfo_update,NULL);
g_idle_add(sliders_active_receiver_changed,NULL);
}
break;
/////////////////////////////////////////////////////////// "SWAPVFO"
case SWAP_VFO: // only key supported
if (type == MIDI_KEY) {
g_idle_add(ext_vfo_a_swap_b,NULL);
}
break;
/////////////////////////////////////////////////////////// "TUNE"
case MIDI_TUNE: // only key supported
if (type == MIDI_KEY && can_transmit) {
new = !tune;
g_idle_add(ext_tune_update, GINT_TO_POINTER(new));
}
break;
/////////////////////////////////////////////////////////// "VFOA"
/////////////////////////////////////////////////////////// "VFOB"
case VFOA: // only wheel supported
case VFOB: // only wheel supported
if (type == MIDI_WHEEL && !locked) {
ip=malloc(2*sizeof(int));
*ip = (action == VFOA) ? 0 : 1; // could use (action - VFOA) to support even more VFOs
*(ip+1)=val;
g_idle_add(ext_vfo_id_step, ip);
}
break;
/////////////////////////////////////////////////////////// "VFOSTEPDOWN"
/////////////////////////////////////////////////////////// "VFOSTEPUP"
case VFO_STEP_DOWN: // key or wheel supported
case VFO_STEP_UP:
switch (type) {
case MIDI_KEY:
new = (action == VFO_STEP_UP) ? 1 : -1;
g_idle_add(ext_update_vfo_step, GINT_TO_POINTER(new));
break;
case MIDI_WHEEL:
new = (val > 0) ? 1 : -1;
g_idle_add(ext_update_vfo_step, GINT_TO_POINTER(new));
break;
default:
// do nothing
// we should not come here anyway
break;
}
break;
/////////////////////////////////////////////////////////// "VOX"
case VOX: // only key supported
// toggle VOX
if (type == MIDI_KEY) {
vox_enabled = !vox_enabled;
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "VOXLEVEL"
case VOXLEVEL: // knob or wheel supported
switch (type) {
case MIDI_WHEEL:
// This changes the value incrementally,
// but stay within limits (0.0 through 1.0)
vox_threshold += (double) val * 0.01;
if (vox_threshold > 1.0) vox_threshold=1.0;
if (vox_threshold < 0.0) vox_threshold=0.0;
break;
case MIDI_KNOB:
vox_threshold = 0.01 * (double) val;
break;
default:
// do nothing
// we should not come here anyway
break;
}
// VOX level not shown on screen, hence no VFO update
break;
/////////////////////////////////////////////////////////// "XITCLEAR"
case MIDI_XIT_CLEAR: // only key supported
if (type == MIDI_KEY) {
// this clears the XIT value and disables XIT
if(can_transmit) {
transmitter->xit = 0;
transmitter->xit_enabled = 0;
g_idle_add(ext_vfo_update, NULL);
}
}
break;
/////////////////////////////////////////////////////////// "XITVAL"
case XIT_VAL: // wheel and knob supported.
if (can_transmit) {
switch (type) {
case MIDI_WHEEL:
// This changes the XIT value incrementally,
// but we restrict the change to +/ 9.999 kHz
new = transmitter->xit + val*rit_increment;
if (new > 9999) new= 9999;
if (new < -9999) new=-9999;
transmitter->xit = new;
break;
case MIDI_KNOB:
// knob: adjust in the range +/ 50*rit_increment
new = (val-50) * rit_increment;
transmitter->xit = new;
break;
default:
// do nothing
// we should not come here anyway
break;
}
// enable/disable XIT according to XIT value
transmitter->xit_enabled = (transmitter->xit == 0) ? 0 : 1;
g_idle_add(ext_vfo_update, NULL);
}
break;
/////////////////////////////////////////////////////////// "ZOOM"
case MIDI_ZOOM: // wheel and knob
switch (type) {
case MIDI_WHEEL:
g_print("MIDI_ZOOM: MIDI_WHEEL: val=%d\n",val);
g_idle_add(ext_zoom_update,GINT_TO_POINTER(val));
break;
case MIDI_KNOB:
g_print("MIDI_ZOOM: MIDI_KNOB: val=%d\n",val);
g_idle_add(ext_zoom_set,GINT_TO_POINTER(val));
break;
default:
// no action for keys (should not come here anyway)
break;
}
break;
/////////////////////////////////////////////////////////// "ZOOMDOWN"
/////////////////////////////////////////////////////////// "ZOOMUP"
case ZOOM_UP: // key
case ZOOM_DOWN: // key
switch (type) {
case MIDI_KEY:
new = (action == ZOOM_UP) ? 1 : -1;
g_idle_add(ext_zoom_update,GINT_TO_POINTER(new));
break;
case MIDI_WHEEL:
new = (val > 0) ? 1 : -1;
g_idle_add(ext_zoom_update,GINT_TO_POINTER(new));
break;
default:
// do nothing
// we should not come here anyway
break;
}
break;
case ACTION_NONE:
// No error message, this is the "official" action for un-used controller buttons.
break;
default:
// This means we have forgotten to implement an action, so we inform on stderr.
fprintf(stderr,"Unimplemented MIDI action: A=%d\n", (int) action);
}
}