fader implementation finished

This commit is contained in:
Volker Fischer 2006-12-09 18:37:40 +00:00
parent d0bb262193
commit 92b695f7da
8 changed files with 123 additions and 56 deletions

View File

@ -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<double> ( 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<CChannelShortInfo>& 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;
}
}

View File

@ -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<CChannelShortInfo>& vecChanInfo );
protected:
std::string GenFaderText ( CChannelShortInfo& ChanInfo );
CVector<CChannelFader*> 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 );
};

View File

@ -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<uint8_t>)),this,SLOT(OnSendProtMessCh0(CVector<uint8_t>)));

View File

@ -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<uint8_t> mess) {emit MessReadyForSending(0,mess);}

View File

@ -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 */

View File

@ -213,7 +213,7 @@ void CLlconClientDlg::OnConnectDisconBut()
OnTimerStatus();
// clear mixer board (remove all faders)
MainMixerBoard->Clear();
MainMixerBoard->HideAll();
}
else
{

View File

@ -439,7 +439,7 @@ void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( 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<int> ( dGain * ( 1 << 15 ) );
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iCurGain ), 2 );
CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData );
@ -455,7 +455,7 @@ void CProtocol::EvaluateChanGainMes ( unsigned int iPos, const CVector<uint8_t>&
const int iData =
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
const double dNewGain = (double) iData / ( 1 << 16 );
const double dNewGain = static_cast<double> ( iData ) / ( 1 << 15 );
// invoke message action
emit ChangeChanGain ( iCurID, dNewGain );
@ -472,7 +472,7 @@ void CProtocol::CreateConClientListMes ( const CVector<CChannelShortInfo>& 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<CChannelShortInfo>& vecCh
// channel ID
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecChanInfo[i].veciChanID ), 1 );
static_cast<uint32_t> ( vecChanInfo[i].iChanID ), 1 );
// IP address (4 bytes)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecChanInfo[i].veciIpAddr ), 4 );
static_cast<uint32_t> ( vecChanInfo[i].iIpAddr ), 4 );
// number of bytes for name string (2 bytes)
PutValOnStream ( vecData, iPos,
@ -498,7 +498,7 @@ void CProtocol::CreateConClientListMes ( const CVector<CChannelShortInfo>& vecCh
{
// byte-by-byte copying of the string data
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecChanInfo[i].vecstrName[j] ), 1 );
static_cast<uint32_t> ( vecChanInfo[i].strName[j] ), 1 );
}
}

View File

@ -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;
};