You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
#pragma once |
|
|
|
#include <QObject> |
|
#include <QHash> |
|
#include <QString> |
|
#include <QByteArray> |
|
|
|
struct ma_engine; |
|
struct ma_decoder; |
|
struct ma_sound; |
|
|
|
class SoundManager : public QObject { |
|
Q_OBJECT |
|
public: |
|
struct EventSettings { |
|
bool enabled = true; |
|
float volume = 0.8f; |
|
}; |
|
|
|
static SoundManager* instance(); |
|
|
|
bool init(); |
|
void shutdown(); |
|
|
|
void setEnabled(bool enabled); |
|
bool isEnabled() const; |
|
void setVolume(float volume); |
|
float volume() const; |
|
|
|
void setEvent(const QString& name, bool enabled, float volume); |
|
EventSettings eventSettings(const QString& name) const; |
|
|
|
bool loadSound(const QString& name, const QString& filePath); |
|
void play(const QString& name); |
|
|
|
private: |
|
SoundManager() = default; |
|
~SoundManager(); |
|
|
|
struct LoadedSound { |
|
QByteArray mp3Data; |
|
ma_decoder* decoder = nullptr; |
|
ma_sound* sound = nullptr; |
|
}; |
|
|
|
ma_engine* m_engine = nullptr; |
|
bool m_initialized = false; |
|
bool m_enabled = true; |
|
float m_volume = 0.8f; |
|
QHash<QString, EventSettings> m_eventSettings; |
|
QHash<QString, LoadedSound> m_sounds; |
|
};
|
|
|