From 92b695f7da4b17bc00a36df585b9109e321d84f9 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 9 Dec 2006 18:37:40 +0000 Subject: [PATCH] fader implementation finished --- src/audiomixerboard.cpp | 117 ++++++++++++++++++++++++++-------------- src/audiomixerboard.h | 32 ++++++++++- src/channel.cpp | 1 + src/channel.h | 1 + src/global.h | 4 +- src/llconclientdlg.cpp | 2 +- src/protocol.cpp | 12 ++--- src/util.h | 10 ++-- 8 files changed, 123 insertions(+), 56 deletions(-) diff --git a/src/audiomixerboard.cpp b/src/audiomixerboard.cpp index 54b1f512..1f4c4315 100755 --- a/src/audiomixerboard.cpp +++ b/src/audiomixerboard.cpp @@ -36,18 +36,15 @@ CChannelFader::CChannelFader ( QWidget* pNW, { // create new GUI control objects and store pointers to them pMainGrid = new QGridLayout ( pNW, 2, 1 ); - pFader = new QSlider ( Qt::Vertical, pNW ); - pLabel = new QLabel ( "", pNW ); + pFader = new QSlider ( Qt::Vertical, pNW ); + pLabel = new QLabel ( "", pNW ); // setup slider pFader->setPageStep ( 1 ); pFader->setTickmarks ( QSlider::Both ); pFader->setRange ( 0, AUD_MIX_FADER_MAX ); pFader->setTickInterval ( AUD_MIX_FADER_MAX / 9 ); - -// TEST set value and make read only -pFader->setValue ( 0 ); -pFader->setEnabled ( FALSE ); + pFader->setValue ( 0 ); // set init value // set label text pLabel->setText ( sName ); @@ -59,6 +56,21 @@ pFader->setEnabled ( FALSE ); pMainGrid->addWidget( pLabel, 1, 0, Qt::AlignHCenter ); pParentLayout->insertLayout ( 0, pMainGrid ); + + + // connections ------------------------------------------------------------- + QObject::connect ( pFader, SIGNAL ( valueChanged ( int ) ), + this, SLOT ( OnValueChanged ( int ) ) ); +} + +void CChannelFader::OnValueChanged ( int value ) +{ + // convert actual slider range in gain values + // reverse linear scale and normalize so that maximum gain is 1 + const double dCurGain = + static_cast ( AUD_MIX_FADER_MAX - value ) / AUD_MIX_FADER_MAX; + + emit valueChanged ( dCurGain ); } void CChannelFader::SetText ( const std::string sText ) @@ -97,30 +109,27 @@ CAudioMixerBoard::CAudioMixerBoard ( QWidget* parent, vecpChanFader.Init ( MAX_NUM_CHANNELS ); for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) { - vecpChanFader[i] = new CChannelFader ( this, - pMainLayout, "test" ); - + vecpChanFader[i] = new CChannelFader ( this, pMainLayout, "" ); vecpChanFader[i]->Hide(); } -// TEST -//vecpChanFader.Init(0); -//vecpChanFader.Add(new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout, "test")); - -//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders )); -/* -for ( int z = 0; z < 100; z++) -{ -CLlconClientDlg::CChannelFader* pTest = new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout); -delete pTest; -} -*/ - - + // connections ------------------------------------------------------------- + // CODE TAG: MAX_NUM_CHANNELS_TAG + // make sure we have MAX_NUM_CHANNELS connections!!! + QObject::connect(vecpChanFader[0],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh0(double))); + QObject::connect(vecpChanFader[1],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh1(double))); + QObject::connect(vecpChanFader[2],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh2(double))); + QObject::connect(vecpChanFader[3],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh3(double))); + QObject::connect(vecpChanFader[4],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh4(double))); + QObject::connect(vecpChanFader[5],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh5(double))); + QObject::connect(vecpChanFader[6],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh6(double))); + QObject::connect(vecpChanFader[7],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh7(double))); + QObject::connect(vecpChanFader[8],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh8(double))); + QObject::connect(vecpChanFader[9],SIGNAL(valueChanged(double)),this,SLOT(OnValueChangedCh9(double))); } -void CAudioMixerBoard::Clear() +void CAudioMixerBoard::HideAll() { // make old controls invisible for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) @@ -131,27 +140,53 @@ void CAudioMixerBoard::Clear() void CAudioMixerBoard::ApplyNewConClientList ( CVector& vecChanInfo ) { - int i; + // search for channels with are already present and preserver their gain + // setting, for all other channels, reset gain + for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) + { + bool bFaderIsUsed = false; + for ( int j = 0; j < vecChanInfo.Size(); j++ ) + { + // search if current fader is used + if ( vecChanInfo[j].iChanID == i ) + { + // check if fader was already in use -> preserve gain value + if ( !vecpChanFader[i]->IsVisible() ) + { + vecpChanFader[i]->ResetGain(); -// TODO + // show fader + vecpChanFader[i]->Show(); + } -// make old controls invisible -Clear(); + // update text + vecpChanFader[i]->SetText ( GenFaderText ( vecChanInfo[j] ) ); + bFaderIsUsed = true; + } + } -// TEST add current faders -for ( i = 0; i < vecChanInfo.Size(); i++ ) + // if current fader is not used, hide it + if ( !bFaderIsUsed ) + { + vecpChanFader[i]->Hide(); + } + } +} + +std::string CAudioMixerBoard::GenFaderText ( CChannelShortInfo& ChanInfo ) { - QHostAddress addrTest ( vecChanInfo[i].veciIpAddr ); - - vecpChanFader[i]->SetText ( addrTest.toString().latin1() ); - vecpChanFader[i]->Show(); - - - -// vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders, -// FrameAudioFadersLayout, addrTest.toString() ); -} - + // if text is empty, show IP address instead + if ( ChanInfo.strName.empty() ) + { + // convert IP address to text and show it + const QHostAddress addrTest ( ChanInfo.iIpAddr ); + return addrTest.toString().latin1(); + } + else + { + // show name of channel + return ChanInfo.strName; + } } diff --git a/src/audiomixerboard.h b/src/audiomixerboard.h index caf79305..be09b1db 100755 --- a/src/audiomixerboard.h +++ b/src/audiomixerboard.h @@ -44,8 +44,10 @@ /* Classes ********************************************************************/ -class CChannelFader +class CChannelFader : public QObject { + Q_OBJECT + public: CChannelFader ( QWidget* pNW, QHBoxLayout* pNPtLy, QString sName ); ~CChannelFader() @@ -59,6 +61,10 @@ public: void SetText ( const std::string sText ); void Show() { pLabel->show(); pFader->show(); } void Hide() { pLabel->hide(); pFader->hide(); } + bool IsVisible() { return pLabel->isVisible(); } + + // init gain value -> maximum value as definition according to server + void ResetGain() { pFader->setValue ( 0 ); } protected: QGridLayout* pMainGrid; @@ -66,6 +72,12 @@ protected: QLabel* pLabel; QHBoxLayout* pParentLayout; + +public slots: + void OnValueChanged ( int value ); + +signals: + void valueChanged ( double value ); }; @@ -76,13 +88,29 @@ class CAudioMixerBoard : public QFrame public: CAudioMixerBoard ( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ); - void Clear(); + void HideAll(); void ApplyNewConClientList ( CVector& vecChanInfo ); protected: + std::string GenFaderText ( CChannelShortInfo& ChanInfo ); + CVector vecpChanFader; QHBoxLayout* pMainLayout; +public slots: + // CODE TAG: MAX_NUM_CHANNELS_TAG + // make sure we have MAX_NUM_CHANNELS connections!!! + void OnValueChangedCh0 ( double dValue ) { emit ChangeChanGain ( 0, dValue ); } + void OnValueChangedCh1 ( double dValue ) { emit ChangeChanGain ( 1, dValue ); } + void OnValueChangedCh2 ( double dValue ) { emit ChangeChanGain ( 2, dValue ); } + void OnValueChangedCh3 ( double dValue ) { emit ChangeChanGain ( 3, dValue ); } + void OnValueChangedCh4 ( double dValue ) { emit ChangeChanGain ( 4, dValue ); } + void OnValueChangedCh5 ( double dValue ) { emit ChangeChanGain ( 5, dValue ); } + void OnValueChangedCh6 ( double dValue ) { emit ChangeChanGain ( 6, dValue ); } + void OnValueChangedCh7 ( double dValue ) { emit ChangeChanGain ( 7, dValue ); } + void OnValueChangedCh8 ( double dValue ) { emit ChangeChanGain ( 8, dValue ); } + void OnValueChangedCh9 ( double dValue ) { emit ChangeChanGain ( 9, dValue ); } + signals: void ChangeChanGain ( int iId, double dGain ); }; diff --git a/src/channel.cpp b/src/channel.cpp index 33b9f19f..86c21636 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -36,6 +36,7 @@ CChannelSet::CChannelSet() vecChannels[i].SetEnable ( true ); } + // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!! // send message QObject::connect(&vecChannels[0],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh0(CVector))); diff --git a/src/channel.h b/src/channel.h index 3859993a..d4a704bf 100755 --- a/src/channel.h +++ b/src/channel.h @@ -238,6 +238,7 @@ protected: QMutex Mutex; public slots: + // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!! // send message void OnSendProtMessCh0(CVector mess) {emit MessReadyForSending(0,mess);} diff --git a/src/global.h b/src/global.h index 64768e87..9325f6ec 100755 --- a/src/global.h +++ b/src/global.h @@ -83,7 +83,9 @@ #endif // maximum number of internet connections (channels) -// if you want to change this paramter, change the connections in channel class, too! +// if you want to change this paramter, there has to be done code modifications +// on other places, too! The code tag "MAX_NUM_CHANNELS_TAG" shows these places +// (just search for the tag in the entire code) #define MAX_NUM_CHANNELS 10 /* max number channels for server */ /* sample rate offset estimation algorithm */ diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index b5a1410f..76784dc7 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -213,7 +213,7 @@ void CLlconClientDlg::OnConnectDisconBut() OnTimerStatus(); // clear mixer board (remove all faders) - MainMixerBoard->Clear(); + MainMixerBoard->HideAll(); } else { diff --git a/src/protocol.cpp b/src/protocol.cpp index 2a192cb2..ac9e38dc 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -439,7 +439,7 @@ void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) PutValOnStream ( vecData, iPos, static_cast ( iChanID ), 1 ); // actual gain, we convert from double with range 0..1 to integer - const int iCurGain = (int) ( dGain * ( 1 << 16 ) ); + const int iCurGain = static_cast ( dGain * ( 1 << 15 ) ); PutValOnStream ( vecData, iPos, static_cast ( iCurGain ), 2 ); CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData ); @@ -455,7 +455,7 @@ void CProtocol::EvaluateChanGainMes ( unsigned int iPos, const CVector& const int iData = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); - const double dNewGain = (double) iData / ( 1 << 16 ); + const double dNewGain = static_cast ( iData ) / ( 1 << 15 ); // invoke message action emit ChangeChanGain ( iCurID, dNewGain ); @@ -472,7 +472,7 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh for ( int i = 0; i < iNumClients; i++ ) { // current string size - const int iCurStrLen = vecChanInfo[i].vecstrName.size(); + const int iCurStrLen = vecChanInfo[i].strName.size(); // size of current list entry const int iCurListEntrLen = @@ -483,11 +483,11 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh // channel ID PutValOnStream ( vecData, iPos, - static_cast ( vecChanInfo[i].veciChanID ), 1 ); + static_cast ( vecChanInfo[i].iChanID ), 1 ); // IP address (4 bytes) PutValOnStream ( vecData, iPos, - static_cast ( vecChanInfo[i].veciIpAddr ), 4 ); + static_cast ( vecChanInfo[i].iIpAddr ), 4 ); // number of bytes for name string (2 bytes) PutValOnStream ( vecData, iPos, @@ -498,7 +498,7 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh { // byte-by-byte copying of the string data PutValOnStream ( vecData, iPos, - static_cast ( vecChanInfo[i].vecstrName[j] ), 1 ); + static_cast ( vecChanInfo[i].strName[j] ), 1 ); } } diff --git a/src/util.h b/src/util.h index 92dfd567..7256fa94 100755 --- a/src/util.h +++ b/src/util.h @@ -363,13 +363,13 @@ public: class CChannelShortInfo { public: - CChannelShortInfo() : veciChanID ( 0 ), veciIpAddr ( 0 ), vecstrName ( "" ) {} + CChannelShortInfo() : iChanID ( 0 ), iIpAddr ( 0 ), strName ( "" ) {} CChannelShortInfo ( const int iNID, const uint32_t nIP, const std::string nN ) : - veciChanID ( iNID ), veciIpAddr ( nIP ), vecstrName ( nN ) {} + iChanID ( iNID ), iIpAddr ( nIP ), strName ( nN ) {} - int veciChanID; - uint32_t veciIpAddr; - std::string vecstrName; + int iChanID; + uint32_t iIpAddr; + std::string strName; };