Skip to content

Commit

Permalink
Convert to smart pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlaltca committed Aug 1, 2024
1 parent 070d7b8 commit 386e46e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
40 changes: 7 additions & 33 deletions src/modules/snd/libkvisnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ KviSoundPlayer::KviSoundPlayer()
m_pThreadList = new KviPointerList<KviSoundThread>;
m_pThreadList->setAutoDelete(true);

#ifdef COMPILE_PHONON_SUPPORT
m_pPhononPlayer = nullptr;
#endif //!COMPILE_PHONON_SUPPORT

#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
m_pMediaPlayer = nullptr;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
m_pAudioOutput = nullptr;
#endif
#endif //COMPILE_QTMULTIMEDIA_SUPPORT

m_pLastUsedSoundPlayerEntry = nullptr;

m_pSoundSystemDict = new KviPointerHashTable<QString, KviSoundPlayerEntry>(17, false);
Expand Down Expand Up @@ -138,20 +127,6 @@ KviSoundPlayer::~KviSoundPlayer()

delete m_pSoundSystemDict;

#ifdef COMPILE_PHONON_SUPPORT
if(m_pPhononPlayer)
delete m_pPhononPlayer;
#endif //COMPILE_PHONON_SUPPORT

#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if(m_pAudioOutput)
delete m_pAudioOutput;
#endif
if(m_pMediaPlayer)
delete m_pMediaPlayer;
#endif //!COMPILE_QTMULTIMEDIA_SUPPORT

g_pSoundPlayer = nullptr;
}

Expand Down Expand Up @@ -270,7 +245,7 @@ bool KviSoundPlayer::playPhonon(const QString & szFileName)
Phonon::MediaSource media(QUrl::fromLocalFile(szFileName));

if(!m_pPhononPlayer)
m_pPhononPlayer = Phonon::createPlayer(Phonon::MusicCategory, media);
m_pPhononPlayer = std::unique_ptr<Phonon::MediaObject>(Phonon::createPlayer(Phonon::MusicCategory, media));
else
m_pPhononPlayer->setCurrentSource(media);

Expand All @@ -296,8 +271,8 @@ void KviSoundPlayer::cleanupPhonon()
{
if(!m_pPhononPlayer)
return;
delete m_pPhononPlayer; // must be stopped
m_pPhononPlayer = nullptr;
m_pPhononPlayer->stop();
m_pPhononPlayer.reset();
}
#endif //!COMPILE_PHONON_SUPPORT

Expand Down Expand Up @@ -358,10 +333,10 @@ bool KviSoundPlayer::playQt(const QString & szFileName)
return true;

if(!m_pMediaPlayer)
m_pMediaPlayer = new QMediaPlayer;
m_pMediaPlayer = std::make_unique<QMediaPlayer>();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
m_pAudioOutput = new QAudioOutput;
m_pMediaPlayer->setAudioOutput(m_pAudioOutput);
m_pAudioOutput = std::make_unique<QAudioOutput>();
m_pMediaPlayer->setAudioOutput(m_pAudioOutput.get());
m_pMediaPlayer->setSource(QUrl::fromLocalFile(szFileName));
#else
m_pMediaPlayer->setMedia(QUrl::fromLocalFile(szFileName));
Expand All @@ -376,8 +351,7 @@ void KviSoundPlayer::cleanupQt()
return;

m_pMediaPlayer->stop();
delete m_pMediaPlayer;
m_pMediaPlayer = nullptr;
m_pMediaPlayer.reset();
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/modules/snd/libkvisnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ class KviSoundPlayer : public QObject
KviPointerList<KviSoundThread> * m_pThreadList;
KviPointerHashTable<QString, KviSoundPlayerEntry> * m_pSoundSystemDict;
#ifdef COMPILE_PHONON_SUPPORT
Phonon::MediaObject * m_pPhononPlayer;
std::unique_ptr<Phonon::MediaObject> m_pPhononPlayer;
#endif //!COMPILE_PHONON_SUPPORT
#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
QMediaPlayer * m_pMediaPlayer;
std::unique_ptr<QMediaPlayer> m_pMediaPlayer;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QAudioOutput * m_pAudioOutput;
std::unique_ptr<QAudioOutput> m_pAudioOutput;
#endif
#endif //!COMPILE_QTMULTIMEDIA_SUPPORT
KviSoundPlayerEntry * m_pLastUsedSoundPlayerEntry;
Expand Down

0 comments on commit 386e46e

Please sign in to comment.