RedstartWindow.cpp 44.4 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
	connect( &m_qSporadicTimer, SIGNAL( timeout() ), ui->graphicsView_input_levels, SLOT( UpdateLevels() ) );
	connect( &m_qSporadicTimer, SIGNAL( timeout() ), ui->graphicsView_output_levels, SLOT( UpdateLevels() ) );
181 182 183

}

184 185 186 187
void RedstartWindow::LoadConfiguration()
{
	RestoreWindowSize();

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

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
	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" ) )
209 210 211 212
	{
		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
213

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

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

	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
229

230 231 232 233 234 235 236
	// 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
237

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

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

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

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

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

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

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

274
	m_qSettings.setValue( "Redstart/audio/devicelist", voAudioDevices );
275 276

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

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

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

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

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

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

	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();
	}
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

	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
342 343 344 345 346 347 348
}

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

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

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

366 367 368 369 370 371 372 373 374 375 376 377 378
	// 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
379
}
380 381 382 383 384 385 386

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
387 388 389 390 391
void RedstartWindow::HandleVAEvent( const CVAEvent* pEvent )
{
	// Handle pushable events
	switch( pEvent->iEventType )
	{
392
	case CVAEvent::PROGRESS_UPDATE:
393
		//ui->statusBar->showMessage( pEvent->sParam.c_str() );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
394
		break;
395
	case CVAEvent::MEASURES_UPDATE:
396 397 398 399 400 401
		if( pEvent->sParam == "RenderingModule" )
			; // @todo update rendering module GUI for sObjectID
		else if( pEvent->sParam == "ReproductionModule" )
			; // @todo update reproduction module GUI for sObjectID
		else if( pEvent->sParam.empty() )
			UpdateMeasures( pEvent->vfInputRMSs, pEvent->vfInputPeaks, pEvent->vfOutputRMSs, pEvent->vfOutputPeaks ); // Core i/o
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
402 403 404
		break;
	}

405
	/* Don't handle events that have been triggered from this interface connection
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
406
	if( pEvent->pSender == m_pVAInterface )
407 408
	return;
	*/
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
409

410 411
	switch( pEvent->iEventType )
	{
412
	case CVAEvent::GLOBAL_AURALIZATION_MODE_CHANGED:
413 414 415 416
		emit GlobalAuralizationModeChanged( pEvent->iAuralizationMode );
		break;
	}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
417 418
	switch( pEvent->iEventType )
	{
419
	case CVAEvent::INPUT_GAIN_CHANGED:
420
		emit InputSignalChangedDecibel( ratio_to_db20( pEvent->dVolume ) );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
421
		break;
422
	case CVAEvent::OUTPUT_GAIN_CHANGED:
423
		emit OutputSignalChangedDecibel( ratio_to_db20( pEvent->dVolume ) );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
424
		break;
425
	case CVAEvent::INPUT_MUTING_CHANGED:
426
		emit InputIsMutedChanged( pEvent->bMuted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
427
		break;
428
	case CVAEvent::OUTPUT_MUTING_CHANGED:
429
		emit OutputIsMutedChanged( pEvent->bMuted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
430 431 432 433 434 435
		break;
	}
}

void RedstartWindow::UpdateMeasures( const std::vector< float >& vfInputRMSs, const std::vector< float >& vfInputPeaks, const std::vector< float >& vfOutputRMSs, const std::vector< float >& vfOutputPeaks )
{
436 437 438 439 440 441 442 443 444 445 446 447 448
	int iNumInputChannels = (int) vfInputRMSs.size();
	assert( vfInputRMSs.size() == vfInputPeaks.size() );
	if( ui->graphicsView_input_levels->GetNumChannels() != iNumInputChannels )
		ui->graphicsView_input_levels->SetNumChannels( iNumInputChannels );

	ui->graphicsView_input_levels->SetRMSs( vfInputRMSs );
	ui->graphicsView_input_levels->SetPeaks( vfInputPeaks );

	int iNumOutputChannels = ( int ) vfOutputRMSs.size();
	assert( vfOutputRMSs.size() == vfOutputPeaks.size() );
	if( ui->graphicsView_output_levels->GetNumChannels() != iNumOutputChannels )
		ui->graphicsView_output_levels->SetNumChannels( iNumOutputChannels );

449 450
	ui->graphicsView_output_levels->SetRMSs( vfOutputRMSs );
	ui->graphicsView_output_levels->SetPeaks( vfOutputPeaks );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
451 452
}

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

457 458 459 460 461 462 463 464
	try
	{
		ITAsioInitializeLibrary();

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

465
		m_voAudioDevices.clear();
466 467 468 469 470

		for( long i = 0; i < lDrivers; i++ )
		{
			CAudioDeviceSpecs oDeviceSpecs;
			oDeviceSpecs.iDriverNumber = i;
471
			oDeviceSpecs.iBackend = AudioBackend::ASIO;
472 473 474 475 476 477
			oDeviceSpecs.sName = ITAsioGetDriverName( i );

			try
			{
				ITAsioInitializeDriver( i );

478 479
				long in = 0;
				long out = 0;
480 481
				ITAsioGetChannels( &in, &out );
				oDeviceSpecs.iNumInputChannels = int( in );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
482
				oDeviceSpecs.iNumOutputChannels = int( out );
483 484 485 486 487 488 489 490 491 492 493 494 495

				ITAsioFinalizeDriver();

				oDeviceSpecs.bInitializable = true;

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

			if( oDeviceSpecs.bInitializable )
496
				m_voAudioDevices.push_back( oDeviceSpecs );
497 498 499 500 501 502 503 504 505 506 507 508
		}

		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
509 510 511
	for( const CAudioDeviceSpecs oDevice : voAudioDevices )
		if( oDevice.iBackend != AudioBackend::ASIO )
			m_voAudioDevices.push_back( oDevice );
512 513
}

514 515 516
void RedstartWindow::PopulateAudioDevices()
{
	ui->comboBox_audio_iface_device->clear();
517
	int iCurrentBackend = ui->comboBox_audio_driver->currentIndex();
518 519
	for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
	{
520 521 522 523 524 525 526 527 528
		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
529 530
		else
			ui->comboBox_audio_iface_device->setEnabled( true );
531 532 533 534 535
	}
	else
	{
		ui->checkBox_portaudio_default_device->setEnabled( false );
		ui->comboBox_audio_iface_device->setEnabled( true );
536 537 538
	}
}

539 540
void RedstartWindow::AcquirePortaudioDevices()
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
	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();
562

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
563 564 565 566 567 568 569 570 571 572
			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;
573

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
			}
			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 );
598 599
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
600
void RedstartWindow::on_pushButton_start_stop_clicked()
601
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
602 603
	try
	{
604
		if( ui->checkBox_redstart_network_connect_as_client->isChecked() == false )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
605 606 607 608
		{
			if( m_pVAInterface )
			{
				m_pVANetServer->Finalize();
609

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
610 611 612 613 614 615 616 617 618 619 620
				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
			{
621
				CVAStruct oVAConfigArgs = ui->listView_redstart_session_list->GetCurrentConfig();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647

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

648 649 650 651
				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
652 653

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

656
				m_pVAInterface->Initialize();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
657
				m_pVAInterface->AttachEventHandler( this );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
658 659 660 661 662 663 664 665 666 667 668 669
				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 )
				{
670
					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
671

672 673
					ui->pushButton_add_local_path->setEnabled( true );

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
					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() );
699

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
700 701 702 703 704 705 706
			if( iStatus != IVANetClient::VA_NO_ERROR )
			{
				VA_EXCEPT2( INVALID_PARAMETER, "Could not initialize client, connection failed." );
			}

			m_pVAInterface = m_pVANetClient->GetCoreInstance();

707 708
			ui->pushButton_add_local_path->setEnabled( false );

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
709
			// @todo attach network event handler to detect server connection loss or abortion
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
710 711 712 713 714
			//m_pVANetClient->AttachEventHandler( this );
		}
	}
	catch( const CVAException& ex )
	{
Dipl.-Ing. Jonas Stienen's avatar
Mooore  
Dipl.-Ing. Jonas Stienen committed
715 716 717 718 719 720 721

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

722
		ui->statusBar->showMessage( QString::fromStdString( ex.ToString() ) + ". Will deactivate auto-start checkbox." );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
723 724
		ui->checkBox_redstart_auto_start->setChecked( false );
	}
725
}
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741

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
742
void RedstartWindow::on_comboBox_audio_driver_currentIndexChanged( int )
743 744 745 746
{
	PopulateAudioDevices();
}

Dipl.-Ing. Jonas Stienen's avatar
Mooore  
Dipl.-Ing. Jonas Stienen committed
747
void RedstartWindow::on_comboBox_audio_iface_device_currentIndexChanged( int )
748 749 750
{

}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
751 752 753

void RedstartWindow::on_actionWebsite_triggered()
{
754 755
	QUrl urlVAWebsite( "http://www.virtualacoustics.org/work" );
	QDesktopServices::openUrl( urlVAWebsite );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
756 757 758 759
}

void RedstartWindow::on_actionGet_started_triggered()
{
760 761
	QUrl urlVAWebsiteGetStarted( "http://www.virtualacoustics.org/work/start.html" );
	QDesktopServices::openUrl( urlVAWebsiteGetStarted );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
762 763 764 765
}

void RedstartWindow::on_actionDocumentation_triggered()
{
766 767
	QUrl urlVAWebsiteDocumentation( "http://www.virtualacoustics.org/work/documentation.html" );
	QDesktopServices::openUrl( urlVAWebsiteDocumentation );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
768 769 770 771
}

void RedstartWindow::on_actionGet_help_triggered()
{
772 773
	QUrl urlVAWebsiteGetHelp( "http://www.virtualacoustics.org/work/help.html" );
	QDesktopServices::openUrl( urlVAWebsiteGetHelp );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
774
}
775 776 777 778 779 780 781 782 783 784 785 786

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
787
	{
788
		ui->comboBox_audio_iface_device->setEnabled( false );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
789 790 791
		if( ui->comboBox_audio_iface_device->count() >= m_iPortaudioDefaultDevice )
			ui->comboBox_audio_iface_device->setCurrentIndex( m_iPortaudioDefaultDevice );
	}
792 793 794 795
	else
		ui->comboBox_audio_iface_device->setEnabled( true );
}

796
void RedstartWindow::on_listView_redstart_session_list_clicked( const QModelIndex &index )
797
{
Dipl.-Ing. Jonas Stienen's avatar
Mooore  
Dipl.-Ing. Jonas Stienen committed
798 799 800 801 802 803
	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 );
	}
804
}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
805 806 807 808 809

void RedstartWindow::on_actionBinauralHeadphones_triggered()
{
	RedstartSessionBinauralHeadphonesDialog d( this );
	if( d.exec() )
Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
810
	{
811 812 813 814 815 816
		// 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
817 818 819
		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
820 821
}

822 823 824 825 826 827 828
void RedstartWindow::on_actionImport_session_triggered()
{
	RedstartSessionImportDialog d( this );
	if( d.exec() )
	{
		try
		{
829 830 831 832 833
			// 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
834 835 836
			CVAStruct oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
			ui->treeView_session_details->SetStruct( oStruct );

837 838 839 840 841 842 843 844 845 846 847
		}
		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
848 849
void RedstartWindow::on_actionDefault_experimental_session_triggered()
{
850 851
	RedstartSessionExperimentalTalkthroughDialog d( this );
	if( d.exec() )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
852
	{
853 854 855 856 857 858
		// 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
859 860
		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
861 862
	}
}
863 864 865

void RedstartWindow::on_actionCirculating_source_triggered()
{
866 867
	if( !m_pVAInterface )
		return;
868

869 870 871
	m_pCirculatingSourceDialog->SetVAInterface( m_pVAInterface );
	m_pCirculatingSourceDialog->exec();
	m_pCirculatingSourceDialog->hide();
872
}
873 874 875 876 877

void RedstartWindow::on_actionAmbisonics_triggered()
{

}
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919

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
920 921 922 923 924
}

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

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
926 927 928
	CVAStruct oStruct;
	if( !ui->listView_redstart_session_list->GetCurrentSessionID().isEmpty() )
		oStruct = ui->listView_redstart_session_list->GetCurrentConfig();
929

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
930
	ui->treeView_session_details->SetStruct( oStruct );
931
}
Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
932 933 934 935 936 937 938

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

	QString sCurrentSessionID = ui->listView_redstart_session_list->GetCurrentSessionID();
	CVAStruct oCurrentConfig;
939 940 941 942 943 944 945
	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
946
	{
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
		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
970
	}
971 972 973 974 975 976 977
}

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

	d.SetDuplicationOptionDeactivated();
Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
978 979 980 981

	if( d.exec() )
	{
		QVariantHash oNewConfig = d.GetCoreConfig();
982 983 984 985 986 987 988 989
		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
990
		else
991 992 993 994
		{
			ui->listView_redstart_session_list->AddSession( d.GetSessionName(), oNewConfig );
		}

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
995 996 997 998
		ui->treeView_session_details->SetStruct( ConvertQHashToVAStruct( oNewConfig ) );
	}
}

999
void RedstartWindow::on_actionDuplicate_current_session_triggered()
Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
1000
{
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
	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
1013 1014
	if( d.exec() )
	{
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
		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";
			ui->listView_redstart_session_list->AddSession( sNewID, oNewConfig ); // In any case save the session so no data is lost
		}
		else
		{
			ui->listView_redstart_session_list->AddSession( d.GetSessionName(), oNewConfig );
		}

		ui->treeView_session_details->SetStruct( ConvertQHashToVAStruct( oNewConfig ) );
Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
1030 1031 1032
	}
}

1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
void RedstartWindow::CoreChangeInputSignalDecibel( int iLevelDB )
{
	emit InputSignalChangedDecibel( iLevelDB );
	emit InputSignalChangedDecibel( ( double ) iLevelDB );
}

void RedstartWindow::CoreChangeInputSignalDecibel( double dLevelDB )
{
	emit InputSignalChangedDecibel( dLevelDB );
	emit InputSignalChangedDecibel( ( int ) dLevelDB );

	if( m_pVAInterface )
	{
		const double dGain = db20_to_ratio( dLevelDB );
		m_pVAInterface->SetInputGain( dGain );
	}
}

1051
void RedstartWindow::CoreChangeInputIsMuted( int iMuted )
1052
{
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
	emit InputIsMutedChanged( ( bool ) iMuted );

	if( m_pVAInterface )
		m_pVAInterface->SetInputMuted( ( bool ) iMuted );
}

void RedstartWindow::CoreChangeOutputSignalDecibel( int iLevelDB )
{
	emit OutputSignalChangedDecibel( iLevelDB );
	emit OutputSignalChangedDecibel( ( double ) iLevelDB );
1063
}
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084

void RedstartWindow::CoreChangeOutputSignalDecibel( double dLevelDB )
{
	emit OutputSignalChangedDecibel( dLevelDB );
	emit OutputSignalChangedDecibel( ( int ) dLevelDB );

	if( m_pVAInterface )
	{
		const double dGain = db20_to_ratio( dLevelDB );
		m_pVAInterface->SetOutputGain( dGain );
	}
}

void RedstartWindow::CoreChangeOutputIsMuted( int iMuted )
{
	emit OutputIsMutedChanged( ( bool ) iMuted );

	if( m_pVAInterface )
		m_pVAInterface->SetOutputMuted( ( bool ) iMuted );
}

1085
void RedstartWindow::CoreChangeAuralizationMode( bool bActivateMode, int iMode )
1086 1087 1088 1089 1090 1091
{
	if( !m_pVAInterface )
		return;

	int iAM = m_pVAInterface->GetGlobalAuralizationMode();

1092 1093
	if( bActivateMode == true )
		iAM |= iMode;
1094
	else
1095
		iAM &= ~iMode;
1096 1097 1098 1099

	m_pVAInterface->SetGlobalAuralizationMode( iAM );
}

1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130