jamulus/src/llconclientdlg.cpp

396 lines
14 KiB
C++
Raw Normal View History

/******************************************************************************\
* Copyright (c) 2004-2008
*
* 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
*
\******************************************************************************/
#include "llconclientdlg.h"
/* Implementation *************************************************************/
CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
Qt::WindowFlags f )
: pClient ( pNCliP ), QDialog ( parent, f ),
ClientSettingsDlg ( pNCliP, parent, Qt::WindowMinMaxButtonsHint ),
ChatDlg ( parent, Qt::WindowMinMaxButtonsHint )
{
setupUi ( this );
// add help text to controls
2007-09-08 12:45:14 +02:00
QString strInpLevH = tr ( "<b>Input level meter:</b> Shows the level of the "
"input audio signal of the sound card. The level is in dB. Overload "
2007-09-08 12:45:14 +02:00
"should be avoided." );
TextLabelInputLevel->setWhatsThis ( strInpLevH );
ProgressBarInputLevelL->setWhatsThis ( strInpLevH );
ProgressBarInputLevelR->setWhatsThis ( strInpLevH );
PushButtonConnect->setWhatsThis ( tr ( "<b>Connect / Disconnect Button:"
"</b> Push this button to connect the server. A valid IP address has "
"to be specified before. If the client is connected, pressing this "
2007-09-08 12:45:14 +02:00
"button will disconnect the connection." ) );
TextLabelStatus->setWhatsThis ( tr ( "<b>Status Bar:</b> In the status bar "
"different messages are displayed. E.g., if an error occurred or the "
2007-09-08 12:45:14 +02:00
"status of the connection is shown." ) );
2007-09-08 12:45:14 +02:00
QString strServAddrH = tr ( "<b>Server Address:</b> In this edit control, "
"the IP address of the server can be set. If an invalid address was "
2007-09-08 12:45:14 +02:00
"chosen, an error message is shown in the status bar." );
TextLabelServerAddr->setWhatsThis ( strServAddrH );
LineEditServerAddr->setWhatsThis ( strServAddrH );
2007-09-08 12:45:14 +02:00
QString strFaderTag = tr ( "<b>Fader Tag:</b> In this edit control, "
2006-12-10 12:06:14 +01:00
"the tag string of your fader can be set. This tag will appear "
2006-12-10 13:36:43 +01:00
"at your fader on the mixer board when connected to the server.");
TextLabelServerTag->setWhatsThis ( strFaderTag );
LineEditFaderTag->setWhatsThis ( strFaderTag );
2006-12-10 12:06:14 +01:00
QString strAudFader = tr ( "<b>Audio Fader:</b> With the audio fader "
"control the level of left and right audio input channels can "
"be controlled." );
TextAudInFader->setWhatsThis ( strAudFader );
SliderAudInFader->setWhatsThis ( strAudFader );
QString strAudReverb = tr ( "<b>Reverberation Level:</b> The level of "
"reverberation effect can be set with this control. The channel to "
"which that reverberation effect shall be applied can be chosen "
"with the Reverberation Channel Selection radio buttons." );
TextLabelAudReverb->setWhatsThis ( strAudReverb );
SliderAudReverb->setWhatsThis ( strAudReverb );
QString strRevChanSel = tr ( "<b>Reverberation Channel Selection:</b> "
"With these radio buttons the audio input channel on which the "
"reverberation effect is applied can be chosen. Either the left "
"or right input channel can be selected." );
TextLabelReverbSelection->setWhatsThis ( strRevChanSel );
RadioButtonRevSelL->setWhatsThis ( strRevChanSel );
RadioButtonRevSelR->setWhatsThis ( strRevChanSel );
LEDOverallStatus->setWhatsThis ( tr ( "<b>Overall Status:</b> "
"The overall status of the software is shown. If either the "
"network or sound interface has bad status, this LED will show "
"red color." ) );
2006-12-10 12:06:14 +01:00
// init fader tag line edit
2008-01-22 22:15:04 +01:00
LineEditFaderTag->setText ( pClient->strName );
2006-12-10 12:06:14 +01:00
// init server address line edit
2008-01-22 22:15:04 +01:00
LineEditServerAddr->setText ( pClient->strIPAddress );
2006-12-10 12:06:14 +01:00
// we want the cursor to be at IP address line edit at startup
LineEditServerAddr->setFocus();
// init status label
OnTimerStatus();
// init connection button text
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
// init input level meter bars
ProgressBarInputLevelL->setMinimum ( 0 );
ProgressBarInputLevelL->setMaximum ( NUM_STEPS_INP_LEV_METER );
ProgressBarInputLevelL->setValue ( 0 );
ProgressBarInputLevelR->setMinimum ( 0 );
ProgressBarInputLevelR->setMaximum ( NUM_STEPS_INP_LEV_METER );
ProgressBarInputLevelR->setValue ( 0 );
2006-01-28 12:29:22 +01:00
2006-12-10 12:06:14 +01:00
// init slider controls ---
// audio in fader
SliderAudInFader->setRange ( AUD_FADER_IN_MIN, AUD_FADER_IN_MAX );
const int iCurAudInFader = pClient->GetAudioInFader();
SliderAudInFader->setValue ( iCurAudInFader );
SliderAudInFader->setTickInterval ( AUD_FADER_IN_MAX / 9 );
2006-01-28 12:29:22 +01:00
// audio reverberation
SliderAudReverb->setRange ( 0, AUD_REVERB_MAX );
const int iCurAudReverb = pClient->GetReverbLevel();
2008-02-02 10:35:58 +01:00
SliderAudReverb->setValue ( iCurAudReverb );
SliderAudReverb->setTickInterval ( AUD_REVERB_MAX / 9 );
2006-01-28 12:29:22 +01:00
2006-12-10 12:06:14 +01:00
// set radio buttons ---
// reverb channel
2006-12-09 16:00:24 +01:00
if ( pClient->IsReverbOnLeftChan() )
{
2006-12-09 16:00:24 +01:00
RadioButtonRevSelL->setChecked ( true );
}
else
{
2006-12-09 16:00:24 +01:00
RadioButtonRevSelR->setChecked ( true );
}
2006-01-28 12:29:22 +01:00
2008-01-22 20:58:53 +01:00
// Settings menu ----------------------------------------------------------
pSettingsMenu = new QMenu ( "&View", this );
pSettingsMenu->addAction ( tr ( "&Chat..." ), this,
SLOT ( OnOpenChatDialog() ) );
pSettingsMenu->addAction ( tr ( "&General Settings..." ), this,
SLOT ( OnOpenGeneralSettings() ) );
pSettingsMenu->addSeparator();
pSettingsMenu->addAction ( tr ( "E&xit" ), this,
SLOT ( close() ), QKeySequence ( Qt::CTRL + Qt::Key_Q ) );
2008-01-22 20:58:53 +01:00
// Main menu bar -----------------------------------------------------------
pMenu = new QMenuBar ( this );
pMenu->addMenu ( pSettingsMenu );
pMenu->addMenu ( new CLlconHelpMenu ( this ) );
// Now tell the layout about the menu
layout()->setMenuBar ( pMenu );
2008-01-22 20:58:53 +01:00
// Connections -------------------------------------------------------------
// push-buttons
2007-09-08 12:45:14 +02:00
QObject::connect ( PushButtonConnect, SIGNAL ( clicked() ),
this, SLOT ( OnConnectDisconBut() ) );
// timers
2007-09-08 12:45:14 +02:00
QObject::connect ( &TimerSigMet, SIGNAL ( timeout() ),
this, SLOT ( OnTimerSigMet() ) );
QObject::connect ( &TimerStatus, SIGNAL ( timeout() ),
this, SLOT ( OnTimerStatus() ) );
// sliders
2007-09-08 12:45:14 +02:00
QObject::connect ( SliderAudInFader, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderAudInFader ( int ) ) );
QObject::connect ( SliderAudReverb, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderAudReverb ( int ) ) );
// radio buttons
2007-09-08 12:45:14 +02:00
QObject::connect ( RadioButtonRevSelL, SIGNAL ( clicked() ),
this, SLOT ( OnRevSelL() ) );
QObject::connect ( RadioButtonRevSelR, SIGNAL ( clicked() ),
this, SLOT ( OnRevSelR() ) );
2006-12-10 12:06:14 +01:00
// line edits
QObject::connect ( LineEditFaderTag, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnFaderTagTextChanged ( const QString& ) ) );
2006-11-26 22:25:56 +01:00
// other
2006-12-09 16:00:24 +01:00
QObject::connect ( pClient,
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ),
2006-11-26 22:25:56 +01:00
this, SLOT ( OnConClientListMesReceived ( CVector<CChannelShortInfo> ) ) );
QObject::connect ( pClient,
SIGNAL ( ChatTextReceived ( QString ) ),
this, SLOT ( OnChatTextReceived ( QString ) ) );
2006-12-09 16:00:24 +01:00
QObject::connect ( MainMixerBoard, SIGNAL ( ChangeChanGain ( int, double ) ),
this, SLOT ( OnChangeChanGain ( int, double ) ) );
QObject::connect ( &ChatDlg, SIGNAL ( NewLocalInputText ( QString ) ),
this, SLOT ( OnNewLocalInputText ( QString ) ) );
2006-11-26 22:25:56 +01:00
2008-01-22 20:58:53 +01:00
// Timers ------------------------------------------------------------------
// start timer for status bar
2007-09-08 12:45:14 +02:00
TimerStatus.start ( STATUSBAR_UPDATE_TIME );
}
CLlconClientDlg::~CLlconClientDlg()
{
// if connected, terminate connection
2007-09-08 12:45:14 +02:00
if ( pClient->IsRunning() )
{
pClient->Stop();
}
2006-01-28 12:29:22 +01:00
}
void CLlconClientDlg::closeEvent ( QCloseEvent * Event )
{
// if settings dialog or chat dialog is open, close it
ClientSettingsDlg.close();
ChatDlg.close();
// store IP address
2008-01-22 22:15:04 +01:00
pClient->strIPAddress = LineEditServerAddr->text();
2006-01-28 12:29:22 +01:00
2006-12-10 12:06:14 +01:00
// store fader tag
2008-01-22 22:15:04 +01:00
pClient->strName = LineEditFaderTag->text();
2006-12-10 12:06:14 +01:00
// default implementation of this event handler routine
Event->accept();
2006-01-28 12:29:22 +01:00
}
void CLlconClientDlg::OnConnectDisconBut()
2006-11-27 23:35:22 +01:00
{
// start/stop client, set button text
if ( pClient->IsRunning() )
{
pClient->Stop();
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
// stop timer for level meter bars and reset them
TimerSigMet.stop();
ProgressBarInputLevelL->setValue ( 0 );
ProgressBarInputLevelR->setValue ( 0 );
// immediately update status bar
2006-12-09 16:00:24 +01:00
OnTimerStatus();
2006-12-09 16:00:24 +01:00
// clear mixer board (remove all faders)
2006-12-09 19:37:40 +01:00
MainMixerBoard->HideAll();
}
else
{
// set address and check if address is valid
if ( pClient->SetServerAddr ( LineEditServerAddr->text() ) )
{
pClient->start ( QThread::TimeCriticalPriority );
2008-02-02 10:35:58 +01:00
PushButtonConnect->setText ( CON_BUT_DISCONNECTTEXT );
// start timer for level meter bar
TimerSigMet.start ( LEVELMETER_UPDATE_TIME );
}
else
{
// Restart timer to ensure that the text is visible at
// least the time for one complete interval
2008-03-28 19:41:46 +01:00
TimerStatus.start ( STATUSBAR_UPDATE_TIME );
// show the error in the status bar
TextLabelStatus->setText ( tr ( "invalid address" ) );
}
}
}
void CLlconClientDlg::OnOpenGeneralSettings()
{
// open general settings dialog
ClientSettingsDlg.show();
// make sure dialog is upfront and has focus
ClientSettingsDlg.raise();
ClientSettingsDlg.activateWindow();
}
2006-12-10 12:06:14 +01:00
void CLlconClientDlg::OnChatTextReceived ( QString strChatText )
{
ChatDlg.AddChatText ( strChatText );
// if requested, open window
if ( pClient->GetOpenChatOnNewMessage() )
{
ShowChatWindow();
}
}
void CLlconClientDlg::ShowChatWindow()
{
// open chat dialog
ChatDlg.show();
// make sure dialog is upfront and has focus
ChatDlg.raise();
ChatDlg.activateWindow();
}
2006-12-10 12:06:14 +01:00
void CLlconClientDlg::OnFaderTagTextChanged ( const QString& strNewName )
{
// refresh internal name parameter
2008-01-22 22:15:04 +01:00
pClient->strName = strNewName;
2006-12-10 12:06:14 +01:00
// update name at server
pClient->SetRemoteName();
}
void CLlconClientDlg::OnTimerSigMet()
{
// get current input levels
double dCurSigLevelL = pClient->MicLevelL();
2006-12-09 16:00:24 +01:00
double dCurSigLevelR = pClient->MicLevelR();
/* linear transformation of the input level range to the progress-bar
range */
dCurSigLevelL -= LOW_BOUND_SIG_METER;
dCurSigLevelL *= NUM_STEPS_INP_LEV_METER /
( UPPER_BOUND_SIG_METER - LOW_BOUND_SIG_METER );
// lower bound the signal
if ( dCurSigLevelL < 0 )
{
dCurSigLevelL = 0;
}
dCurSigLevelR -= LOW_BOUND_SIG_METER;
dCurSigLevelR *= NUM_STEPS_INP_LEV_METER /
( UPPER_BOUND_SIG_METER - LOW_BOUND_SIG_METER );
// lower bound the signal
if ( dCurSigLevelR < 0 )
{
dCurSigLevelR = 0;
}
// show current level
ProgressBarInputLevelL->setValue ( (int) ceil ( dCurSigLevelL ) );
ProgressBarInputLevelR->setValue ( (int) ceil ( dCurSigLevelR ) );
}
void CLlconClientDlg::UpdateDisplay()
{
// show connection status in status bar
if ( pClient->IsConnected() && pClient->IsRunning() )
{
TextLabelStatus->setText ( tr ( "connected" ) );
}
else
{
TextLabelStatus->setText ( tr ( "disconnected" ) );
}
// TEST
//TextLabelStatus->setText ( QString( "Std dev: %1" ).arg ( pClient->GetTimingStdDev() ) );
2006-01-28 12:29:22 +01:00
}
void CLlconClientDlg::customEvent ( QEvent* Event )
{
if ( Event->type() == QEvent::User + 11 )
{
2007-09-08 12:45:14 +02:00
const int iMessType = ( (CLlconEvent*) Event )->iMessType;
2009-02-13 00:06:41 +01:00
const int iStatus = ( (CLlconEvent*) Event )->iStatus;
switch ( iMessType )
{
case MS_SOUND_IN:
case MS_SOUND_OUT:
case MS_JIT_BUF_PUT:
case MS_JIT_BUF_GET:
// show overall status -> if any LED goes red, this LED will go red
LEDOverallStatus->SetLight ( iStatus );
break;
case MS_RESET_ALL:
LEDOverallStatus->Reset();
break;
2009-02-13 00:06:41 +01:00
case MS_SET_JIT_BUF_SIZE:
pClient->SetSockBufSize ( iStatus );
}
// update general settings dialog, too
ClientSettingsDlg.SetStatus ( iMessType, iStatus );
}
}