From cffee928482da548b5080326b10c481b0ce940eb Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 22 Apr 2023 23:31:59 -0700 Subject: [PATCH] Fix issue where we may be overly aggressive buffering tracks after play queue mutations. --- src/musikcore/audio/PlaybackService.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/musikcore/audio/PlaybackService.cpp b/src/musikcore/audio/PlaybackService.cpp index 70e8d3fb5..6382af8f8 100755 --- a/src/musikcore/audio/PlaybackService.cpp +++ b/src/musikcore/audio/PlaybackService.cpp @@ -78,6 +78,7 @@ using Editor = PlaybackService::Editor; #define MESSAGE_RELOAD_OUTPUT 1010 #define MESSAGE_LOAD_PLAYBACK_CONTEXT 1011 #define MESSAGE_MARK_TRACK_PLAYED 1012 +#define MESSAGE_NEXT_TRACK_EDITED 1013 class StreamMessage: public Message { public: @@ -392,6 +393,21 @@ void PlaybackService::ProcessMessage(IMessage &message) { this->PlaybackStateChanged(static_cast(eventType)); } + else if (type == MESSAGE_NEXT_TRACK_EDITED) { + if (transport->GetPlaybackState() != PlaybackState::Stopped) { + const size_t updatedIndex = static_cast(message.UserData1()); + + if (updatedIndex != NO_POSITION) { + this->index = updatedIndex; + this->nextIndex = NO_POSITION; /* force recalc */ + } + + /* the user may be moving things around aggressively; we wait a few seconds + before actually scheduling the next track lookup to avoid a bunch of unnecessary + I/O (note: the I/O may be over the network in some cases) */ + this->messageQueue.Debounce(Message::Create(this, MESSAGE_PREPARE_NEXT_TRACK, updatedIndex), 2500); + } + } else if (type == MESSAGE_PREPARE_NEXT_TRACK) { if (transport->GetPlaybackState() != PlaybackState::Stopped) { const size_t updatedIndex = static_cast(message.UserData1()); @@ -1000,7 +1016,7 @@ PlaybackService::Editor::~Editor() { } this->queue.Post(Message::Create( - &this->playback, MESSAGE_PREPARE_NEXT_TRACK, this->playIndex, 0)); + &this->playback, MESSAGE_NEXT_TRACK_EDITED, this->playIndex)); } this->playback.messageQueue.Post(Message::Create(