Progress

parent 526e2109
......@@ -53,6 +53,7 @@ endif( )
# Qt UI form compiler
qt5_wrap_ui( "ui_RedstartWindow.h" "ui/RedstartWindow.ui" )
qt5_wrap_ui( "ui_RedstartSessionBinauralHeadphonesDialog.h" "ui/RedstartSessionBinauralHeadphonesDialog.ui" )
include_directories( "${CMAKE_CURRENT_BINARY_DIR}" ) # Qt UI form compiler generates files into this folder
......@@ -61,7 +62,7 @@ include_directories( "${CMAKE_CURRENT_BINARY_DIR}" ) # Qt UI form compiler gener
qt5_add_resources( VA_REDSTART_RESOURCES "res/QRedstart.qrc" OPTIONS -compress 3 )
add_executable( Redstart ${VA_REDSTART_RESOURCES} "src/main.cpp" "src/RedstartWindow.cpp" "src/RedstartWindow.h" "src/RedstartUtils.h" "ui/RedstartWindow.ui" )
add_executable( Redstart ${VA_REDSTART_RESOURCES} "src/main.cpp" "src/RedstartWindow.cpp" "src/RedstartWindow.h" "src/RedstartRunSimpleExample.h" "src/RedstartUtils.h" "src/RedstartSessionBinauralHeadphonesDialog.h" "ui/RedstartWindow.ui" "ui/RedstartSessionBinauralHeadphonesDialog.ui" )
target_link_libraries( Redstart ${VISTA_USE_PACKAGE_LIBRARIES} ${VISTAINTERPROCCOMM_ADDITIONAL_DEPENDENCIES} Qt5::Widgets )
install( TARGETS Redstart RUNTIME DESTINATION "bin" )
......
/*
* --------------------------------------------------------------------------------------------
*
* 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
*
* --------------------------------------------------------------------------------------------
*/
#ifndef IW_REDSTART_RUN_SIMPLE_EXAMPLE
#define IW_REDSTART_RUN_SIMPLE_EXAMPLE
#include <VA.h>
inline void RunSimpleExample( IVAInterface* pVA )
{
const std::string sSignalSourceID = pVA->CreateSignalSourceBufferFromFile( "$(DemoSound)" );
pVA->SetSignalSourceBufferPlaybackAction( sSignalSourceID, IVAInterface::VA_PLAYBACK_ACTION_PLAY );
pVA->SetSignalSourceBufferLooping( sSignalSourceID, true );
const int iSoundSourceID = pVA->CreateSoundSource( "Redstart C++ example sound source" );
pVA->SetSoundSourcePose( iSoundSourceID, VAVec3( 2.0f, 1.7f, 2.0f ), VAQuat( 0.0f, 0.0f, 0.0f, 1.0f ) );
pVA->SetSoundSourceSignalSource( iSoundSourceID, sSignalSourceID );
const int iHRIR = pVA->CreateDirectivityFromFile( "$(DefaultHRIR)" );
const int iSoundReceiverID = pVA->CreateSoundReceiver( "Redstart C++ example sound receiver" );
pVA->SetSoundReceiverPose( iSoundReceiverID, VAVec3( 0.0f, 1.7f, 0.0f ), VAQuat( 0.0f, 0.0f, 0.0f, 1.0f ) );
pVA->SetSoundReceiverDirectivity( iSoundReceiverID, iHRIR );
};
#endif // IW_REDSTART_RUN_SIMPLE_EXAMPLE
/*
* --------------------------------------------------------------------------------------------
*
* 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
*
* --------------------------------------------------------------------------------------------
*/
#ifndef IW_REDSTART_SESSION_BINAURAL_HEADPHONES_DIALOG
#define IW_REDSTART_SESSION_BINAURAL_HEADPHONES_DIALOG
#include <QDialog>
#include <QDir>
#include <QString>
#include <QSettings>
#include <QHash>
#include "ui_RedstartSessionBinauralHeadphonesDialog.h"
namespace Ui
{
class RedstartSessionBinauralHeadphonesDialog;
}
class RedstartSessionBinauralHeadphonesDialog : public QDialog
{
Q_OBJECT
public:
inline explicit RedstartSessionBinauralHeadphonesDialog( QWidget *parent )
: QDialog( parent ),
ui( new Ui::RedstartSessionBinauralHeadphonesDialog )
{
ui->setupUi( this );
};
inline ~RedstartSessionBinauralHeadphonesDialog()
{
//m_qSettings.setValue( "Redstart/Sessions/", ui->checkBox_IncludeAllChannels->checkState() );
};
QVariantHash GetCoreConfig() const
{
QVariantHash oHash;
//ui->line
return oHash;
};
private slots:
private:
Ui::RedstartSessionBinauralHeadphonesDialog *ui;
QDir m_oBasePath;
QString m_sFileBaseName;
QSettings m_qSettings;
};
#endif // IW_REDSTART_SESSION_BINAURAL_HEADPHONES_DIALOG
......@@ -19,6 +19,10 @@
#include "RedstartWindow.h"
#include <ui_RedstartWindow.h>
#include "RedstartRunSimpleExample.h"
#include "RedstartSessionBinauralHeadphonesDialog.h"
#include "RedstartUtils.h"
#include <VA.h>
#include <VACore.h>
#include <VANet.h>
......@@ -47,6 +51,8 @@ RedstartWindow::RedstartWindow( bool bFailSafeMode, bool bAutoStart, bool bSkipC
ui->comboBox_audio_iface_buffer_size->addItem( "AUTO", AudioBufferSize::AUTO );
m_iPortaudioDefaultDevice = -1;
if( !bSkipConfig )
LoadConfiguration();
......@@ -83,13 +89,7 @@ void RedstartWindow::LoadConfiguration()
if( !bValOK )
iAudioBackend = AudioBackend::ASIO;
ui->comboBox_audio_driver->setCurrentIndex( iAudioBackend );
if( iAudioBackend == AudioBackend::PORTAUDIO )
PopulatePortaudioDevicesFromSettings();
else
PopulateAsioDevicesFromSettings();
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 );
......@@ -107,6 +107,10 @@ void RedstartWindow::LoadConfiguration()
if( m_qSettings.contains( "Redstart/autostart" ) )
ui->checkBox_redstart_auto_start->setChecked( m_qSettings.value( "Redstart/autostart" ).toBool() );
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() );
QVariantList voAudioDevices;
voAudioDevices = m_qSettings.value( "Redstart/audio/devicelist" ).toList();
......@@ -114,6 +118,10 @@ void RedstartWindow::LoadConfiguration()
m_voAudioDevices.push_back( CAudioDeviceSpecs( oAudioDevice.toHash() ) );
PopulateAudioDevices();
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 );
}
void RedstartWindow::StoreConfiguration()
......@@ -136,6 +144,12 @@ void RedstartWindow::StoreConfiguration()
m_qSettings.setValue( "Redstart/network/client_mode", ui->checkBox_redstart_network_connect_as_client->isChecked() );
m_qSettings.setValue( "Redstart/autostart", ui->checkBox_redstart_auto_start->isChecked() );
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 );
m_qSettings.setValue( "Redstart/audio/portaudio_use_default_device", ui->checkBox_portaudio_default_device->isChecked() );
QVariantList voAudioDevices;
for( const CAudioDeviceSpecs& oDevice : m_voAudioDevices )
voAudioDevices.push_back( oDevice.asHash() );
......@@ -148,124 +162,6 @@ void RedstartWindow::on_actionQuit_triggered()
close();
}
void RedstartWindow::on_pushButton_start_stop_clicked()
{
try
{
if( !ui->checkBox_redstart_network_connect_as_client->isChecked() )
{
if( m_pVAInterface )
{
m_pVANetServer->Finalize();
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
{
// @todo get config from session
CVAStruct oVAConfigArgs = VACore::GetCoreConfigFromFile( "../VACore/conf/VACore.ini" );
// 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;
oVAConfigArgs[ "Paths" ][ "redstart_data" ] = "../VACore/data";
m_pVAInterface = VACore::CreateCoreInstance( oVAConfigArgs );
m_pVAInterface->Initialize();
// @todo attach event handler
//m_pVAInterface->AttachEventHandler( this );
m_pVANetServer->SetCoreInstance( m_pVAInterface );
bool bOK;
int iPort = ui->lineEdit_redstart_network_port->text().toInt( &bOK );
int iStatus = -1;
if( bOK )
iStatus = m_pVANetServer->Initialize( ui->lineEdit_redstart_network_address->text().toStdString(), iPort );
else
iStatus = m_pVANetServer->Initialize( ui->lineEdit_redstart_network_address->text().toStdString() );
if( m_pVAInterface->GetState() == IVAInterface::VA_CORESTATE_READY && iStatus == IVANetServer::VA_NO_ERROR )
{
ui->statusBar->showMessage( "VA core successfully initialized and network server started." );
PostCoreStart();
}
else
{
ui->statusBar->showMessage( "VA core initialization failed." );
m_pVANetServer->Finalize();
delete m_pVAInterface;
m_pVAInterface = NULL;
}
}
}
else
{
// Client mode
if( m_pVANetClient->IsConnected() )
m_pVANetClient->Disconnect();
m_pVAInterface = NULL;
bool bOK;
int iPort = ui->lineEdit_redstart_network_port->text().toInt( &bOK );
int iStatus = -1;
if( bOK )
iStatus = m_pVANetClient->Initialize( ui->lineEdit_redstart_network_address->text().toStdString(), iPort );
else
iStatus = m_pVANetClient->Initialize( ui->lineEdit_redstart_network_address->text().toStdString() );
if( iStatus != IVANetClient::VA_NO_ERROR )
{
VA_EXCEPT2( INVALID_PARAMETER, "Could not initialize client, connection failed." );
}
m_pVAInterface = m_pVANetClient->GetCoreInstance();
// @todo attach event handler
//m_pVANetClient->AttachEventHandler( this );
}
}
catch( const CVAException& ex )
{
ui->statusBar->showMessage( QString::fromStdString( ex.ToString() ) );
ui->checkBox_redstart_auto_start->setChecked( false );
}
}
void RedstartWindow::PostCoreStart()
{
ui->pushButton_start_stop->setText( "Stop" );
......@@ -277,7 +173,7 @@ void RedstartWindow::PostCoreStart()
ui->groupBox_core->setEnabled( true );
ui->groupBox_paths->setEnabled( true );
ui->groupBox_macros->setEnabled( true );
ui->menuRun->setEnabled( true );
CVAVersionInfo oVersion;
m_pVAInterface->GetVersionInfo( &oVersion );
......@@ -301,6 +197,7 @@ void RedstartWindow::PostCoreStop()
ui->groupBox_core->setEnabled( false );
ui->groupBox_paths->setEnabled( false );
ui->groupBox_macros->setEnabled( false );
ui->menuRun->setEnabled( false );
}
void RedstartWindow::RestoreWindowSize()
......@@ -311,6 +208,8 @@ void RedstartWindow::RestoreWindowSize()
void RedstartWindow::AcquireAsioDevices()
{
std::vector< CAudioDeviceSpecs > voAudioDevices = m_voAudioDevices;
try
{
ITAsioInitializeLibrary();
......@@ -336,7 +235,7 @@ void RedstartWindow::AcquireAsioDevices()
long out = 0;
ITAsioGetChannels( &in, &out );
oDeviceSpecs.iNumInputChannels = int( in );
oDeviceSpecs.iNumInputChannels = int( out );
oDeviceSpecs.iNumOutputChannels = int( out );
ITAsioFinalizeDriver();
......@@ -362,11 +261,10 @@ void RedstartWindow::AcquireAsioDevices()
oErrMsg.showMessage( sErrorMessage );
oErrMsg.exec();
}
}
void RedstartWindow::PopulateAsioDevicesFromSettings()
{
for( const CAudioDeviceSpecs oDevice : voAudioDevices )
if( oDevice.iBackend != AudioBackend::ASIO )
m_voAudioDevices.push_back( oDevice );
}
void RedstartWindow::PopulateAudioDevices()
......@@ -384,6 +282,8 @@ void RedstartWindow::PopulateAudioDevices()
ui->checkBox_portaudio_default_device->setEnabled( true );
if( ui->checkBox_portaudio_default_device->isChecked() )
ui->comboBox_audio_iface_device->setEnabled( false );
else
ui->comboBox_audio_iface_device->setEnabled( true );
}
else
{
......@@ -394,12 +294,181 @@ void RedstartWindow::PopulateAudioDevices()
void RedstartWindow::AcquirePortaudioDevices()
{
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();
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;
}
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 );
}
void RedstartWindow::PopulatePortaudioDevicesFromSettings()
void RedstartWindow::on_pushButton_start_stop_clicked()
{
try
{
if( !ui->checkBox_redstart_network_connect_as_client->isChecked() )
{
if( m_pVAInterface )
{
m_pVANetServer->Finalize();
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
{
// @todo get config from session
CVAStruct oVAConfigArgs = VACore::GetCoreConfigFromFile( "../VACore/conf/VACore.ini" );
// 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;
oVAConfigArgs[ "Paths" ][ "redstart_data" ] = "../VACore/data";
m_pVAInterface = VACore::CreateCoreInstance( oVAConfigArgs );
m_pVAInterface->Initialize();
// @todo attach event handler
//m_pVAInterface->AttachEventHandler( this );
m_pVANetServer->SetCoreInstance( m_pVAInterface );
bool bOK;
int iPort = ui->lineEdit_redstart_network_port->text().toInt( &bOK );
int iStatus = -1;
if( bOK )
iStatus = m_pVANetServer->Initialize( ui->lineEdit_redstart_network_address->text().toStdString(), iPort );
else
iStatus = m_pVANetServer->Initialize( ui->lineEdit_redstart_network_address->text().toStdString() );
if( m_pVAInterface->GetState() == IVAInterface::VA_CORESTATE_READY && iStatus == IVANetServer::VA_NO_ERROR )
{
ui->statusBar->showMessage( "VA core successfully initialized and network server started." );
PostCoreStart();
}
else
{
ui->statusBar->showMessage( "VA core initialization failed." );
m_pVANetServer->Finalize();
delete m_pVAInterface;
m_pVAInterface = NULL;
}
}
}
else
{
// Client mode
if( m_pVANetClient->IsConnected() )
m_pVANetClient->Disconnect();
m_pVAInterface = NULL;
bool bOK;
int iPort = ui->lineEdit_redstart_network_port->text().toInt( &bOK );
int iStatus = -1;
if( bOK )
iStatus = m_pVANetClient->Initialize( ui->lineEdit_redstart_network_address->text().toStdString(), iPort );
else
iStatus = m_pVANetClient->Initialize( ui->lineEdit_redstart_network_address->text().toStdString() );
if( iStatus != IVANetClient::VA_NO_ERROR )
{
VA_EXCEPT2( INVALID_PARAMETER, "Could not initialize client, connection failed." );
}
m_pVAInterface = m_pVANetClient->GetCoreInstance();
// @todo attach event handler
//m_pVANetClient->AttachEventHandler( this );
}
}
catch( const CVAException& ex )
{
ui->statusBar->showMessage( QString::fromStdString( ex.ToString() ) );
ui->checkBox_redstart_auto_start->setChecked( false );
}
}
void RedstartWindow::on_pushButton_refresh_clicked()
......@@ -462,13 +531,46 @@ void RedstartWindow::on_checkBox_redstart_network_connect_as_client_clicked()
void RedstartWindow::on_checkBox_portaudio_default_device_clicked()
{
if( ui->checkBox_portaudio_default_device->isChecked() )
{
ui->comboBox_audio_iface_device->setEnabled( false );
if( ui->comboBox_audio_iface_device->count() >= m_iPortaudioDefaultDevice )
ui->comboBox_audio_iface_device->setCurrentIndex( m_iPortaudioDefaultDevice );
}
else
ui->comboBox_audio_iface_device->setEnabled( true );
}
void RedstartWindow::on_listView_redstart_session_list_clicked(const QModelIndex &index)
{
// m_pSessionManager->SetCurrentSession( index );
}
void RedstartWindow::on_actionBinauralHeadphones_triggered()
{
RedstartSessionBinauralHeadphonesDialog d( this );
if( d.exec() )
{
d.GetCoreConfig();
// add session
}
}
void RedstartWindow::on_actionDefault_experimental_session_triggered()
{
}
void RedstartWindow::on_actionRunSimpleExample_triggered()
{
try
{
RunSimpleExample( m_pVAInterface );
}
catch( CVAException& e )
{
QString sErrorMessage = QString( "Could not run simple example scene: %1" ).arg( QString::fromStdString( e.ToString() ) );
QErrorMessage oErrMsg;
oErrMsg.showMessage( sErrorMessage );
oErrMsg.exec();
}
}
......@@ -72,12 +72,12 @@ public:
inline CAudioDeviceSpecs()
{
int iDriverNumber = -1;
int iNumInputChannels = -1;
int iNumOutputChannels = -1;
bool bInitializable = false;
bool bDefaultDevice = false;
int iBackend = -1;
iDriverNumber = -1;
iNumInputChannels = -1;
iNumOutputChannels = -1;
bInitializable = false;
bDefaultDevice = false;
iBackend = -1;
};
inline CAudioDeviceSpecs( const QVariantHash& oHash )
......@@ -130,6 +130,12 @@ private slots:
void on_checkBox_portaudio_default_device_clicked();
void on_listView_redstart_session_list_clicked( const QModelIndex &index );
void on_actionBinauralHeadphones_triggered();
void on_actionDefault_experimental_session_triggered();
void on_actionRunSimpleExample_triggered();
private:
void PostCoreStart();
void PostCoreStop();
......@@ -144,19 +150,16 @@ private:
IVANetServer* m_pVANetServer;
std::vector< CAudioDeviceSpecs > m_voAudioDevices;
int m_iPortaudioDefaultDevice;
QSettings m_qSettings;
void LoadConfiguration();
void StoreConfiguration();
void PopulateAudioDevices();
void AcquireAsioDevices();
void PopulateAsioDevicesFromSettings();
void AcquirePortaudioDevices();
void PopulatePortaudioDevicesFromSettings();
void PopulateAudioDevices();
};