1 /******************************************************************************\
2  * Copyright (c) 2004-2020
3  *
4  * Author(s):
5  *  Volker Fischer
6  *
7  ******************************************************************************
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation; either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22  *
23 \******************************************************************************/
24 
25 #pragma once
26 
27 #include <QFrame>
28 #include <QScrollArea>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QCheckBox>
32 #include <QLayout>
33 #include <QString>
34 #include <QSlider>
35 #include <QDial>
36 #include <QSizePolicy>
37 #include <QHostAddress>
38 #include <QListWidget>
39 #include <QMenu>
40 #include <QMutex>
41 #include "global.h"
42 #include "util.h"
43 #include "levelmeter.h"
44 #include "settings.h"
45 
46 /* Classes ********************************************************************/
47 class CChannelFader : public QObject
48 {
49     Q_OBJECT
50 
51 public:
52     CChannelFader ( QWidget* pNW );
53 
GetReceivedName()54     QString GetReceivedName() { return cReceivedChanInfo.strName; }
GetReceivedInstrument()55     int     GetReceivedInstrument() { return cReceivedChanInfo.iInstrument; }
GetReceivedCity()56     QString GetReceivedCity() { return cReceivedChanInfo.strCity; }
57     void    SetChannelInfos ( const CChannelInfo& cChanInfo );
Show()58     void    Show() { pFrame->show(); }
Hide()59     void    Hide() { pFrame->hide(); }
IsVisible()60     bool    IsVisible() { return !pFrame->isHidden(); }
IsSolo()61     bool    IsSolo() { return pcbSolo->isChecked(); }
IsMute()62     bool    IsMute() { return pcbMute->isChecked(); }
GetGroupID()63     int     GetGroupID() { return iGroupID; }
64     void    SetGUIDesign ( const EGUIDesign eNewDesign );
65     void    SetDisplayChannelLevel ( const bool eNDCL );
66     bool    GetDisplayChannelLevel();
67     void    SetDisplayPans ( const bool eNDP );
GetMainWidget()68     QFrame* GetMainWidget() { return pFrame; }
69 
70     void SetPanValue ( const int iPan );
71     void SetFaderIsSolo ( const bool bIsSolo );
72     void SetFaderIsMute ( const bool bIsMute );
73     void SetGroupID ( const int iNGroupID );
74     void SetRemoteFaderIsMute ( const bool bIsMute );
75     void SetFaderLevel ( const double dLevel, const bool bIsGroupUpdate = false );
76 
GetFaderLevel()77     int    GetFaderLevel() { return pFader->value(); }
GetPreviousFaderLevel()78     double GetPreviousFaderLevel() { return dPreviousFaderLevel; }
GetPanValue()79     int    GetPanValue() { return pPan->value(); }
80     void   Reset();
SetRunningNewClientCnt(const int iNRunningNewClientCnt)81     void   SetRunningNewClientCnt ( const int iNRunningNewClientCnt ) { iRunningNewClientCnt = iNRunningNewClientCnt; }
GetRunningNewClientCnt()82     int    GetRunningNewClientCnt() { return iRunningNewClientCnt; }
83     void   SetChannelLevel ( const uint16_t iLevel );
SetIsMyOwnFader()84     void   SetIsMyOwnFader() { bIsMyOwnFader = true; }
85     void   UpdateSoloState ( const bool bNewOtherSoloState );
86 
87 protected:
88     void UpdateGroupIDDependencies();
89     void SetMute ( const bool bState );
90     void SetupFaderTag ( const ESkillLevel eSkillLevel );
91     void SendPanValueToServer ( const int iPan );
92     void SendFaderLevelToServer ( const double dLevel, const bool bIsGroupUpdate );
93 
94     QFrame* pFrame;
95 
96     QWidget*     pLevelsBox;
97     QWidget*     pMuteSoloBox;
98     CLevelMeter* plbrChannelLevel;
99     QSlider*     pFader;
100     QDial*       pPan;
101     QLabel*      pPanLabel;
102     QLabel*      pInfoLabel;
103     QHBoxLayout* pLabelGrid;
104     QVBoxLayout* pLabelPictGrid;
105 
106     QCheckBox* pcbMute;
107     QCheckBox* pcbSolo;
108     QCheckBox* pcbGroup;
109     QMenu*     pGroupPopupMenu;
110 
111     QGroupBox* pLabelInstBox;
112     QLabel*    plblLabel;
113     QLabel*    plblInstrument;
114     QLabel*    plblCountryFlag;
115 
116     CChannelInfo cReceivedChanInfo;
117 
118     bool       bOtherChannelIsSolo;
119     bool       bIsMyOwnFader;
120     bool       bIsMutedAtServer;
121     double     dPreviousFaderLevel;
122     int        iGroupID;
123     QString    strGroupBaseText;
124     int        iRunningNewClientCnt;
125     int        iInstrPicMaxWidth;
126     EGUIDesign eDesign;
127     QPixmap    BitmapMutedIcon;
128 
129 public slots:
OnLevelValueChanged(int value)130     void OnLevelValueChanged ( int value )
131     {
132         SendFaderLevelToServer ( value,
133                                  QGuiApplication::keyboardModifiers() ==
134                                      Qt::ShiftModifier ); /* isolate a channel from the group temporarily with shift-click-drag (#695) */
135     }
136 
137     void OnPanValueChanged ( int value );
138     void OnMuteStateChanged ( int value );
139     void OnGroupStateChanged ( int );
140 
OnGroupMenuGrp(int iGrp)141     void OnGroupMenuGrp ( int iGrp ) { SetGroupID ( iGrp ); }
142 
143 signals:
144     void gainValueChanged ( float value, bool bIsMyOwnFader, bool bIsGroupUpdate, bool bSuppressServerUpdate, double dLevelRatio );
145 
146     void panValueChanged ( float value );
147     void soloStateChanged ( int value );
148 };
149 
150 template<unsigned int slotId>
151 class CAudioMixerBoardSlots : public CAudioMixerBoardSlots<slotId - 1>
152 {
153 public:
OnChGainValueChanged(float fValue,bool bIsMyOwnFader,bool bIsGroupUpdate,bool bSuppressServerUpdate,double dLevelRatio)154     void OnChGainValueChanged ( float fValue, bool bIsMyOwnFader, bool bIsGroupUpdate, bool bSuppressServerUpdate, double dLevelRatio )
155     {
156         UpdateGainValue ( slotId - 1, fValue, bIsMyOwnFader, bIsGroupUpdate, bSuppressServerUpdate, dLevelRatio );
157     }
158 
OnChPanValueChanged(float fValue)159     void OnChPanValueChanged ( float fValue ) { UpdatePanValue ( slotId - 1, fValue ); }
160 
161 protected:
162     virtual void UpdateGainValue ( const int    iChannelIdx,
163                                    const float  fValue,
164                                    const bool   bIsMyOwnFader,
165                                    const bool   bIsGroupUpdate,
166                                    const bool   bSuppressServerUpdate,
167                                    const double dLevelRatio ) = 0;
168 
169     virtual void UpdatePanValue ( const int iChannelIdx, const float fValue ) = 0;
170 };
171 
172 template<>
173 class CAudioMixerBoardSlots<0>
174 {};
175 
176 class CAudioMixerBoard : public QGroupBox, public CAudioMixerBoardSlots<MAX_NUM_CHANNELS>
177 {
178     Q_OBJECT
179 
180 public:
181     CAudioMixerBoard ( QWidget* parent = nullptr );
182 
183     virtual ~CAudioMixerBoard();
184 
SetSettingsPointer(CClientSettings * pNSet)185     void    SetSettingsPointer ( CClientSettings* pNSet ) { pSettings = pNSet; }
186     void    HideAll();
187     void    ApplyNewConClientList ( CVector<CChannelInfo>& vecChanInfo );
188     void    SetServerName ( const QString& strNewServerName );
GetServerName()189     QString GetServerName() { return strServerName; }
190     void    SetGUIDesign ( const EGUIDesign eNewDesign );
191     void    SetDisplayPans ( const bool eNDP );
192     void    SetPanIsSupported();
193     void    SetRemoteFaderIsMute ( const int iChannelIdx, const bool bIsMute );
SetMyChannelID(const int iChannelIdx)194     void    SetMyChannelID ( const int iChannelIdx ) { iMyChannelID = iChannelIdx; }
GetMyChannelID()195     int     GetMyChannelID() const { return iMyChannelID; }
196 
197     void SetFaderLevel ( const int iChannelIdx, const int iValue );
198 
199     void SetPanValue ( const int iChannelIdx, const int iValue );
200 
201     void SetFaderIsSolo ( const int iChannelIdx, const bool bIsSolo );
202 
203     void SetFaderIsMute ( const int iChannelIdx, const bool bIsMute );
204 
205     void SetNumMixerPanelRows ( const int iNNumMixerPanelRows );
GetNumMixerPanelRows()206     int  GetNumMixerPanelRows() { return iNumMixerPanelRows; }
207 
208     void        SetFaderSorting ( const EChSortType eNChSortType );
GetFaderSorting()209     EChSortType GetFaderSorting() { return eChSortType; }
210 
211     void SetChannelLevels ( const CVector<uint16_t>& vecChannelLevel );
212 
213     void           SetRecorderState ( const ERecorderState newRecorderState );
GetRecorderState()214     ERecorderState GetRecorderState() { return eRecorderState; };
215 
216     void SetAllFaderLevelsToNewClientLevel();
217     void StoreAllFaderSettings();
218     void LoadAllFaderSettings();
219     void AutoAdjustAllFaderLevels();
220 
221     void MuteMyChannel();
222 
223 protected:
224     class CMixerBoardScrollArea : public QScrollArea
225     {
226     public:
QScrollArea(parent)227         CMixerBoardScrollArea ( QWidget* parent = nullptr ) : QScrollArea ( parent ) {}
228 
229     protected:
resizeEvent(QResizeEvent * event)230         virtual void resizeEvent ( QResizeEvent* event )
231         {
232             // if after a resize of the main window a vertical scroll bar is required, make
233             // sure that the fader label is visible (scroll down completely)
234             ensureVisible ( 0, 2000 ); // use a large value here
235             QScrollArea::resizeEvent ( event );
236         }
237     };
238 
239     void ChangeFaderOrder ( const EChSortType eChSortType );
240 
241     bool GetStoredFaderSettings ( const QString& strName,
242                                   int&           iStoredFaderLevel,
243                                   int&           iStoredPanValue,
244                                   bool&          bStoredFaderIsSolo,
245                                   bool&          bStoredFaderIsMute,
246                                   int&           iGroupID );
247 
248     void StoreFaderSettings ( CChannelFader* pChanFader );
249     void UpdateSoloStates();
250     void UpdateTitle();
251 
252     CClientSettings*        pSettings;
253     CVector<CChannelFader*> vecpChanFader;
254     CMixerBoardScrollArea*  pScrollArea;
255     QGridLayout*            pMainLayout;
256     bool                    bDisplayPans;
257     bool                    bIsPanSupported;
258     bool                    bNoFaderVisible;
259     int                     iMyChannelID;
260     int                     iRunningNewClientCnt; // integer type is sufficient, will never overrun for its purpose
261     int                     iNumMixerPanelRows;
262     QString                 strServerName;
263     ERecorderState          eRecorderState;
264     QMutex                  Mutex;
265     EChSortType             eChSortType;
266     CVector<float>          vecAvgLevels;
267 
268     virtual void UpdateGainValue ( const int    iChannelIdx,
269                                    const float  fValue,
270                                    const bool   bIsMyOwnFader,
271                                    const bool   bIsGroupUpdate,
272                                    const bool   bSuppressServerUpdate,
273                                    const double dLevelRatio );
274 
275     virtual void UpdatePanValue ( const int iChannelIdx, const float fValue );
276 
277     template<unsigned int slotId>
278     inline void connectFaderSignalsToMixerBoardSlots();
279 
280 signals:
281     void ChangeChanGain ( int iId, float fGain, bool bIsMyOwnFader );
282     void ChangeChanPan ( int iId, float fPan );
283     void NumClientsChanged ( int iNewNumClients );
284 };
285