diff options
| author | TrickyLeifa <date.epoch@gmail.com> | 2024-05-17 16:39:30 +0200 |
|---|---|---|
| committer | TrickyLeifa <date.epoch@gmail.com> | 2024-05-17 19:04:57 +0200 |
| commit | 1ef96383c8f7ed136a0e028aef0835b4838b5e95 (patch) | |
| tree | e87a9df097a50b4d1f918f8a4f37d210562d10d6 /src/aoblipplayer.cpp | |
| parent | 39e4354b1dae5d8487ea5b84be9f304b1950a61a (diff) | |
Lightly reworked `NetworkManager`, ...
* Lightly reworked `NetworkManager`
* Added new modules to handle various connection types.
* TCP
* WebSocket
* Added general string splitter alias based on Qt version.
* Replaced `lobby_constructed` and `courtroom_constructed`
* Refactored and partially reimplemented the following classes:
* `AOBlipPlayer`
* `AOEmotePreview`
* `AOMusicPlayer`
* `AOSfxPlayer`
* `AOTextArea`
Diffstat (limited to 'src/aoblipplayer.cpp')
| -rw-r--r-- | src/aoblipplayer.cpp | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/src/aoblipplayer.cpp b/src/aoblipplayer.cpp index cf877fd7..3a13d787 100644 --- a/src/aoblipplayer.cpp +++ b/src/aoblipplayer.cpp @@ -1,64 +1,54 @@ #include "aoblipplayer.h" -AOBlipPlayer::AOBlipPlayer(AOApplication *p_ao_app) - : ao_app(p_ao_app) +AOBlipPlayer::AOBlipPlayer(AOApplication *ao_app) + : ao_app(ao_app) {} -void AOBlipPlayer::set_blips(QString p_sfx) +void AOBlipPlayer::setVolume(int value) { - QString f_path = ao_app->get_sfx_suffix(ao_app->get_sounds_path(p_sfx)); + m_volume = value; + updateInternalVolume(); +} - for (int n_stream = 0; n_stream < 5; ++n_stream) +void AOBlipPlayer::setMuted(bool enabled) +{ + m_muted = enabled; + updateInternalVolume(); +} + +void AOBlipPlayer::setBlip(QString blip) +{ + QString path = ao_app->get_sfx_suffix(ao_app->get_sounds_path(blip)); + for (int i = 0; i < STREAM_COUNT; ++i) { - BASS_StreamFree(m_stream_list[n_stream]); + BASS_StreamFree(m_stream[i]); - if (f_path.endsWith(".opus")) + if (path.endsWith(".opus")) { - m_stream_list[n_stream] = BASS_OPUS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); + m_stream[i] = BASS_OPUS_StreamCreateFile(FALSE, path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); } else { - m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); + m_stream[i] = BASS_StreamCreateFile(FALSE, path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); } } - set_volume_internal(m_volume); + updateInternalVolume(); } -void AOBlipPlayer::blip_tick() +void AOBlipPlayer::playBlip() { - int f_cycle = m_cycle++; - - if (m_cycle == 5) - { - m_cycle = 0; - } - - HSTREAM f_stream = m_stream_list[f_cycle]; - - BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); - BASS_ChannelPlay(f_stream, false); -} - -void AOBlipPlayer::set_muted(bool toggle) -{ - m_muted = toggle; - set_volume_internal(m_volume); + HSTREAM stream = m_stream[m_cycle]; + BASS_ChannelSetDevice(stream, BASS_GetDevice()); + BASS_ChannelPlay(stream, false); + m_cycle = ++m_cycle % STREAM_COUNT; } -void AOBlipPlayer::set_volume(int p_value) +void AOBlipPlayer::updateInternalVolume() { - m_volume = static_cast<qreal>(p_value) / 100; - set_volume_internal(m_volume); -} - -void AOBlipPlayer::set_volume_internal(qreal p_value) -{ - // If muted, volume will always be 0 - float volume = static_cast<float>(p_value) * !m_muted; - - for (int n_stream = 0; n_stream < 5; ++n_stream) + float volume = m_muted ? 0.0f : (m_volume * 0.01); + for (int i = 0; i < STREAM_COUNT; ++i) { - BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); + BASS_ChannelSetAttribute(m_stream[i], BASS_ATTRIB_VOL, volume); } } |
