* Tweaks to curses input polling to reduce CPU usage in Windows.

* Run Player thread in a higher prioirty in Windows
* Don't show the context menu on track row headers
This commit is contained in:
casey langen 2017-03-23 17:09:51 -07:00
parent 648edc92c8
commit b9619ade2c
7 changed files with 35 additions and 35 deletions

View File

@ -267,6 +267,10 @@ void Player::UpdateNextMixPointTime() {
} }
void musik::core::audio::playerThreadLoop(Player* player) { void musik::core::audio::playerThreadLoop(Player* player) {
#ifdef WIN32
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
#endif
player->stream = Stream::Create(); player->stream = Stream::Create();
Buffer* buffer = nullptr; Buffer* buffer = nullptr;

View File

@ -206,17 +206,12 @@ void BrowseLayout::SetCategory(const std::string& fieldName) {
bool BrowseLayout::KeyPress(const std::string& key) { bool BrowseLayout::KeyPress(const std::string& key) {
if (key == "KEY_ENTER") { if (key == "KEY_ENTER") {
playback::Play(this->trackList, this->playback, this->GetFocus()); /* 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; 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;
}
}
} }
else if (Hotkeys::Is(Hotkeys::ViewRefresh, key)) { else if (Hotkeys::Is(Hotkeys::ViewRefresh, key)) {
this->categoryList->Requery(); this->categoryList->Requery();

View File

@ -136,23 +136,13 @@ void TrackSearchLayout::OnInputChanged(cursespp::TextInput* sender, std::string
void TrackSearchLayout::OnEnterPressed(cursespp::TextInput* sender) { void TrackSearchLayout::OnEnterPressed(cursespp::TextInput* sender) {
if (this->trackList->GetTrackList()->Count()) { if (this->trackList->GetTrackList()->Count()) {
playback::Play(this->trackList, this->playback, this->GetFocus()); playback::Play(*(this->trackList.get()), this->playback);
this->SetFocus(this->trackList); this->SetFocus(this->trackList);
} }
} }
bool TrackSearchLayout::KeyPress(const std::string& key) { bool TrackSearchLayout::KeyPress(const std::string& key) {
if (key == "KEY_ENTER") { if (key == "KEY_DOWN") {
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 (this->GetFocus() == this->input) { if (this->GetFocus() == this->input) {
this->FocusNext(); this->FocusNext();
return true; return true;

View File

@ -43,17 +43,16 @@ namespace musik {
namespace box { namespace box {
namespace playback { namespace playback {
void Play( void Play(
std::shared_ptr<musik::box::TrackListView> trackList, musik::box::TrackListView& trackList,
musik::core::audio::PlaybackService& playback, musik::core::audio::PlaybackService& playback)
cursespp::IWindowPtr focused)
{ {
auto tracks = trackList->GetTrackList(); auto tracks = trackList.GetTrackList();
if (tracks && tracks->Count()) { if (tracks && tracks->Count()) {
size_t index = 0; size_t index = 0;
if (focused.get() == trackList.get()) {
index = trackList->GetSelectedTrackIndex();
if (trackList.IsFocused()) {
index = trackList.GetSelectedTrackIndex();
if (index == cursespp::ListWindow::NO_SELECTION) { if (index == cursespp::ListWindow::NO_SELECTION) {
return; return;
} }

View File

@ -43,9 +43,8 @@ namespace musik {
namespace box { namespace box {
namespace playback { namespace playback {
void Play( void Play(
std::shared_ptr<musik::box::TrackListView> trackList, musik::box::TrackListView& trackList,
musik::core::audio::PlaybackService& playback, musik::core::audio::PlaybackService& playback);
cursespp::IWindowPtr focused);
} }
} }
} }

View File

@ -44,6 +44,7 @@
#include <glue/util/Duration.h> #include <glue/util/Duration.h>
#include <app/util/Hotkeys.h> #include <app/util/Hotkeys.h>
#include <app/util/Playback.h>
#include <app/overlay/PlayQueueOverlays.h> #include <app/overlay/PlayQueueOverlays.h>
#include <boost/format.hpp> #include <boost/format.hpp>
@ -114,7 +115,7 @@ void TrackListView::OnQueryCompleted(IQuery* query) {
if (this->query && query == this->query.get()) { if (this->query && query == this->query.get()) {
if (this->query->GetStatus() == IQuery::Finished) { if (this->query->GetStatus() == IQuery::Finished) {
bool hadTracks = this->tracks && this->tracks->Count() > 0; 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->tracks = this->query->GetResult();
this->headers.Set(this->query->GetHeaders()); this->headers.Set(this->query->GetHeaders());
@ -217,6 +218,19 @@ bool TrackListView::KeyPress(const std::string& key) {
handled = true; 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)) { else if (Hotkeys::Is(Hotkeys::NavigateJumpToPlaying, key)) {
this->ScrollToPlaying(); this->ScrollToPlaying();
@ -242,8 +256,7 @@ void TrackListView::OnTrackChanged(size_t index, musik::core::TrackPtr track) {
this->playing = track; this->playing = track;
this->OnAdapterChanged(); this->OnAdapterChanged();
if (now() - lastChanged >= AUTO_SCROLL_COOLDOWN) if (now() - lastChanged >= AUTO_SCROLL_COOLDOWN) {
{
this->ScrollToPlaying(); this->ScrollToPlaying();
} }
} }

View File

@ -40,7 +40,7 @@
#include <core/runtime/IMessageQueue.h> #include <core/runtime/IMessageQueue.h>
#ifdef WIN32 #ifdef WIN32
#define IDLE_TIMEOUT_MS 0 #define IDLE_TIMEOUT_MS 10
#define REDRAW_DEBOUNCE_MS 100 #define REDRAW_DEBOUNCE_MS 100
#else #else
#define IDLE_TIMEOUT_MS 75 #define IDLE_TIMEOUT_MS 75