jamulus/src/clientdlg.cpp

1199 lines
40 KiB
C++
Raw Normal View History

2011-06-16 20:33:48 +02:00
/******************************************************************************\
2013-01-23 11:41:13 +01:00
* Copyright (c) 2004-2013
2011-06-16 20:33:48 +02:00
*
* 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
*
\******************************************************************************/
2013-03-24 11:49:25 +01:00
#include "clientdlg.h"
2011-06-16 20:33:48 +02:00
/* Implementation *************************************************************/
2013-03-24 16:42:23 +01:00
CClientDlg::CClientDlg ( CClient* pNCliP,
CSettings* pNSetP,
const bool bNewConnectOnStartup,
const bool bNewDisalbeLEDs,
const bool bNewShowComplRegConnList,
const bool bShowAnalyzerConsole,
QWidget* parent,
Qt::WindowFlags f ) :
2011-06-16 20:33:48 +02:00
QDialog ( parent, f ),
pClient ( pNCliP ),
pSettings ( pNSetP ),
bUnreadChatMessage ( false ),
ClientSettingsDlg ( pNCliP, parent, Qt::Window ),
ChatDlg ( parent, Qt::Window ),
ConnectDlg ( bNewShowComplRegConnList, parent, Qt::Dialog ),
AnalyzerConsole ( pNCliP, parent, Qt::Window )
2011-06-16 20:33:48 +02:00
{
setupUi ( this );
// Add help text to controls -----------------------------------------------
// input level meter
QString strInpLevH = tr ( "<b>Input Level Meter:</b> The input level "
"indicators show the input level of the two stereo channels "
"of the current selected audio input.<br>"
"Make sure not to clip the input signal to avoid distortions of the "
"audio signal." );
QString strInpLevHTT = tr ( "If the " ) + APP_NAME +
tr ( " software is connected and "
2011-06-16 20:33:48 +02:00
"you play your instrument/sing in the microphone, the LED level "
"meter should flicker. If this is not the case, you have "
"probably selected the wrong input channel (e.g. line in instead "
"of the microphone input) or set the input gain too low in the "
"(Windows) audio mixer.<br>For a proper usage of the " ) + APP_NAME +
tr ( " software, "
2011-06-16 20:33:48 +02:00
"you should not hear your singing/instrument in the loudspeaker or "
"your headphone when the " ) + APP_NAME +
tr ( " software is not connected. This can "
2011-06-16 20:33:48 +02:00
"be achieved by muting your input audio channel in the Playback "
"mixer (<b>not</b> the Recording mixer!)." ) + TOOLTIP_COM_END_TEXT;
QString strInpLevHAccText = tr ( "Input level meter" );
QString strInpLevHAccDescr = tr ( "Simulates an analog LED level meter." );
lblInputLEDMeter->setWhatsThis ( strInpLevH );
lblLevelMeterLeft->setWhatsThis ( strInpLevH );
lblLevelMeterRight->setWhatsThis ( strInpLevH );
lbrInputLevelL->setWhatsThis ( strInpLevH );
lbrInputLevelL->setAccessibleName ( strInpLevHAccText );
lbrInputLevelL->setAccessibleDescription ( strInpLevHAccDescr );
lbrInputLevelL->setToolTip ( strInpLevHTT );
lbrInputLevelR->setWhatsThis ( strInpLevH );
lbrInputLevelR->setAccessibleName ( strInpLevHAccText );
lbrInputLevelR->setAccessibleDescription ( strInpLevHAccDescr );
lbrInputLevelR->setToolTip ( strInpLevHTT );
// connect/disconnect button
butConnect->setWhatsThis ( tr ( "<b>Connect / Disconnect Button:"
"</b> Push this button to connect a server. A dialog where you can "
"select a server will open. If you are connected, pressing this "
"button will end the session." ) );
butConnect->setAccessibleName (
tr ( "Connect and disconnect toggle button" ) );
butConnect->setAccessibleDescription ( tr ( "Clicking on this "
"button changes the caption of the button from Connect to "
"Disconnect, i.e., it implements a toggle functionality for connecting "
2013-02-18 19:20:02 +01:00
"and disconnecting the " ) + APP_NAME + tr ( " software." ) );
2011-06-16 20:33:48 +02:00
// fader tag
QString strFaderTag = tr ( "<b>Your Alias/Instrument:</b> Set your name "
"or an alias here so that the other musicians you want to play with "
"know who you are. Additionally you may set an instrument picture of "
"the instrument you play. "
2011-06-16 20:33:48 +02:00
"What you set here will appear at your fader on the mixer board when "
"you are connected to a " ) + APP_NAME + tr ( " server. This tag will "
"also show up at each client which is connected to the same server as "
"you. If the fader tag is empty, the IP address is shown instead." );
QString strFaderTagTT = tr ( "Set your name and/or instrument and/or "
"pseoudonym here so that the other musicians can identify you." ) +
TOOLTIP_COM_END_TEXT;
lblServerTag->setWhatsThis ( strFaderTag );
lblServerTag->setToolTip ( strFaderTagTT );
edtFaderTag->setWhatsThis ( strFaderTag );
edtFaderTag->setToolTip ( strFaderTagTT );
edtFaderTag->setAccessibleName ( tr ( "Fader tag edit box" ) );
butInstPicture->setWhatsThis ( strFaderTag );
butInstPicture->setToolTip ( strFaderTagTT );
butInstPicture->setAccessibleName ( tr ( "Instrument picture button" ) );
2011-06-16 20:33:48 +02:00
// local audio input fader
QString strAudFader = tr ( "<b>Local Audio Input Fader:</b> With the "
"audio fader, the relative levels of the left and right local audio "
"channels can be changed. For a mono signal it acts like a panning "
"between the two channels. If, e.g., a microphone is connected to "
"the right input channel and an instrument is connected to the left "
"input channel which is much louder than the microphone, move the "
"audio fader in a direction where the label above the fader shows "
2011-06-17 00:04:58 +02:00
"<i>L -x</i>, where <i>x</i> is the current attenuation indicator." );
2011-06-16 20:33:48 +02:00
lblAudioPan->setWhatsThis ( strAudFader );
lblAudioPanValue->setWhatsThis ( strAudFader );
sldAudioPan->setWhatsThis ( strAudFader );
sldAudioPan->setAccessibleName ( tr ( "Local audio input fader (left/right)" ) );
// reverberation level
QString strAudReverb = tr ( "<b>Reverberation Level:</b> A reverberation "
"effect can be applied to one local mono audio channel or to both "
"channels in stereo mode. The mone channel selection and the "
"reverberation level can be modified. If, e.g., "
"the microphone signal is fed into the right audio channel of the "
"sound card and a reverberation effect shall be applied, set the "
"channel selector to right and move the fader upwards until the "
"desired reverberation level is reached.<br>"
"The reverberation effect requires significant CPU so that it should "
"only be used on fast PCs. If the reverberation level fader is set to "
"minimum (which is the default setting), the reverberation effect is "
"switched off and does not cause any additional CPU usage." );
lblAudioReverb->setWhatsThis ( strAudReverb );
sldAudioReverb->setWhatsThis ( strAudReverb );
sldAudioReverb->setAccessibleName ( tr ( "Reverberation effect level setting" ) );
// reverberation channel selection
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." );
rbtReverbSelL->setWhatsThis ( strRevChanSel );
rbtReverbSelL->setAccessibleName ( tr ( "Left channel selection for reverberation" ) );
rbtReverbSelR->setWhatsThis ( strRevChanSel );
rbtReverbSelR->setAccessibleName ( tr ( "Right channel selection for reverberation" ) );
// connection LED
QString strLEDConnection = tr ( "<b>Connection Status LED:</b> "
"The connection status LED indicator shows the current connection "
"status. If the light is green, a successful connection to the "
"server is established. If the light blinks red right after "
"pressing the connect button, the server address is invalid. "
"If the light turns red and stays red, the connection to the "
"server is lost." );
lblConnection->setWhatsThis ( strLEDConnection );
ledConnection->setWhatsThis ( strLEDConnection );
ledConnection->setAccessibleName ( tr ( "Connection status LED indicator" ) );
// delay LED
QString strLEDDelay = tr ( "<b>Delay Status LED:</b> "
"The delay status LED indicator shows the current audio delay "
"status. If the light is green, the delay is perfect for a jam "
"session. If the ligth is yellow, a session is still possible but "
"it may be harder to play. If the light is red, the delay is too "
"large for jamming." );
lblDelay->setWhatsThis ( strLEDDelay );
ledDelay->setWhatsThis ( strLEDDelay );
ledDelay->setToolTip ( tr ( "If this LED indicator turns red, "
"you will not have much fun using the " ) + APP_NAME +
tr ( " software." ) + TOOLTIP_COM_END_TEXT );
2011-06-16 20:33:48 +02:00
ledDelay->setAccessibleName ( tr ( "Delay status LED indicator" ) );
// buffers LED
QString strLEDBuffers = tr ( "<b>Buffers Status LED:</b> "
"The buffers status LED indicator shows the current audio/streaming "
"status. If the light is green, there are no buffer overruns/underruns "
"and the audio stream is not interrupted. If the light is red, the "
"audio stream is interrupted caused by one of the following problems:"
"<ul>"
"<li>The network jitter buffer is not large enough for the current "
"network/audio interface jitter.</li>"
"<li>The sound card buffer delay (buffer size) is set to a too small "
"value.</li>"
"<li>The upload or download stream rate is too high for the current "
"available internet bandwidth.</li>"
"<li>The CPU of the client or server is at 100%.</li>"
"</ul>" );
lblBuffers->setWhatsThis ( strLEDBuffers );
ledBuffers->setWhatsThis ( strLEDBuffers );
ledBuffers->setAccessibleName ( tr ( "Buffers status LED indicator" ) );
// chat LED
QString strLEDChat = tr ( "<b>Chat Status LED:</b> "
"If the option Open Chat on New Message is not activated, this "
"status LED will turn green on a new received chat message." );
lblChat->setWhatsThis ( strLEDChat );
ledChat->setWhatsThis ( strLEDChat );
ledBuffers->setAccessibleName ( tr ( "Chat status LED indicator" ) );
// init GUI design
SetGUIDesign ( pClient->GetGUIDesign() );
// reset mixer board
MainMixerBoard->HideAll();
// restore fader settings
MainMixerBoard->vecStoredFaderTags = pClient->vecStoredFaderTags;
MainMixerBoard->vecStoredFaderLevels = pClient->vecStoredFaderLevels;
// init fader tag line edit and instrument picture
edtFaderTag->setText ( pClient->ChannelInfo.strName );
butInstPicture->setIcon ( QIcon (
CInstPictures::GetResourceReference ( pClient->ChannelInfo.iInstrument ) ) );
2011-06-16 20:33:48 +02:00
// init status label
OnTimerStatus();
// init connection button text
butConnect->setText ( CON_BUT_CONNECTTEXT );
// init input level meter bars
lbrInputLevelL->setValue ( 0 );
lbrInputLevelR->setValue ( 0 );
// init status LEDs
ledConnection->SetUpdateTime ( 2 * LED_BAR_UPDATE_TIME_MS );
ledChat->SetUpdateTime ( 2 * LED_BAR_UPDATE_TIME_MS );
ledDelay->SetUpdateTime ( 2 * PING_UPDATE_TIME_MS );
ledDelay->Reset();
// init slider controls ---
// audio in fader
sldAudioPan->setRange ( AUD_FADER_IN_MIN, AUD_FADER_IN_MAX );
sldAudioPan->setTickInterval ( AUD_FADER_IN_MAX / 5 );
UpdateAudioFaderSlider();
// audio reverberation
sldAudioReverb->setRange ( 0, AUD_REVERB_MAX );
const int iCurAudReverb = pClient->GetReverbLevel();
sldAudioReverb->setValue ( iCurAudReverb );
sldAudioReverb->setTickInterval ( AUD_REVERB_MAX / 5 );
// init reverb channel
UpdateRevSelection();
2013-02-17 22:26:29 +01:00
// set window title (with no clients connected -> "0")
SetMyWindowTitle ( 0 );
2011-06-16 20:33:48 +02:00
// Connect on startup ------------------------------------------------------
2011-06-16 20:33:48 +02:00
if ( bNewConnectOnStartup )
{
// per definition use the last connection (first entry in the
// stored address list)
const QString strSelectedAddress = pClient->vstrIPAddress[0];
// only if address is not empty, start the client
if ( !strSelectedAddress.isEmpty() )
{
// initiate connection (always show the address in the mixer board
// (no alias))
Connect ( strSelectedAddress, strSelectedAddress );
}
2011-06-16 20:33:48 +02:00
}
// Disable controls on request ---------------------------------------------
2011-06-16 20:33:48 +02:00
// disable LEDs in main window if requested
if ( bNewDisalbeLEDs )
{
lbrInputLevelL->setEnabled ( false );
lbrInputLevelR->setEnabled ( false );
ledConnection->setEnabled ( false );
ledBuffers->setEnabled ( false );
ledDelay->setEnabled ( false );
ledChat->setEnabled ( false );
butConnect->setFocus();
}
// Mac Workaround:
// If the connect button is the default button, on Mac it is highlighted
// by fading in and out a blue backgroud color. This operation consumes so
// much CPU that we get audio interruptions.
// Better solution: increase thread priority of worker thread (since the
// user can always highlight the button manually, too) -> TODO
#if defined ( __APPLE__ ) || defined ( __MACOSX )
butConnect->setDefault ( false );
#endif
// View menu --------------------------------------------------------------
pViewMenu = new QMenu ( "&View", this );
pViewMenu->addAction ( tr ( "&Connection Setup..." ), this,
SLOT ( OnOpenConnectionSetupDialog() ) );
pViewMenu->addAction ( tr ( "C&hat..." ), this,
2011-06-16 20:33:48 +02:00
SLOT ( OnOpenChatDialog() ) );
pViewMenu->addAction ( tr ( "&General Settings..." ), this,
SLOT ( OnOpenGeneralSettings() ) );
// optionally show analyzer console entry
if ( bShowAnalyzerConsole )
{
pViewMenu->addAction ( tr ( "&Analyzer Console..." ), this,
SLOT ( OnOpenAnalyzerConsole() ) );
}
2011-06-16 20:33:48 +02:00
pViewMenu->addSeparator();
pViewMenu->addAction ( tr ( "E&xit" ), this,
SLOT ( close() ), QKeySequence ( Qt::CTRL + Qt::Key_Q ) );
// Main menu bar -----------------------------------------------------------
pMenu = new QMenuBar ( this );
pMenu->addMenu ( pViewMenu );
2013-03-24 16:42:23 +01:00
pMenu->addMenu ( new CHelpMenu ( this ) );
2011-06-16 20:33:48 +02:00
// Now tell the layout about the menu
layout()->setMenuBar ( pMenu );
// Instrument pictures popup menu ------------------------------------------
pInstrPictPopupMenu = new QMenu ( this );
// add an entry for all known instruments
for ( int iCurInst = 0; iCurInst < CInstPictures::GetNumAvailableInst(); iCurInst++ )
{
// create a menu action with text and image
QAction* pCurAction = new QAction (
QIcon ( CInstPictures::GetResourceReference ( iCurInst ) ),
CInstPictures::GetName ( iCurInst ),
this );
// add data to identify the action data when it is triggered
pCurAction->setData ( iCurInst );
pInstrPictPopupMenu->addAction ( pCurAction );
}
// Window positions --------------------------------------------------------
// main window
if ( !pClient->vecWindowPosMain.isEmpty() && !pClient->vecWindowPosMain.isNull() )
{
restoreGeometry ( pClient->vecWindowPosMain );
}
// settings window
if ( !pClient->vecWindowPosSettings.isEmpty() && !pClient->vecWindowPosSettings.isNull() )
{
ClientSettingsDlg.restoreGeometry ( pClient->vecWindowPosSettings );
}
if ( pClient->bWindowWasShownSettings )
{
ShowGeneralSettings();
}
// chat window
if ( !pClient->vecWindowPosChat.isEmpty() && !pClient->vecWindowPosChat.isNull() )
{
ChatDlg.restoreGeometry ( pClient->vecWindowPosChat );
}
if ( pClient->bWindowWasShownChat )
{
ShowChatWindow();
}
// connection setup window
if ( !pClient->vecWindowPosConnect.isEmpty() && !pClient->vecWindowPosConnect.isNull() )
{
ConnectDlg.restoreGeometry ( pClient->vecWindowPosConnect );
}
if ( pClient->bWindowWasShownConnect )
{
ShowConnectionSetupDialog();
}
2011-06-16 20:33:48 +02:00
// Connections -------------------------------------------------------------
// push buttons
QObject::connect ( butConnect, SIGNAL ( clicked() ),
this, SLOT ( OnConnectDisconBut() ) );
QObject::connect ( butInstPicture, SIGNAL ( clicked() ),
this, SLOT ( OnInstPictureBut() ) );
2011-06-16 20:33:48 +02:00
// check boxes
QObject::connect ( chbSettings, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnSettingsStateChanged ( int ) ) );
QObject::connect ( chbChat, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnChatStateChanged ( int ) ) );
// timers
QObject::connect ( &TimerSigMet, SIGNAL ( timeout() ),
this, SLOT ( OnTimerSigMet() ) );
QObject::connect ( &TimerStatus, SIGNAL ( timeout() ),
this, SLOT ( OnTimerStatus() ) );
QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPing() ) );
// sliders
QObject::connect ( sldAudioPan, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnAudioPanValueChanged ( int ) ) );
QObject::connect ( sldAudioReverb, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnAudioReverbValueChanged ( int ) ) );
// radio buttons
QObject::connect ( rbtReverbSelL, SIGNAL ( clicked() ),
this, SLOT ( OnReverbSelLClicked() ) );
QObject::connect ( rbtReverbSelR, SIGNAL ( clicked() ),
this, SLOT ( OnReverbSelRClicked() ) );
// line edits
QObject::connect ( edtFaderTag, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnFaderTagTextChanged ( const QString& ) ) );
// menus
QObject::connect ( pInstrPictPopupMenu, SIGNAL ( triggered ( QAction* ) ),
this, SLOT ( OnInstPicturesMenuTriggered ( QAction* ) ) );
2011-06-16 20:33:48 +02:00
// other
QObject::connect ( pClient,
SIGNAL ( ConClientListNameMesReceived ( CVector<CChannelInfo> ) ),
this, SLOT ( OnConClientListMesReceived ( CVector<CChannelInfo> ) ) );
QObject::connect ( pClient,
SIGNAL ( ConClientListMesReceived ( CVector<CChannelInfo> ) ),
this, SLOT ( OnConClientListMesReceived ( CVector<CChannelInfo> ) ) );
2011-06-16 20:33:48 +02:00
QObject::connect ( pClient,
SIGNAL ( Disconnected() ),
this, SLOT ( OnDisconnected() ) );
QObject::connect ( pClient,
SIGNAL ( ChatTextReceived ( QString ) ),
this, SLOT ( OnChatTextReceived ( QString ) ) );
QObject::connect ( pClient, SIGNAL ( PingTimeReceived ( int ) ),
this, SLOT ( OnPingTimeResult ( int ) ) );
QObject::connect ( pClient,
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ),
this, SLOT ( OnCLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ) );
QObject::connect ( pClient,
SIGNAL ( CLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ),
this, SLOT ( OnCLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ) );
QObject::connect ( pClient,
SIGNAL ( UpstreamRateChanged() ),
this, SLOT ( OnUpstreamRateChanged() ) );
2011-06-16 20:33:48 +02:00
QObject::connect ( QCoreApplication::instance(), SIGNAL ( aboutToQuit() ),
this, SLOT ( OnAboutToQuit() ) );
QObject::connect ( &ClientSettingsDlg, SIGNAL ( GUIDesignChanged() ),
this, SLOT ( OnGUIDesignChanged() ) );
QObject::connect ( &ClientSettingsDlg, SIGNAL ( StereoCheckBoxChanged() ),
this, SLOT ( OnStereoCheckBoxChanged() ) );
QObject::connect ( MainMixerBoard, SIGNAL ( ChangeChanGain ( int, double ) ),
this, SLOT ( OnChangeChanGain ( int, double ) ) );
QObject::connect ( MainMixerBoard, SIGNAL ( NumClientsChanged ( int ) ),
this, SLOT ( OnNumClientsChanged ( int ) ) );
QObject::connect ( &ChatDlg, SIGNAL ( NewLocalInputText ( QString ) ),
this, SLOT ( OnNewLocalInputText ( QString ) ) );
QObject::connect ( &ConnectDlg, SIGNAL ( ReqServerListQuery ( CHostAddress ) ),
this, SLOT ( OnReqServerListQuery ( CHostAddress ) ) );
QObject::connect ( &ConnectDlg, SIGNAL ( CreateCLServerListPingMes ( CHostAddress ) ),
this, SLOT ( OnCreateCLServerListPingMes ( CHostAddress ) ) );
QObject::connect ( &ConnectDlg, SIGNAL ( accepted() ),
this, SLOT ( OnConnectDlgAccepted() ) );
2011-06-16 20:33:48 +02:00
// Timers ------------------------------------------------------------------
// start timer for status bar
TimerStatus.start ( LED_BAR_UPDATE_TIME_MS );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::closeEvent ( QCloseEvent* Event )
2011-06-16 20:33:48 +02:00
{
// store window positions
pClient->vecWindowPosMain = saveGeometry();
pClient->vecWindowPosSettings = ClientSettingsDlg.saveGeometry();
pClient->vecWindowPosChat = ChatDlg.saveGeometry();
pClient->vecWindowPosConnect = ConnectDlg.saveGeometry();
pClient->bWindowWasShownSettings = ClientSettingsDlg.isVisible();
pClient->bWindowWasShownChat = ChatDlg.isVisible();
pClient->bWindowWasShownConnect = ConnectDlg.isVisible();
2011-06-16 20:33:48 +02:00
// if settings/connect dialog or chat dialog is open, close it
ClientSettingsDlg.close();
ChatDlg.close();
ConnectDlg.close();
AnalyzerConsole.close();
2011-06-16 20:33:48 +02:00
// if connected, terminate connection
if ( pClient->IsRunning() )
{
pClient->Stop();
}
// store fader tag
pClient->ChannelInfo.strName = edtFaderTag->text();
2011-06-16 20:33:48 +02:00
// store mixer fader settings (we have to hide all mixer faders first to
// initiate a storage of the current mixer fader levels in case we are
// just in a connected state)
MainMixerBoard->HideAll();
pClient->vecStoredFaderTags = MainMixerBoard->vecStoredFaderTags;
pClient->vecStoredFaderLevels = MainMixerBoard->vecStoredFaderLevels;
2011-06-16 20:33:48 +02:00
// default implementation of this event handler routine
Event->accept();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::UpdateAudioFaderSlider()
2011-06-16 20:33:48 +02:00
{
// update slider and label of audio fader
const int iCurAudInFader = pClient->GetAudioInFader();
sldAudioPan->setValue ( iCurAudInFader );
// show in label the center position and what channel is
// attenuated
if ( iCurAudInFader == AUD_FADER_IN_MIDDLE )
{
lblAudioPanValue->setText ( "Center" );
}
else
{
if ( iCurAudInFader > AUD_FADER_IN_MIDDLE )
{
// attenuation on right channel
lblAudioPanValue->setText ( "R -" +
QString().setNum ( iCurAudInFader - AUD_FADER_IN_MIDDLE ) );
}
else
{
// attenuation on left channel
lblAudioPanValue->setText ( "L -" +
QString().setNum ( AUD_FADER_IN_MIDDLE - iCurAudInFader ) );
}
}
}
2013-03-24 16:42:23 +01:00
void CClientDlg::UpdateRevSelection()
2011-06-16 20:33:48 +02:00
{
if ( pClient->GetUseStereo() )
{
// for stereo make channel selection invisible since
// reverberation effect is always applied to both channels
rbtReverbSelL->setVisible ( false );
rbtReverbSelR->setVisible ( false );
}
else
{
// make radio buttons visible
rbtReverbSelL->setVisible ( true );
rbtReverbSelR->setVisible ( true );
// update value
if ( pClient->IsReverbOnLeftChan() )
{
rbtReverbSelL->setChecked ( true );
}
else
{
rbtReverbSelR->setChecked ( true );
}
}
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnAudioPanValueChanged ( int value )
2011-06-16 20:33:48 +02:00
{
pClient->SetAudioInFader ( value );
UpdateAudioFaderSlider();
}
void CClientDlg::OnConnectDlgAccepted()
{
// get the address from the connect dialog
const QString strSelectedAddress = ConnectDlg.GetSelectedAddress();
// only store new host address in our data base if the address is
// not empty and it was not a server list item (only the addresses
// typed in manually are stored by definition)
if ( !strSelectedAddress.isEmpty() &&
!ConnectDlg.GetServerListItemWasChosen() )
{
// store new address at the top of the list, if the list was already
// full, the last element is thrown out
pClient->vstrIPAddress.StringFiFoWithCompare ( strSelectedAddress );
}
// get name to be set in audio mixer group box title
QString strMixerBoardLabel;
if ( ConnectDlg.GetServerListItemWasChosen() )
{
// in case a server in the server list was chosen,
// display the server name of the server list
strMixerBoardLabel = ConnectDlg.GetSelectedServerName();
}
else
{
// an item of the server address combo box was chosen,
// just show the address string as it was entered by the
// user
strMixerBoardLabel = strSelectedAddress;
}
// first check if we are already connected, if this is the case we have to
// disconnect the old server first
if ( pClient->IsRunning() )
{
Disconnect();
}
// initiate connection
Connect ( strSelectedAddress, strMixerBoardLabel );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnConnectDisconBut()
2011-06-16 20:33:48 +02:00
{
// the connect/disconnect button implements a toggle functionality
if ( pClient->IsRunning() )
{
Disconnect();
}
else
{
ShowConnectionSetupDialog();
}
}
void CClientDlg::OnDisconnected()
{
// channel is now disconnected, clear mixer board (remove all faders)
MainMixerBoard->HideAll();
UpdateDisplay();
2011-06-16 20:33:48 +02:00
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnInstPictureBut()
{
// open a menu which shows all available instrument pictures which
// always appears at the same position relative to the instrument
// picture button
pInstrPictPopupMenu->exec ( this->mapToGlobal ( butInstPicture->pos() ) );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnInstPicturesMenuTriggered ( QAction* SelAction )
{
// get selected instrument
const int iSelInstrument = SelAction->data().toInt();
// set the new value in the data base
pClient->ChannelInfo.iInstrument = iSelInstrument;
// update channel info at the server
pClient->SetRemoteInfo();
// update icon on the instrument selection button
butInstPicture->setIcon ( QIcon (
CInstPictures::GetResourceReference ( iSelInstrument ) ) );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnChatTextReceived ( QString strChatText )
2011-06-16 20:33:48 +02:00
{
// init flag (will maybe overwritten later in this function)
bUnreadChatMessage = false;
ChatDlg.AddChatText ( strChatText );
// if requested, open window
if ( pClient->GetOpenChatOnNewMessage() )
{
ShowChatWindow();
}
else
{
if ( !ChatDlg.isVisible() )
{
bUnreadChatMessage = true;
}
}
UpdateDisplay();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo )
2011-06-16 20:33:48 +02:00
{
// update mixer board with the additional client infos
2011-06-16 20:33:48 +02:00
MainMixerBoard->ApplyNewConClientList ( vecChanInfo );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnNumClientsChanged ( int iNewNumClients )
2011-06-16 20:33:48 +02:00
{
// update window title
SetMyWindowTitle ( iNewNumClients );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::SetMyWindowTitle ( const int iNumClients )
2011-06-16 20:33:48 +02:00
{
// show number of connected clients in window title (and therefore also in
// the task bar of the OS)
if ( iNumClients == 0 )
{
// only application name
setWindowTitle ( APP_NAME );
}
else
{
if ( iNumClients == 1 )
{
setWindowTitle ( QString ( APP_NAME ) + " (1 user)" );
}
else
{
setWindowTitle ( QString ( APP_NAME ) +
QString ( " (%1 users)" ).arg ( iNumClients ) );
}
}
}
void CClientDlg::ShowConnectionSetupDialog()
{
// get the central server address string
const QString strCurCentServAddr =
SELECT_SERVER_ADDRESS ( pClient->GetUseDefaultCentralServerAddress(),
pClient->GetServerListCentralServerAddress() );
// init the connect dialog
ConnectDlg.Init ( strCurCentServAddr, pClient->vstrIPAddress );
// show connect dialog
ConnectDlg.show();
// make sure dialog is upfront and has focus
ConnectDlg.raise();
ConnectDlg.activateWindow();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::ShowGeneralSettings()
2011-06-16 20:33:48 +02:00
{
// open general settings dialog
ClientSettingsDlg.show();
// make sure dialog is upfront and has focus
ClientSettingsDlg.raise();
ClientSettingsDlg.activateWindow();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::ShowChatWindow()
2011-06-16 20:33:48 +02:00
{
// open chat dialog
ChatDlg.show();
// make sure dialog is upfront and has focus
ChatDlg.raise();
ChatDlg.activateWindow();
// chat dialog is opened, reset unread message flag
bUnreadChatMessage = false;
UpdateDisplay();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::ShowAnalyzerConsole()
{
// open analyzer console dialog
AnalyzerConsole.show();
// make sure dialog is upfront and has focus
AnalyzerConsole.raise();
AnalyzerConsole.activateWindow();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnSettingsStateChanged ( int value )
2011-06-16 20:33:48 +02:00
{
if ( value == Qt::Checked )
{
ShowGeneralSettings();
}
else
{
ClientSettingsDlg.hide();
}
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnChatStateChanged ( int value )
2011-06-16 20:33:48 +02:00
{
if ( value == Qt::Checked )
{
ShowChatWindow();
}
else
{
ChatDlg.hide();
}
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnFaderTagTextChanged ( const QString& strNewName )
2011-06-16 20:33:48 +02:00
{
// check length
if ( strNewName.length() <= MAX_LEN_FADER_TAG )
{
// refresh internal name parameter
pClient->ChannelInfo.strName = strNewName;
2011-06-16 20:33:48 +02:00
// update channel info at the server
pClient->SetRemoteInfo();
2011-06-16 20:33:48 +02:00
}
else
{
// text is too long, update control with shortend text
edtFaderTag->setText ( strNewName.left ( MAX_LEN_FADER_TAG ) );
}
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnTimerSigMet()
2011-06-16 20:33:48 +02:00
{
// get current input levels
double dCurSigLevelL = pClient->MicLevelL();
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
lbrInputLevelL->setValue ( (int) ceil ( dCurSigLevelL ) );
lbrInputLevelR->setValue ( (int) ceil ( dCurSigLevelR ) );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnTimerPing()
2011-06-16 20:33:48 +02:00
{
// send ping message to the server
pClient->CreateCLPingMes();
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnPingTimeResult ( int iPingTime )
2011-06-16 20:33:48 +02:00
{
// calculate overall delay
const int iOverallDelayMs = pClient->EstimatedOverallDelay ( iPingTime );
// color definition: <= 40 ms green, <= 65 ms yellow, otherwise red
int iOverallDelayLEDColor;
if ( iOverallDelayMs <= 40 )
{
iOverallDelayLEDColor = MUL_COL_LED_GREEN;
}
else
{
if ( iOverallDelayMs <= 65 )
{
iOverallDelayLEDColor = MUL_COL_LED_YELLOW;
}
else
{
iOverallDelayLEDColor = MUL_COL_LED_RED;
}
}
// only update delay information on settings dialog if it is visible to
// avoid CPU load on working thread if not necessary
if ( ClientSettingsDlg.isVisible() )
{
// set ping time result to general settings dialog
ClientSettingsDlg.SetPingTimeResult ( iPingTime,
iOverallDelayMs,
iOverallDelayLEDColor );
}
// update delay LED on the main window
ledDelay->SetLight ( iOverallDelayLEDColor );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
int iPingTime,
int iNumClients )
2011-06-16 20:33:48 +02:00
{
// color definition: <= 25 ms green, <= 50 ms yellow, otherwise red
int iPingTimeLEDColor;
if ( iPingTime <= 25 )
{
iPingTimeLEDColor = MUL_COL_LED_GREEN;
}
else
{
if ( iPingTime <= 50 )
{
iPingTimeLEDColor = MUL_COL_LED_YELLOW;
}
else
{
iPingTimeLEDColor = MUL_COL_LED_RED;
}
}
// update connection dialog server list
ConnectDlg.SetPingTimeAndNumClientsResult ( InetAddr,
iPingTime,
iPingTimeLEDColor,
iNumClients );
}
void CClientDlg::Connect ( const QString& strSelectedAddress,
const QString& strMixerBoardLabel )
2011-06-16 20:33:48 +02:00
{
// set address and check if address is valid
if ( pClient->SetServerAddr ( strSelectedAddress ) )
2011-06-16 20:33:48 +02:00
{
// try to start client, if error occurred, do not go in
// running state but show error message
try
{
pClient->Start();
}
2011-06-16 20:33:48 +02:00
catch ( CGenErr generr )
2011-06-16 20:33:48 +02:00
{
// show error message and return the function
QMessageBox::critical (
this, APP_NAME, generr.GetErrorText(), "Close", 0 );
2011-06-16 20:33:48 +02:00
return;
}
// change connect button text to "disconnect"
butConnect->setText ( CON_BUT_DISCONNECTTEXT );
2011-06-16 20:33:48 +02:00
// set server name in audio mixer group box title
MainMixerBoard->SetServerName ( strMixerBoardLabel );
2011-06-16 20:33:48 +02:00
// start timer for level meter bar and ping time measurement
TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
TimerPing.start ( PING_UPDATE_TIME_MS );
2011-06-16 20:33:48 +02:00
}
else
{
// show the error as red light
ledConnection->SetLight ( MUL_COL_LED_RED );
}
}
void CClientDlg::Disconnect()
{
// only stop client if currently running, in case we received
// the stopped message, the client is already stopped but the
// connect/disconnect button and other GUI controls must be
// updated
if ( pClient->IsRunning() )
{
pClient->Stop();
}
2011-06-16 20:33:48 +02:00
// change connect button text to "connect"
butConnect->setText ( CON_BUT_CONNECTTEXT );
2011-06-16 20:33:48 +02:00
// reset server name in audio mixer group box title
MainMixerBoard->SetServerName ( "" );
2011-06-16 20:33:48 +02:00
// stop timer for level meter bars and reset them
TimerSigMet.stop();
lbrInputLevelL->setValue ( 0 );
lbrInputLevelR->setValue ( 0 );
2011-06-16 20:33:48 +02:00
// stop ping time measurement timer
TimerPing.stop();
2011-06-16 20:33:48 +02:00
// TODO is this still required???
// immediately update status bar
OnTimerStatus();
// TODO this seems not to work, LEDs are still updated afterwards...
// reset LEDs
ledConnection->Reset();
ledBuffers->Reset();
ledDelay->Reset();
ledChat->Reset();
// clear mixer board (remove all faders)
MainMixerBoard->HideAll();
2011-06-16 20:33:48 +02:00
}
2013-03-24 16:42:23 +01:00
void CClientDlg::UpdateDisplay()
2011-06-16 20:33:48 +02:00
{
// update status LEDs
if ( pClient->IsRunning() )
{
if ( pClient->IsConnected() )
{
// chat LED
if ( bUnreadChatMessage )
{
ledChat->SetLight ( MUL_COL_LED_GREEN );
}
else
{
ledChat->Reset();
}
// connection LED
ledConnection->SetLight ( MUL_COL_LED_GREEN );
}
else
{
// connection LED
ledConnection->SetLight ( MUL_COL_LED_RED );
}
}
// update settings/chat buttons (do not fire signals since it is an update)
if ( chbSettings->isChecked() && !ClientSettingsDlg.isVisible() )
{
chbSettings->blockSignals ( true );
chbSettings->setChecked ( false );
chbSettings->blockSignals ( false );
}
if ( !chbSettings->isChecked() && ClientSettingsDlg.isVisible() )
{
chbSettings->blockSignals ( true );
chbSettings->setChecked ( true );
chbSettings->blockSignals ( false );
}
if ( chbChat->isChecked() && !ChatDlg.isVisible() )
{
chbChat->blockSignals ( true );
chbChat->setChecked ( false );
chbChat->blockSignals ( false );
}
if ( !chbChat->isChecked() && ChatDlg.isVisible() )
{
chbChat->blockSignals ( true );
chbChat->setChecked ( true );
chbChat->blockSignals ( false );
}
}
2013-03-24 16:42:23 +01:00
void CClientDlg::SetGUIDesign ( const EGUIDesign eNewDesign )
2011-06-16 20:33:48 +02:00
{
// apply GUI design to current window
switch ( eNewDesign )
{
case GD_ORIGINAL:
backgroundFrame->setStyleSheet (
"QFrame#backgroundFrame { border-image: url(:/png/fader/res/mixerboardbackground.png) 34px 30px 40px 40px;"
" border-top: 34px transparent;"
" border-bottom: 40px transparent;"
" border-left: 30px transparent;"
" border-right: 40px transparent;"
" padding: -5px;"
" margin: -5px, -5px, 0px, 0px; }"
"QLabel { color: rgb(148, 148, 148);"
" font: bold; }"
"QRadioButton { color: rgb(148, 148, 148);"
" font: bold; }"
"QGroupBox::title { color: rgb(148, 148, 148); }"
"QCheckBox::indicator { width: 38px;"
" height: 21px; }"
"QCheckBox::indicator:unchecked {"
" image: url(:/png/fader/res/ledbuttonnotpressed.png); }"
"QCheckBox::indicator:checked {"
" image: url(:/png/fader/res/ledbuttonpressed.png); }"
"QCheckBox { color: rgb(148, 148, 148);"
" font: bold; }" );
#ifdef _WIN32
// Workaround QT-Windows problem: This should not be necessary since in the
// background frame the style sheet for QRadioButton was already set. But it
// seems that it is only applied if the style was set to default and then back
// to GD_ORIGINAL. This seems to be a QT related issue...
rbtReverbSelL->setStyleSheet ( "color: rgb(148, 148, 148);"
"font: bold;" );
rbtReverbSelR->setStyleSheet ( "color: rgb(148, 148, 148);"
"font: bold;" );
#endif
break;
default:
// reset style sheet and set original paramters
backgroundFrame->setStyleSheet ( "" );
#ifdef _WIN32
// Workaround QT-Windows problem: See above description
rbtReverbSelL->setStyleSheet ( "" );
rbtReverbSelR->setStyleSheet ( "" );
#endif
break;
}
// also apply GUI design to child GUI controls
MainMixerBoard->SetGUIDesign ( eNewDesign );
}
2013-03-24 16:42:23 +01:00
void CClientDlg::customEvent ( QEvent* Event )
2011-06-16 20:33:48 +02:00
{
if ( Event->type() == QEvent::User + 11 )
{
2013-03-24 16:42:23 +01:00
const int iMessType = ( (CCustomEvent*) Event )->iMessType;
const int iStatus = ( (CCustomEvent*) Event )->iStatus;
2011-06-16 20:33:48 +02:00
switch ( iMessType )
{
case MS_JIT_BUF_PUT:
case MS_JIT_BUF_GET:
// buffer status -> if any buffer goes red, this LED will go red
ledBuffers->SetLight ( iStatus );
break;
case MS_RESET_ALL:
ledConnection->Reset();
ledBuffers->Reset();
ledDelay->Reset();
ledChat->Reset();
break;
}
// update general settings dialog, too
ClientSettingsDlg.SetStatus ( iMessType, iStatus );
}
}