diff --git a/src/core/AudioEngine/AudioEngine.cpp b/src/core/AudioEngine/AudioEngine.cpp index da6bd7704..ccc9ef347 100644 --- a/src/core/AudioEngine/AudioEngine.cpp +++ b/src/core/AudioEngine/AudioEngine.cpp @@ -460,7 +460,7 @@ void AudioEngine::clearAudioBuffers( uint32_t nFrames ) #ifdef H2CORE_HAVE_JACK if ( Hydrogen::get_instance()->haveJackAudioDriver() ) { - JackAudioDriver * pJackAudioDriver = dynamic_cast(m_pAudioDriver); + JackAudioDriver* pJackAudioDriver = static_cast(m_pAudioDriver); if( pJackAudioDriver ) { pJackAudioDriver->clearPerTrackAudioBuffers( nFrames ); @@ -494,61 +494,38 @@ AudioOutput* AudioEngine::createDriver( const QString& sDriver ) if ( sDriver == "OSS" ) { pDriver = new OssDriver( m_AudioProcessCallback ); - if ( pDriver->class_name() == NullDriver::_class_name() ) { - delete pDriver; - pDriver = nullptr; - } } else if ( sDriver == "JACK" ) { pDriver = new JackAudioDriver( m_AudioProcessCallback ); - if ( pDriver->class_name() == NullDriver::_class_name() ) { - delete pDriver; - pDriver = nullptr; - } else { #ifdef H2CORE_HAVE_JACK - static_cast(pDriver)->setConnectDefaults( - Preferences::get_instance()->m_bJackConnectDefaults - ); -#endif + if ( auto pJackDriver = dynamic_cast( pDriver ) ) { + pJackDriver->setConnectDefaults( + Preferences::get_instance()->m_bJackConnectDefaults + ); } +#endif } else if ( sDriver == "ALSA" ) { pDriver = new AlsaAudioDriver( m_AudioProcessCallback ); - if ( pDriver->class_name() == NullDriver::_class_name() ) { - delete pDriver; - pDriver = nullptr; - } } else if ( sDriver == "PortAudio" ) { pDriver = new PortAudioDriver( m_AudioProcessCallback ); - if ( pDriver->class_name() == NullDriver::_class_name() ) { - delete pDriver; - pDriver = nullptr; - } - } - //#ifdef Q_OS_MACX - else if ( sDriver == "CoreAudio" ) { + } else if ( sDriver == "CoreAudio" ) { ___INFOLOG( "Creating CoreAudioDriver" ); pDriver = new CoreAudioDriver( m_AudioProcessCallback ); - if ( pDriver->class_name() == NullDriver::_class_name() ) { - delete pDriver; - pDriver = nullptr; - } - } - //#endif - else if ( sDriver == "PulseAudio" ) { + } else if ( sDriver == "PulseAudio" ) { pDriver = new PulseAudioDriver( m_AudioProcessCallback ); - if ( pDriver->class_name() == NullDriver::_class_name() ) { - delete pDriver; - pDriver = nullptr; - } - } - else if ( sDriver == "Fake" ) { + } else if ( sDriver == "Fake" ) { ___WARNINGLOG( "*** Using FAKE audio driver ***" ); pDriver = new FakeDriver( m_AudioProcessCallback ); } else { ___ERRORLOG( "Unknown driver " + sDriver ); raiseError( Hydrogen::UNKNOWN_DRIVER ); } + + if ( dynamic_cast(pDriver) != nullptr ) { + delete pDriver; + pDriver = nullptr; + } - if ( pDriver ) { + if ( pDriver != nullptr ) { // initialize the audio driver int res = pDriver->init( pPref->m_nBufferSize ); if ( res != 0 ) { @@ -681,8 +658,7 @@ void AudioEngine::setAudioDriver( AudioOutput* pAudioDriver ) { mx.unlock(); this->unlock(); - if ( m_pAudioDriver != nullptr && - m_pAudioDriver->class_name() != DiskWriterDriver::_class_name() ) { + if ( m_pAudioDriver != nullptr ) { int res = m_pAudioDriver->connect(); if ( res != 0 ) { raiseError( Hydrogen::ERROR_STARTING_DRIVER ); @@ -697,11 +673,9 @@ void AudioEngine::setAudioDriver( AudioOutput* pAudioDriver ) { m_pAudioDriver->connect(); } -#ifdef H2CORE_HAVE_JACK - if ( pSong != nullptr ) { + if ( pSong != nullptr && pHydrogen->haveJackAudioDriver() ) { pHydrogen->renameJackPorts( pSong ); } -#endif setupLadspaFX(); } @@ -1113,7 +1087,7 @@ int AudioEngine::audioEngine_process( uint32_t nframes, void* /*arg*/ ) RIGHT_HERE ) ) { ___ERRORLOG( QString( "Failed to lock audioEngine in allowed %1 ms, missed buffer" ).arg( fSlackTime ) ); - if ( pAudioEngine->m_pAudioDriver->class_name() == DiskWriterDriver::_class_name() ) { + if ( dynamic_cast(pAudioEngine->m_pAudioDriver) != nullptr ) { return 2; // inform the caller that we could not aquire the lock } @@ -1152,9 +1126,8 @@ int AudioEngine::audioEngine_process( uint32_t nframes, void* /*arg*/ ) pAudioEngine->stop(); pAudioEngine->locate( 0 ); // locate 0, reposition from start of the song - if ( (pAudioEngine->m_pAudioDriver->class_name() == DiskWriterDriver::_class_name() ) - || ( pAudioEngine->m_pAudioDriver->class_name() == FakeDriver::_class_name() ) - ) { + if ( dynamic_cast(pAudioEngine->m_pAudioDriver) != nullptr + || dynamic_cast(pAudioEngine->m_pAudioDriver) != nullptr ) { ___INFOLOG( "End of song." ); return 1; // kill the audio AudioDriver thread @@ -1837,7 +1810,7 @@ void AudioEngine::play() { setNextState( State::Playing ); - if ( m_pAudioDriver->class_name() == FakeDriver::_class_name() ) { + if ( dynamic_cast(m_pAudioDriver) != nullptr ) { static_cast( m_pAudioDriver )->processCallback(); } } diff --git a/src/core/Hydrogen.cpp b/src/core/Hydrogen.cpp index bfac80e98..d5e377adc 100644 --- a/src/core/Hydrogen.cpp +++ b/src/core/Hydrogen.cpp @@ -636,23 +636,13 @@ void Hydrogen::startExportSong( const QString& filename) DiskWriterDriver* pDiskWriterDriver = static_cast(pAudioEngine->getAudioDriver()); pDiskWriterDriver->setFileName( filename ); - - if ( pDiskWriterDriver->connect() != 0 ) { - ERRORLOG( "Error starting disk writer driver [DiskWriterDriver::connect()]" ); - } - + pDiskWriterDriver->write(); } void Hydrogen::stopExportSong() { AudioEngine* pAudioEngine = m_pAudioEngine; - - if ( pAudioEngine->getAudioDriver()->class_name() != DiskWriterDriver::_class_name() ) { - return; - } - pAudioEngine->getSampler()->stopPlayingNotes(); - pAudioEngine->getAudioDriver()->disconnect(); pAudioEngine->reset(); } @@ -668,7 +658,7 @@ void Hydrogen::stopExportSession() pAudioEngine->startAudioDrivers(); if ( pAudioEngine->getAudioDriver() == nullptr ) { - ERRORLOG( "pAudioEngine->getAudioDriver() = nullptr" ); + ERRORLOG( "Unable to restart previous audio driver after exporting song." ); } m_bExportSessionIsActive = false; } @@ -1301,7 +1291,7 @@ bool Hydrogen::haveJackAudioDriver() const { #ifdef H2CORE_HAVE_JACK AudioEngine* pAudioEngine = m_pAudioEngine; if ( pAudioEngine->getAudioDriver() != nullptr ) { - if ( JackAudioDriver::_class_name() == pAudioEngine->getAudioDriver()->class_name() ){ + if ( dynamic_cast(pAudioEngine->getAudioDriver()) != nullptr ) { return true; } } @@ -1315,7 +1305,7 @@ bool Hydrogen::haveJackTransport() const { #ifdef H2CORE_HAVE_JACK AudioEngine* pAudioEngine = m_pAudioEngine; if ( pAudioEngine->getAudioDriver() != nullptr ) { - if ( JackAudioDriver::_class_name() == pAudioEngine->getAudioDriver()->class_name() && + if ( dynamic_cast(pAudioEngine->getAudioDriver()) != nullptr && Preferences::get_instance()->m_bJackTransportMode == Preferences::USE_JACK_TRANSPORT ){ return true; @@ -1330,13 +1320,13 @@ bool Hydrogen::haveJackTransport() const { float Hydrogen::getMasterBpm() const { #ifdef H2CORE_HAVE_JACK if ( m_pAudioEngine->getAudioDriver() != nullptr ) { - if ( JackAudioDriver::_class_name() == m_pAudioEngine->getAudioDriver()->class_name() ) { - return static_cast(m_pAudioEngine->getAudioDriver())->getMasterBpm(); - } else { - return std::nan("No JACK driver"); - } + if ( dynamic_cast(m_pAudioEngine->getAudioDriver()) != nullptr ) { + return static_cast(m_pAudioEngine->getAudioDriver())->getMasterBpm(); + } else { + return std::nan("No JACK driver"); + } } else { - return std::nan("No audio driver"); + return std::nan("No audio driver"); } #else return std::nan("No JACK support"); diff --git a/src/core/IO/DiskWriterDriver.cpp b/src/core/IO/DiskWriterDriver.cpp index 06b6fbad0..9f1e96584 100644 --- a/src/core/IO/DiskWriterDriver.cpp +++ b/src/core/IO/DiskWriterDriver.cpp @@ -263,31 +263,28 @@ int DiskWriterDriver::init( unsigned nBufferSize ) INFOLOG( QString( "Init, buffer size: %1" ).arg( nBufferSize ) ); m_nBufferSize = nBufferSize; + + m_pOut_L = new float[ m_nBufferSize ]; + m_pOut_R = new float[ m_nBufferSize ]; return 0; } - -/// -/// Connect -/// return 0: Ok -/// int DiskWriterDriver::connect() +{ + return 0; +} + +void DiskWriterDriver::write() { INFOLOG( "" ); - m_pOut_L = new float[ m_nBufferSize ]; - m_pOut_R = new float[ m_nBufferSize ]; - pthread_attr_t attr; pthread_attr_init( &attr ); pthread_create( &diskWriterDriverThread, &attr, diskWriterDriver_thread, this ); - - return 0; } - /// disconnect void DiskWriterDriver::disconnect() { diff --git a/src/core/IO/DiskWriterDriver.h b/src/core/IO/DiskWriterDriver.h index df6ff7c01..fb4757517 100644 --- a/src/core/IO/DiskWriterDriver.h +++ b/src/core/IO/DiskWriterDriver.h @@ -59,7 +59,7 @@ class DiskWriterDriver : public Object, public AudioOutput virtual int connect() override; virtual void disconnect() override; - void write( float* buffer_L, float* buffer_R, unsigned int bufferSize ); + void write(); virtual unsigned getBufferSize() override { return m_nBufferSize; diff --git a/src/core/IO/OssDriver.cpp b/src/core/IO/OssDriver.cpp index 58d9c8f3a..35a36d9ab 100644 --- a/src/core/IO/OssDriver.cpp +++ b/src/core/IO/OssDriver.cpp @@ -68,7 +68,7 @@ void* ossDriver_processCaller( void* param ) OssDriver::OssDriver( audioProcessCallback processCallback ) - : AudioOutput( __class_name ) + : AudioOutput() { audioBuffer = NULL; ossDriver_running = false; diff --git a/src/gui/src/SongEditor/SongEditor.cpp b/src/gui/src/SongEditor/SongEditor.cpp index 0b79c4325..c76cedb5c 100644 --- a/src/gui/src/SongEditor/SongEditor.cpp +++ b/src/gui/src/SongEditor/SongEditor.cpp @@ -35,7 +35,6 @@ #include #include #include -#include using namespace H2Core; #include "UndoActions.h"