Changes to support transport focus:

1) Added VolumeUp, VolumeDown, SeekForwad, SeekBack to Playback util
2) Updated GlobalHotkeys for (1)
3) Added support for UP/RIGHT to increase volume or seek forward, and DOWN/LEFT
   to decrease volume or seek back.
This commit is contained in:
casey langen 2016-09-17 23:04:34 -07:00
parent bec8caf280
commit e7752eb3d0
6 changed files with 87 additions and 21 deletions

View File

@ -256,9 +256,20 @@ IWindowPtr LibraryLayout::FocusPrev() {
} }
IWindowPtr LibraryLayout::GetFocus() { IWindowPtr LibraryLayout::GetFocus() {
return this->transportView->IsFocused() if (this->transportView->IsFocused()) {
? this->transportView return this->transportView;
: this->visibleLayout->GetFocus(); }
/* if nothing in the visible layout is focused, go
ahead and focus the transport so the user has something
to interact with. */
IWindowPtr focused = this->visibleLayout->GetFocus();
if (!focused) {
this->transportView->FocusFirst();
return this->transportView;
}
return focused;
} }
bool LibraryLayout::SetFocus(cursespp::IWindowPtr window) { bool LibraryLayout::SetFocus(cursespp::IWindowPtr window) {

View File

@ -57,11 +57,11 @@ bool GlobalHotkeys::Handle(const std::string& kn) {
return true; return true;
} }
else if (Hotkeys::Is(Hotkeys::VolumeUp, kn)) { else if (Hotkeys::Is(Hotkeys::VolumeUp, kn)) {
this->transport.SetVolume(this->transport.Volume() + 0.05); playback::VolumeUp(this->transport);
return true; return true;
} }
else if (Hotkeys::Is(Hotkeys::VolumeDown, kn)) { else if (Hotkeys::Is(Hotkeys::VolumeDown, kn)) {
this->transport.SetVolume(this->transport.Volume() - 0.05); playback::VolumeDown(this->transport);
return true; return true;
} }
else if (Hotkeys::Is(Hotkeys::Previous, kn)) { else if (Hotkeys::Is(Hotkeys::Previous, kn)) {
@ -73,13 +73,11 @@ bool GlobalHotkeys::Handle(const std::string& kn) {
return true; return true;
} }
else if (Hotkeys::Is(Hotkeys::SeekBack, kn)) { else if (Hotkeys::Is(Hotkeys::SeekBack, kn)) {
double time = this->transport.Position(); playback::SeekBack(this->transport);
this->transport.SetPosition(time - 10.0f);
return true; return true;
} }
else if (Hotkeys::Is(Hotkeys::SeekForward, kn)) { else if (Hotkeys::Is(Hotkeys::SeekForward, kn)) {
double time = this->transport.Position(); playback::SeekForward(this->transport);
this->transport.SetPosition(time + 10.0f);
return true; return true;
} }
else if (Hotkeys::Is(Hotkeys::ToggleRepeat, kn)) { else if (Hotkeys::Is(Hotkeys::ToggleRepeat, kn)) {

View File

@ -68,19 +68,35 @@ namespace musik {
void ToggleRepeatMode(PlaybackService& playback) { void ToggleRepeatMode(PlaybackService& playback) {
PlaybackService::RepeatMode mode = playback.GetRepeatMode(); PlaybackService::RepeatMode mode = playback.GetRepeatMode();
switch (mode) { switch (mode) {
case PlaybackService::RepeatNone: case PlaybackService::RepeatNone:
playback.SetRepeatMode(PlaybackService::RepeatList); playback.SetRepeatMode(PlaybackService::RepeatList);
break; break;
case PlaybackService::RepeatList: case PlaybackService::RepeatList:
playback.SetRepeatMode(PlaybackService::RepeatTrack); playback.SetRepeatMode(PlaybackService::RepeatTrack);
break; break;
default: default:
playback.SetRepeatMode(PlaybackService::RepeatNone); playback.SetRepeatMode(PlaybackService::RepeatNone);
break; break;
} }
} }
void VolumeUp(ITransport& transport) {
transport.SetVolume(transport.Volume() + 0.05);
}
void VolumeDown(ITransport& transport) {
transport.SetVolume(transport.Volume() - 0.05);
}
void SeekForward(ITransport& transport) {
transport.SetPosition(transport.Position() + 10.0f);
}
void SeekBack(ITransport& transport) {
transport.SetPosition(transport.Position() - 10.0f);
}
} }
} }
} }

View File

@ -47,6 +47,11 @@ namespace musik {
musik::box::PlaybackService& playback, musik::box::PlaybackService& playback,
cursespp::IWindowPtr focused); cursespp::IWindowPtr focused);
void VolumeUp(musik::core::audio::ITransport& transport);
void VolumeDown(musik::core::audio::ITransport& transport);
void SeekForward(musik::core::audio::ITransport& transport);
void SeekBack(musik::core::audio::ITransport& transport);
void PauseOrResume(musik::core::audio::ITransport& transport); void PauseOrResume(musik::core::audio::ITransport& transport);
void ToggleRepeatMode(PlaybackService& playback); void ToggleRepeatMode(PlaybackService& playback);

View File

@ -41,6 +41,7 @@
#include <cursespp/Text.h> #include <cursespp/Text.h>
#include <app/util/Duration.h> #include <app/util/Duration.h>
#include <app/util/Playback.h>
#include <core/debug.h> #include <core/debug.h>
#include <core/library/LocalLibraryConstants.h> #include <core/library/LocalLibraryConstants.h>
@ -130,7 +131,7 @@ void tokenize(const std::string& format, TokenList& tokens) {
/* writes the colorized formatted string to the specified window. accounts for /* writes the colorized formatted string to the specified window. accounts for
utf8 characters and ellipsizing */ utf8 characters and ellipsizing */
size_t writePlayingFormat( static size_t writePlayingFormat(
WINDOW *w, WINDOW *w,
std::string title, std::string title,
std::string album, std::string album,
@ -198,12 +199,19 @@ size_t writePlayingFormat(
return (width - remaining); return (width - remaining);
} }
static inline bool inc(const std::string& kn) {
return (kn == "KEY_UP" || kn == "KEY_RIGHT");
}
static inline bool dec(const std::string& kn) {
return (kn == "KEY_DOWN" || kn == "KEY_LEFT");
}
TransportWindow::TransportWindow(musik::box::PlaybackService& playback) TransportWindow::TransportWindow(musik::box::PlaybackService& playback)
: Window(nullptr) : Window(nullptr)
, playback(playback) , playback(playback)
, transport(playback.GetTransport()) , transport(playback.GetTransport())
, focus(FocusNone) , focus(FocusNone) {
{
this->SetFrameVisible(false); this->SetFrameVisible(false);
this->playback.TrackChanged.connect(this, &TransportWindow::OnPlaybackServiceTrackChanged); this->playback.TrackChanged.connect(this, &TransportWindow::OnPlaybackServiceTrackChanged);
this->playback.ModeChanged.connect(this, &TransportWindow::OnPlaybackModeChanged); this->playback.ModeChanged.connect(this, &TransportWindow::OnPlaybackModeChanged);
@ -243,6 +251,31 @@ void TransportWindow::Show() {
this->Update(); this->Update();
} }
bool TransportWindow::KeyPress(const std::string& kn) {
if (this->focus == FocusVolume) {
if (inc(kn)) {
playback::VolumeUp(this->transport);
return true;
}
else if (dec(kn)) {
playback::VolumeDown(this->transport);
return true;
}
}
else if (this->focus == FocusTime) {
if (inc(kn)) {
playback::SeekForward(this->transport);
return true;
}
else if (dec(kn)) {
playback::SeekBack(this->transport);
return true;
}
}
return false;
}
bool TransportWindow::FocusNext() { bool TransportWindow::FocusNext() {
this->SetFocus((FocusTarget)(((int) this->focus + 1) % 3)); this->SetFocus((FocusTarget)(((int) this->focus + 1) % 3));
return (this->focus != FocusNone); return (this->focus != FocusNone);

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include <cursespp/Window.h> #include <cursespp/Window.h>
#include <cursespp/IKeyHandler.h>
#include <core/library/track/Track.h> #include <core/library/track/Track.h>
#include <app/service/PlaybackService.h> #include <app/service/PlaybackService.h>
#include <sigslot/sigslot.h> #include <sigslot/sigslot.h>
@ -44,6 +45,7 @@ namespace musik {
namespace box { namespace box {
class TransportWindow : class TransportWindow :
public cursespp::Window, public cursespp::Window,
public cursespp::IKeyHandler,
#if (__clang_major__ == 7 && __clang_minor__ == 3) #if (__clang_major__ == 7 && __clang_minor__ == 3)
public std::enable_shared_from_this<TransportWindow>, public std::enable_shared_from_this<TransportWindow>,
#endif #endif
@ -62,6 +64,7 @@ namespace musik {
virtual void ProcessMessage(cursespp::IMessage &message); virtual void ProcessMessage(cursespp::IMessage &message);
virtual void Show(); virtual void Show();
virtual void OnFocusChanged(bool focused); virtual void OnFocusChanged(bool focused);
virtual bool KeyPress(const std::string& key);
void SetFocus(FocusTarget target); void SetFocus(FocusTarget target);
FocusTarget GetFocus() const; FocusTarget GetFocus() const;