Ref T731, changed Samples to use settings and new file names

This commit is contained in:
Klaus Basan
2019-09-28 19:45:29 +02:00
committed by Mat Sutcliffe
parent 34848ddd46
commit a076705d77
2 changed files with 57 additions and 22 deletions

View File

@@ -8,36 +8,45 @@
#include "samples.h"
#include "blackmisc/directoryutils.h"
#include "blackmisc/fileutils.h"
using namespace BlackMisc;
using namespace BlackMisc::Audio;
namespace BlackSound
{
namespace SampleProvider
{
Samples &Samples::instance()
const Samples &Samples::instance()
{
static Samples samples;
static const Samples samples;
return samples;
}
Samples::Samples() :
m_crackle(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/Crackle_f32.wav"),
m_click(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/Click_f32.wav"),
m_whiteNoise(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/WhiteNoise_f32.wav")
{ }
CResourceSound Samples::click() const
m_crackle(CFileUtils::soundFilePathAndFileName(fnCrackle())),
m_click(CFileUtils::soundFilePathAndFileName(fnClick())),
m_whiteNoise(CFileUtils::soundFilePathAndFileName(fnWhiteNoise()))
{
return m_click;
this->initSounds();
}
CResourceSound Samples::crackle() const
void Samples::initSounds()
{
return m_crackle;
const CSettings settings = m_audioSettings.get();
QString f = settings.getNotificationFilePath(fnCrackle());
if (!m_crackle.isSameFileName(f)) { m_crackle = CResourceSound(f); }
f = settings.getNotificationFilePath(fnClick());
if (!m_click.isSameFileName(f)) { m_click = CResourceSound(f); }
f = settings.getNotificationFilePath(fnWhiteNoise());
if (!m_whiteNoise.isSameFileName(f)) { m_whiteNoise = CResourceSound(f); }
}
CResourceSound Samples::whiteNoise() const
void Samples::onSettingsChanged()
{
return m_whiteNoise;
this->initSounds();
}
}
}
} // ns
} // ns

View File

@@ -8,26 +8,43 @@
//! \file
#ifndef SAMPLES_H
#define SAMPLES_H
#ifndef BLACKSOUND_SAMPLEPROVIDER_SAMPLES_H
#define BLACKSOUND_SAMPLEPROVIDER_SAMPLES_H
#include "blackmisc/audio/audiosettings.h"
#include "blackmisc/settingscache.h"
#include "blacksound/blacksoundexport.h"
#include "resourcesound.h"
#include <QObject>
namespace BlackSound
{
namespace SampleProvider
{
class BLACKSOUND_EXPORT Samples
//! Sound samples from resources (wav files)
class BLACKSOUND_EXPORT Samples : public QObject
{
public:
//! Singleton
static Samples &instance();
static const Samples &instance();
//! Avoid to copy
Samples(const Samples &) = delete;
//! Various samples (sounds) @{
CResourceSound crackle() const;
CResourceSound click() const;
CResourceSound whiteNoise() const;
const CResourceSound &crackle() const { return m_crackle; }
const CResourceSound &click() const { return m_click; }
const CResourceSound &whiteNoise() const { return m_whiteNoise; }
//! @}
//! Play the click sound
bool playClick() const { return m_audioSettings.get().pttClickUp(); }
//! File names @{
static const QString &fnCrackle() { static const QString f = "afv_crackle_f32.wav"; return f; }
static const QString &fnClick() { static const QString f = "afv_click_f32.wav"; return f; }
static const QString &fnWhiteNoise() { static const QString f = "afv_whitenoise_f32.wav"; return f; }
//! @}
private:
@@ -37,7 +54,16 @@ namespace BlackSound
CResourceSound m_crackle;
CResourceSound m_click;
CResourceSound m_whiteNoise;
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &Samples::onSettingsChanged };
//! Init sounds
void initSounds();
//! Settings have been changed
void onSettingsChanged();
};
} // ns
} // ns