forked from jamulussoftware/jamulus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
executable file
·1357 lines (1122 loc) · 38.1 KB
/
Copy pathutil.h
File metadata and controls
executable file
·1357 lines (1122 loc) · 38.1 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-2020
*
* 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#pragma once
#include <QTcpSocket>
#include <QHostAddress>
#include <QHostInfo>
#include <QMenu>
#include <QWhatsThis>
#include <QTextBrowser>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QDateTime>
#include <QFile>
#include <QDesktopServices>
#include <QUrl>
#include <QLocale>
#include <QElapsedTimer>
#include <vector>
#include <algorithm>
#include "global.h"
using namespace std; // because of the library: "vector"
#ifdef _WIN32
# include <winsock2.h>
# include <ws2ipdef.h>
# include <windows.h>
# include <mmsystem.h>
#elif defined ( __APPLE__ ) || defined ( __MACOSX )
# include <mach/mach.h>
# include <mach/mach_error.h>
# include <mach/mach_time.h>
#else
# include <sys/time.h>
#endif
#include "ui_aboutdlgbase.h"
class CClient; // forward declaration of CClient
/* Definitions ****************************************************************/
#define METER_FLY_BACK 2
#define INVALID_MIDI_CH -1 // invalid MIDI channel definition
/* Global functions ***********************************************************/
// converting double to short
inline short Double2Short ( const double dInput )
{
// lower bound
if ( dInput < _MINSHORT )
{
return _MINSHORT;
}
// upper bound
if ( dInput > _MAXSHORT )
{
return _MAXSHORT;
}
return static_cast<short> ( dInput );
}
// debug error handling
void DebugError ( const QString& pchErDescr,
const QString& pchPar1Descr,
const double dPar1,
const QString& pchPar2Descr,
const double dPar2 );
// calculate the bit rate in bits per second from the number of coded bytes
inline int CalcBitRateBitsPerSecFromCodedBytes ( const int iCeltNumCodedBytes,
const int iFrameSize )
{
return ( SYSTEM_SAMPLE_RATE_HZ * iCeltNumCodedBytes * 8 ) / iFrameSize;
}
/******************************************************************************\
* CVector Base Class *
\******************************************************************************/
template<class TData> class CVector : public std::vector<TData>
{
public:
CVector() {}
CVector ( const int iNeSi ) { Init ( iNeSi ); }
CVector ( const int iNeSi,
const TData tInVa ) { Init ( iNeSi, tInVa ); }
CVector ( CVector const& ) = default;
void Init ( const int iNewSize );
// use this init to give all elements a defined value
void Init ( const int iNewSize,
const TData tIniVal );
// set all values to the given reset value
void Reset ( const TData tResetVal )
{
std::fill ( this->begin(), this->end(), tResetVal );
}
void Enlarge ( const int iAddedSize )
{
std::vector<TData>::resize ( std::vector<TData>::size() + iAddedSize );
}
void Add ( const TData& tI )
{
Enlarge ( 1 );
std::vector<TData>::back() = tI;
}
int StringFiFoWithCompare ( const QString strNewValue,
const bool bDoAdding = true );
// this function simply converts the type of size to integer
inline int Size() const { return static_cast<int> ( std::vector<TData>::size() ); }
// This operator allows for a l-value assignment of this object:
// CVector[x] = y is possible
inline TData& operator[] ( const int iPos )
{
#ifdef _DEBUG_
if ( ( iPos < 0 ) || ( iPos > Size() - 1 ) )
{
DebugError ( "Writing vector out of bounds", "Vector size",
Size(), "New parameter", iPos );
}
#endif
return std::vector<TData>::operator[] ( iPos );
}
inline TData operator[] ( const int iPos ) const
{
#ifdef _DEBUG_
if ( ( iPos < 0 ) || ( iPos > Size() - 1 ) )
{
DebugError ( "Reading vector out of bounds", "Vector size",
Size(), "New parameter", iPos );
}
#endif
return std::vector<TData>::operator[] ( iPos );
}
inline CVector<TData>& operator= ( const CVector<TData>& vecI )
{
#ifdef _DEBUG_
// vectors which shall be copied MUST have same size!
if ( vecI.Size() != Size() )
{
DebugError ( "Vector operator=() different size", "Vector size",
Size(), "New parameter", vecI.Size() );
}
#endif
std::vector<TData>::operator= ( vecI );
return *this;
}
};
/* Implementation *************************************************************/
template<class TData> void CVector<TData>::Init ( const int iNewSize )
{
// clear old buffer and reserve memory for new buffer
std::vector<TData>::clear();
std::vector<TData>::resize ( iNewSize );
}
template<class TData> void CVector<TData>::Init ( const int iNewSize,
const TData tIniVal )
{
// call actual init routine and reset all values to the given value
Init ( iNewSize );
Reset ( tIniVal );
}
// note: this is only supported for string vectors
template<class TData> int CVector<TData>::StringFiFoWithCompare ( const QString strNewValue,
const bool bDoAdding )
{
const int iVectorSize = Size();
CVector<QString> vstrTempList ( iVectorSize, "" );
// init with illegal index per definition
int iOldIndex = -1;
// init temporary list count (may be overwritten later on)
int iTempListCnt = 0;
if ( bDoAdding )
{
// store the new element in the current storage list at
// the top, make sure we do not have more than allowed stored
// elements
vstrTempList[0] = strNewValue;
iTempListCnt = 1;
}
for ( int iIdx = 0; iIdx < iVectorSize; iIdx++ )
{
// first check if we still have space in our data storage
if ( iTempListCnt < iVectorSize )
{
// only add old element if it is not the same as the
// selected one
if ( operator[] ( iIdx ).compare ( strNewValue ) )
{
vstrTempList[iTempListCnt] = operator[] ( iIdx );
iTempListCnt++;
}
else
{
iOldIndex = iIdx;
}
}
}
// copy new generated list to data base
*this = vstrTempList;
return iOldIndex;
}
/******************************************************************************\
* CFIFO Class (First In, First Out) *
\******************************************************************************/
template<class TData> class CFIFO : public CVector<TData>
{
public:
CFIFO() : iCurIdx ( 0 ) {}
CFIFO ( const int iNeSi ) : CVector<TData> ( iNeSi ), iCurIdx ( 0 ) {}
CFIFO ( const int iNeSi, const TData tInVa ) :
CVector<TData> ( iNeSi, tInVa ), iCurIdx ( 0 ) {}
void Add ( const TData tNewD );
inline TData Get() { return CVector<TData>::operator[] ( iCurIdx ); }
virtual void Init ( const int iNewSize );
virtual void Init ( const int iNewSize,
const TData tIniVal );
protected:
int iCurIdx;
};
template<class TData> void CFIFO<TData>::Init ( const int iNewSize )
{
iCurIdx = 0;
CVector<TData>::Init ( iNewSize );
}
template<class TData> void CFIFO<TData>::Init ( const int iNewSize,
const TData tIniVal )
{
iCurIdx = 0;
CVector<TData>::Init ( iNewSize, tIniVal );
}
template<class TData> void CFIFO<TData>::Add ( const TData tNewD )
{
CVector<TData>::operator[] ( iCurIdx ) = tNewD;
// increment index and check for wrap around
iCurIdx++;
if ( iCurIdx >= CVector<TData>::Size() )
{
iCurIdx = 0;
}
}
/******************************************************************************\
* CMovingAv Class (Moving Average) *
\******************************************************************************/
template<class TData> class CMovingAv : public CVector<TData>
{
public:
CMovingAv() :
CVector<TData>(),
iCurIdx ( 0 ),
iNorm ( 0 ),
dCurAvResult ( 0 ),
dNoDataResult ( 0 ) {}
void Add ( const TData tNewD );
void Init ( const int iNewSize,
const double dNNoDRes = 0 );
void Reset();
inline double GetAverage()
{
// make sure we do not divide by zero
if ( iNorm == 0 )
{
return dNoDataResult;
}
else
{
return dCurAvResult / iNorm;
}
}
double InitializationState() const
{
// make sure we do not divide by zero
if ( CVector<TData>::Size() != 0 )
{
return static_cast<double> ( iNorm ) / CVector<TData>::Size();
}
else
{
return 0;
}
}
protected:
int iCurIdx;
int iNorm;
double dCurAvResult;
double dNoDataResult;
};
template<class TData> void CMovingAv<TData>::Init ( const int iNewSize,
const double dNNoDRes )
{
iNorm = 0;
iCurIdx = 0;
dCurAvResult = 0; // only for scalars!
dNoDataResult = dNNoDRes;
CVector<TData>::Init ( iNewSize );
}
template<class TData> void CMovingAv<TData>::Reset()
{
iNorm = 0;
iCurIdx = 0;
dCurAvResult = 0; // only for scalars!
CVector<TData>::Reset ( TData ( 0 ) );
}
template<class TData> void CMovingAv<TData>::Add ( const TData tNewD )
{
/*
Optimized calculation of the moving average. We only add a new value and
subtract the old value from the result. We only need one addition and a
history buffer.
*/
// subtract oldest value
dCurAvResult -= CVector<TData>::operator[] ( iCurIdx );
// add new value and write in memory
dCurAvResult += tNewD;
CVector<TData>::operator[] ( iCurIdx ) = tNewD;
// increase position pointer and test if wrap
iCurIdx++;
if ( iCurIdx >= CVector<TData>::Size() )
{
iCurIdx = 0;
}
// take care of norm
if ( iNorm < CVector<TData>::Size() )
{
iNorm++;
}
}
/******************************************************************************\
* GUI Utilities *
\******************************************************************************/
// About dialog ----------------------------------------------------------------
class CAboutDlg : public QDialog, private Ui_CAboutDlgBase
{
Q_OBJECT
public:
CAboutDlg ( QWidget* parent = nullptr );
static QString GetVersionAndNameStr ( const bool bWithHtml = true );
};
// Licence dialog --------------------------------------------------------------
class CLicenceDlg : public QDialog
{
Q_OBJECT
public:
CLicenceDlg ( QWidget* parent = nullptr );
protected:
QPushButton* butAccept;
public slots:
void OnAgreeStateChanged ( int value ) { butAccept->setEnabled ( value == Qt::Checked ); }
};
// Musician profile dialog -----------------------------------------------------
class CMusProfDlg : public QDialog
{
Q_OBJECT
public:
CMusProfDlg ( CClient* pNCliP,
QWidget* parent = nullptr );
protected:
virtual void showEvent ( QShowEvent* );
QLineEdit* pedtAlias;
QComboBox* pcbxInstrument;
QComboBox* pcbxCountry;
QLineEdit* pedtCity;
QComboBox* pcbxSkill;
CClient* pClient;
public slots:
void OnAliasTextChanged ( const QString& strNewName );
void OnInstrumentActivated ( int iCntryListItem );
void OnCountryActivated ( int iCntryListItem );
void OnCityTextChanged ( const QString& strNewName );
void OnSkillActivated ( int iCntryListItem );
};
// Help menu -------------------------------------------------------------------
class CHelpMenu : public QMenu
{
Q_OBJECT
public:
CHelpMenu ( const bool bIsClient, QWidget* parent = nullptr );
protected:
CAboutDlg AboutDlg;
public slots:
void OnHelpWhatsThis() { QWhatsThis::enterWhatsThisMode(); }
void OnHelpAbout() { AboutDlg.exec(); }
void OnHelpClientGetStarted() { QDesktopServices::openUrl ( QUrl ( CLIENT_GETTING_STARTED_URL ) ); }
void OnHelpServerGetStarted() { QDesktopServices::openUrl ( QUrl ( SERVER_GETTING_STARTED_URL ) ); }
void OnHelpSoftwareMan() { QDesktopServices::openUrl ( QUrl ( SOFTWARE_MANUAL_URL ) ); }
};
// Console writer factory ------------------------------------------------------
// this class was written by pljones
class ConsoleWriterFactory
{
public:
ConsoleWriterFactory() : ptsConsole ( nullptr ) { }
QTextStream* get();
private:
QTextStream* ptsConsole;
};
/******************************************************************************\
* Other Classes/Enums *
\******************************************************************************/
// Audio channel configuration -------------------------------------------------
enum EAudChanConf
{
// used for settings -> enum values should be fixed
CC_MONO = 0,
CC_MONO_IN_STEREO_OUT = 1,
CC_STEREO = 2
};
// Audio compression type enum -------------------------------------------------
enum EAudComprType
{
// used for protocol -> enum values must be fixed!
CT_NONE = 0,
CT_CELT = 1,
CT_OPUS = 2,
CT_OPUS64 = 3 // using OPUS with 64 samples frame size
};
// Audio quality enum ----------------------------------------------------------
enum EAudioQuality
{
// used for settings and the comobo box index -> enum values must be fixed!
AQ_LOW = 0,
AQ_NORMAL = 1,
AQ_HIGH = 2
};
// Get data status enum --------------------------------------------------------
enum EGetDataStat
{
GS_BUFFER_OK,
GS_BUFFER_UNDERRUN,
GS_CHAN_NOW_DISCONNECTED,
GS_CHAN_NOT_CONNECTED
};
// GUI design enum -------------------------------------------------------------
enum EGUIDesign
{
// used for settings -> enum values should be fixed
GD_STANDARD = 0,
GD_ORIGINAL = 1
};
// Server licence type enum ----------------------------------------------------
enum ELicenceType
{
// used for protocol -> enum values must be fixed!
LT_NO_LICENCE = 0,
LT_CREATIVECOMMONS = 1
};
// Central server address type -------------------------------------------------
enum ECSAddType
{
// used for settings -> enum values should be fixed
AT_DEFAULT = 0,
AT_ALL_GENRES = 1,
AT_GENRE_ROCK = 2,
AT_GENRE_JAZZ = 3,
AT_GENRE_CLASSICAL_FOLK = 4,
AT_CUSTOM = 5 // Must be the last entry!
};
inline QString csCentServAddrTypeToString ( ECSAddType eAddrType )
{
switch ( eAddrType )
{
case AT_CUSTOM:
return QCoreApplication::translate ( "CClientSettingsDlg", "Custom" );
case AT_ALL_GENRES:
return QCoreApplication::translate ( "CClientSettingsDlg", "All Genres" );
case AT_GENRE_ROCK:
return QCoreApplication::translate ( "CClientSettingsDlg", "Genre Rock" );
case AT_GENRE_JAZZ:
return QCoreApplication::translate ( "CClientSettingsDlg", "Genre Jazz" );
case AT_GENRE_CLASSICAL_FOLK:
return QCoreApplication::translate ( "CClientSettingsDlg", "Genre Classical/Folk/Choir" );
default: // AT_DEFAULT
return QCoreApplication::translate ( "CClientSettingsDlg", "Default" );
}
}
// Slave server registration state ---------------------------------------------
enum ESvrRegStatus
{
SRS_UNREGISTERED = 0,
SRS_BAD_ADDRESS = 1,
SRS_REQUESTED = 2,
SRS_TIME_OUT = 3,
SRS_UNKNOWN_RESP = 4,
SRS_REGISTERED = 5,
SRS_CENTRAL_SVR_FULL = 6
};
inline QString svrRegStatusToString ( ESvrRegStatus eSvrRegStatus )
{
switch ( eSvrRegStatus )
{
case SRS_UNREGISTERED:
return QCoreApplication::translate ( "CServerDlg", "Unregistered" );
case SRS_BAD_ADDRESS:
return QCoreApplication::translate ( "CServerDlg", "Bad address" );
case SRS_REQUESTED:
return QCoreApplication::translate ( "CServerDlg", "Registration requested" );
case SRS_TIME_OUT:
return QCoreApplication::translate ( "CServerDlg", "Registration failed" );
case SRS_UNKNOWN_RESP:
return QCoreApplication::translate ( "CServerDlg", "Check server version" );
case SRS_REGISTERED:
return QCoreApplication::translate ( "CServerDlg", "Registered" );
case SRS_CENTRAL_SVR_FULL:
return QCoreApplication::translate ( "CServerDlg", "Central Server full" );
}
return QString ( QCoreApplication::translate ( "CServerDlg", "Unknown value " ) ).append ( eSvrRegStatus );
}
// Central server registration outcome -----------------------------------------
enum ESvrRegResult
{
// used for protocol -> enum values must be fixed!
SRR_REGISTERED = 0,
SRR_CENTRAL_SVR_FULL = 1
};
// Skill level enum ------------------------------------------------------------
enum ESkillLevel
{
// used for protocol -> enum values must be fixed!
SL_NOT_SET = 0,
SL_BEGINNER = 1,
SL_INTERMEDIATE = 2,
SL_PROFESSIONAL = 3
};
// define the GUI RGB colors for each skill level
#define RGBCOL_R_SL_NOT_SET 255
#define RGBCOL_G_SL_NOT_SET 255
#define RGBCOL_B_SL_NOT_SET 255
#define RGBCOL_R_SL_BEGINNER 255
#define RGBCOL_G_SL_BEGINNER 255
#define RGBCOL_B_SL_BEGINNER 200
#define RGBCOL_R_SL_INTERMEDIATE 225
#define RGBCOL_G_SL_INTERMEDIATE 255
#define RGBCOL_B_SL_INTERMEDIATE 225
#define RGBCOL_R_SL_SL_PROFESSIONAL 255
#define RGBCOL_G_SL_SL_PROFESSIONAL 225
#define RGBCOL_B_SL_SL_PROFESSIONAL 225
// Stereo signal level meter ---------------------------------------------------
class CStereoSignalLevelMeter
{
public:
CStereoSignalLevelMeter() { Reset(); }
void Update ( const CVector<short>& vecsAudio );
double MicLeveldBLeft() { return CalcLogResult ( dCurLevelL ); }
double MicLeveldBRight() { return CalcLogResult ( dCurLevelR ); }
static double CalcLogResult ( const double& dLinearLevel );
void Reset()
{
dCurLevelL = 0.0;
dCurLevelR = 0.0;
}
protected:
double UpdateCurLevel ( double dCurLevel,
const short& sMax );
double dCurLevelL;
double dCurLevelR;
};
// Host address ----------------------------------------------------------------
class CHostAddress
{
public:
enum EStringMode
{
SM_IP_PORT,
SM_IP_NO_LAST_BYTE,
SM_IP_NO_LAST_BYTE_PORT
};
CHostAddress() :
InetAddr ( static_cast<quint32> ( 0 ) ),
iPort ( 0 ) {}
CHostAddress ( const QHostAddress NInetAddr,
const quint16 iNPort ) :
InetAddr ( NInetAddr ),
iPort ( iNPort ) {}
CHostAddress ( const CHostAddress& NHAddr ) :
InetAddr ( NHAddr.InetAddr ),
iPort ( NHAddr.iPort ) {}
// copy operator
CHostAddress& operator= ( const CHostAddress& NHAddr )
{
InetAddr = NHAddr.InetAddr;
iPort = NHAddr.iPort;
return *this;
}
// compare operator
bool operator== ( const CHostAddress& CompAddr ) const
{
return ( ( CompAddr.InetAddr == InetAddr ) &&
( CompAddr.iPort == iPort ) );
}
QString toString ( const EStringMode eStringMode = SM_IP_PORT ) const
{
QString strReturn = InetAddr.toString();
// special case: for local host address, we do not replace the last byte
if ( ( ( eStringMode == SM_IP_NO_LAST_BYTE ) ||
( eStringMode == SM_IP_NO_LAST_BYTE_PORT ) ) &&
( InetAddr != QHostAddress ( QHostAddress::LocalHost ) ) )
{
// replace last byte by an "x"
strReturn = strReturn.section ( ".", 0, 2 ) + ".x";
}
if ( ( eStringMode == SM_IP_PORT ) ||
( eStringMode == SM_IP_NO_LAST_BYTE_PORT ) )
{
// add port number after a semicolon
strReturn += ":" + QString().setNum ( iPort );
}
return strReturn;
}
QHostAddress InetAddr;
quint16 iPort;
};
// Instrument picture data base ------------------------------------------------
// this is a pure static class
class CInstPictures
{
public:
enum EInstCategory
{
IC_OTHER_INSTRUMENT,
IC_WIND_INSTRUMENT,
IC_STRING_INSTRUMENT,
IC_PLUCKING_INSTRUMENT,
IC_PERCUSSION_INSTRUMENT,
IC_KEYBOARD_INSTRUMENT,
IC_MULTIPLE_INSTRUMENT
};
// per definition: the very first instrument is the "not used" instrument
static int GetNotUsedInstrument() { return 0; }
static bool IsNotUsedInstrument ( const int iInstrument ) { return iInstrument == 0; }
static int GetNumAvailableInst() { return GetTable().Size(); }
static QString GetResourceReference ( const int iInstrument );
static QString GetName ( const int iInstrument );
static EInstCategory GetCategory ( const int iInstrument );
// TODO make use of instrument category (not yet implemented)
protected:
class CInstPictProps
{
public:
CInstPictProps() :
strName ( "" ),
strResourceReference ( "" ),
eInstCategory ( IC_OTHER_INSTRUMENT ) {}
CInstPictProps ( const QString NsName,
const QString NsResRef,
const EInstCategory NeInstCat ) :
strName ( NsName ),
strResourceReference ( NsResRef ),
eInstCategory ( NeInstCat ) {}
QString strName;
QString strResourceReference;
EInstCategory eInstCategory;
};
static bool IsInstIndexInRange ( const int iIdx );
static CVector<CInstPictProps>& GetTable();
};
// Locale management class -----------------------------------------------------
class CLocale
{
public:
static QString GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry );
static ECSAddType GetCentralServerAddressType ( const QLocale::Country eCountry );
};
// Info of a channel -----------------------------------------------------------
class CChannelCoreInfo
{
public:
CChannelCoreInfo() :
strName ( "" ),
eCountry ( QLocale::AnyCountry ),
strCity ( "" ),
iInstrument ( CInstPictures::GetNotUsedInstrument() ),
eSkillLevel ( SL_NOT_SET ) {}
CChannelCoreInfo ( const QString NsName,
const QLocale::Country& NeCountry,
const QString& NsCity,
const int NiInstrument,
const ESkillLevel NeSkillLevel ) :
strName ( NsName ),
eCountry ( NeCountry ),
strCity ( NsCity ),
iInstrument ( NiInstrument ),
eSkillLevel ( NeSkillLevel ) {}
CChannelCoreInfo ( const CChannelCoreInfo& NCorInf ) :
strName ( NCorInf.strName ),
eCountry ( NCorInf.eCountry ),
strCity ( NCorInf.strCity ),
iInstrument ( NCorInf.iInstrument ),
eSkillLevel ( NCorInf.eSkillLevel ) {}
// compare operator
bool operator!= ( const CChannelCoreInfo& CompChanInfo )
{
return ( ( CompChanInfo.strName != strName ) ||
( CompChanInfo.eCountry != eCountry ) ||
( CompChanInfo.strCity != strCity ) ||
( CompChanInfo.iInstrument != iInstrument ) ||
( CompChanInfo.eSkillLevel != eSkillLevel ) );
}
CChannelCoreInfo& operator= ( const CChannelCoreInfo& ) = default;
// fader tag text (channel name)
QString strName;
// country in which the client is located
QLocale::Country eCountry;
// city in which the client is located
QString strCity;
// instrument ID of the client (which instrument is he/she playing)
int iInstrument;
// skill level of the musician
ESkillLevel eSkillLevel;
};
class CChannelInfo : public CChannelCoreInfo
{
public:
CChannelInfo() :
iChanID ( 0 ),
iIpAddr ( 0 ) {}
CChannelInfo ( const int NiID,
const quint32 NiIP,
const CChannelCoreInfo& NCorInf ) :
CChannelCoreInfo ( NCorInf ),
iChanID ( NiID ),
iIpAddr ( NiIP ) {}
CChannelInfo ( const int NiID,
const quint32 NiIP,
const QString NsName,
const QLocale::Country& NeCountry,
const QString& NsCity,
const int NiInstrument,
const ESkillLevel NeSkillLevel ) :
CChannelCoreInfo ( NsName,
NeCountry,
NsCity,
NiInstrument,
NeSkillLevel ),
iChanID ( NiID ),
iIpAddr ( NiIP ) {}
QString GenNameForDisplay() const
{
// if text is empty, show IP address instead
if ( strName.isEmpty() )
{
// convert IP address to text and show it (use dummy port number
// since it is not used here)
const CHostAddress TempAddr =
CHostAddress ( QHostAddress ( iIpAddr ), 0 );
return TempAddr.toString ( CHostAddress::SM_IP_NO_LAST_BYTE );
}
else
{
// show name of channel
return strName;
}
}
// ID of the channel
int iChanID;
// IP address of the channel
quint32 iIpAddr;
};
// Server info -----------------------------------------------------------------
class CServerCoreInfo
{
public:
CServerCoreInfo() :
strName ( "" ),
eCountry ( QLocale::AnyCountry ),
strCity ( "" ),
iMaxNumClients ( 0 ),
bPermanentOnline ( false ) {}
CServerCoreInfo (
const QString& NsName,
const QLocale::Country& NeCountry,
const QString& NsCity,
const int NiMaxNumClients,
const bool NbPermOnline) :
strName ( NsName ),
eCountry ( NeCountry ),
strCity ( NsCity ),
iMaxNumClients ( NiMaxNumClients ),
bPermanentOnline ( NbPermOnline ) {}
// name of the server
QString strName;
// country in which the server is located
QLocale::Country eCountry;
// city in which the server is located
QString strCity;
// maximum number of clients which can connect to the server at the same
// time
int iMaxNumClients;
// is the server permanently online or not (flag)
bool bPermanentOnline;
};
class CServerInfo : public CServerCoreInfo
{
public:
CServerInfo() :
HostAddr ( CHostAddress() ),
LHostAddr ( CHostAddress() )
{}
CServerInfo (
const CHostAddress& NHAddr,
const CHostAddress& NLAddr,
const QString& NsName,
const QLocale::Country& NeCountry,
const QString& NsCity,