From ad93dd82388c071a1ca5cdb2bff072e96c44265a Mon Sep 17 00:00:00 2001 From: in1tiate <32779090+in1tiate@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:29:03 -0500 Subject: [PATCH] add not-broken looping code using seconds instead of samples (#944) --- src/aomusicplayer.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index 1bbcf5a..b8c6dc6 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -61,11 +61,19 @@ QString AOMusicPlayer::play(QString p_song, int channel, bool loop, if (loop && file_exists(d_path)) // Contains loop/etc. information file { QStringList lines = ao_app->read_file(d_path).split("\n"); + bool seconds_mode = false; foreach (QString line, lines) { QStringList args = line.split("="); if (args.size() < 2) continue; QString arg = args[0].trimmed(); + if (arg == "seconds") { + if (args[1].trimmed() == "true") { + seconds_mode = true; // Use new epic behavior + continue; + } + continue; + } float sample_rate; BASS_ChannelGetAttribute(newstream, BASS_ATTRIB_FREQ, &sample_rate); @@ -77,8 +85,15 @@ QString AOMusicPlayer::play(QString p_song, int channel, bool loop, int num_channels = 2; // Calculate the bytes for loop_start/loop_end to use with the sync proc - QWORD bytes = static_cast(args[1].trimmed().toUInt() * - sample_size * num_channels); + QWORD bytes; + if (seconds_mode) { + bytes = + BASS_ChannelSeconds2Bytes(newstream, args[1].trimmed().toDouble()); + } + else { + bytes = static_cast(args[1].trimmed().toUInt() * sample_size * + num_channels); + } if (arg == "loop_start") loop_start[channel] = bytes; else if (arg == "loop_length")