During #475 found issue with deleter

* changed / improved deleter
* formatting in related class soundgenerator
This commit is contained in:
Klaus Basan
2015-09-30 05:01:34 +02:00
committed by Mathew Sutcliffe
parent 84b06c51d9
commit 68d0b8cc98
4 changed files with 87 additions and 40 deletions

View File

@@ -22,6 +22,7 @@
#include <QFile>
#include <QDir>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Audio;
@@ -35,7 +36,7 @@ namespace BlackSound
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
m_device(device), m_audioFormat(format), m_audioOutput(new QAudioOutput(format))
{
Q_ASSERT(tones.size() > 0);
Q_ASSERT_X(tones.size() > 0, Q_FUNC_INFO, "No tones");
}
CSoundGenerator::CSoundGenerator(const QList<Tone> &tones, CNotificationSounds::PlayMode mode, QObject *parent)
@@ -44,7 +45,7 @@ namespace BlackSound
m_device(QAudioDeviceInfo::defaultOutputDevice()), m_audioFormat(CSoundGenerator::defaultAudioFormat()),
m_audioOutput(new QAudioOutput(CSoundGenerator::defaultAudioFormat()))
{
Q_ASSERT(tones.size() > 0);
Q_ASSERT_X(tones.size() > 0, Q_FUNC_INFO, "No tones");
}
CSoundGenerator::~CSoundGenerator()
@@ -92,7 +93,9 @@ namespace BlackSound
// in auto delete mode force deleteLater when thread is finished
if (this->m_playMode == CNotificationSounds::SingleWithAutomaticDeletion)
{
connect(this->m_ownThread, &QThread::finished, this, &CSoundGenerator::deleteLater);
}
// start thread and begin processing by calling start via signal startThread
this->m_ownThread->start();
@@ -517,7 +520,7 @@ namespace BlackSound
mediaPlayer->setVolume(volume); // 0-100
mediaPlayer->play();
// I cannot delete the file here, only after it has been played
if (removeFileAfterPlaying) BlackMisc::CFileDeleter::addFileForDeletion(file);
if (removeFileAfterPlaying) { new CTimedFileDeleter(file, 1000 * 60, QCoreApplication::instance()); }
}
void CSoundGenerator::printAllQtSoundDevices(QTextStream &out)

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2015
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
@@ -179,6 +179,9 @@ namespace BlackSound
//! \remarks With singleShot the signal indicates that sound sequence has finished
void stopped();
//! Generator is stopping
void stopping();
public slots:
//! Play sound, open device
//! \param volume 0..100
@@ -190,10 +193,6 @@ namespace BlackSound
//! \param volume 0..100
void startInOwnThread(int volume);
signals:
//! Generator is stopping
void stopping();
private slots:
//! Push mode, timer expired
void pushTimerExpired();
@@ -203,18 +202,18 @@ namespace BlackSound
void generateData();
private:
QList<Tone> m_tones; //!< tones to be played
qint64 m_position; //!< position in buffer
QList<Tone> m_tones; //!< tones to be played
qint64 m_position; //!< position in buffer
CNotificationSounds::PlayMode m_playMode; //!< end data provisioning after playing all tones, play endless loop
bool m_endReached; //!< indicates end in combination with single play
qint64 m_oneCycleDurationMs; //!< how long is one cycle of tones
QByteArray m_buffer; //!< generated buffer for data
QAudioDeviceInfo m_device; //!< audio device
QAudioFormat m_audioFormat; //!< used format
bool m_endReached; //!< indicates end in combination with single play
qint64 m_oneCycleDurationMs; //!< how long is one cycle of tones
QByteArray m_buffer; //!< generated buffer for data
QAudioDeviceInfo m_device; //!< audio device
QAudioFormat m_audioFormat; //!< used format
QScopedPointer<QAudioOutput> m_audioOutput;
QTimer *m_pushTimer = nullptr; //!< Push mode timer
QIODevice *m_pushModeIODevice = nullptr; //!< IO device when used in push mode
QThread *m_ownThread = nullptr;
QTimer *m_pushTimer = nullptr; //!< Push mode timer
QIODevice *m_pushModeIODevice = nullptr; //!< IO device when used in push mode
QThread *m_ownThread = nullptr;
static QDateTime s_selcalStarted;
//! Header for saving .wav files