notification sounds with miniaudio

This commit is contained in:
ouwou
2023-03-06 20:45:10 -05:00
parent 64085fafec
commit fbbfdc9606
6 changed files with 41 additions and 2 deletions

View File

@@ -2,9 +2,19 @@
#include <glibmm/ustring.h>
#include <gdkmm/pixbuf.h>
#ifdef WITH_MINIAUDIO
#include <miniaudio.h>
#endif
class Notifier {
public:
Notifier();
~Notifier();
void Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action);
private:
#ifdef WITH_MINIAUDIO
ma_engine m_engine;
#endif
};

View File

@@ -1,11 +1,30 @@
#include "notifier.hpp"
#include <giomm/notification.h>
Notifier::Notifier() {}
#define MINIAUDIO_IMPLEMENTATION
#include <miniaudio.h>
Notifier::Notifier() {
#ifdef WITH_MINIAUDIO
if (ma_engine_init(nullptr, &m_engine) != MA_SUCCESS) {
printf("failed to initialize miniaudio engine\n");
}
#endif
}
Notifier::~Notifier() {
#ifdef WITH_MINIAUDIO
ma_engine_uninit(&m_engine);
#endif
}
void Notifier::Notify(const Glib::ustring &title, const Glib::ustring &text, const Glib::ustring &default_action) {
auto n = Gio::Notification::create(title);
n->set_body(text);
n->set_default_action(default_action);
Abaddon::Get().GetApp()->send_notification(n);
#ifdef WITH_MINIAUDIO
ma_engine_play_sound(&m_engine, Abaddon::Get().GetResPath("/sound/message.mp3").c_str(), nullptr);
#endif
}