* 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) {
#ifdef WIN32
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
#endif
player->stream = Stream::Create();
Buffer* buffer = nullptr;

View File

@ -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)) {

View File

@ -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;

View File

@ -43,17 +43,16 @@ namespace musik {
namespace box {
namespace playback {
void Play(
std::shared_ptr<musik::box::TrackListView> 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;
}

View File

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

View File

@ -44,6 +44,7 @@
#include <glue/util/Duration.h>
#include <app/util/Hotkeys.h>
#include <app/util/Playback.h>
#include <app/overlay/PlayQueueOverlays.h>
#include <boost/format.hpp>
@ -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();
}
}

View File

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