From 44a4a2d23ede7986212558e9cc53387d6f3a1dc9 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sat, 4 Jul 2020 20:15:52 +0300 Subject: [PATCH] Fix an issue where the Ambience layer would break looping points for all other channels due to loop_start and loop_end only being a single variable. (#164) This occurs due to BASS not having any private variables of its own, so it was simply using the public variables loop_start and loop_end as reference - since those changed for any new song playing on another channel, the old looping points got replaced, and the seamless looping stops working. The solution was easy - just make a loop_start/loop_end variable for every supported channel - so 4 variables in our case. --- include/aomusicplayer.h | 4 ++-- src/aomusicplayer.cpp | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/aomusicplayer.h b/include/aomusicplayer.h index de673e5..82751b6 100644 --- a/include/aomusicplayer.h +++ b/include/aomusicplayer.h @@ -25,8 +25,8 @@ public: const int m_channelmax = 4; // These have to be public for the stupid sync thing - int loop_start = 0; - int loop_end = 0; + int loop_start[4] = {0, 0, 0, 0}; + int loop_end[4] = {0, 0, 0, 0}; public slots: void play(QString p_song, int channel = 0, bool loop = false, diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index 8ba1641..249e01e 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -40,8 +40,8 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop, QString d_path = f_path + ".txt"; - loop_start = 0; - loop_end = BASS_ChannelGetLength(newstream, BASS_POS_BYTE); + loop_start[channel] = 0; + loop_end[channel] = BASS_ChannelGetLength(newstream, BASS_POS_BYTE); if (loop && file_exists(d_path)) // Contains loop/etc. information file { QStringList lines = ao_app->read_file(d_path).split("\n"); @@ -64,11 +64,11 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop, QWORD bytes = static_cast(args[1].trimmed().toFloat() * sample_size * num_channels); if (arg == "loop_start") - loop_start = bytes; + loop_start[channel] = bytes; else if (arg == "loop_length") - loop_end = loop_start + bytes; + loop_end[channel] = loop_start[channel] + bytes; else if (arg == "loop_end") - loop_end = bytes; + loop_end[channel] = bytes; } qDebug() << "Found data file for song" << p_song << "length" << BASS_ChannelGetLength(newstream, BASS_POS_BYTE) << "loop start" @@ -111,7 +111,7 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop, else this->set_volume(m_volume[channel], channel); - this->set_looping(loop); // Have to do this here due to any + this->set_looping(loop, channel); // Have to do this here due to any // crossfading-related changes, etc. } @@ -145,6 +145,7 @@ void CALLBACK loopProc(HSYNC handle, DWORD channel, DWORD data, void *user) void AOMusicPlayer::set_looping(bool toggle, int channel) { + qDebug() << "Setting looping for channel" << channel << "to" << toggle; m_looping = toggle; if (!m_looping) { if (BASS_ChannelFlags(m_stream_list[channel], 0, 0) & BASS_SAMPLE_LOOP) @@ -161,13 +162,13 @@ void AOMusicPlayer::set_looping(bool toggle, int channel) loop_sync[channel]); // remove the sync loop_sync[channel] = 0; } - if (loop_start > 0) { - if (loop_end == 0) - loop_end = BASS_ChannelGetLength(m_stream_list[channel], BASS_POS_BYTE); - if (loop_end > 0) // Don't loop zero length songs even if we're asked to + if (loop_start[channel] > 0) { + if (loop_end[channel] == 0) + loop_end[channel] = BASS_ChannelGetLength(m_stream_list[channel], BASS_POS_BYTE); + if (loop_end[channel] > 0) // Don't loop zero length songs even if we're asked to loop_sync[channel] = BASS_ChannelSetSync( - m_stream_list[channel], BASS_SYNC_POS | BASS_SYNC_MIXTIME, loop_end, - loopProc, &loop_start); + m_stream_list[channel], BASS_SYNC_POS | BASS_SYNC_MIXTIME, loop_end[channel], + loopProc, &loop_start[channel]); } } }