RedstartWindow.cpp 43.1 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
#include <QFileDialog>
20

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

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
24
25
#include "RedstartRunSimpleExample.h"
#include "RedstartSessionBinauralHeadphonesDialog.h"
26
#include "RedstartSessionExperimentalTalkthroughDialog.h"
27
#include "RedstartSessionImportDialog.h"
28
#include "RedstartSessionWizardDialog.h"
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
29
#include "RedstartUtils.h"
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
30
#include "RedstartCoreOutputPlainTextEdit.h"
31
#include "RedstartRunCirculatingSourceDialog.h"
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
32

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
33
34
35
36
#include <VA.h>
#include <VACore.h>
#include <VANet.h>

37
#include <ITAAsioInterface.h>
38
#include <ITAPortaudioInterface.h>
39
#include <ITAException.h>
40
#include <ITANumericUtils.h>
41
42


43
RedstartWindow::RedstartWindow( bool bFailSafeMode, bool bAutoStart, bool bSkipConfig, QWidget* pParent )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
44
45
	: QMainWindow( pParent )
	, ui( new Ui::RedstartWindow )
46
	, m_pVAInterface( NULL )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
47
48
49
{
	ui->setupUi( this );

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

Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
52
53
54
55
56
57
58
59
60
61
62
	// 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() ) );

63
64
65
	m_pVANetServer = IVANetServer::Create();
	m_pVANetClient = IVANetClient::Create();

66
67
68
	ui->comboBox_audio_driver->addItem( "ASIO" );
	ui->comboBox_audio_driver->addItem( "Portaudio" );

69
70
71
72
73
74
	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 );

75
76
77
78
79
80
81
82
83
	m_pPathsModel = new QStringListModel( ui->listView_paths );
	ui->listView_paths->setModel( m_pPathsModel );

	m_pMacrosModel = new QStringListModel( ui->listView_macros );
	ui->listView_macros->setModel( m_pMacrosModel );

	m_pNetServerClientsModel = new QStringListModel( ui->listView_server_connected_clients );
	ui->listView_server_connected_clients->setModel( m_pNetServerClientsModel );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
84
	m_iPortaudioDefaultDevice = -1;
85

86
87
	if( !bSkipConfig )
		LoadConfiguration();
88

89
	// Signals & slots
90
	ConnectSignalsAndSlots();
91

92

93
94
	ui->menuRun->setEnabled( false );

95
96
	if( ui->checkBox_redstart_network_connect_as_client->isChecked() )
		ui->groupBox_redstart_audio_iface->setEnabled( false );
97

98
99
100
	if( ( ui->checkBox_redstart_auto_start->isChecked() || bAutoStart ) && !bFailSafeMode )
		on_pushButton_start_stop_clicked();

101
102
	m_pCirculatingSourceDialog = new RedstartRunCirculatingSourceDialog( this );

103
104
105
	m_qSporadicTimer.setTimerType( Qt::TimerType::VeryCoarseTimer );
	m_qSporadicTimer.setInterval( m_qSettings.value( "sporadic_timeout_interval", 200 ).toInt() );
	m_qSporadicTimer.start();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
106
107
108
109
}

RedstartWindow::~RedstartWindow()
{
110
111
	m_qSporadicTimer.stop();

112
	StoreConfiguration();
113

114
115
116
117
118
119
120
121
122
123
	if( m_pVANetServer->IsClientConnected() )
	{
		m_pVANetServer->Finalize();
		delete m_pVAInterface;
	}
	delete m_pVANetServer;

	if( m_pVANetClient->IsConnected() )
		m_pVANetClient->Disconnect();
	delete m_pVANetClient;
124
125
126

	delete m_pPathsModel;
	delete m_pMacrosModel;
127
128
}

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
void RedstartWindow::ConnectSignalsAndSlots()
{
	// Input control
	connect( ui->doubleSpinBox_input_gain, SIGNAL( valueChanged( double ) ), this, SLOT( CoreChangeInputSignalDecibel( double ) ) );
	connect( this, SIGNAL( InputSignalChangedDecibel( double ) ), ui->doubleSpinBox_input_gain, SLOT( setValue( double ) ) );
	connect( ui->dial_core_control_input_gain, SIGNAL( valueChanged( int ) ), this, SLOT( CoreChangeInputSignalDecibel( int ) ) );
	connect( this, SIGNAL( InputSignalChangedDecibel( int ) ), ui->dial_core_control_input_gain, SLOT( setValue( int ) ) );
	connect( this, SIGNAL( InputIsMutedChanged( bool ) ), ui->checkBox_core_control_input_mute, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_core_control_input_mute, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeInputIsMuted( int ) ) );

	// Output control
	connect( ui->doubleSpinBox_output_gain, SIGNAL( valueChanged( double ) ), this, SLOT( CoreChangeOutputSignalDecibel( double ) ) );
	connect( this, SIGNAL( OutputSignalChangedDecibel( double ) ), ui->doubleSpinBox_output_gain, SLOT( setValue( double ) ) );
	connect( ui->dial_core_control_output_gain, SIGNAL( valueChanged( int ) ), this, SLOT( CoreChangeOutputSignalDecibel( int ) ) );
	connect( this, SIGNAL( OutputSignalChangedDecibel( int ) ), ui->dial_core_control_output_gain, SLOT( setValue( int ) ) );
	connect( this, SIGNAL( OutputIsMutedChanged( bool ) ), ui->checkBox_core_control_output_mute, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_core_control_output_mute, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeOutputIsMuted( int ) ) );

147
148
149
150
	// Auralization modes
	connect( this, SIGNAL( GlobalAuralizationModeChanged( int ) ), this, SLOT( CoreChangeGlobalAuralizationMode( int ) ) );
	connect( this, SIGNAL( AuralizationModeDSChanged( bool ) ), ui->checkBox_am_ds, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_ds, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeDS( int ) ) );
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
	connect( this, SIGNAL( AuralizationModeERChanged( bool ) ), ui->checkBox_am_er, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_er, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeER( int ) ) );
	connect( this, SIGNAL( AuralizationModeDDChanged( bool ) ), ui->checkBox_am_dd, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_dd, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeDD( int ) ) );
	connect( this, SIGNAL( AuralizationModeDIRChanged( bool ) ), ui->checkBox_am_dir, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_dir, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeDIR( int ) ) );
	connect( this, SIGNAL( AuralizationModeDPChanged( bool ) ), ui->checkBox_am_dp, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_dp, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeDP( int ) ) );
	connect( this, SIGNAL( AuralizationModeSLChanged( bool ) ), ui->checkBox_am_sl, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_sl, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeSL( int ) ) );
	connect( this, SIGNAL( AuralizationModeDIFChanged( bool ) ), ui->checkBox_am_dif, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_dif, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeDIF( int ) ) );
	connect( this, SIGNAL( AuralizationModeSCChanged( bool ) ), ui->checkBox_am_sca, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_sca, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeSC( int ) ) );
	connect( this, SIGNAL( AuralizationModeNFChanged( bool ) ), ui->checkBox_am_nf, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_nf, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeNF( int ) ) );
	connect( this, SIGNAL( AuralizationModeTVChanged( bool ) ), ui->checkBox_am_tv, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_tv, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeTV( int ) ) );
	connect( this, SIGNAL( AuralizationModeMAChanged( bool ) ), ui->checkBox_am_ma, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_ma, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeMA( int ) ) );
	connect( this, SIGNAL( AuralizationModeABChanged( bool ) ), ui->checkBox_am_ab, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_ab, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeAB( int ) ) );
	connect( this, SIGNAL( AuralizationModeTRChanged( bool ) ), ui->checkBox_am_tr, SLOT( setChecked( bool ) ) );
	connect( ui->checkBox_am_tr, SIGNAL( stateChanged( int ) ), this, SLOT( CoreChangeAuralizationModeTR( int ) ) );
175
176
177
178

	connect( ui->comboBox_core_settings_log_level, SIGNAL( currentIndexChanged( int ) ), this, SLOT( CoreChangeLogLevel( int ) ) );

	connect( &m_qSporadicTimer, SIGNAL( timeout() ), this, SLOT( SporadicTimeout() ) );
179
180
181

}

182
183
184
185
void RedstartWindow::LoadConfiguration()
{
	RestoreWindowSize();

186
187
	bool bValOK;
	int iAudioBackend = m_qSettings.value( "Redstart/audio/backend_idx" ).toInt( &bValOK );
188
189
190
	if( !bValOK )
		iAudioBackend = AudioBackend::ASIO;
	ui->comboBox_audio_driver->setCurrentIndex( iAudioBackend );
191

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
	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" ) )
207
208
209
210
	{
		bool bAutostart = m_qSettings.value( "Redstart/autostart" ).toBool();
		ui->checkBox_redstart_auto_start->setChecked( bAutostart );
	}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
211

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
212
213
214
	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() );
215

216
217
218
219
220
221
222
	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
223
224
225
226

	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
227

228
229
230
231
232
233
234
	// 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
235

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
236
237
	if( ui->listView_redstart_session_list->GetCurrentSessionID().isEmpty() == false )
		ui->treeView_session_details->SetStruct( ui->listView_redstart_session_list->GetCurrentConfig() );
238
239
240
241
242
243
244
}

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

245
246
247
248
249
250
251
252
253
254
255
256
257
	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() );
258

259
260
	bool bAutostart = ui->checkBox_redstart_auto_start->isChecked();
	m_qSettings.setValue( "Redstart/autostart", bAutostart );
261

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
262
263
264
	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
265

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
266
	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
267

268
269
270
	QVariantList voAudioDevices;
	for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
		voAudioDevices.push_back( oDevice.asHash() );
271

272
	m_qSettings.setValue( "Redstart/audio/devicelist", voAudioDevices );
273
274

	m_qSettings.setValue( "sporadic_timeout_interval", m_qSporadicTimer.interval() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
275
}
276

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
277
278
279
void RedstartWindow::on_actionQuit_triggered()
{
	close();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
280
281
282
283
284
285
286
}

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

	// Switch UI elements enabled
287
	ui->groupBox_redstart_audio_iface->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
288
	ui->groupBox_redstart_network->setEnabled( false );
289
290
	ui->groupBox_session_list->setEnabled( false );
	ui->groupBox_session_details->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
291
292
293
	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
294
	ui->menuRun->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
295
	ui->groupBox_core_control->setEnabled( true );
296
297
298
	ui->graphicsView_input_levels->setEnabled( true );
	ui->graphicsView_output_levels->setEnabled( true );
	ui->groupBox_global_am->setEnabled( true );
299
	ui->groupBox_output->setEnabled( true );
300
	ui->groupBox_clients->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
301
302

	CVAVersionInfo oVersion;
303
	m_pVAInterface->GetVersionInfo( &oVersion );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
304
305
306
307
	ui->lineEdit_core_settings_version->setText( QString::fromStdString( oVersion.ToString() ) );

	CVAStruct oArgs;
	oArgs[ "getloglevel" ] = true;
308
	oArgs[ "getmacros" ] = true;
309
	const CVAStruct oReturn = m_pVAInterface->CallModule( "VACore", oArgs );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
310
	const int iCurrentLogLevel = oReturn[ "loglevel" ];
311
	ui->comboBox_core_settings_log_level->setCurrentIndex( iCurrentLogLevel );
312
313
314
315
316
317
318
319
320
321

	CVAStruct oSearchPaths = m_pVAInterface->GetSearchPaths();
	QStringList sPathList;
	CVAStruct::const_iterator cit = oSearchPaths.Begin();
	while( cit != oSearchPaths.End() )
	{
		const CVAStructValue& oValue( cit++->second );
		if( oValue.IsString() )
			sPathList << std::string( oValue ).c_str();
	}
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

	m_pPathsModel->setStringList( sPathList );

	if( oReturn.HasKey( "macros" ) )
	{
		CVAStruct oMacros = oReturn[ "macros" ];
		QStringList sMacrosList;
		CVAStruct::const_iterator cit = oMacros.Begin();
		while( cit != oMacros.End() )
		{
			std::string sName( cit->first );
			const CVAStructValue& oValue( cit++->second );
			if( oValue.IsString() )
				sMacrosList << ( sName + " = " + std::string( oValue ) ).c_str();
		}

		m_pMacrosModel->setStringList( sMacrosList );
	}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
340
341
342
343
344
345
346
}

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

	// Switch UI elements enabled
347
	ui->groupBox_redstart_audio_iface->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
348
	ui->groupBox_redstart_network->setEnabled( true );
349
350
	ui->groupBox_session_list->setEnabled( true );
	ui->groupBox_session_details->setEnabled( true );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
351
352
353
	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
354
	ui->menuRun->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
355
	ui->groupBox_core_control->setEnabled( false );
356
357
358
	ui->graphicsView_input_levels->setEnabled( false );
	ui->graphicsView_output_levels->setEnabled( false );
	ui->groupBox_global_am->setEnabled( false );
359
	ui->groupBox_output->setEnabled( false );
360
361
	ui->groupBox_clients->setEnabled( false );
	ui->pushButton_add_local_path->setEnabled( false );
362

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

364
365
366
367
368
369
370
371
372
373
374
375
376
	// Clear
	ui->lineEdit_core_settings_version->clear();
	ui->listView_paths->reset();

	// Reset elements
	bool bPreserveCoreControlValues = m_qSettings.value( "PreserveCoreControlValues", true ).toBool(); // @todo control this setting via preferences dialog
	if( !bPreserveCoreControlValues )
	{
		emit InputSignalChangedDecibel( 0.0f );
		emit OutputSignalChangedDecibel( 0.0f );
		emit InputIsMutedChanged( false );
		emit OutputIsMutedChanged( false );
	}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
377
}
378
379
380
381
382
383
384

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

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
385
386
387
388
389
390
void RedstartWindow::HandleVAEvent( const CVAEvent* pEvent )
{
	// Handle pushable events
	switch( pEvent->iEventType )
	{
	case CVAEvent::VA_EVENT_PROGRESS_UPDATE:
391
		//ui->statusBar->showMessage( pEvent->sParam.c_str() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
392
393
394
395
396
397
		break;
	case CVAEvent::VA_EVENT_MEASURES_UPDATE:
		UpdateMeasures( pEvent->vfInputRMSs, pEvent->vfInputPeaks, pEvent->vfOutputRMSs, pEvent->vfOutputPeaks );
		break;
	}

398
	/* Don't handle events that have been triggered from this interface connection
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
399
	if( pEvent->pSender == m_pVAInterface )
400
401
	return;
	*/
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
402

403
404
405
406
407
408
409
	switch( pEvent->iEventType )
	{
	case CVAEvent::VA_EVENT_GLOBAL_AURALIZATION_MODE_CHANGED:
		emit GlobalAuralizationModeChanged( pEvent->iAuralizationMode );
		break;
	}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
410
411
412
	switch( pEvent->iEventType )
	{
	case CVAEvent::VA_EVENT_INPUT_GAIN_CHANGED:
413
		emit InputSignalChangedDecibel( ratio_to_db20( pEvent->dVolume ) );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
414
415
		break;
	case CVAEvent::VA_EVENT_OUTPUT_GAIN_CHANGED:
416
		emit OutputSignalChangedDecibel( ratio_to_db20( pEvent->dVolume ) );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
417
418
		break;
	case CVAEvent::VA_EVENT_INPUT_MUTING_CHANGED:
419
		emit InputIsMutedChanged( pEvent->bMuted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
420
421
		break;
	case CVAEvent::VA_EVENT_OUTPUT_MUTING_CHANGED:
422
		emit OutputIsMutedChanged( pEvent->bMuted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
423
424
425
426
427
428
429
430
431
		break;
	}
}

void RedstartWindow::UpdateMeasures( const std::vector< float >& vfInputRMSs, const std::vector< float >& vfInputPeaks, const std::vector< float >& vfOutputRMSs, const std::vector< float >& vfOutputPeaks )
{
	// @todo feed level meters 
}

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

436
437
438
439
440
441
442
443
	try
	{
		ITAsioInitializeLibrary();

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

444
		m_voAudioDevices.clear();
445
446
447
448
449

		for( long i = 0; i < lDrivers; i++ )
		{
			CAudioDeviceSpecs oDeviceSpecs;
			oDeviceSpecs.iDriverNumber = i;
450
			oDeviceSpecs.iBackend = AudioBackend::ASIO;
451
452
453
454
455
456
			oDeviceSpecs.sName = ITAsioGetDriverName( i );

			try
			{
				ITAsioInitializeDriver( i );

457
458
				long in = 0;
				long out = 0;
459
460
				ITAsioGetChannels( &in, &out );
				oDeviceSpecs.iNumInputChannels = int( in );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
461
				oDeviceSpecs.iNumOutputChannels = int( out );
462
463
464
465
466
467
468
469
470
471
472
473
474

				ITAsioFinalizeDriver();

				oDeviceSpecs.bInitializable = true;

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

			if( oDeviceSpecs.bInitializable )
475
				m_voAudioDevices.push_back( oDeviceSpecs );
476
477
478
479
480
481
482
483
484
485
486
487
		}

		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
488
489
490
	for( const CAudioDeviceSpecs oDevice : voAudioDevices )
		if( oDevice.iBackend != AudioBackend::ASIO )
			m_voAudioDevices.push_back( oDevice );
491
492
}

493
494
495
void RedstartWindow::PopulateAudioDevices()
{
	ui->comboBox_audio_iface_device->clear();
496
	int iCurrentBackend = ui->comboBox_audio_driver->currentIndex();
497
498
	for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
	{
499
500
501
502
503
504
505
506
507
		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
508
509
		else
			ui->comboBox_audio_iface_device->setEnabled( true );
510
511
512
513
514
	}
	else
	{
		ui->checkBox_portaudio_default_device->setEnabled( false );
		ui->comboBox_audio_iface_device->setEnabled( true );
515
516
517
	}
}

518
519
void RedstartWindow::AcquirePortaudioDevices()
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
	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();
541

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
542
543
544
545
546
547
548
549
550
551
			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;
552

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
			}
			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 );
577
578
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
579
void RedstartWindow::on_pushButton_start_stop_clicked()
580
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
581
582
	try
	{
583
		if( ui->checkBox_redstart_network_connect_as_client->isChecked() == false )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
584
585
586
587
		{
			if( m_pVAInterface )
			{
				m_pVANetServer->Finalize();
588

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
589
590
591
592
593
594
595
596
597
598
599
				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
			{
600
				CVAStruct oVAConfigArgs = ui->listView_redstart_session_list->GetCurrentConfig();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626

				// 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;

627
628
629
630
				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
631
632

				m_pVAInterface = VACore::CreateCoreInstance( oVAConfigArgs );
633
				m_pVAInterface->SetOutputStream( ui->plainTextEdit_core_output->GetOutputStream() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
634

635
				m_pVAInterface->Initialize();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
636
				m_pVAInterface->AttachEventHandler( this );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
637
638
639
640
641
642
643
644
645
646
647
648
				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 )
				{
649
					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
650

651
652
					ui->pushButton_add_local_path->setEnabled( true );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
					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() );
678

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
679
680
681
682
683
684
685
			if( iStatus != IVANetClient::VA_NO_ERROR )
			{
				VA_EXCEPT2( INVALID_PARAMETER, "Could not initialize client, connection failed." );
			}

			m_pVAInterface = m_pVANetClient->GetCoreInstance();

686
687
			ui->pushButton_add_local_path->setEnabled( false );

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
688
			// @todo attach network event handler to detect server connection loss or abortion
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
689
690
691
692
693
			//m_pVANetClient->AttachEventHandler( this );
		}
	}
	catch( const CVAException& ex )
	{
Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
694
695
696
697
698
699
700

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

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
701
702
703
		ui->statusBar->showMessage( QString::fromStdString( ex.ToString() ) );
		ui->checkBox_redstart_auto_start->setChecked( false );
	}
704
}
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720

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
721
void RedstartWindow::on_comboBox_audio_driver_currentIndexChanged( int )
722
723
724
725
{
	PopulateAudioDevices();
}

Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
726
void RedstartWindow::on_comboBox_audio_iface_device_currentIndexChanged( int )
727
728
729
{

}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
730
731
732

void RedstartWindow::on_actionWebsite_triggered()
{
733
734
	QUrl urlVAWebsite( "http://www.virtualacoustics.org/work" );
	QDesktopServices::openUrl( urlVAWebsite );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
735
736
737
738
}

void RedstartWindow::on_actionGet_started_triggered()
{
739
740
	QUrl urlVAWebsiteGetStarted( "http://www.virtualacoustics.org/work/start.html" );
	QDesktopServices::openUrl( urlVAWebsiteGetStarted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
741
742
743
744
}

void RedstartWindow::on_actionDocumentation_triggered()
{
745
746
	QUrl urlVAWebsiteDocumentation( "http://www.virtualacoustics.org/work/documentation.html" );
	QDesktopServices::openUrl( urlVAWebsiteDocumentation );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
747
748
749
750
}

void RedstartWindow::on_actionGet_help_triggered()
{
751
752
	QUrl urlVAWebsiteGetHelp( "http://www.virtualacoustics.org/work/help.html" );
	QDesktopServices::openUrl( urlVAWebsiteGetHelp );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
753
}
754
755
756
757
758
759
760
761
762
763
764
765

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
766
	{
767
		ui->comboBox_audio_iface_device->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
768
769
770
		if( ui->comboBox_audio_iface_device->count() >= m_iPortaudioDefaultDevice )
			ui->comboBox_audio_iface_device->setCurrentIndex( m_iPortaudioDefaultDevice );
	}
771
772
773
774
	else
		ui->comboBox_audio_iface_device->setEnabled( true );
}

775
void RedstartWindow::on_listView_redstart_session_list_clicked( const QModelIndex &index )
776
{
Dipl.-Ing. Jonas Stienen's avatar
Mooore    
Dipl.-Ing. Jonas Stienen committed
777
778
779
780
781
782
	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 );
	}
783
}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
784
785
786
787
788

void RedstartWindow::on_actionBinauralHeadphones_triggered()
{
	RedstartSessionBinauralHeadphonesDialog d( this );
	if( d.exec() )
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
789
	{
790
791
792
793
794
795
		// Enforce unique session id if id is already existing
		QString sNewID = d.GetSessionName();
		while( ui->listView_redstart_session_list->SessionNameExists( sNewID ) )
			sNewID += "_new";
		ui->listView_redstart_session_list->AddSession( sNewID, d.GetCoreConfig() ); // In any case save the session so no data is lost

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
796
797
798
		CVAStruct oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
		ui->treeView_session_details->SetStruct( oStruct );
	}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
799
800
}

801
802
803
804
805
806
807
void RedstartWindow::on_actionImport_session_triggered()
{
	RedstartSessionImportDialog d( this );
	if( d.exec() )
	{
		try
		{
808
809
810
811
812
			// Enforce unique session id if id is already existing
			QString sNewID = d.GetSessionName();
			while( ui->listView_redstart_session_list->SessionNameExists( sNewID ) )
				sNewID += "_new";
			ui->listView_redstart_session_list->AddSession( sNewID, d.GetCoreConfig() ); // In any case save the session so no data is lost
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
813
814
815
			CVAStruct oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
			ui->treeView_session_details->SetStruct( oStruct );

816
817
818
819
820
821
822
823
824
825
826
		}
		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();
		}
	}
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
827
828
void RedstartWindow::on_actionDefault_experimental_session_triggered()
{
829
830
	RedstartSessionExperimentalTalkthroughDialog d( this );
	if( d.exec() )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
831
	{
832
833
834
835
836
837
		// Enforce unique session id if id is already existing
		QString sNewID = d.GetSessionName();
		while( ui->listView_redstart_session_list->SessionNameExists( sNewID ) )
			sNewID += "_new";
		ui->listView_redstart_session_list->AddSession( sNewID, d.GetCoreConfig() ); // In any case save the session so no data is lost

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
838
839
		CVAStruct oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
		ui->treeView_session_details->SetStruct( oStruct );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
840
841
	}
}
842
843
844

void RedstartWindow::on_actionCirculating_source_triggered()
{
845
846
	if( !m_pVAInterface )
		return;
847

848
849
850
	m_pCirculatingSourceDialog->SetVAInterface( m_pVAInterface );
	m_pCirculatingSourceDialog->exec();
	m_pCirculatingSourceDialog->hide();
851
}
852
853
854
855
856

void RedstartWindow::on_actionAmbisonics_triggered()
{

}
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898

void RedstartWindow::on_actionExport_to_file_triggered()
{
	QFileDialog fd;
	fd.setNameFilters( QStringList() << "INI files (*.ini)" << "Any file (*.*)" );
	fd.setViewMode( QFileDialog::Detail );
	fd.setAcceptMode( QFileDialog::AcceptSave );

	QDir oLastDir( m_qSettings.value( "Redstart/last_browse_folder" ).toString() );
	if( oLastDir.exists() )
		fd.setDirectory( oLastDir );
	else
		fd.setDirectory( QDir( QApplication::applicationDirPath() ) );

	QString sFileName = ui->listView_redstart_session_list->GetCurrentSessionID();
	if( sFileName.isEmpty() == false )
		fd.selectFile( sFileName + ".ini" );

	if( fd.exec() )
	{
		QStringList lFiles = fd.selectedFiles();
		if( lFiles.empty() == false )
		{
			QString sFilePath = lFiles[ 0 ];
			QFileInfo oFile( sFilePath );
			if( fd.directory().exists() )
				m_qSettings.setValue( "Redstart/last_browse_folder", oFile.absolutePath() );

			try
			{
				CVAStruct oConfig = ui->listView_redstart_session_list->GetCurrentConfig();
				VACore::StoreCoreConfigToFile( oConfig, sFilePath.toStdString() );
			}
			catch( CVAException& e )
			{
				QString sErrorMessage = QString( "Could not export session configuration: %1" ).arg( QString::fromStdString( e.ToString() ) );
				QErrorMessage oErrMsg;
				oErrMsg.showMessage( sErrorMessage );
				oErrMsg.exec();
			}
		}
	}
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
899
900
901
902
903
}

void RedstartWindow::on_actionRemove_triggered()
{
	ui->listView_redstart_session_list->RemoveCurrentSession();
904

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
905
906
907
	CVAStruct oStruct;
	if( !ui->listView_redstart_session_list->GetCurrentSessionID().isEmpty() )
		oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
908

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
909
	ui->treeView_session_details->SetStruct( oStruct );
910
}
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
911
912
913
914
915
916
917

void RedstartWindow::on_actionEdit_session_triggered()
{
	RedstartSessionWizardDialog d( this );

	QString sCurrentSessionID = ui->listView_redstart_session_list->GetCurrentSessionID();
	CVAStruct oCurrentConfig;
918
919
920
921
922
923
924
	if( sCurrentSessionID.isEmpty() )
		return;

	oCurrentConfig = ui->listView_redstart_session_list->GetCurrentConfig();
	d.SetSession( sCurrentSessionID, ConvertVAStructToQHash( oCurrentConfig ) );

	if( d.exec() )
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
925
	{
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
		bool bEnforceDuplicate = true;
		if( sCurrentSessionID != d.GetSessionName() && !ui->listView_redstart_session_list->SessionNameExists( d.GetSessionName() ) )
		{
			ui->listView_redstart_session_list->RenameSession( sCurrentSessionID, d.GetSessionName() );
			bEnforceDuplicate = false;
		}

		QVariantHash oNewConfig = d.GetCoreConfig();
		if( d.GetDuplicationRequested() || bEnforceDuplicate )
		{
			// Enforce unique session id if duplicate requested or session should be renamed to an already existing session
			QString sNewID = d.GetSessionName();
			while( ui->listView_redstart_session_list->SessionNameExists( sNewID ) )
				sNewID += "_copy";

			ui->listView_redstart_session_list->AddSession( sNewID, oNewConfig );
		}
		else
		{
			ui->listView_redstart_session_list->UpdateSession( d.GetSessionName(), oNewConfig );
		}

		ui->treeView_session_details->SetStruct( ConvertQHashToVAStruct( oNewConfig ) );
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
949
	}
950
951
952
953
954
955
956
}

void RedstartWindow::on_actionSession_wizard_triggered()
{
	RedstartSessionWizardDialog d( this );

	d.SetDuplicationOptionDeactivated();
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
957
958
959
960

	if( d.exec() )
	{
		QVariantHash oNewConfig = d.GetCoreConfig();
961
962
963
964
965
966
967
968
		if( ui->listView_redstart_session_list->SessionNameExists( d.GetSessionName() ) )
		{
			// Enforce unique session id if id is already existing
			QString sNewID = d.GetSessionName();
			while( ui->listView_redstart_session_list->SessionNameExists( sNewID ) )
				sNewID += "_new";
			ui->listView_redstart_session_list->AddSession( sNewID, oNewConfig ); // In any case save the session so no data is lost
		}
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
969
		else
970
971
972
973
		{
			ui->listView_redstart_session_list->AddSession( d.GetSessionName(), oNewConfig );
		}

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
974
975
976
977
		ui->treeView_session_details->SetStruct( ConvertQHashToVAStruct( oNewConfig ) );
	}
}

978
void RedstartWindow::on_actionDuplicate_current_session_triggered()
Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
979
{
980
981
982
983
984
985
986
987
988
989
990
991
	RedstartSessionWizardDialog d( this );

	QString sCurrentSessionID = ui->listView_redstart_session_list->GetCurrentSessionID();
	CVAStruct oCurrentConfig;
	if( sCurrentSessionID.isEmpty() )
		return;

	oCurrentConfig = ui->listView_redstart_session_list->GetCurrentConfig();
	d.SetSession( sCurrentSessionID, ConvertVAStructToQHash( oCurrentConfig ) );

	d.SetDuplicationOptionActivated();

Dipl.-Ing. Jonas Stienen's avatar
WIP    
Dipl.-Ing. Jonas Stienen committed
992
993
	if( d.exec() )
	{
994
995
996
997
998
999
1000
		QVariantHash oNewConfig = d.GetCoreConfig();
		if( ui->listView_redstart_session_list->SessionNameExists( d.GetSessionName() ) )
		{
			// Enforce unique session id if id is already existing
			QString sNewID = d.GetSessionName();
			while( ui->listView_redstart_session_list->SessionNameExists( sNewID ) )
				sNewID += "_copy";
For faster browsing, not all history is shown. View entire blame