Moving more source code, now all looks tidy

parent 91cbae21
......@@ -3,12 +3,34 @@ set( RelativeSourceGroup "src\\core" )
set( SubDirs )
set( DirFiles
clock.cpp
config.cpp
control.cpp
core.h
core.cpp
directivity.cpp
events.cpp
file_handling.cpp
finalize.cpp
geometry.cpp
init.cpp
homogeneous_medium.cpp
initialize.cpp
locking.cpp
material.cpp
module.cpp
object.cpp
progress.cpp
rendering.cpp
reproduction.cpp
reset.cpp
scene.cpp
signal_source.cpp
sound_portal.cpp
sound_receiver.cpp
sound_source.cpp
state.cpp
thread_loop.cpp
version.cpp
_SourceFiles.cmake
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......
/*
* --------------------------------------------------------------------------------------------
*
* 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-2018
* VVVVVV AAA Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University
*
* --------------------------------------------------------------------------------------------
*/
#include "core.h"
double CVACoreImpl::GetCoreClock() const
{
// Clock ist immer da, reentrance hier erlaubt
double dNow = m_pClock->getTime();
double dOffset = ( double ) m_fCoreClockOffset;
return ( dNow - dOffset );
}
void CVACoreImpl::SetCoreClock( const double dSeconds )
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
VA_TRY
{
if( dSeconds < 0 )
VA_EXCEPT2( INVALID_PARAMETER, "Time must not be negative" );
// Aktuelle Zeit holen
double dNow = m_pClock->getTime();
double dOffset = dSeconds - dNow;
// TODO: Sollte eigentlich ber doubles gehen. Leider noch keine AtomicDoubles...
m_fCoreClockOffset = ( float ) dOffset;
VA_VERBOSE( "Core", "Set clock to " << timeToString( dSeconds ) );
}
VA_RETHROW;
}
/*
* --------------------------------------------------------------------------------------------
*
* 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-2018
* VVVVVV AAA Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University
*
* --------------------------------------------------------------------------------------------
*/
#include "core.h"
const CVACoreConfig* CVACoreImpl::GetCoreConfig() const
{
return &m_oCoreConfig;
}
void VACore::StoreCoreConfigToFile( const CVAStruct& oConfig, const std::string& sConfigFilePath )
{
StoreStructToINIFile( sConfigFilePath, oConfig );
}
CVAStruct VACore::LoadCoreConfigFromFile( const std::string& sConfigFilePath )
{
CVAStruct oFinalCoreConfigStruct, oCurrentConfig;
VistaFileSystemFile oConfigFile( sConfigFilePath );
std::list< VistaFileSystemFile > voConfigFiles;
std::vector< VistaFileSystemDirectory > voIncludePaths;
if( oConfigFile.Exists() && oConfigFile.GetParentDirectory().empty() == false )
voIncludePaths.push_back( oConfigFile.GetParentDirectory() );
voConfigFiles.push_back( VistaFileSystemFile( sConfigFilePath ) );
VA_INFO( "Core", "Working directory: '" << VistaFileSystemDirectory::GetCurrentWorkingDirectory() << "'" );
while( voConfigFiles.empty() == false )
{
VistaFileSystemFile oCurrentConfigFile( voConfigFiles.front() );
voConfigFiles.pop_front();
if( oCurrentConfigFile.Exists() == false )
{
for( size_t n = 0; n < voIncludePaths.size(); n++ )
{
std::string sCombinedFilePath = voIncludePaths[ n ].GetName() + PATH_SEPARATOR + oCurrentConfigFile.GetLocalName();
oCurrentConfigFile.SetName( sCombinedFilePath );
if( oCurrentConfigFile.Exists() && oCurrentConfigFile.IsFile() )
{
VA_INFO( "Config", "Including further configuration file '" + oCurrentConfigFile.GetLocalName() +
"' from include path '" + voIncludePaths[ n ].GetName() + "'" );
break;
}
}
if( !oCurrentConfigFile.Exists() )
{
VA_EXCEPT2( FILE_NOT_FOUND, "Configuration file '" + oCurrentConfigFile.GetLocalName() + "' not found, aborting." );
}
}
VA_VERBOSE( "Config", std::string( "Reading INI file '" ) + oCurrentConfigFile.GetLocalName() + "'" );
LoadStructFromINIFIle( oCurrentConfigFile.GetName(), oCurrentConfig );
if( oCurrentConfig.HasKey( "paths" ) )
{
const CVAStruct& oPaths( oCurrentConfig[ "paths" ] );
CVAStruct::const_iterator it = oPaths.Begin();
while( it != oPaths.End() )
{
const CVAStructValue& oIncludePath( ( it++ )->second );
VistaFileSystemDirectory oNewPathDir( oIncludePath );
if( oNewPathDir.Exists() && oNewPathDir.IsDirectory() )
voIncludePaths.push_back( oNewPathDir );
}
}
if( oCurrentConfig.HasKey( "files" ) )
{
const CVAStruct& oPaths( oCurrentConfig[ "files" ] );
CVAStruct::const_iterator it = oPaths.Begin();
while( it != oPaths.End() )
{
const CVAStructValue& oIncludeFile( ( it++ )->second );
voConfigFiles.push_back( VistaFileSystemFile( oIncludeFile ) );
}
}
oCurrentConfig.RemoveKey( "files" );
// Merge structs (check for uniqueness)
oFinalCoreConfigStruct.Merge( oCurrentConfig, true );
}
return oFinalCoreConfigStruct;
}
CVAStruct CVACoreImpl::GetCoreConfiguration( const bool bFilterEnabled ) const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
CVAStruct oCoreConfig;
if( bFilterEnabled )
{
CVAStruct::const_iterator cit = m_oCoreConfig.GetStruct().Begin();
while( cit != m_oCoreConfig.GetStruct().End() )
{
const std::string sKey( cit->first );
const CVAStructValue& oVal( cit->second );
++cit;
if( oVal.IsStruct() )
{
const CVAStruct& oSection( oVal.GetStruct() );
if( oSection.HasKey( "enabled" ) )
if( bool( oSection[ "enabled" ] ) == false )
continue; // Only skip if explicitly not enabled
oCoreConfig[ sKey ] = oVal;
}
}
}
else
{
oCoreConfig = m_oCoreConfig.GetStruct();
}
return oCoreConfig;
}
CVAStruct CVACoreImpl::GetHardwareConfiguration() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
return m_oCoreConfig.oHardwareSetup.GetStruct();
}
/*
* --------------------------------------------------------------------------------------------
*
* 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-2018
* VVVVVV AAA Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University
*
* --------------------------------------------------------------------------------------------
*/
#include "core.h"
bool CVACoreImpl::GetInputMuted() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
return m_bInputMuted;
}
void CVACoreImpl::SetInputMuted( const bool bMuted )
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
VA_TRY
{
if( m_bInputMuted == bMuted )
return;
m_bInputMuted = bMuted;
if( m_pInputAmp )
{
if( m_bInputMuted )
m_pInputAmp->SetGain( 0.0f );
else
m_pInputAmp->SetGain( ( float ) m_dInputGain );
}
VA_INFO( "Core", "Input mute toggled" );
CVAEvent ev;
ev.iEventType = CVAEvent::INPUT_MUTING_CHANGED;
ev.pSender = this;
ev.bMuted = m_bInputMuted;
m_pEventManager->BroadcastEvent( ev );
}
VA_RETHROW;
}
double CVACoreImpl::GetInputGain() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
return m_dInputGain;
}
void CVACoreImpl::SetInputGain( double dGain )
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
VA_TRY
{
if( !GetVolumeValid( dGain ) )
VA_EXCEPT2( INVALID_PARAMETER, "Invalid gain" );
if( m_dInputGain == dGain )
return;
m_dInputGain = dGain;
if( m_pInputAmp )
{
if( m_bInputMuted )
m_pInputAmp->SetGain( 0 );
else
m_pInputAmp->SetGain( ( float ) dGain );
}
// Ereignis generieren
CVAEvent ev;
ev.iEventType = CVAEvent::INPUT_GAIN_CHANGED;
ev.pSender = this;
ev.dVolume = dGain;
m_pEventManager->BroadcastEvent( ev );
VA_VERBOSE( "Core", "Set input gain = " << IVAInterface::GetVolumeStrDecibel( dGain ) );
}
VA_RETHROW;
}
double CVACoreImpl::GetOutputGain() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
return m_dOutputGain;
}
void CVACoreImpl::SetOutputGain( const double dGain )
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
VA_TRY
{
if( !GetVolumeValid( dGain ) )
VA_EXCEPT2( INVALID_PARAMETER, "Invalid gain" );
if( m_dOutputGain == dGain )
return;
m_dOutputGain = dGain;
if( m_pOutputPatchbay )
{
if( m_bOutputMuted )
m_pOutputPatchbay->SetOutputGain( 0, 0.0f );
else
m_pOutputPatchbay->SetOutputGain( 0, dGain );
}
// Ereignis generieren
CVAEvent ev;
ev.iEventType = CVAEvent::OUTPUT_GAIN_CHANGED;
ev.pSender = this;
ev.dVolume = dGain;
m_pEventManager->BroadcastEvent( ev );
VA_VERBOSE( "Core", "Set output gain = " << IVAInterface::GetVolumeStrDecibel( dGain ) );
}
VA_RETHROW;
}
bool CVACoreImpl::GetOutputMuted() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
return m_bOutputMuted;
}
void CVACoreImpl::SetOutputMuted( const bool bMuted )
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
VA_TRY
{
if( m_bOutputMuted == bMuted )
return;
m_bOutputMuted = bMuted;
VA_INFO( "Core", "Output mute toggled" );
if( m_pOutputPatchbay )
m_pOutputPatchbay->SetOutputMuted( 0, bMuted );
// Ereignis generieren
CVAEvent ev;
ev.iEventType = CVAEvent::OUTPUT_MUTING_CHANGED;
ev.pSender = this;
ev.bMuted = m_bOutputMuted;
m_pEventManager->BroadcastEvent( ev );
}
VA_RETHROW;
}
int CVACoreImpl::GetGlobalAuralizationMode() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
return m_iGlobalAuralizationMode;
}
void CVACoreImpl::SetGlobalAuralizationMode( const int iAuralizationMode )
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
VA_TRY
{
if( !GetAuralizationModeValid( iAuralizationMode ) )
VA_EXCEPT2( INVALID_PARAMETER, "Invalid auralization mode" );
if( m_iGlobalAuralizationMode == iAuralizationMode )
{
return;
}
m_iGlobalAuralizationMode = iAuralizationMode;
// Neuberechnung der Schallpfade triggern
m_pCoreThread->Trigger();
// Ereignis generieren
CVAEvent ev;
ev.iEventType = CVAEvent::GLOBAL_AURALIZATION_MODE_CHANGED;
ev.pSender = this;
ev.iAuralizationMode = iAuralizationMode;
m_pEventManager->BroadcastEvent( ev );
VA_VERBOSE( "Core", "Set global auralization mode = " << IVAInterface::GetAuralizationModeStr( iAuralizationMode, true ) );
}
VA_RETHROW;
}
This diff is collapsed.
/*
* --------------------------------------------------------------------------------------------
*
* 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-2018
* VVVVVV AAA Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University
*
* --------------------------------------------------------------------------------------------
*/
#include "core.h"
/*
* --------------------------------------------------------------------------------------------
*
* 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-2018
* VVVVVV AAA Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University
*
* --------------------------------------------------------------------------------------------
*/
#include "core.h"
void CVACoreImpl::AttachEventHandler( IVAEventHandler* pCoreEventHandler )
{
VA_TRY
{
// Immer mglich. Unabhngig vom Zustand. Thread-safety wird im Manager geregelt.
m_pEventManager->AttachHandler( pCoreEventHandler );
}
VA_RETHROW;
}
void CVACoreImpl::DetachEventHandler( IVAEventHandler* pCoreEventHandler )
{
VA_TRY
{
// Immer mglich. Unabhngig vom Zustand. Thread-safety wird im Manager geregelt.
m_pEventManager->DetachHandler( pCoreEventHandler );
}
VA_RETHROW;
}
void CVACoreImpl::SendAudioDeviceDetectorUpdateEvent()
{
CVAEvent ev;
ev.iEventType = CVAEvent::MEASURES_UPDATE;
ev.pSender = this;
if( m_pInputStreamDetector )
{
ev.vfInputPeaks.resize( m_oCoreConfig.oAudioDriverConfig.iInputChannels );
m_pInputStreamDetector->GetPeaks( ev.vfInputPeaks, true );
ev.vfInputRMSs.resize( m_oCoreConfig.oAudioDriverConfig.iInputChannels );
m_pInputStreamDetector->GetRMSs( ev.vfInputRMSs, true );
}
if( m_pOutputStreamDetector )
{
ev.vfOutputPeaks.resize( m_oCoreConfig.oAudioDriverConfig.iOutputChannels );
m_pOutputStreamDetector->GetPeaks( ev.vfOutputPeaks, true );
ev.vfOutputRMSs.resize( m_oCoreConfig.oAudioDriverConfig.iOutputChannels );
m_pOutputStreamDetector->GetRMSs( ev.vfOutputRMSs, true );
}
ev.fSysLoad = 0;
// TODO: Sollte am Ende gemessen werden! => StreamTracker
ev.fDSPLoad = 0;
//ev.fDSPLoad = m_pAudiostreamProcessor->GetDSPLoad();
m_pEventManager->BroadcastEvent( ev );
}
/*
* --------------------------------------------------------------------------------------------
*
* 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-2018
* VVVVVV AAA Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University
*
* --------------------------------------------------------------------------------------------
*/
#include "core.h"
#ifdef WIN32
// Trick um DLL-Pfad zu ermitteln
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#endif
std::string VACore::GetCoreLibFilePath()
{
#ifdef WIN32
CHAR pszPath[ MAX_PATH + 1 ] = { 0 };
GetModuleFileNameA( ( HINSTANCE ) &__ImageBase, pszPath, _countof( pszPath ) );
return std::string( pszPath );
#else
VA_EXCEPT2( NOT_IMPLEMENTED, "This function is not implemented for your platform. Sorry." );
return "";
#endif // WIN32
}
CVAStruct CVACoreImpl::GetSearchPaths() const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
CVAStruct oSearchPaths;
for( size_t i = 0; i < m_oCoreConfig.vsSearchPaths.size(); i++ )
oSearchPaths[ "path_" + std::to_string( long( i ) ) ] = m_oCoreConfig.vsSearchPaths[ i ];
return oSearchPaths;
}
CVAStruct CVACoreImpl::GetFileList( const bool bRecursive, const std::string& sFileSuffixFilter ) const
{
VA_NO_REENTRANCE;
VA_CHECK_INITIALIZED;
CVAStruct oFileList;
for( size_t i = 0; i < m_oCoreConfig.vsSearchPaths.size(); i++ )
{
if( bRecursive )
{
RecursiveFileList( m_oCoreConfig.vsSearchPaths[ i ], oFileList, sFileSuffixFilter );
}
else
{
std::vector< std::string > vsFileList;
FileList( m_oCoreConfig.vsSearchPaths[ i ], vsFileList, sFileSuffixFilter );
CVAStruct oMoreFiles;
for( size_t j = 0; j < vsFileList.size(); j++ )
oMoreFiles[ std::to_string( long( j ) ) ] = vsFileList[ j ];
oFileList[ m_oCoreConfig.vsSearchPaths[ i ] ] = oMoreFiles;
}
}
return oFileList;
}
std::string CVACoreImpl::FindFilePath( const std::string& sRelativeFilePath ) const
{
VA_TRY
{
std::string sRelativeFilePathSubstituted = SubstituteMacros( sRelativeFilePath );
VistaFileSystemFile oFile( sRelativeFilePathSubstituted );
if( oFile.Exists() && oFile.IsFile() )
return sRelativeFilePathSubstituted;
// Search with paths list
std::string sFinalPathWithSearch;
for( size_t i = 0; i < m_oCoreConfig.vsSearchPaths.size(); i++ )
{
const std::string& sSearchPath( m_oCoreConfig.vsSearchPaths[ i ] );
std::string sCombinedFilePath = correctPath( sSearchPath + PATH_SEPARATOR + sRelativeFilePathSubstituted );
VistaFileSystemFile oFile( sCombinedFilePath );
VA_TRACE( "Core:FindFilePath", "Searching in directory '" + sSearchPath + "' for file '" + sRelativeFilePathSubstituted + "'" );
if( oFile.Exists() && oFile.IsFile() )
{
if( sFinalPathWithSearch.empty() )
{
sFinalPathWithSearch = sCombinedFilePath;
}
else
{
VA_WARN( "Core", "Found ambiguous file path '" + sCombinedFilePath + "' (skipped), using first path '" + sFinalPathWithSearch + "'" );
}
}
}
return sFinalPathWithSearch;
}