RedstartWindow.cpp 19.7 KB
Newer Older
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 *  --------------------------------------------------------------------------------------------
 *
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
 *       VVV  VVV     AAA        Copyright 2015-2017
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
 *
 *  --------------------------------------------------------------------------------------------
 */

14
#include <QErrorMessage>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
15
#include <QUrl>
16
17
#include <QDesktopServices>
#include <QHash>
Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
18
#include <QShortcut>
19

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
20
21
22
#include "RedstartWindow.h"
#include <ui_RedstartWindow.h>

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
23
24
#include "RedstartRunSimpleExample.h"
#include "RedstartSessionBinauralHeadphonesDialog.h"
25
#include "RedstartSessionExperimentalTalkthroughDialog.h"
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
26
27
#include "RedstartUtils.h"

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
28
29
30
31
#include <VA.h>
#include <VACore.h>
#include <VANet.h>

32
#include <ITAAsioInterface.h>
33
#include <ITAPortaudioInterface.h>
34
35
36
#include <ITAException.h>


37
RedstartWindow::RedstartWindow( bool bFailSafeMode, bool bAutoStart, bool bSkipConfig, QWidget* pParent )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
38
39
	: QMainWindow( pParent )
	, ui( new Ui::RedstartWindow )
40
	, m_pVAInterface( NULL )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
41
42
43
{
	ui->setupUi( this );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
44
45
	ui->statusBar->showMessage( "Welcome to VA." );

Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
46
47
48
49
50
51
52
53
54
55
56
	// Shortcuts
	QShortcut* start_b = new QShortcut( this );
	start_b->setKey( Qt::Key_F5 );
	start_b->setContext( Qt::WindowShortcut );
	QShortcut* start_c = new QShortcut( this );
	start_c->setKey( QKeySequence( tr( "CTRL+R" ) ) );
	start_c->setContext( Qt::WindowShortcut );

	connect( start_b, SIGNAL( activated() ), this, SLOT( on_pushButton_start_stop_clicked() ) );
	connect( start_c, SIGNAL( activated() ), this, SLOT( on_pushButton_start_stop_clicked() ) );

57
58
59
	m_pVANetServer = IVANetServer::Create();
	m_pVANetClient = IVANetClient::Create();

60
61
62
	ui->comboBox_audio_driver->addItem( "ASIO" );
	ui->comboBox_audio_driver->addItem( "Portaudio" );

63
64
65
66
67
68
	ui->comboBox_audio_iface_sampling_rate->addItem( "44.1 kHz", AudioSamplingRate::FS_44kHz );
	ui->comboBox_audio_iface_sampling_rate->addItem( "48 kHz", AudioSamplingRate::FS_48kHz );
	//ui->comboBox_audio_iface_sampling_rate->addItem( "96 kHz", AudioSamplingRate::FS_96kHz );

	ui->comboBox_audio_iface_buffer_size->addItem( "AUTO", AudioBufferSize::AUTO );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
69
	m_iPortaudioDefaultDevice = -1;
70

71
72
	if( !bSkipConfig )
		LoadConfiguration();
73

74
75
	if( ui->checkBox_redstart_network_connect_as_client->isChecked() )
		ui->groupBox_redstart_audio_iface->setEnabled( false );
76

77
78
79
	if( ( ui->checkBox_redstart_auto_start->isChecked() || bAutoStart ) && !bFailSafeMode )
		on_pushButton_start_stop_clicked();

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
80
81
82
83
84
	//connect( &m_qRenderTimer, SIGNAL( timeout() ), this, SLOT( Render() ) );
}

RedstartWindow::~RedstartWindow()
{
85
	StoreConfiguration();
86
87
88
89
90
91
92
93
94
95
	if( m_pVANetServer->IsClientConnected() )
	{
		m_pVANetServer->Finalize();
		delete m_pVAInterface;
	}
	delete m_pVANetServer;

	if( m_pVANetClient->IsConnected() )
		m_pVANetClient->Disconnect();
	delete m_pVANetClient;
96
97
98
99
100
101
}

void RedstartWindow::LoadConfiguration()
{
	RestoreWindowSize();

102
103
	bool bValOK;
	int iAudioBackend = m_qSettings.value( "Redstart/audio/backend_idx" ).toInt( &bValOK );
104
105
106
	if( !bValOK )
		iAudioBackend = AudioBackend::ASIO;
	ui->comboBox_audio_driver->setCurrentIndex( iAudioBackend );
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	const int iBufferSizeIndex = m_qSettings.value( "Redstart/audio/buffersize_idx" ).toInt( &bValOK );
	if( bValOK && iBufferSizeIndex < ui->comboBox_audio_iface_buffer_size->count() )
		ui->comboBox_audio_iface_buffer_size->setCurrentIndex( iBufferSizeIndex );

	const int iSamplingRateIndex = m_qSettings.value( "Redstart/audio/fs_idx" ).toInt( &bValOK );
	if( bValOK && iSamplingRateIndex < ui->comboBox_audio_iface_sampling_rate->count() )
		ui->comboBox_audio_iface_sampling_rate->setCurrentIndex( iSamplingRateIndex );

	if( m_qSettings.contains( "Redstart/network/address" ) )
		ui->lineEdit_redstart_network_address->setText( m_qSettings.value( "Redstart/network/address" ).toString() );
	if( m_qSettings.contains( "Redstart/network/port" ) )
		ui->lineEdit_redstart_network_address->setText( m_qSettings.value( "Redstart/network/port" ).toString() );
	ui->checkBox_redstart_network_connect_as_client->setChecked( m_qSettings.value( "Redstart/network/client_mode" ).toBool() );

	if( m_qSettings.contains( "Redstart/autostart" ) )
123
		ui->checkBox_redstart_auto_start->setChecked( m_qSettings.value( "Redstart/autostart" ).toBool() );
124

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
125

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
126
127
128
	m_iPortaudioDefaultDevice = m_qSettings.value( "Redstart/audio/portaudio_default_device", -1 ).toInt();

	ui->checkBox_portaudio_default_device->setChecked( m_qSettings.value( "Redstart/audio/portaudio_use_default_device", true ).toBool() );
129

130
131
132
133
134
135
136
	QVariantList voAudioDevices;
	voAudioDevices = m_qSettings.value( "Redstart/audio/devicelist" ).toList();

	for( const QVariant oAudioDevice : voAudioDevices )
		m_voAudioDevices.push_back( CAudioDeviceSpecs( oAudioDevice.toHash() ) );

	PopulateAudioDevices();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
137
138
139
140

	int iLastDevice = m_qSettings.value( "Redstart/audio/current_device", 0 ).toInt( &bValOK );
	if( bValOK && ui->comboBox_audio_iface_device->count() >= iLastDevice )
		ui->comboBox_audio_iface_device->setCurrentIndex( iLastDevice );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
141

142
143
144
145
146
147
148
	// Core control
	ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( IVAInterface::VA_LOG_LEVEL_QUIET ) ) );
	ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( IVAInterface::VA_LOG_LEVEL_ERROR ) ) );
	ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( IVAInterface::VA_LOG_LEVEL_WARNING ) ) );
	ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( IVAInterface::VA_LOG_LEVEL_INFO ) ) );
	ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( IVAInterface::VA_LOG_LEVEL_VERBOSE ) ) );
	ui->comboBox_core_settings_log_level->addItem( QString::fromStdString( m_pVAInterface->GetLogLevelStr( IVAInterface::VA_LOG_LEVEL_TRACE ) ) );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
149

150
151
152
153
154
155
156
}

void RedstartWindow::StoreConfiguration()
{
	m_qSettings.setValue( "Redstart/gui/WindowGeometry", saveGeometry() );
	m_qSettings.setValue( "Redstart/gui/WindowState", saveState() );

157
158
159
160
161
162
163
164
165
166
167
168
169
170
	m_qSettings.setValue( "Redstart/audio/backend_idx", ui->comboBox_audio_driver->currentIndex() );

	m_qSettings.setValue( "Redstart/audio/buffersize_idx", ui->comboBox_audio_iface_buffer_size->currentIndex() );
	m_qSettings.setValue( "Redstart/audio/fs_idx", ui->comboBox_audio_iface_sampling_rate->currentIndex() );

	m_qSettings.setValue( "Redstart/network/address", ui->lineEdit_redstart_network_address->text() );

	bool bValOK;
	int iPort = ui->lineEdit_redstart_network_address->text().toInt( &bValOK );
	if( bValOK )
		m_qSettings.setValue( "Redstart/network/port", iPort );

	m_qSettings.setValue( "Redstart/network/client_mode", ui->checkBox_redstart_network_connect_as_client->isChecked() );
	m_qSettings.setValue( "Redstart/autostart", ui->checkBox_redstart_auto_start->isChecked() );
171

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
172
173
174
	m_qSettings.setValue( "Redstart/audio/portaudio_default_device", m_iPortaudioDefaultDevice );
	int iLastDevice = ui->comboBox_audio_iface_device->currentIndex();
	m_qSettings.setValue( "Redstart/audio/current_device", iLastDevice );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
175

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
176
	m_qSettings.setValue( "Redstart/audio/portaudio_use_default_device", ui->checkBox_portaudio_default_device->isChecked() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
177

178
179
180
	QVariantList voAudioDevices;
	for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
		voAudioDevices.push_back( oDevice.asHash() );
181

182
	m_qSettings.setValue( "Redstart/audio/devicelist", voAudioDevices );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
183
}
184

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
185
186
187
void RedstartWindow::on_actionQuit_triggered()
{
	close();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
188
189
190
191
192
193
194
}

void RedstartWindow::PostCoreStart()
{
	ui->pushButton_start_stop->setText( "Stop" );

	// Switch UI elements enabled
195
	ui->groupBox_redstart_audio_iface->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
196
	ui->groupBox_redstart_network->setEnabled( false );
197
	ui->horizontalLayout_redstart_session->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
198
199
200
	ui->groupBox_core->setEnabled( true );
	ui->groupBox_paths->setEnabled( true );
	ui->groupBox_macros->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
201
	ui->menuRun->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
202
203

	CVAVersionInfo oVersion;
204
	m_pVAInterface->GetVersionInfo( &oVersion );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
205
206
207
208
	ui->lineEdit_core_settings_version->setText( QString::fromStdString( oVersion.ToString() ) );

	CVAStruct oArgs;
	oArgs[ "getloglevel" ] = true;
209
	const CVAStruct oReturn = m_pVAInterface->CallModule( "VACore", oArgs );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
210
	const int iCurrentLogLevel = oReturn[ "loglevel" ];
211
212

	ui->comboBox_core_settings_log_level->setCurrentIndex( iCurrentLogLevel );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
213
214
215
216
217
218
219
}

void RedstartWindow::PostCoreStop()
{
	ui->pushButton_start_stop->setText( "Start" );

	// Switch UI elements enabled
220
	ui->groupBox_redstart_audio_iface->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
221
	ui->groupBox_redstart_network->setEnabled( true );
222
	ui->horizontalLayout_redstart_session->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
223
224
225
	ui->groupBox_core->setEnabled( false );
	ui->groupBox_paths->setEnabled( false );
	ui->groupBox_macros->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
226
	ui->menuRun->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
227
}
228
229
230
231
232
233
234
235
236

void RedstartWindow::RestoreWindowSize()
{
	restoreGeometry( m_qSettings.value( "Redstart/gui/WindowGeometry" ).toByteArray() );
	restoreState( m_qSettings.value( "Redstart/gui/WindowState" ).toByteArray() );
}

void RedstartWindow::AcquireAsioDevices()
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
237
238
	std::vector< CAudioDeviceSpecs > voAudioDevices = m_voAudioDevices;

239
240
241
242
243
244
245
246
	try
	{
		ITAsioInitializeLibrary();

		long lDrivers = ITAsioGetNumDrivers();
		if( lDrivers <= 0 )
			ITA_EXCEPT1( INVALID_PARAMETER, "No ASIO-compatibel drivers could be found on this system." );

247
		m_voAudioDevices.clear();
248
249
250
251
252

		for( long i = 0; i < lDrivers; i++ )
		{
			CAudioDeviceSpecs oDeviceSpecs;
			oDeviceSpecs.iDriverNumber = i;
253
			oDeviceSpecs.iBackend = AudioBackend::ASIO;
254
255
256
257
258
259
			oDeviceSpecs.sName = ITAsioGetDriverName( i );

			try
			{
				ITAsioInitializeDriver( i );

260
261
				long in = 0;
				long out = 0;
262
263
				ITAsioGetChannels( &in, &out );
				oDeviceSpecs.iNumInputChannels = int( in );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
264
				oDeviceSpecs.iNumOutputChannels = int( out );
265
266
267
268
269
270
271
272
273
274
275
276
277

				ITAsioFinalizeDriver();

				oDeviceSpecs.bInitializable = true;

			}
			catch( const ITAException& )
			{
				oDeviceSpecs.bInitializable = false;
				continue;
			}

			if( oDeviceSpecs.bInitializable )
278
				m_voAudioDevices.push_back( oDeviceSpecs );
279
280
281
282
283
284
285
286
287
288
289
290
		}

		ITAsioFinalizeLibrary();
	}
	catch( const ITAException& e )
	{
		QString sErrorMessage = QString( "Error during ASIO device acquisition: %1" ).arg( QString::fromStdString( e.ToString() ) );
		QErrorMessage oErrMsg;
		oErrMsg.showMessage( sErrorMessage );
		oErrMsg.exec();
	}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
291
292
293
	for( const CAudioDeviceSpecs oDevice : voAudioDevices )
		if( oDevice.iBackend != AudioBackend::ASIO )
			m_voAudioDevices.push_back( oDevice );
294
295
}

296
297
298
void RedstartWindow::PopulateAudioDevices()
{
	ui->comboBox_audio_iface_device->clear();
299
	int iCurrentBackend = ui->comboBox_audio_driver->currentIndex();
300
301
	for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
	{
302
303
304
305
306
307
308
309
310
		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 );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
311
312
		else
			ui->comboBox_audio_iface_device->setEnabled( true );
313
314
315
316
317
	}
	else
	{
		ui->checkBox_portaudio_default_device->setEnabled( false );
		ui->comboBox_audio_iface_device->setEnabled( true );
318
319
320
	}
}

321
322
void RedstartWindow::AcquirePortaudioDevices()
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
	std::vector< CAudioDeviceSpecs > voAudioDevices = m_voAudioDevices;

	try
	{
		ITAPortaudioInterface oPortaudio( 44100, 1024 );
		oPortaudio.Initialize();
		int lDrivers = oPortaudio.GetNumDevices();

		if( lDrivers <= 0 )
			ITA_EXCEPT1( INVALID_PARAMETER, "No Portaudio output devices could be found on this system." );

		m_iPortaudioDefaultDevice = oPortaudio.GetDefaultOutputDevice();

		m_voAudioDevices.clear();

		for( long i = 0; i < lDrivers; i++ )
		{
			CAudioDeviceSpecs oDeviceSpecs;
			oDeviceSpecs.iDriverNumber = i;
			oDeviceSpecs.iBackend = AudioBackend::PORTAUDIO;
			oDeviceSpecs.sName = oPortaudio.GetDeviceName( i ).c_str();
344

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
345
346
347
348
349
350
351
352
353
354
			try
			{
				oPortaudio.GetNumChannels( i, oDeviceSpecs.iNumInputChannels, oDeviceSpecs.iNumOutputChannels );

				oDeviceSpecs.bInitializable = true; // only a guess

				if( i == oPortaudio.GetDefaultOutputDevice() )
					oDeviceSpecs.bDefaultDevice = true;
				else
					oDeviceSpecs.bDefaultDevice = false;
355

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
			}
			catch( const ITAException& )
			{
				oDeviceSpecs.bInitializable = false;
				continue;
			}

			if( oDeviceSpecs.bInitializable )
				m_voAudioDevices.push_back( oDeviceSpecs );
		}

		oPortaudio.Finalize();
	}
	catch( const ITAException& e )
	{
		QString sErrorMessage = QString( "Error during Portaudio device acquisition: %1" ).arg( QString::fromStdString( e.ToString() ) );
		QErrorMessage oErrMsg;
		oErrMsg.showMessage( sErrorMessage );
		oErrMsg.exec();
	}

	for( const CAudioDeviceSpecs oDevice : voAudioDevices )
		if( oDevice.iBackend != AudioBackend::ASIO )
			m_voAudioDevices.push_back( oDevice );
380
381
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
382
void RedstartWindow::on_pushButton_start_stop_clicked()
383
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
384
385
386
387
388
389
390
	try
	{
		if( !ui->checkBox_redstart_network_connect_as_client->isChecked() )
		{
			if( m_pVAInterface )
			{
				m_pVANetServer->Finalize();
391

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
392
393
394
395
396
397
398
399
400
401
402
				if( m_pVAInterface->GetState() == IVAInterface::VA_CORESTATE_READY )
					m_pVAInterface->Finalize();

				delete m_pVAInterface;
				m_pVAInterface = nullptr;

				ui->statusBar->showMessage( "VA core has been stopped." );
				PostCoreStop();
			}
			else
			{
403
				CVAStruct oVAConfigArgs = ui->listView_redstart_session_list->GetCurrentConfig();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

				// Override configs
				std::string sBackend, sDevice;
				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;

430
431
432
433
				if( !oVAConfigArgs.HasKey( "Paths" ) )
					oVAConfigArgs[ "Paths" ] = CVAStruct();
				oVAConfigArgs[ "Paths" ][ "redstart_data" ] = "data";
				oVAConfigArgs[ "Paths" ][ "redstart_data_dev" ] = "../VACore/data";
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452

				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 )
				{
453
					ui->statusBar->showMessage( "VA core successfully initialized and network server started. Running session " + ui->listView_redstart_session_list->GetCurrentSessionID() + "." );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479

					PostCoreStart();
				}
				else
				{
					ui->statusBar->showMessage( "VA core initialization failed." );
					m_pVANetServer->Finalize();

					delete m_pVAInterface;
					m_pVAInterface = NULL;
				}
			}
		}
		else
		{
			// Client mode
			if( m_pVANetClient->IsConnected() )
				m_pVANetClient->Disconnect();

			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() );
480

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
481
482
483
484
485
486
487
488
489
490
491
492
493
			if( iStatus != IVANetClient::VA_NO_ERROR )
			{
				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 )
	{
Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
494
495
496
497
498
499
500

		if( m_pVAInterface )
		{
			delete m_pVAInterface;
			m_pVAInterface = NULL;
		}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
501
502
503
		ui->statusBar->showMessage( QString::fromStdString( ex.ToString() ) );
		ui->checkBox_redstart_auto_start->setChecked( false );
	}
504
}
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

void RedstartWindow::on_pushButton_refresh_clicked()
{
	const int iAudioBackend = ui->comboBox_audio_driver->currentIndex();
	if( iAudioBackend == AudioBackend::PORTAUDIO )
	{
		AcquirePortaudioDevices();
	}
	else
	{
		AcquireAsioDevices();
	}

	PopulateAudioDevices();
}

Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
521
void RedstartWindow::on_comboBox_audio_driver_currentIndexChanged( int )
522
523
524
525
{
	PopulateAudioDevices();
}

Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
526
void RedstartWindow::on_comboBox_audio_iface_device_currentIndexChanged( int )
527
528
529
{

}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
530
531
532

void RedstartWindow::on_actionWebsite_triggered()
{
533
534
	QUrl urlVAWebsite( "http://www.virtualacoustics.org/work" );
	QDesktopServices::openUrl( urlVAWebsite );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
535
536
537
538
}

void RedstartWindow::on_actionGet_started_triggered()
{
539
540
	QUrl urlVAWebsiteGetStarted( "http://www.virtualacoustics.org/work/start.html" );
	QDesktopServices::openUrl( urlVAWebsiteGetStarted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
541
542
543
544
}

void RedstartWindow::on_actionDocumentation_triggered()
{
545
546
	QUrl urlVAWebsiteDocumentation( "http://www.virtualacoustics.org/work/documentation.html" );
	QDesktopServices::openUrl( urlVAWebsiteDocumentation );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
547
548
549
550
}

void RedstartWindow::on_actionGet_help_triggered()
{
551
552
	QUrl urlVAWebsiteGetHelp( "http://www.virtualacoustics.org/work/help.html" );
	QDesktopServices::openUrl( urlVAWebsiteGetHelp );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
553
}
554
555
556
557
558
559
560
561
562
563
564
565

void RedstartWindow::on_checkBox_redstart_network_connect_as_client_clicked()
{
	if( ui->checkBox_redstart_network_connect_as_client->isChecked() )
		ui->groupBox_redstart_audio_iface->setEnabled( false );
	else
		ui->groupBox_redstart_audio_iface->setEnabled( true );
}

void RedstartWindow::on_checkBox_portaudio_default_device_clicked()
{
	if( ui->checkBox_portaudio_default_device->isChecked() )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
566
	{
567
		ui->comboBox_audio_iface_device->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
568
569
570
		if( ui->comboBox_audio_iface_device->count() >= m_iPortaudioDefaultDevice )
			ui->comboBox_audio_iface_device->setCurrentIndex( m_iPortaudioDefaultDevice );
	}
571
572
573
574
	else
		ui->comboBox_audio_iface_device->setEnabled( true );
}

575
void RedstartWindow::on_listView_redstart_session_list_clicked( const QModelIndex &index )
576
{
Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
577
578
579
580
581
582
	if( ui->listView_redstart_session_list->model()->data( index ).isValid() )
	{
		std::string sSessionName = ui->listView_redstart_session_list->model()->data( index ).toString().toStdString();
		CVAStruct oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
		ui->treeView_session_details->SetStruct( oStruct );
	}
583
}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
584
585
586
587
588

void RedstartWindow::on_actionBinauralHeadphones_triggered()
{
	RedstartSessionBinauralHeadphonesDialog d( this );
	if( d.exec() )
589
		ui->listView_redstart_session_list->AddSession( d.GetSessionName(), d.GetCoreConfig() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
590
591
592
593
}

void RedstartWindow::on_actionDefault_experimental_session_triggered()
{
594
595
	RedstartSessionExperimentalTalkthroughDialog d( this );
	if( d.exec() )
Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
596
		ui->listView_redstart_session_list->AddSession( d.GetSessionName(), d.GetCoreConfig() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
597
598
599
600
}

void RedstartWindow::on_actionRunSimpleExample_triggered()
{
601

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
602
603
	try
	{
604
605
606
		if( !m_pVAInterface )
			VA_EXCEPT2( INVALID_PARAMETER, "No VA interface available. Please start a session, first." );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
607
608
609
610
611
612
613
614
615
616
		RunSimpleExample( m_pVAInterface );
	}
	catch( CVAException& e )
	{
		QString sErrorMessage = QString( "Could not run simple example scene: %1" ).arg( QString::fromStdString( e.ToString() ) );
		QErrorMessage oErrMsg;
		oErrMsg.showMessage( sErrorMessage );
		oErrMsg.exec();
	}
}
617
618
619
620
621

void RedstartWindow::on_actionCirculating_source_triggered()
{

}
622
623
624
625
626

void RedstartWindow::on_actionAmbisonics_triggered()
{

}