chatgui: per-event sound settings with DB persistence

- Sound files loaded from filesystem (sound_dir in INI config, absolute or relative)
- Per-event enable/disable + volume stored in DB (ui_state table)
- SoundManager: setEvent(), effective volume = master * per-event
- SoundSettingsPage UI: 4 event rows (checkbox + slider)
- chat_core_save_ui_state() for async DB writes via uasync thread
- DbManager::getUiStateInt() for reading settings from GUI thread
- Default sounds copied to sounds/ dir next to DB, config entries written
This commit is contained in:
Evgeny committed 2026-07-19 15:17:52 +03:00
1 parent 1593079da8
commit 98bfb9dcd2
12 files changed
+267 -114

No files matched your search

+28 -28
View File
@@ -31,30 +31,17 @@ void SoundManager::shutdown() {
if (!m_initialized) return;
for (auto it = m_sounds.begin(); it != m_sounds.end(); ++it) {
if (it->sound) {
ma_sound_uninit(it->sound);
delete it->sound;
}
if (it->decoder) {
ma_decoder_uninit(it->decoder);
delete it->decoder;
}
if (it->sound) { ma_sound_uninit(it->sound); delete it->sound; }
if (it->decoder) { ma_decoder_uninit(it->decoder); delete it->decoder; }
}
m_sounds.clear();
if (m_engine) {
ma_engine_uninit(m_engine);
delete m_engine;
m_engine = nullptr;
}
if (m_engine) { ma_engine_uninit(m_engine); delete m_engine; m_engine = nullptr; }
m_initialized = false;
qDebug("SoundManager: shutdown");
}
void SoundManager::setEnabled(bool enabled) {
m_enabled = enabled;
qDebug("SoundManager: enabled=%d", enabled);
}
void SoundManager::setEnabled(bool enabled) { m_enabled = enabled; }
bool SoundManager::isEnabled() const { return m_enabled; }
@@ -62,15 +49,25 @@ void SoundManager::setVolume(float volume) {
if (volume < 0.0f) volume = 0.0f;
if (volume > 1.0f) volume = 1.0f;
m_volume = volume;
for (auto it = m_sounds.begin(); it != m_sounds.end(); ++it) {
if (it->sound)
ma_sound_set_volume(it->sound, m_volume);
}
}
float SoundManager::volume() const { return m_volume; }
bool SoundManager::loadSound(const QString& name, const QString& qrcPath) {
void SoundManager::setEvent(const QString& name, bool enabled, float volume) {
if (volume < 0.0f) volume = 0.0f;
if (volume > 1.0f) volume = 1.0f;
EventSettings es;
es.enabled = enabled;
es.volume = volume;
m_eventSettings[name] = es;
qDebug("SoundManager: event '%s' enabled=%d vol=%.2f", qPrintable(name), enabled, volume);
}
SoundManager::EventSettings SoundManager::eventSettings(const QString& name) const {
return m_eventSettings.value(name);
}
bool SoundManager::loadSound(const QString& name, const QString& filePath) {
if (!m_initialized) {
qWarning("SoundManager: not initialized, cannot load %s", qPrintable(name));
return false;
@@ -80,9 +77,9 @@ bool SoundManager::loadSound(const QString& name, const QString& qrcPath) {
return false;
}
QFile f(qrcPath);
QFile f(filePath);
if (!f.open(QIODevice::ReadOnly)) {
qWarning("SoundManager: cannot open %s", qPrintable(qrcPath));
qWarning("SoundManager: cannot open %s", qPrintable(filePath));
return false;
}
@@ -105,26 +102,29 @@ bool SoundManager::loadSound(const QString& name, const QString& qrcPath) {
0, NULL, ls.sound);
if (result != MA_SUCCESS) {
qWarning("SoundManager: sound init failed for %s (%d)", qPrintable(name), result);
ma_decoder_uninit(ls.decoder);
delete ls.decoder;
ma_decoder_uninit(ls.decoder); delete ls.decoder;
delete ls.sound;
return false;
}
ma_sound_set_volume(ls.sound, m_volume);
m_sounds.insert(name, ls);
qDebug("SoundManager: loaded '%s' from %s (%lld bytes)",
qPrintable(name), qPrintable(qrcPath), (long long)ls.mp3Data.size());
qPrintable(name), qPrintable(filePath), (long long)ls.mp3Data.size());
return true;
}
void SoundManager::play(const QString& name) {
if (!m_enabled || !m_initialized) return;
EventSettings es = m_eventSettings.value(name);
if (!es.enabled) return;
auto it = m_sounds.find(name);
if (it == m_sounds.end()) return;
ma_sound* s = it->sound;
float effectiveVolume = m_volume * es.volume;
ma_sound_set_volume(s, effectiveVolume);
ma_sound_stop(s);
ma_sound_seek_to_pcm_frame(s, 0);
ma_sound_start(s);