Implementing server/client feature

parent 17a5e843
......@@ -29,10 +29,13 @@
RedstartWindow::RedstartWindow( bool bFailSafeMode, bool bAutoStart, QWidget* pParent )
: QMainWindow( pParent )
, ui( new Ui::RedstartWindow )
, m_pCoreInstance( NULL )
, m_pVAInterface( NULL )
{
ui->setupUi( this );
m_pVANetServer = IVANetServer::Create();
m_pVANetClient = IVANetClient::Create();
LoadConfiguration();
if( ( ui->checkBox_redstart_auto_start->isChecked() || bAutoStart ) && !bFailSafeMode )
......@@ -44,6 +47,16 @@ RedstartWindow::RedstartWindow( bool bFailSafeMode, bool bAutoStart, QWidget* pP
RedstartWindow::~RedstartWindow()
{
StoreConfiguration();
if( m_pVANetServer->IsClientConnected() )
{
m_pVANetServer->Finalize();
delete m_pVAInterface;
}
delete m_pVANetServer;
if( m_pVANetClient->IsConnected() )
m_pVANetClient->Disconnect();
delete m_pVANetClient;
}
void RedstartWindow::LoadConfiguration()
......@@ -84,7 +97,7 @@ void RedstartWindow::LoadConfiguration()
ui->checkBox_redstart_network_connect_as_client->setChecked( m_qSettings.value( "Redstart/network/client_mode" ).toBool() );
if( m_qSettings.contains( "Redstart/autostart" ) )
ui->checkBox_redstart_auto_start->setChecked( m_qSettings.value( "Redstart/autostart" ).toBool());
ui->checkBox_redstart_auto_start->setChecked( m_qSettings.value( "Redstart/autostart" ).toBool() );
}
void RedstartWindow::StoreConfiguration()
......@@ -115,38 +128,111 @@ void RedstartWindow::on_actionQuit_triggered()
void RedstartWindow::on_pushButton_start_stop_clicked()
{
ui->pushButton_start_stop->setEnabled( false );
try
{
if( m_pCoreInstance )
if( !ui->checkBox_redstart_network_connect_as_client->isChecked() )
{
if( m_pCoreInstance->GetState() == IVAInterface::VA_CORESTATE_READY )
m_pCoreInstance->Finalize();
if( m_pVAInterface )
{
m_pVANetServer->Finalize();
if( m_pVAInterface->GetState() == IVAInterface::VA_CORESTATE_READY )
m_pVAInterface->Finalize();
delete m_pCoreInstance;
m_pCoreInstance = nullptr;
delete m_pVAInterface;
m_pVAInterface = nullptr;
ui->statusBar->showMessage( "VA core has been stopped." );
PostCoreStop();
ui->statusBar->showMessage( "VA core has been stopped." );
PostCoreStop();
}
else
{
CVAStruct oVAConfigArgs = VACore::GetCoreConfigFromFile( "../VACore/conf/VACore.ini" );
std::string sBackend, sDevice;
// Override configs
switch( ui->comboBox_audio_driver->currentIndex() )
{
case AudioBackend::ASIO:
{
sBackend = "ASIO";
sDevice = ui->comboBox_audio_iface_device->currentText().toStdString();
break;
}
case AudioBackend::PORTAUDIO:
default:
{
sBackend = "Portaudio";
if( ui->checkBox_portaudio_default_device->isChecked() )
sDevice = "default";
else
sDevice = ui->comboBox_audio_iface_device->currentIndex();
}
}
oVAConfigArgs[ "Audio driver" ] = CVAStruct();
oVAConfigArgs[ "Audio driver" ][ "Driver" ] = sBackend;
oVAConfigArgs[ "Audio driver" ][ "Device" ] = sDevice;
oVAConfigArgs[ "Paths" ][ "redstart_data" ] = "../VACore/data";
m_pVAInterface = VACore::CreateCoreInstance( oVAConfigArgs );
m_pVAInterface->Initialize();
// @todo attach event handler
//m_pVAInterface->AttachEventHandler( this );
m_pVANetServer->SetCoreInstance( m_pVAInterface );
bool bOK;
int iPort = ui->lineEdit_redstart_network_port->text().toInt( &bOK );
int iStatus = -1;
if( bOK )
iStatus = m_pVANetServer->Initialize( ui->lineEdit_redstart_network_address->text().toStdString(), iPort );
else
iStatus = m_pVANetServer->Initialize( ui->lineEdit_redstart_network_address->text().toStdString() );
if( m_pVAInterface->GetState() == IVAInterface::VA_CORESTATE_READY && iStatus == IVANetServer::VA_NO_ERROR )
{
ui->statusBar->showMessage( "VA core successfully initialized and network server started." );
PostCoreStart();
}
else
{
ui->statusBar->showMessage( "VA core initialization failed." );
m_pVANetServer->Finalize();
delete m_pVAInterface;
m_pVAInterface = NULL;
}
}
}
else
{
CVAStruct oVAConfigArgs;
m_pCoreInstance = VACore::CreateCoreInstance( "../VACore/conf/VACore.ini" );
m_pCoreInstance->Initialize();
// Client mode
if( m_pVANetClient->IsConnected() )
m_pVANetClient->Disconnect();
if( m_pCoreInstance->GetState() == IVAInterface::VA_CORESTATE_READY )
{
ui->statusBar->showMessage( "VA core successfully initialized" );
m_pVAInterface = NULL;
PostCoreStart();
}
bool bOK;
int iPort = ui->lineEdit_redstart_network_port->text().toInt( &bOK );
int iStatus = -1;
if( bOK )
iStatus = m_pVANetClient->Initialize( ui->lineEdit_redstart_network_address->text().toStdString(), iPort );
else
iStatus = m_pVANetClient->Initialize( ui->lineEdit_redstart_network_address->text().toStdString() );
if( iStatus != IVANetClient::VA_NO_ERROR )
{
ui->statusBar->showMessage( "VA core initialization failed." );
delete m_pCoreInstance;
m_pCoreInstance = NULL;
VA_EXCEPT2( INVALID_PARAMETER, "Could not initialize client, connection failed." );
}
m_pVAInterface = m_pVANetClient->GetCoreInstance();
// @todo attach event handler
//m_pVANetClient->AttachEventHandler( this );
}
}
catch( const CVAException& ex )
......@@ -154,7 +240,6 @@ void RedstartWindow::on_pushButton_start_stop_clicked()
ui->statusBar->showMessage( QString::fromStdString( ex.ToString() ) );
ui->checkBox_redstart_auto_start->setChecked( false );
}
ui->pushButton_start_stop->setEnabled( true );
}
void RedstartWindow::PostCoreStart()
......@@ -162,23 +247,23 @@ void RedstartWindow::PostCoreStart()
ui->pushButton_start_stop->setText( "Stop" );
// Switch UI elements enabled
ui->groupBox_redstart_audio_iface->setEnabled( false );
ui->groupBox_redstart_audio_iface->setEnabled( false );
ui->groupBox_redstart_network->setEnabled( false );
ui->horizontalLayout_redstart_session->setEnabled( false );
ui->horizontalLayout_redstart_session->setEnabled( false );
ui->groupBox_core->setEnabled( true );
ui->groupBox_paths->setEnabled( true );
ui->groupBox_macros->setEnabled( true );
CVAVersionInfo oVersion;
m_pCoreInstance->GetVersionInfo( &oVersion );
m_pVAInterface->GetVersionInfo( &oVersion );
ui->lineEdit_core_settings_version->setText( QString::fromStdString( oVersion.ToString() ) );
CVAStruct oArgs;
oArgs[ "getloglevel" ] = true;
const CVAStruct oReturn = m_pCoreInstance->CallModule( "VACore", oArgs );
const CVAStruct oReturn = m_pVAInterface->CallModule( "VACore", oArgs );
const int iCurrentLogLevel = oReturn[ "loglevel" ];
ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pCoreInstance->GetLogLevelStr( iCurrentLogLevel ) ) );
ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( iCurrentLogLevel ) ) );
}
void RedstartWindow::PostCoreStop()
......@@ -186,9 +271,9 @@ void RedstartWindow::PostCoreStop()
ui->pushButton_start_stop->setText( "Start" );
// Switch UI elements enabled
ui->groupBox_redstart_audio_iface->setEnabled( true );
ui->groupBox_redstart_audio_iface->setEnabled( true );
ui->groupBox_redstart_network->setEnabled( true );
ui->horizontalLayout_redstart_session->setEnabled( true );
ui->horizontalLayout_redstart_session->setEnabled( true );
ui->groupBox_core->setEnabled( false );
ui->groupBox_paths->setEnabled( false );
ui->groupBox_macros->setEnabled( false );
......@@ -216,6 +301,7 @@ void RedstartWindow::AcquireAsioDevices()
{
CAudioDeviceSpecs oDeviceSpecs;
oDeviceSpecs.iDriverNumber = i;
oDeviceSpecs.iBackend = AudioBackend::ASIO;
oDeviceSpecs.sName = ITAsioGetDriverName( i );
try
......@@ -262,9 +348,23 @@ void RedstartWindow::PopulateAsioDevicesFromSettings()
void RedstartWindow::PopulateAudioDevices()
{
ui->comboBox_audio_iface_device->clear();
int iCurrentBackend = ui->comboBox_audio_driver->currentIndex();
for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
{
ui->comboBox_audio_iface_device->addItem( oDevice.sName, QVariant( oDevice.iDriverNumber ) );
if( oDevice.iBackend == iCurrentBackend )
ui->comboBox_audio_iface_device->addItem( oDevice.sName, QVariant( oDevice.iDriverNumber ) );
}
if( ui->comboBox_audio_driver->currentIndex() == AudioBackend::PORTAUDIO )
{
ui->checkBox_portaudio_default_device->setEnabled( true );
if( ui->checkBox_portaudio_default_device->isChecked() )
ui->comboBox_audio_iface_device->setEnabled( false );
}
else
{
ui->checkBox_portaudio_default_device->setEnabled( false );
ui->comboBox_audio_iface_device->setEnabled( true );
}
}
......@@ -305,24 +405,24 @@ void RedstartWindow::on_comboBox_audio_iface_device_currentIndexChanged( int ind
void RedstartWindow::on_actionWebsite_triggered()
{
QUrl urlVAWebsite( "http://www.virtualacoustics.org/work" );
QDesktopServices::openUrl( urlVAWebsite );
QUrl urlVAWebsite( "http://www.virtualacoustics.org/work" );
QDesktopServices::openUrl( urlVAWebsite );
}
void RedstartWindow::on_actionGet_started_triggered()
{
QUrl urlVAWebsiteGetStarted( "http://www.virtualacoustics.org/work/start.html" );
QDesktopServices::openUrl( urlVAWebsiteGetStarted );
QUrl urlVAWebsiteGetStarted( "http://www.virtualacoustics.org/work/start.html" );
QDesktopServices::openUrl( urlVAWebsiteGetStarted );
}
void RedstartWindow::on_actionDocumentation_triggered()
{
QUrl urlVAWebsiteDocumentation( "http://www.virtualacoustics.org/work/documentation.html" );
QDesktopServices::openUrl( urlVAWebsiteDocumentation );
QUrl urlVAWebsiteDocumentation( "http://www.virtualacoustics.org/work/documentation.html" );
QDesktopServices::openUrl( urlVAWebsiteDocumentation );
}
void RedstartWindow::on_actionGet_help_triggered()
{
QUrl urlVAWebsiteGetHelp( "http://www.virtualacoustics.org/work/help.html" );
QDesktopServices::openUrl( urlVAWebsiteGetHelp );
QUrl urlVAWebsiteGetHelp( "http://www.virtualacoustics.org/work/help.html" );
QDesktopServices::openUrl( urlVAWebsiteGetHelp );
}
......@@ -24,6 +24,8 @@
#endif
class IVAInterface;
class IVANetClient;
class IVANetServer;
namespace Ui
{
......@@ -64,6 +66,7 @@ public:
int iNumOutputChannels;
bool bInitializable;
bool bDefaultDevice;
int iBackend;
inline CAudioDeviceSpecs()
{
......@@ -99,7 +102,9 @@ private:
private:
Ui::RedstartWindow* ui;
IVAInterface* m_pCoreInstance;
IVAInterface* m_pVAInterface;
IVANetClient* m_pVANetClient;
IVANetServer* m_pVANetServer;
std::vector< QString > m_vsAudioBackends;
std::vector< CAudioDeviceSpecs > m_voAudioDevices;
......
......@@ -65,8 +65,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1023</width>
<height>661</height>
<width>1025</width>
<height>658</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0,0,0,1">
......@@ -230,13 +230,16 @@ background-color: rgb(254, 228, 255);</string>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0">
<item>
<layout class="QGridLayout" name="gridLayout_Settings_redstart_vaserver_audio_iface" columnstretch="0,1,0" columnminimumwidth="0,1,0">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Driver</string>
<string>Buffer size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_audio_iface_device"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
......@@ -244,38 +247,51 @@ background-color: rgb(254, 228, 255);</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Buffer size</string>
<string>Driver</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_audio_iface_device"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_audio_driver"/>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_audio_iface_sampling_rate"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Sampling rate</string>
</property>
</widget>
</item>
<item row="1" column="2">
<item row="3" column="1">
<widget class="QComboBox" name="comboBox_audio_iface_buffer_size"/>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_refresh">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBox_audio_iface_buffer_size"/>
<item row="1" column="2">
<widget class="QCheckBox" name="checkBox_portaudio_default_device">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Portaudio default device (not available for ASIO backend)</string>
</property>
<property name="text">
<string>default</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment