-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSounds.cpp
46 lines (38 loc) · 926 Bytes
/
Sounds.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <QDir>
#include "Sounds.h"
#include <iostream>
using namespace KA;
Sounds* Sounds::instance()
{
static Sounds uniqueInstance;
return &uniqueInstance;
}
Sounds::Sounds()
{
QStringList sound_files = QDir("sounds/").entryList(QStringList() << "*.wav", QDir::Files);
for (auto& f : sound_files) {
std::string name = QFileInfo(f).baseName().toStdString();
_sounds[name] = new QSoundEffect();
_sounds[name]->setSource(QUrl::fromLocalFile(QString("sounds/") + f));
}
}
void Sounds::playSound(const std::string& id)
{
if (_sounds.find(id) != _sounds.end()) {
_sounds[id]->play();
}
}
void Sounds::playLoopedSound(const std::string& id, bool loop)
{
if (_sounds.find(id) != _musics.end())
{
if (loop)
_sounds[id]->setLoopCount(QSoundEffect::Infinite);
_sounds[id]->play();
}
}
void Sounds::stopSound(const std::string& id)
{
if (_sounds.find(id) != _sounds.end())
_sounds[id]->stop();
}