jamulus/src/audiomixerboard.cpp

200 lines
6.8 KiB
C++
Raw Normal View History

/******************************************************************************\
* Copyright (c) 2004-2008
*
* Author(s):
* Volker Fischer
*
* Description:
*
*
******************************************************************************
*
* 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
*
\******************************************************************************/
#include "audiomixerboard.h"
2006-12-09 16:00:24 +01:00
/* Implementation *************************************************************/
CChannelFader::CChannelFader ( QWidget* pNW,
QHBoxLayout* pParentLayout,
QString sName )
2006-12-09 16:00:24 +01:00
{
// create new GUI control objects and store pointers to them
pMainGrid = new QGridLayout();
pFader = new QSlider ( Qt::Vertical, pNW );
pLabel = new QLabel ( "", pNW );
2006-12-09 16:00:24 +01:00
// setup slider
pFader->setPageStep ( 1 );
pFader->setTickPosition ( QSlider::TicksBothSides );
2006-12-09 16:00:24 +01:00
pFader->setRange ( 0, AUD_MIX_FADER_MAX );
pFader->setTickInterval ( AUD_MIX_FADER_MAX / 9 );
2006-12-09 19:37:40 +01:00
pFader->setValue ( 0 ); // set init value
2006-12-09 16:00:24 +01:00
// set label text
pLabel->setText ( sName );
// add slider to grid as position 0 / 0
pMainGrid->addWidget( pFader, 0, 0, Qt::AlignHCenter );
// add label to grid as position 1 / 0
pMainGrid->addWidget( pLabel, 1, 0, Qt::AlignHCenter );
pParentLayout->insertLayout ( 0, pMainGrid );
2006-12-09 19:37:40 +01:00
// add help text to controls
pFader->setWhatsThis ( "<b>Mixer Fader:</b> Adjusts the audio level of this "
2008-02-02 10:35:58 +01:00
"channel. All connected clients at the server will be assigned an audio "
"fader at each client" );
pLabel->setWhatsThis ( "<b>Mixer Fader Label:</b> Label (fader tag) identifying "
2008-02-02 10:35:58 +01:00
"the connected client. The tag name can be set in the clients main window." );
2006-12-09 19:37:40 +01:00
// connections -------------------------------------------------------------
QObject::connect ( pFader, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnValueChanged ( int ) ) );
}
void CChannelFader::OnValueChanged ( int value )
{
// convert actual slider range in gain values
2008-02-02 10:35:58 +01:00
// and normalize so that maximum gain is 1
const double dCurGain = static_cast<double> ( value ) / AUD_MIX_FADER_MAX;
2006-12-09 19:37:40 +01:00
emit valueChanged ( dCurGain );
2006-12-09 16:00:24 +01:00
}
2008-01-22 22:15:04 +01:00
void CChannelFader::SetText ( const QString sText )
2006-12-09 16:00:24 +01:00
{
2006-12-10 13:36:43 +01:00
const int iBreakPos = 7;
2006-12-09 16:00:24 +01:00
2006-12-10 13:36:43 +01:00
// break text at predefined position, if text is too short, break anyway to
// make sure we have two lines for fader tag
2008-01-22 22:15:04 +01:00
QString sModText = sText;
2006-12-09 16:00:24 +01:00
if ( sModText.length() > iBreakPos )
{
sModText.insert ( iBreakPos, QString ( "<br>" ) );
}
2006-12-10 13:36:43 +01:00
else
{
sModText.append ( QString ( "<br>" ) );
}
2006-12-09 16:00:24 +01:00
// use bold text
sModText.prepend ( "<b>" );
sModText.append ( "</b>" );
pLabel->setText ( sModText );
}
CAudioMixerBoard::CAudioMixerBoard ( QWidget* parent, Qt::WindowFlags f ) : QFrame ( parent, f )
2006-12-09 16:00:24 +01:00
{
// set modified style
setFrameShape ( QFrame::StyledPanel );
setFrameShadow ( QFrame::Sunken );
// add hboxlayout with horizontal spacer
// TODO is this ok this way? Don't we need the border 11 and space 0?
pMainLayout = new QHBoxLayout ( this );//, 11, 0 );
2006-12-09 16:00:24 +01:00
pMainLayout->addItem ( new QSpacerItem ( 0, 0, QSizePolicy::Expanding ) );
// create all mixer controls and make them invisible
vecpChanFader.Init ( MAX_NUM_CHANNELS );
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
2006-12-09 19:37:40 +01:00
vecpChanFader[i] = new CChannelFader ( this, pMainLayout, "" );
2006-12-09 16:00:24 +01:00
vecpChanFader[i]->Hide();
}
2006-12-09 19:37:40 +01:00
// 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)));
2006-12-09 16:00:24 +01:00
}
2006-12-09 19:37:40 +01:00
void CAudioMixerBoard::HideAll()
2006-12-09 16:00:24 +01:00
{
// make old controls invisible
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
vecpChanFader[i]->Hide();
}
}
void CAudioMixerBoard::ApplyNewConClientList ( CVector<CChannelShortInfo>& vecChanInfo )
{
2006-12-09 19:37:40 +01:00
// 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();
// show fader
vecpChanFader[i]->Show();
}
// update text
vecpChanFader[i]->SetText ( GenFaderText ( vecChanInfo[j] ) );
bFaderIsUsed = true;
}
}
// if current fader is not used, hide it
if ( !bFaderIsUsed )
{
vecpChanFader[i]->Hide();
}
}
2006-12-09 16:00:24 +01:00
}
2008-01-22 22:15:04 +01:00
QString CAudioMixerBoard::GenFaderText ( CChannelShortInfo& ChanInfo )
2006-12-09 19:37:40 +01:00
{
// if text is empty, show IP address instead
2008-01-22 22:15:04 +01:00
if ( ChanInfo.strName.isEmpty() )
2006-12-09 19:37:40 +01:00
{
// convert IP address to text and show it
const QHostAddress addrTest ( ChanInfo.iIpAddr );
2008-01-22 22:15:04 +01:00
return addrTest.toString();
2006-12-09 19:37:40 +01:00
}
else
{
// show name of channel
return ChanInfo.strName;
}
2006-12-09 16:00:24 +01:00
}