From 3c0cedbe922c9fcacd0d171423f83e375f66e178 Mon Sep 17 00:00:00 2001 From: iamgoofball Date: Fri, 18 Jan 2019 19:08:56 -0800 Subject: Add screenshake, frame-specific effects, looping SFX, and clientside music looping Committed by patch since Goof is currently banned on GitHub for no good reason. --- src/aosfxplayer.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/aosfxplayer.cpp') diff --git a/src/aosfxplayer.cpp b/src/aosfxplayer.cpp index 7fe7987..e219c03 100644 --- a/src/aosfxplayer.cpp +++ b/src/aosfxplayer.cpp @@ -1,10 +1,13 @@ #include "aosfxplayer.h" #include "file_functions.h" -AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) +AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() { m_parent = parent; ao_app = p_ao_app; + sfx_loop_timer = new QTimer(this); + sfx_loop_timer->setSingleShot(true); + connect(sfx_loop_timer, SIGNAL(timeout()), this, SLOT(restart_loop())); } void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) @@ -28,7 +31,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) f_path = misc_path; else f_path = sound_path; - + BASS_ChannelStop(m_stream); m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); set_volume(m_volume); @@ -36,11 +39,35 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); + sfx_loop_timer->stop(); + QWORD len=BASS_ChannelGetLength(m_stream, BASS_POS_BYTE); // the length in bytes + double time=BASS_ChannelBytes2Seconds(m_stream, len); // the length in seconds + if(time > 0 && looping_sfx && ao_app->get_looping_sfx()) + { + sfx_loop_timer->start(time*1000); + } +} + +void AOSfxPlayer::setLooping(bool is_looping) +{ + this->looping_sfx = is_looping; } void AOSfxPlayer::stop() { BASS_ChannelStop(m_stream); + sfx_loop_timer->stop(); +} + +void AOSfxPlayer::restart_loop() +{ + if(ao_app->get_looping_sfx() && looping_sfx) + { + QWORD len=BASS_ChannelGetLength(m_stream, BASS_POS_BYTE); // the length in bytes + double time=BASS_ChannelBytes2Seconds(m_stream, len); // the length in seconds + sfx_loop_timer->start(time*1000); + BASS_ChannelPlay(m_stream, true); + } } void AOSfxPlayer::set_volume(int p_value) -- cgit From fc984fcfe2a4416274810de81a8f36fe77b0dba9 Mon Sep 17 00:00:00 2001 From: iamgoofball Date: Fri, 1 Feb 2019 16:28:14 -0800 Subject: bugfixes and shit --- src/aosfxplayer.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/aosfxplayer.cpp') diff --git a/src/aosfxplayer.cpp b/src/aosfxplayer.cpp index e219c03..e39071e 100644 --- a/src/aosfxplayer.cpp +++ b/src/aosfxplayer.cpp @@ -5,9 +5,6 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() { m_parent = parent; ao_app = p_ao_app; - sfx_loop_timer = new QTimer(this); - sfx_loop_timer->setSingleShot(true); - connect(sfx_loop_timer, SIGNAL(timeout()), this, SLOT(restart_loop())); } void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) @@ -39,12 +36,13 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); - sfx_loop_timer->stop(); - QWORD len=BASS_ChannelGetLength(m_stream, BASS_POS_BYTE); // the length in bytes - double time=BASS_ChannelBytes2Seconds(m_stream, len); // the length in seconds - if(time > 0 && looping_sfx && ao_app->get_looping_sfx()) + if(looping_sfx && ao_app->get_looping_sfx()) { - sfx_loop_timer->start(time*1000); + BASS_ChannelFlags(m_stream, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); + } + else + { + BASS_ChannelFlags(m_stream, 0, BASS_SAMPLE_LOOP); } } @@ -56,18 +54,6 @@ void AOSfxPlayer::setLooping(bool is_looping) void AOSfxPlayer::stop() { BASS_ChannelStop(m_stream); - sfx_loop_timer->stop(); -} - -void AOSfxPlayer::restart_loop() -{ - if(ao_app->get_looping_sfx() && looping_sfx) - { - QWORD len=BASS_ChannelGetLength(m_stream, BASS_POS_BYTE); // the length in bytes - double time=BASS_ChannelBytes2Seconds(m_stream, len); // the length in seconds - sfx_loop_timer->start(time*1000); - BASS_ChannelPlay(m_stream, true); - } } void AOSfxPlayer::set_volume(int p_value) -- cgit From 0afca9243a47f30a946c69a974c4d257574d85e5 Mon Sep 17 00:00:00 2001 From: sD Date: Fri, 21 Feb 2020 16:53:56 +0100 Subject: looping wasnt in --- src/aosfxplayer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/aosfxplayer.cpp') diff --git a/src/aosfxplayer.cpp b/src/aosfxplayer.cpp index 80b6ea3..d2140e3 100644 --- a/src/aosfxplayer.cpp +++ b/src/aosfxplayer.cpp @@ -107,6 +107,11 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) } } +void AOSfxPlayer::setLooping(bool is_looping) +{ + this->looping_sfx = is_looping; +} + void AOSfxPlayer::stop() { m_sfx.stop(); @@ -134,6 +139,11 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) } +void AOSfxPlayer::setLooping(bool is_looping) +{ + this->looping_sfx = is_looping; +} + void AOSfxPlayer::stop() { -- cgit