From 0b6f376f8f635bfcfd72f621a1077a35efc72342 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 12 Mar 2019 19:53:06 +0100 Subject: [PATCH] qt can play the blips just fine --- include/aoblipplayer.h | 42 +++++++++++++++++++++++++ src/aoblipplayer.cpp | 70 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 106 insertions(+), 6 deletions(-) diff --git a/include/aoblipplayer.h b/include/aoblipplayer.h index aebba77..2bbe718 100644 --- a/include/aoblipplayer.h +++ b/include/aoblipplayer.h @@ -1,13 +1,19 @@ #ifndef AOBLIPPLAYER_H #define AOBLIPPLAYER_H +#if defined(BASSAUDIO) #include "bass.h" +#elif defined(QTAUDIO) +#include +#endif + #include "aoapplication.h" #include #include #include +#if defined(BASSAUDIO) class AOBlipPlayer { public: @@ -26,5 +32,41 @@ private: int m_volume; HSTREAM m_stream_list[5]; }; +#elif defined(QTAUDIO) +class AOBlipPlayer +{ +public: + AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app); + + void set_blips(QString p_sfx); + void blip_tick(); + void set_volume(int p_volume); + + int m_cycle = 0; + +private: + QSoundEffect m_blips; + QWidget *m_parent; + AOApplication *ao_app; + + int m_volume; + //HSTREAM m_stream_list[5]; +}; +#else +class AOBlipPlayer +{ +public: + AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app); + + void set_blips(QString p_sfx); + void blip_tick(); + void set_volume(int p_volume); + +private: + QWidget *m_parent; + AOApplication *ao_app; +}; +#endif + #endif // AOBLIPPLAYER_H diff --git a/src/aoblipplayer.cpp b/src/aoblipplayer.cpp index 0a8b427..b95f32a 100644 --- a/src/aoblipplayer.cpp +++ b/src/aoblipplayer.cpp @@ -1,5 +1,6 @@ #include "aoblipplayer.h" +#if defined(BASSAUDIO) //Using bass.dll for the blips AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; @@ -12,11 +13,9 @@ void AOBlipPlayer::set_blips(QString p_sfx) for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) { - #ifdef BASSAUDIO BASS_StreamFree(m_stream_list[n_stream]); m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); - #endif } set_volume(m_volume); @@ -30,11 +29,9 @@ void AOBlipPlayer::blip_tick() m_cycle = 0; HSTREAM f_stream = m_stream_list[f_cycle]; - #ifdef BASSAUDIO if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); BASS_ChannelPlay(f_stream, false); - #endif } void AOBlipPlayer::set_volume(int p_value) @@ -45,8 +42,69 @@ void AOBlipPlayer::set_volume(int p_value) for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) { - #ifdef BASSAUDIO BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); - #endif } } +#elif defined(QTAUDIO) //Using Qt's QSoundEffect class +AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) +{ + m_parent = parent; + ao_app = p_ao_app; +} + +void AOBlipPlayer::set_blips(QString p_sfx) +{ + QString f_path = ao_app->get_sounds_path(p_sfx); + + for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + { + m_blips.setSource(QUrl::fromLocalFile(f_path)); + } + + set_volume(m_volume); +} + +void AOBlipPlayer::blip_tick() +{ + int f_cycle = m_cycle++; + + if (m_cycle == 5) + m_cycle = 0; + + //HSTREAM f_stream = m_stream_list[f_cycle]; + //if (ao_app->get_audio_output_device() != "default") + //BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); + //BASS_ChannelPlay(f_stream, false); + m_blips.play(); +} + +void AOBlipPlayer::set_volume(int p_value) +{ + m_volume = p_value; + + float volume = p_value / 100.0f; + + m_blips.setVolume(volume); +} +#else //No audio +AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) +{ + m_parent = parent; + ao_app = p_ao_app; +} + +void AOBlipPlayer::set_blips(QString p_sfx) +{ + +} + +void AOBlipPlayer::blip_tick() +{ + +} + +void AOBlipPlayer::set_volume(int p_value) +{ + +} +#endif