From 8a4fc4516c406a2fa63039310914c6a5514e7c04 Mon Sep 17 00:00:00 2001 From: sD Date: Sat, 23 May 2020 19:18:35 +0200 Subject: [PATCH] fix qt music player --- include/aomusicplayer.h | 54 ++++++----------------------------------- src/aomusicplayer.cpp | 34 ++++++++++++++++++-------- 2 files changed, 31 insertions(+), 57 deletions(-) diff --git a/include/aomusicplayer.h b/include/aomusicplayer.h index f08b7d2..de673e5 100644 --- a/include/aomusicplayer.h +++ b/include/aomusicplayer.h @@ -8,13 +8,13 @@ #elif defined(QTAUDIO) #include #endif + #include "aoapplication.h" #include #include #include -#if defined(BASSAUDIO) class AOMusicPlayer { public: AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app); @@ -25,8 +25,8 @@ public: const int m_channelmax = 4; // These have to be public for the stupid sync thing - QWORD loop_start = 0; - QWORD loop_end = 0; + int loop_start = 0; + int loop_end = 0; public slots: void play(QString p_song, int channel = 0, bool loop = false, @@ -44,52 +44,12 @@ private: // Channel 1 = ambience // Channel 2 = extra // Channel 3 = extra + #if defined(BASSAUDIO) HSTREAM m_stream_list[4]; HSYNC loop_sync[4]; + #elif defined(QTAUDIO) + QMediaPlayer m_stream_list[4]; + #endif }; -#elif defined(QTAUDIO) -class AOMusicPlayer { -public: - AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app); - ~AOMusicPlayer(); - - void play(QString p_song); - void set_volume(int p_value); - -private: - QMediaPlayer m_player; - QWidget *m_parent; - AOApplication *ao_app; - - int m_volume = 0; -}; -#else -class AOMusicPlayer { -public: - AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app); - virtual ~AOMusicPlayer(); - void set_volume(int p_value, int channel = -1); - void set_looping(bool toggle, int channel = 0); - - const int m_channelmax = 4; - -public slots: - void play(QString p_song, int channel = 0, bool loop = false, - int effect_flags = 0); - void stop(int channel = 0); - -private: - QWidget *m_parent; - AOApplication *ao_app; - - bool m_looping = false; - int m_volume[4] = {0, 0, 0, 0}; - - // Channel 0 = music - // Channel 1 = ambience - // Channel 2 = extra - // Channel 3 = extra -}; -#endif #endif // AOMUSICPLAYER_H diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index 68af961..5878dcd 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -176,26 +176,40 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) ao_app = p_ao_app; } -AOMusicPlayer::~AOMusicPlayer() { m_player.stop(); } +AOMusicPlayer::~AOMusicPlayer() { + for (int n_stream = 0; n_stream < m_channelmax; ++n_stream) { + m_stream_list[n_stream].stop(); + } +} -void AOMusicPlayer::play(QString p_song) +void AOMusicPlayer::play(QString p_song, int channel, bool loop, + int effect_flags) { - m_player.stop(); - + channel = channel % m_channelmax; + if (channel < 0) // wtf? + return; QString f_path = ao_app->get_music_path(p_song); - m_player.setMedia(QUrl::fromLocalFile(f_path)); + m_stream_list[channel].stop(); - this->set_volume(m_volume); + m_stream_list[channel].setMedia(QUrl::fromLocalFile(f_path)); - m_player.play(); + this->set_volume(m_volume[channel], channel); + + m_stream_list[channel].play(); } -void AOMusicPlayer::set_volume(int p_value) +void AOMusicPlayer::stop(int channel) { - m_volume = p_value; - m_player.setVolume(m_volume); + m_stream_list[channel].stop(); } + +void AOMusicPlayer::set_volume(int p_value, int channel) +{ + m_volume[channel] = p_value; + m_stream_list[channel].setVolume(m_volume[channel]); +} + #else AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) {