-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathaudiomixerboard.cpp
More file actions
1781 lines (1517 loc) · 68.4 KB
/
audiomixerboard.cpp
File metadata and controls
1781 lines (1517 loc) · 68.4 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
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
/******************************************************************************\
* Copyright (c) 2004-2026
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
\******************************************************************************/
#include "audiomixerboard.h"
/******************************************************************************\
* CChanneFader *
\******************************************************************************/
CChannelFader::CChannelFader ( QWidget* pNW ) :
eDesign ( GD_STANDARD ),
BitmapMutedIcon ( QString::fromUtf8 ( ":/png/fader/res/mutediconorange.png" ) ),
bMIDICtrlUsed ( false )
{
// create new GUI control objects and store pointers to them (note that
// QWidget takes the ownership of the pMainGrid so that this only has
// to be created locally in this constructor)
pFrame = new QFrame ( pNW );
pLevelsBox = new QWidget ( pFrame );
plbrChannelLevel = new CLevelMeter ( pLevelsBox );
pFader = new QSlider ( Qt::Vertical, pLevelsBox );
pPan = new QDial ( pLevelsBox );
pPanLabel = new QLabel ( tr ( "Pan" ), pLevelsBox );
pInfoLabel = new QLabel ( "", pLevelsBox );
pMuteSoloBox = new QWidget ( pFrame );
pcbMute = new QCheckBox ( tr ( "Mute" ), pMuteSoloBox );
pcbSolo = new QCheckBox ( tr ( "Solo" ), pMuteSoloBox );
pcbGroup = new QCheckBox ( "", pMuteSoloBox );
pLabelInstBox = new QGroupBox ( pFrame );
plblLabel = new QLabel ( "", pFrame );
plblInstrument = new QLabel ( pFrame );
plblCountryFlag = new QLabel ( pFrame );
QVBoxLayout* pMainGrid = new QVBoxLayout ( pFrame );
QHBoxLayout* pLevelsGrid = new QHBoxLayout ( pLevelsBox );
QVBoxLayout* pMuteSoloGrid = new QVBoxLayout ( pMuteSoloBox );
pLabelGrid = new QHBoxLayout ( pLabelInstBox );
pLabelPictGrid = new QVBoxLayout();
QVBoxLayout* pPanGrid = new QVBoxLayout();
QHBoxLayout* pPanInfoGrid = new QHBoxLayout();
// define the popup menu for the group checkbox
pGroupPopupMenu = new QMenu ( "", pcbGroup );
pGroupPopupMenu->addAction ( tr ( "&No grouping" ), this, [=] { OnGroupMenuGrp ( INVALID_INDEX ); } );
for ( int iGrp = 0; iGrp < MAX_NUM_FADER_GROUPS; iGrp++ )
{
pGroupPopupMenu->addAction ( tr ( "Assign to group" ) + ( QString ( " &%1" ).arg ( iGrp + 1 ) ), this, [=] { OnGroupMenuGrp ( iGrp ); } );
}
#if ( MAX_NUM_FADER_GROUPS != 8 )
# error "MAX_NUM_FADER_GROUPS must be set to 8, see implementation in CChannelFader()"
#endif
// setup channel level
plbrChannelLevel->setContentsMargins ( 0, 3, 2, 3 );
// setup slider
pFader->setPageStep ( 1 );
pFader->setRange ( 0, AUD_MIX_FADER_MAX );
pFader->setTickInterval ( AUD_MIX_FADER_MAX / 9 );
// setup panning control and info label
pPan->setRange ( 0, AUD_MIX_PAN_MAX );
pPan->setValue ( AUD_MIX_PAN_MAX / 2 );
pPan->setNotchesVisible ( true );
pInfoLabel->setMinimumHeight ( 14 ); // prevents jitter when muting/unmuting (#811)
pInfoLabel->setAlignment ( Qt::AlignTop );
pPanInfoGrid->addWidget ( pPanLabel, 0, Qt::AlignLeft | Qt::AlignTop );
pPanInfoGrid->addWidget ( pInfoLabel, 0, Qt::AlignHCenter | Qt::AlignTop );
pPanGrid->addLayout ( pPanInfoGrid );
pPanGrid->addWidget ( pPan, 0, Qt::AlignHCenter );
// setup fader tag label (black bold text which is centered)
plblLabel->setTextFormat ( Qt::PlainText );
plblLabel->setAlignment ( Qt::AlignHCenter | Qt::AlignVCenter );
// set margins of the layouts to zero to get maximum space for the controls
pMainGrid->setContentsMargins ( 0, 0, 0, 0 );
pPanGrid->setContentsMargins ( 0, 0, 0, 0 );
pPanGrid->setSpacing ( 0 ); // only minimal space
pLevelsGrid->setContentsMargins ( 0, 0, 0, 0 );
pLevelsGrid->setSpacing ( 0 ); // only minimal space
pMuteSoloGrid->setContentsMargins ( 0, 0, 0, 0 );
pMuteSoloGrid->setSpacing ( 0 ); // only minimal space
pLabelGrid->setContentsMargins ( 0, 0, 0, 0 );
pLabelGrid->setSpacing ( 2 ); // only minimal space between picture and text
// add user controls to the grids
pLabelPictGrid->addWidget ( plblCountryFlag, 0, Qt::AlignHCenter );
pLabelPictGrid->addWidget ( plblInstrument, 0, Qt::AlignHCenter );
pLabelGrid->addLayout ( pLabelPictGrid );
pLabelGrid->addWidget ( plblLabel, 0, Qt::AlignVCenter ); // note: just initial add, may be changed later
pLevelsGrid->addWidget ( plbrChannelLevel, 0, Qt::AlignRight );
pLevelsGrid->addWidget ( pFader, 0, Qt::AlignLeft );
pMuteSoloGrid->addWidget ( pcbGroup, 0, Qt::AlignLeft );
pMuteSoloGrid->addWidget ( pcbMute, 0, Qt::AlignLeft );
pMuteSoloGrid->addWidget ( pcbSolo, 0, Qt::AlignLeft );
pMainGrid->addLayout ( pPanGrid );
pMainGrid->addWidget ( pLevelsBox, 0, Qt::AlignHCenter );
pMainGrid->addWidget ( pMuteSoloBox, 0, Qt::AlignHCenter );
pMainGrid->addWidget ( pLabelInstBox );
// reset current fader
strGroupBaseText = "Grp"; // this will most probably overwritten by SetGUIDesign()
iInstrPicMaxWidth = INVALID_INDEX; // this will most probably overwritten by SetGUIDesign()
Reset();
// add help text to controls
plbrChannelLevel->setWhatsThis ( "<b>" + tr ( "Channel Level" ) + ":</b> " +
tr ( "Displays the pre-fader audio level of this channel. All clients connected to the "
"server will be assigned an audio level, the same value for every client." ) );
plbrChannelLevel->setAccessibleName ( tr ( "Input level of the current audio "
"channel at the server" ) );
pFader->setWhatsThis ( "<b>" + tr ( "Mixer Fader" ) + ":</b> " +
tr ( "Adjusts the audio level of this channel. All clients connected to the server "
"will be assigned an audio fader, displayed at each client, to adjust the local mix." ) );
pFader->setAccessibleName ( tr ( "Local mix level setting of the current audio "
"channel at the server" ) );
pInfoLabel->setWhatsThis ( "<b>" + tr ( "Status Indicator" ) + ":</b> " +
tr ( "Shows a status indication about the client which is assigned to this channel. "
"Supported indicators are:" ) +
"<ul><li>" + tr ( "Speaker with cancellation stroke: Indicates that another client has muted you." ) + "</li></ul>" );
pInfoLabel->setAccessibleName ( tr ( "Status indicator label" ) );
pPan->setWhatsThis ( "<b>" + tr ( "Panning" ) + ":</b> " +
tr ( "Sets the pan from Left to Right of the channel. "
"Works only in stereo or preferably mono in/stereo out mode." ) );
pPan->setAccessibleName ( tr ( "Local panning position of the current audio channel at the server" ) );
pcbMute->setWhatsThis ( "<b>" + tr ( "Mute" ) + ":</b> " + tr ( "With the Mute checkbox, the audio channel can be muted." ) );
pcbMute->setAccessibleName ( tr ( "Mute button" ) );
pcbSolo->setWhatsThis ( "<b>" + tr ( "Solo" ) + ":</b> " +
tr ( "With the Solo checkbox, the "
"audio channel can be set to solo which means that all other channels "
"except the soloed channel are muted. It is possible to set more than "
"one channel to solo." ) );
pcbSolo->setAccessibleName ( tr ( "Solo button" ) );
pcbGroup->setWhatsThis ( "<b>" + tr ( "Group" ) + ":</b> " +
tr ( "With the Grp checkbox, a "
"group of audio channels can be defined. All channel faders in a group are moved "
"in proportional synchronization if any one of the group faders are moved." ) );
pcbGroup->setAccessibleName ( tr ( "Group button" ) );
QString strFaderText = "<b>" + tr ( "Fader Tag" ) + ":</b> " +
tr ( "The fader tag "
"identifies the connected client. The tag name, a picture of your "
"instrument and the flag of your location can be set in the main window." );
plblInstrument->setWhatsThis ( strFaderText );
plblInstrument->setAccessibleName ( tr ( "Mixer channel instrument picture" ) );
plblLabel->setWhatsThis ( strFaderText );
plblLabel->setAccessibleName ( tr ( "Mixer channel label (fader tag)" ) );
plblCountryFlag->setWhatsThis ( strFaderText );
plblCountryFlag->setAccessibleName ( tr ( "Mixer channel country/region flag" ) );
// Connections -------------------------------------------------------------
QObject::connect ( pFader, &QSlider::valueChanged, this, &CChannelFader::OnLevelValueChanged );
QObject::connect ( pPan, &QDial::valueChanged, this, &CChannelFader::OnPanValueChanged );
QObject::connect ( pcbMute, &QCheckBox::stateChanged, this, &CChannelFader::OnMuteStateChanged );
QObject::connect ( pcbSolo, &QCheckBox::stateChanged, this, &CChannelFader::soloStateChanged );
QObject::connect ( pcbGroup, &QCheckBox::stateChanged, this, &CChannelFader::OnGroupStateChanged );
}
void CChannelFader::SetGUIDesign ( const EGUIDesign eNewDesign )
{
eDesign = eNewDesign;
switch ( eNewDesign )
{
case GD_ORIGINAL:
pFader->setStyleSheet ( "QSlider { width: 45px;"
" border-image: url(:/png/fader/res/faderbackground.png) repeat;"
" border-top: 10px transparent;"
" border-bottom: 10px transparent;"
" border-left: 20px transparent;"
" border-right: -25px transparent; }"
"QSlider::groove { image: url(:/png/fader/res/transparent1x1.png);"
" padding-left: -34px;"
" padding-top: -10px;"
" padding-bottom: -15px; }"
"QSlider::handle { image: url(:/png/fader/res/faderhandle.png); }" );
pLabelGrid->addWidget ( plblLabel, 0, Qt::AlignVCenter ); // label next to icons
pLabelInstBox->setMinimumHeight ( 52 ); // maximum height of the instrument+flag pictures
pPan->setFixedSize ( 50, 50 );
pPanLabel->setText ( tr ( "PAN" ) );
pcbMute->setText ( tr ( "MUTE" ) );
pcbSolo->setText ( tr ( "SOLO" ) );
strGroupBaseText = tr ( "GRP" );
iInstrPicMaxWidth = INVALID_INDEX; // no instrument picture scaling
break;
case GD_SLIMFADER:
pLabelPictGrid->addWidget ( plblLabel, 0, Qt::AlignHCenter ); // label below icons
pLabelInstBox->setMinimumHeight ( 130 ); // maximum height of the instrument+flag+label
pPan->setFixedSize ( 28, 28 );
pFader->setTickPosition ( QSlider::NoTicks );
pFader->setStyleSheet ( "" );
pPanLabel->setText ( tr ( "Pan" ) );
pcbMute->setText ( tr ( "M" ) );
pcbSolo->setText ( tr ( "S" ) );
strGroupBaseText = tr ( "G" );
iInstrPicMaxWidth = 18; // scale instrument picture to avoid enlarging the width by the picture
break;
default:
// reset style sheet and set original parameters
pFader->setTickPosition ( QSlider::TicksBothSides );
pFader->setStyleSheet ( "" );
pLabelGrid->addWidget ( plblLabel, 0, Qt::AlignVCenter ); // label next to icons
pLabelInstBox->setMinimumHeight ( 52 ); // maximum height of the instrument+flag pictures
pPan->setFixedSize ( 50, 50 );
pPanLabel->setText ( tr ( "Pan" ) );
pcbMute->setText ( tr ( "Mute" ) );
pcbSolo->setText ( tr ( "Solo" ) );
strGroupBaseText = tr ( "Grp" );
iInstrPicMaxWidth = INVALID_INDEX; // no instrument picture scaling
break;
}
// we need to update since we changed the checkbox text
UpdateGroupIDDependencies();
// the instrument picture might need scaling after a style change
SetChannelInfos ( cReceivedChanInfo );
}
void CChannelFader::SetMeterStyle ( const EMeterStyle eNewMeterStyle )
{
eMeterStyle = eNewMeterStyle;
switch ( eNewMeterStyle )
{
case MT_BAR_NARROW:
plbrChannelLevel->SetLevelMeterType ( CLevelMeter::MT_BAR_NARROW );
// Fader height controls the distribution of the LEDs, if the value is too small the fader might not be movable
pFader->setMinimumHeight ( 85 );
break;
case MT_BAR_WIDE:
plbrChannelLevel->SetLevelMeterType ( CLevelMeter::MT_BAR_WIDE );
// Fader height controls the distribution of the LEDs, if the value is too small the fader might not be movable
pFader->setMinimumHeight ( 120 );
break;
case MT_LED_ROUND_SMALL:
plbrChannelLevel->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_SMALL );
// Fader height controls the distribution of the LEDs, if the value is too small the fader might not be movable
pFader->setMinimumHeight ( 85 );
break;
case MT_LED_ROUND_BIG:
plbrChannelLevel->SetLevelMeterType ( CLevelMeter::MT_LED_ROUND_BIG );
// Fader height controls the distribution of the LEDs, if the value is too small the fader might not be movable
pFader->setMinimumHeight ( 162 );
break;
default:
// reset style sheet and set original parameters
plbrChannelLevel->SetLevelMeterType ( CLevelMeter::MT_LED_STRIPE );
// Fader height controls the distribution of the LEDs, if the value is too small the fader might not be movable
pFader->setMinimumHeight ( 120 );
break;
}
}
void CChannelFader::SetDisplayChannelLevel ( const bool eNDCL ) { plbrChannelLevel->setHidden ( !eNDCL ); }
bool CChannelFader::GetDisplayChannelLevel() { return !plbrChannelLevel->isHidden(); }
void CChannelFader::SetDisplayPans ( const bool eNDP )
{
pPanLabel->setHidden ( !eNDP );
pPan->setHidden ( !eNDP );
}
void CChannelFader::SetupFaderTag ( const ESkillLevel eSkillLevel )
{
// Should never happen here
if ( iGroupID >= MAX_NUM_FADER_GROUPS )
{
SetGroupID ( INVALID_INDEX );
}
// the group ID defines the border color and style
QString strBorderColor = "black";
QString strBorderStyle = "solid";
if ( iGroupID != INVALID_INDEX )
{
switch ( iGroupID % 4 )
{
case 0:
strBorderColor = "#C43AC5";
break;
case 1:
strBorderColor = "#2B93D4";
break;
case 2:
strBorderColor = "#3BC53A";
break;
case 3:
strBorderColor = "#D46C2B";
break;
default:
break;
}
switch ( iGroupID / 4 )
{
case 0:
strBorderStyle = "solid";
break;
case 1:
strBorderStyle = "dashed";
break;
case 2:
strBorderStyle = "dotted";
break;
case 3:
strBorderStyle = "double";
break;
default:
break;
}
}
// setup group box for label/instrument picture: set a thick black border
// with nice round edges
QString strStile = "QGroupBox { border: 2px " + strBorderStyle + " " + strBorderColor +
";"
" border-radius: 4px;"
" padding: 3px;";
// the background color depends on the skill level
switch ( eSkillLevel )
{
case SL_BEGINNER:
strStile +=
QString ( "background-color: rgb(%1, %2, %3); }" ).arg ( RGBCOL_R_SL_BEGINNER ).arg ( RGBCOL_G_SL_BEGINNER ).arg ( RGBCOL_B_SL_BEGINNER );
break;
case SL_INTERMEDIATE:
strStile += QString ( "background-color: rgb(%1, %2, %3); }" )
.arg ( RGBCOL_R_SL_INTERMEDIATE )
.arg ( RGBCOL_G_SL_INTERMEDIATE )
.arg ( RGBCOL_B_SL_INTERMEDIATE );
break;
case SL_PROFESSIONAL:
strStile += QString ( "background-color: rgb(%1, %2, %3); }" )
.arg ( RGBCOL_R_SL_SL_PROFESSIONAL )
.arg ( RGBCOL_G_SL_SL_PROFESSIONAL )
.arg ( RGBCOL_B_SL_SL_PROFESSIONAL );
break;
default:
strStile +=
QString ( "background-color: rgb(%1, %2, %3); }" ).arg ( RGBCOL_R_SL_NOT_SET ).arg ( RGBCOL_G_SL_NOT_SET ).arg ( RGBCOL_B_SL_NOT_SET );
break;
}
pLabelInstBox->setStyleSheet ( strStile );
}
void CChannelFader::Reset()
{
// it is important to reset the group index first (#611)
iGroupID = INVALID_INDEX;
// general initializations
SetRemoteFaderIsMute ( false );
// init gain and pan value -> maximum value as definition according to server
pFader->setValue ( AUD_MIX_FADER_MAX );
dPreviousFaderLevel = AUD_MIX_FADER_MAX;
pPan->setValue ( AUD_MIX_PAN_MAX / 2 );
// reset mute/solo/group check boxes and level meter
pcbMute->setChecked ( false );
pcbSolo->setChecked ( false );
plbrChannelLevel->SetValue ( 0 );
plbrChannelLevel->ClipReset();
// clear instrument picture, country flag, tool tips and label text
plblLabel->setText ( "" );
plblLabel->setToolTip ( "" );
plblInstrument->setVisible ( false );
plblInstrument->setToolTip ( "" );
plblCountryFlag->setVisible ( false );
plblCountryFlag->setToolTip ( "" );
cReceivedChanInfo = CChannelInfo();
SetupFaderTag ( SL_NOT_SET );
// set a defined tool tip time out
const int iToolTipDurMs = 30000;
plblLabel->setToolTipDuration ( iToolTipDurMs );
plblInstrument->setToolTipDuration ( iToolTipDurMs );
plblCountryFlag->setToolTipDuration ( iToolTipDurMs );
bOtherChannelIsSolo = false;
bIsMyOwnFader = false;
bIsMutedAtServer = false;
iRunningNewClientCnt = 0;
UpdateGroupIDDependencies();
}
void CChannelFader::SetFaderLevel ( const double dLevel, const bool bIsGroupUpdate )
{
// first make a range check
if ( dLevel >= 0 )
{
// we set the new fader level in the GUI (slider control) and also tell the
// server about the change (block the signal of the fader since we want to
// call SendFaderLevelToServer with a special additional parameter)
pFader->blockSignals ( true );
pFader->setValue ( std::min ( AUD_MIX_FADER_MAX, MathUtils::round ( dLevel ) ) );
pFader->blockSignals ( false );
SendFaderLevelToServer ( std::min ( static_cast<double> ( AUD_MIX_FADER_MAX ), dLevel ), bIsGroupUpdate );
if ( dLevel > AUD_MIX_FADER_MAX )
{
// If the level is above the maximum, we have to store it for the purpose
// of group fader movement. If you move a fader which has lower volume than
// this one and this clips at max, we want to retain the ratio between this
// fader and the others in the group.
dPreviousFaderLevel = dLevel;
}
}
}
void CChannelFader::SetPanValue ( const int iPan )
{
// first make a range check
if ( ( iPan >= 0 ) && ( iPan <= AUD_MIX_PAN_MAX ) )
{
// we set the new fader level in the GUI (slider control) which then
// emits to signal to tell the server about the change (implicitly)
pPan->setValue ( iPan );
pPan->setAccessibleName ( QString::number ( iPan ) );
}
}
void CChannelFader::SetFaderIsSolo ( const bool bIsSolo )
{
// changing the state automatically emits the signal, too
pcbSolo->setChecked ( bIsSolo );
}
void CChannelFader::SetFaderIsMute ( const bool bIsMute )
{
// changing the state automatically emits the signal, too
pcbMute->setChecked ( bIsMute );
}
void CChannelFader::SetRemoteFaderIsMute ( const bool bIsMute )
{
if ( bIsMute )
{
// show muted icon orange
pInfoLabel->setPixmap ( BitmapMutedIcon );
}
else
{
pInfoLabel->setPixmap ( QPixmap() );
}
}
void CChannelFader::SendFaderLevelToServer ( const double dLevel, const bool bIsGroupUpdate )
{
// if mute flag is set or other channel is on solo, do not apply the new
// fader value to the server (exception: we are on solo, in that case we
// ignore the "other channel is on solo" flag)
const bool bSuppressServerUpdate = !( ( pcbMute->checkState() == Qt::Unchecked ) && ( !bOtherChannelIsSolo || IsSolo() ) );
// emit signal for new fader gain value
emit gainValueChanged ( MathUtils::CalcFaderGain ( static_cast<float> ( dLevel ) ),
bIsMyOwnFader,
bIsGroupUpdate,
bSuppressServerUpdate,
dLevel / dPreviousFaderLevel );
// update previous fader level since the level has changed, avoid to use
// the zero value not to have division by zero and also to retain the ratio
// after the fader is moved up again from the zero position
if ( dLevel > 0 )
{
dPreviousFaderLevel = dLevel;
}
}
void CChannelFader::SendPanValueToServer ( const int iPan ) { emit panValueChanged ( static_cast<float> ( iPan ) / AUD_MIX_PAN_MAX ); }
void CChannelFader::OnPanValueChanged ( int value )
{
// on shift-click the pan shall reset to 0 L/R (#707)
if ( QGuiApplication::keyboardModifiers() == Qt::ShiftModifier )
{
// correct the value to the center position
value = AUD_MIX_PAN_MAX / 2;
// set the GUI control in the center position while deactivating
// the signals to avoid an infinite loop
pPan->blockSignals ( true );
pPan->setValue ( value );
pPan->blockSignals ( false );
}
pPan->setAccessibleName ( QString::number ( value ) );
SendPanValueToServer ( value );
}
void CChannelFader::OnMuteStateChanged ( int value )
{
// call muting function
SetMute ( static_cast<Qt::CheckState> ( value ) == Qt::Checked );
}
void CChannelFader::SetGroupID ( const int iNGroupID )
{
iGroupID = iNGroupID;
UpdateGroupIDDependencies();
}
void CChannelFader::UpdateGroupIDDependencies()
{
// update the group checkbox according the current group ID setting
pcbGroup->blockSignals ( true ); // make sure no signals are fired
if ( iGroupID == INVALID_INDEX )
{
pcbGroup->setCheckState ( Qt::Unchecked );
}
else
{
pcbGroup->setCheckState ( Qt::Checked );
}
pcbGroup->blockSignals ( false );
// update group checkbox text
if ( iGroupID != INVALID_INDEX )
{
pcbGroup->setText ( strGroupBaseText + QString::number ( iGroupID + 1 ) );
}
else
{
pcbGroup->setText ( strGroupBaseText );
}
// if the group is disable for this fader, reset the previous fader level
if ( iGroupID == INVALID_INDEX )
{
// for the special case that the fader is all the way down, use a small
// value instead
if ( GetFaderLevel() > 0 )
{
dPreviousFaderLevel = GetFaderLevel();
}
else
{
dPreviousFaderLevel = 1; // small value
}
}
// the fader tag border color is set according to the selected group
SetupFaderTag ( cReceivedChanInfo.eSkillLevel );
}
void CChannelFader::OnGroupStateChanged ( int )
{
// we want a popup menu shown if the user presses the group checkbox but
// we want to make sure that the checkbox state represents the current group
// setting and not the current click state since the user might not click
// on the menu but at one other place and then the popup menu disappears but
// the checkobx state would be on an invalid state
UpdateGroupIDDependencies();
pGroupPopupMenu->popup ( QCursor::pos() );
}
void CChannelFader::SetMute ( const bool bState )
{
if ( bState )
{
if ( !bIsMutedAtServer )
{
// mute channel -> send gain of 0
emit gainValueChanged ( 0, bIsMyOwnFader, false, false, -1 ); // set level ratio to in invalid value
bIsMutedAtServer = true;
}
}
else
{
// only unmute if we are not solot but an other channel is on solo
if ( ( !bOtherChannelIsSolo || IsSolo() ) && bIsMutedAtServer )
{
// mute was unchecked, get current fader value and apply
emit gainValueChanged ( MathUtils::CalcFaderGain ( GetFaderLevel() ),
bIsMyOwnFader,
false,
false,
-1 ); // set level ratio to in invalid value
bIsMutedAtServer = false;
}
}
}
void CChannelFader::UpdateSoloState ( const bool bNewOtherSoloState )
{
// store state (must be done before the SetMute() call!)
bOtherChannelIsSolo = bNewOtherSoloState;
// mute overwrites solo -> if mute is active, do not change anything
if ( !pcbMute->isChecked() )
{
// mute channel if we are not solo but another channel is solo
SetMute ( bOtherChannelIsSolo && !IsSolo() );
}
}
void CChannelFader::SetChannelLevel ( const uint16_t iLevel ) { plbrChannelLevel->SetValue ( iLevel ); }
void CChannelFader::SetChannelInfos ( const CChannelInfo& cChanInfo )
{
// store received channel info
cReceivedChanInfo = cChanInfo;
// init properties for the tool tip
int iTTInstrument = CInstPictures::GetNotUsedInstrument();
QLocale::Country eTTCountry = QLocale::AnyCountry;
// Label text --------------------------------------------------------------
QString strModText = cChanInfo.strName;
// show channel numbers if --ctrlmidich is used (#241, #95)
if ( bMIDICtrlUsed )
{
strModText.prepend ( QString().setNum ( cChanInfo.iChanID ) + ":" );
}
QTextBoundaryFinder tbfName ( QTextBoundaryFinder::Grapheme, cChanInfo.strName );
int iBreakPos;
// apply break position and font size depending on the selected design
if ( eDesign == GD_SLIMFADER )
{
// in slim mode use a non-bold font (smaller width font)
plblLabel->setStyleSheet ( "QLabel { color: black; }" );
// break at every 4th character
iBreakPos = 4;
}
else
{
// in normal mode use bold font
plblLabel->setStyleSheet ( "QLabel { color: black; font: bold; }" );
// break text at predefined position
iBreakPos = MAX_LEN_FADER_TAG / 2;
}
int iInsPos = iBreakPos;
int iCount = 0;
int iLineNumber = 0;
while ( tbfName.toNextBoundary() != -1 )
{
++iCount;
if ( iCount == iInsPos && tbfName.position() + iLineNumber < strModText.length() )
{
strModText.insert ( tbfName.position() + iLineNumber, QString ( "\n" ) );
iLineNumber++;
iInsPos += iBreakPos;
}
}
plblLabel->setText ( strModText );
// Instrument picture ------------------------------------------------------
// get the resource reference string for this instrument
const QString strCurResourceRef = CInstPictures::GetResourceReference ( cChanInfo.iInstrument );
// first check if instrument picture is used or not and if it is valid
if ( CInstPictures::IsNotUsedInstrument ( cChanInfo.iInstrument ) || strCurResourceRef.isEmpty() )
{
// disable instrument picture
plblInstrument->setVisible ( false );
}
else
{
// set correct picture
QPixmap pixInstr ( strCurResourceRef );
if ( ( iInstrPicMaxWidth != INVALID_INDEX ) && ( pixInstr.width() > iInstrPicMaxWidth ) )
{
// scale instrument picture on request (scale to the width with correct aspect ratio)
plblInstrument->setPixmap ( pixInstr.scaledToWidth ( iInstrPicMaxWidth, Qt::SmoothTransformation ) );
}
else
{
plblInstrument->setPixmap ( pixInstr );
}
iTTInstrument = cChanInfo.iInstrument;
// enable instrument picture
plblInstrument->setVisible ( true );
}
// Country flag icon -------------------------------------------------------
if ( cChanInfo.eCountry != QLocale::AnyCountry )
{
// try to load the country flag icon
QPixmap CountryFlagPixmap ( CLocale::GetCountryFlagIconsResourceReference ( cChanInfo.eCountry ) );
// first check if resource reference was valid
if ( CountryFlagPixmap.isNull() )
{
// disable country flag
plblCountryFlag->setVisible ( false );
}
else
{
// set correct picture
plblCountryFlag->setPixmap ( CountryFlagPixmap );
eTTCountry = cChanInfo.eCountry;
// enable country flag
plblCountryFlag->setVisible ( true );
}
}
else
{
// disable country flag
plblCountryFlag->setVisible ( false );
}
// Skill level background color --------------------------------------------
SetupFaderTag ( cChanInfo.eSkillLevel );
// Tool tip ----------------------------------------------------------------
// complete musician profile in the tool tip
QString strToolTip = "";
QString strAliasAccessible = "";
QString strInstrumentAccessible = "";
QString strLocationAccessible = "";
// alias/name
if ( !cChanInfo.strName.isEmpty() )
{
strToolTip += "<h4>" + tr ( "Alias/Name" ) + "</h4>" + cChanInfo.strName;
strAliasAccessible += cChanInfo.strName;
}
// instrument
if ( !CInstPictures::IsNotUsedInstrument ( iTTInstrument ) )
{
strToolTip += "<h4>" + tr ( "Instrument" ) + "</h4>" + CInstPictures::GetName ( iTTInstrument );
strInstrumentAccessible += CInstPictures::GetName ( iTTInstrument );
}
// location
if ( ( eTTCountry != QLocale::AnyCountry ) || ( !cChanInfo.strCity.isEmpty() ) )
{
strToolTip += "<h4>" + tr ( "Location" ) + "</h4>";
if ( !cChanInfo.strCity.isEmpty() )
{
strToolTip += cChanInfo.strCity;
strLocationAccessible += cChanInfo.strCity;
if ( eTTCountry != QLocale::AnyCountry )
{
strToolTip += ", ";
strLocationAccessible += ", ";
}
}
if ( eTTCountry != QLocale::AnyCountry )
{
strToolTip += QLocale::countryToString ( eTTCountry );
strLocationAccessible += QLocale::countryToString ( eTTCountry );
}
}
// skill level
QString strSkillLevel;
switch ( cChanInfo.eSkillLevel )
{
case SL_BEGINNER:
strSkillLevel = tr ( "Beginner" );
strToolTip += "<h4>" + tr ( "Skill Level" ) + "</h4>" + strSkillLevel;
strInstrumentAccessible += ", " + strSkillLevel;
break;
case SL_INTERMEDIATE:
strSkillLevel = tr ( "Intermediate" );
strToolTip += "<h4>" + tr ( "Skill Level" ) + "</h4>" + strSkillLevel;
strInstrumentAccessible += ", " + strSkillLevel;
break;
case SL_PROFESSIONAL:
strSkillLevel = tr ( "Expert" );
strToolTip += "<h4>" + tr ( "Skill Level" ) + "</h4>" + strSkillLevel;
strInstrumentAccessible += ", " + strSkillLevel;
break;
case SL_NOT_SET:
// skill level not set, do not add this entry
break;
}
// if no information is given, leave the tool tip empty, otherwise add header
if ( !strToolTip.isEmpty() )
{
strToolTip.prepend ( "<h3>" + tr ( "Musician Profile" ) + "</h3>" );
}
plblCountryFlag->setToolTip ( strToolTip );
plblCountryFlag->setAccessibleDescription ( strLocationAccessible );
plblInstrument->setToolTip ( strToolTip );
plblInstrument->setAccessibleDescription ( strInstrumentAccessible );
plblLabel->setToolTip ( strToolTip );
plblLabel->setAccessibleName ( strAliasAccessible );
plblLabel->setAccessibleDescription ( tr ( "Alias" ) );
pcbMute->setAccessibleName ( "Mute " + strAliasAccessible + ", " + strInstrumentAccessible );
pcbSolo->setAccessibleName ( "Solo " + strAliasAccessible + ", " + strInstrumentAccessible );
pcbGroup->setAccessibleName ( "Group " + strAliasAccessible + ", " + strInstrumentAccessible );
dynamic_cast<QWidget*> ( plblLabel->parent() )
->setAccessibleName ( strAliasAccessible + ", " + strInstrumentAccessible + ", " + strLocationAccessible );
}
/******************************************************************************\
* CAudioMixerBoard *
\******************************************************************************/
CAudioMixerBoard::CAudioMixerBoard ( QWidget* parent ) :
QGroupBox ( parent ),
pSettings ( nullptr ),
bDisplayPans ( false ),
bIsPanSupported ( false ),
bNoFaderVisible ( true ),
iMyChannelID ( INVALID_INDEX ),
iRunningNewClientCnt ( 0 ),
iNumMixerPanelRows ( 1 ), // pSettings->iNumMixerPanelRows is not yet available
strServerName ( "" ),
eRecorderState ( RS_UNDEFINED ),
eChSortType ( ST_NO_SORT )
{
// add group box and hboxlayout
QHBoxLayout* pGroupBoxLayout = new QHBoxLayout ( this );
QWidget* pMixerWidget = new QWidget(); // will be added to the scroll area which is then the parent
pScrollArea = new CMixerBoardScrollArea ( this );
pMainLayout = new QGridLayout ( pMixerWidget );
setAccessibleName ( "Personal Mix at the Server groupbox" );
setWhatsThis ( "<b>" + tr ( "Personal Mix at the Server" ) + ":</b> " +
tr ( "When connected to a server, the controls here allow you to set your "
"local mix without affecting what others hear from you. The title shows "
"the server name and, when known, whether it is actively recording." ) );
// set title text (default: no server given)
SetServerName ( "" );
// create all mixer controls and make them invisible
vecpChanFader.Init ( MAX_NUM_CHANNELS );
vecAvgLevels.Init ( MAX_NUM_CHANNELS, 0.0f );
for ( size_t i = 0; i < MAX_NUM_CHANNELS; i++ )
{
vecpChanFader[i] = new CChannelFader ( this );
vecpChanFader[i]->Hide();
}
// insert horizontal spacer (at position MAX_NUM_CHANNELS+1 which is index MAX_NUM_CHANNELS)
pMainLayout->addItem ( new QSpacerItem ( 0, 0, QSizePolicy::Expanding ), 0, MAX_NUM_CHANNELS );
// set margins of the layout to zero to get maximum space for the controls
pGroupBoxLayout->setContentsMargins ( 0, 0, 0, 1 ); // note: to avoid problems at the bottom, use a small margin for that
// add the group box to the scroll area
pScrollArea->setMinimumWidth ( 200 ); // at least two faders shall be visible
pScrollArea->setWidget ( pMixerWidget );
pScrollArea->setWidgetResizable ( true ); // make sure it fills the entire scroll area
pScrollArea->setFrameShape ( QFrame::NoFrame );
pGroupBoxLayout->addWidget ( pScrollArea );
// Connections -------------------------------------------------------------
connectFaderSignalsToMixerBoardSlots<MAX_NUM_CHANNELS>();
}
CAudioMixerBoard::~CAudioMixerBoard()
{
for ( size_t i = 0; i < MAX_NUM_CHANNELS; i++ )
{
delete vecpChanFader[i];
}
}
template<unsigned int slotId>
inline void CAudioMixerBoard::connectFaderSignalsToMixerBoardSlots()
{
size_t iCurChanID = slotId - 1;
void ( CAudioMixerBoard::*pGainValueChanged ) ( float, bool, bool, bool, double ) = &CAudioMixerBoardSlots<slotId>::OnChGainValueChanged;
void ( CAudioMixerBoard::*pPanValueChanged ) ( float ) = &CAudioMixerBoardSlots<slotId>::OnChPanValueChanged;
QObject::connect ( vecpChanFader[iCurChanID], &CChannelFader::soloStateChanged, this, &CAudioMixerBoard::UpdateSoloStates );
QObject::connect ( vecpChanFader[iCurChanID], &CChannelFader::gainValueChanged, this, pGainValueChanged );
QObject::connect ( vecpChanFader[iCurChanID], &CChannelFader::panValueChanged, this, pPanValueChanged );
connectFaderSignalsToMixerBoardSlots<slotId - 1>();
}
template<>
inline void CAudioMixerBoard::connectFaderSignalsToMixerBoardSlots<0>()
{}
void CAudioMixerBoard::SetServerName ( const QString& strNewServerName )
{
// store the current server name
strServerName = strNewServerName;
if ( strServerName.isEmpty() )
{
// no connection or connection was reset: show default title
setTitle ( tr ( "Server" ) );
}
else
{
// Do not set the server name directly but first show a label which indicates
// that we are trying to connect the server. First if a connected client
// list was received, the connection was successful and the title is updated
// with the correct server name. Make sure to choose a "try to connect" title
// which is most striking (we use filled blocks and upper case letters).
setTitle ( u8"\u2588\u2588\u2588\u2588\u2588 " + tr ( "T R Y I N G T O C O N N E C T" ) + u8" \u2588\u2588\u2588\u2588\u2588" );
}
}
void CAudioMixerBoard::SetGUIDesign ( const EGUIDesign eNewDesign )
{
// move the channels tighter together in slim fader mode
if ( eNewDesign == GD_SLIMFADER )
{
pMainLayout->setSpacing ( 2 );
}
else
{
pMainLayout->setSpacing ( 6 ); // Qt default spacing value
}