diff --git a/src/core/audio/Player.cpp b/src/core/audio/Player.cpp index 205a6579b..7e38b4adf 100644 --- a/src/core/audio/Player.cpp +++ b/src/core/audio/Player.cpp @@ -267,6 +267,10 @@ void Player::UpdateNextMixPointTime() { } void musik::core::audio::playerThreadLoop(Player* player) { +#ifdef WIN32 + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); +#endif + player->stream = Stream::Create(); Buffer* buffer = nullptr; diff --git a/src/musikbox/app/layout/BrowseLayout.cpp b/src/musikbox/app/layout/BrowseLayout.cpp index b05db7bfc..de7d2ec63 100755 --- a/src/musikbox/app/layout/BrowseLayout.cpp +++ b/src/musikbox/app/layout/BrowseLayout.cpp @@ -206,16 +206,11 @@ void BrowseLayout::SetCategory(const std::string& fieldName) { bool BrowseLayout::KeyPress(const std::string& key) { if (key == "KEY_ENTER") { - playback::Play(this->trackList, this->playback, this->GetFocus()); - return true; - } - else if (Hotkeys::Is(Hotkeys::ContextMenu, key)) { - if (this->GetFocus() == this->trackList) { - TrackPtr track = this->trackList->GetSelectedTrack(); - if (track) { - PlayQueueOverlays::ShowAddTrackOverlay(this->playback, track->GetId()); - return true; - } + /* if the tracklist is NOT focused (i.e. the focus is on a + category window), start playback from the top. */ + if (this->GetFocus() != this->trackList) { + playback.Play(*trackList->GetTrackList(), 0); + return true; } } else if (Hotkeys::Is(Hotkeys::ViewRefresh, key)) { diff --git a/src/musikbox/app/layout/TrackSearchLayout.cpp b/src/musikbox/app/layout/TrackSearchLayout.cpp index dbfbdf692..3c2055523 100755 --- a/src/musikbox/app/layout/TrackSearchLayout.cpp +++ b/src/musikbox/app/layout/TrackSearchLayout.cpp @@ -136,23 +136,13 @@ void TrackSearchLayout::OnInputChanged(cursespp::TextInput* sender, std::string void TrackSearchLayout::OnEnterPressed(cursespp::TextInput* sender) { if (this->trackList->GetTrackList()->Count()) { - playback::Play(this->trackList, this->playback, this->GetFocus()); + playback::Play(*(this->trackList.get()), this->playback); this->SetFocus(this->trackList); } } bool TrackSearchLayout::KeyPress(const std::string& key) { - if (key == "KEY_ENTER") { - playback::Play(this->trackList, this->playback, this->GetFocus()); - return true; - } - else if (Hotkeys::Is(Hotkeys::ContextMenu, key)) { - TrackPtr track = this->trackList->GetSelectedTrack(); - if (track) { - PlayQueueOverlays::ShowAddTrackOverlay(this->playback, track->GetId()); - } - } - else if (key == "KEY_DOWN") { + if (key == "KEY_DOWN") { if (this->GetFocus() == this->input) { this->FocusNext(); return true; diff --git a/src/musikbox/app/util/Playback.cpp b/src/musikbox/app/util/Playback.cpp index eb499a09b..4bea6726f 100755 --- a/src/musikbox/app/util/Playback.cpp +++ b/src/musikbox/app/util/Playback.cpp @@ -43,17 +43,16 @@ namespace musik { namespace box { namespace playback { void Play( - std::shared_ptr trackList, - musik::core::audio::PlaybackService& playback, - cursespp::IWindowPtr focused) + musik::box::TrackListView& trackList, + musik::core::audio::PlaybackService& playback) { - auto tracks = trackList->GetTrackList(); + auto tracks = trackList.GetTrackList(); if (tracks && tracks->Count()) { size_t index = 0; - if (focused.get() == trackList.get()) { - index = trackList->GetSelectedTrackIndex(); + if (trackList.IsFocused()) { + index = trackList.GetSelectedTrackIndex(); if (index == cursespp::ListWindow::NO_SELECTION) { return; } diff --git a/src/musikbox/app/util/Playback.h b/src/musikbox/app/util/Playback.h index c2173fb32..56a3ace36 100755 --- a/src/musikbox/app/util/Playback.h +++ b/src/musikbox/app/util/Playback.h @@ -43,9 +43,8 @@ namespace musik { namespace box { namespace playback { void Play( - std::shared_ptr trackList, - musik::core::audio::PlaybackService& playback, - cursespp::IWindowPtr focused); + musik::box::TrackListView& trackList, + musik::core::audio::PlaybackService& playback); } } } diff --git a/src/musikbox/app/window/TrackListView.cpp b/src/musikbox/app/window/TrackListView.cpp index 55f4281c4..1bfeb159d 100755 --- a/src/musikbox/app/window/TrackListView.cpp +++ b/src/musikbox/app/window/TrackListView.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -114,7 +115,7 @@ void TrackListView::OnQueryCompleted(IQuery* query) { if (this->query && query == this->query.get()) { if (this->query->GetStatus() == IQuery::Finished) { bool hadTracks = this->tracks && this->tracks->Count() > 0; - bool prevQuerySame = this->lastQueryHash != this->query->GetQueryHash(); + bool prevQuerySame = this->lastQueryHash == this->query->GetQueryHash(); this->tracks = this->query->GetResult(); this->headers.Set(this->query->GetHeaders()); @@ -217,6 +218,19 @@ bool TrackListView::KeyPress(const std::string& key) { handled = true; } + else { + playback::Play(*this, this->playback); + handled = true; + } + } + else if (Hotkeys::Is(Hotkeys::ContextMenu, key)) { + if (!headers.HeaderAt(this->GetSelectedIndex())) { + TrackPtr track = this->GetSelectedTrack(); + if (track) { + PlayQueueOverlays::ShowAddTrackOverlay(this->playback, track->GetId()); + handled = true; + } + } } else if (Hotkeys::Is(Hotkeys::NavigateJumpToPlaying, key)) { this->ScrollToPlaying(); @@ -242,8 +256,7 @@ void TrackListView::OnTrackChanged(size_t index, musik::core::TrackPtr track) { this->playing = track; this->OnAdapterChanged(); - if (now() - lastChanged >= AUTO_SCROLL_COOLDOWN) - { + if (now() - lastChanged >= AUTO_SCROLL_COOLDOWN) { this->ScrollToPlaying(); } } diff --git a/src/musikbox/cursespp/Window.h b/src/musikbox/cursespp/Window.h index 598d158aa..03ec9c35e 100755 --- a/src/musikbox/cursespp/Window.h +++ b/src/musikbox/cursespp/Window.h @@ -40,7 +40,7 @@ #include #ifdef WIN32 -#define IDLE_TIMEOUT_MS 0 +#define IDLE_TIMEOUT_MS 10 #define REDRAW_DEBOUNCE_MS 100 #else #define IDLE_TIMEOUT_MS 75