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() {
return this->transportView->IsFocused()
? this->transportView
: this->visibleLayout->GetFocus();
if (this->transportView->IsFocused()) {
return this->transportView;
}
/* 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) {

View File

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

View File

@ -68,19 +68,35 @@ namespace musik {
void ToggleRepeatMode(PlaybackService& playback) {
PlaybackService::RepeatMode mode = playback.GetRepeatMode();
switch (mode) {
case PlaybackService::RepeatNone:
playback.SetRepeatMode(PlaybackService::RepeatList);
break;
case PlaybackService::RepeatNone:
playback.SetRepeatMode(PlaybackService::RepeatList);
break;
case PlaybackService::RepeatList:
playback.SetRepeatMode(PlaybackService::RepeatTrack);
break;
case PlaybackService::RepeatList:
playback.SetRepeatMode(PlaybackService::RepeatTrack);
break;
default:
playback.SetRepeatMode(PlaybackService::RepeatNone);
break;
default:
playback.SetRepeatMode(PlaybackService::RepeatNone);
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,
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 ToggleRepeatMode(PlaybackService& playback);

View File

@ -41,6 +41,7 @@
#include <cursespp/Text.h>
#include <app/util/Duration.h>
#include <app/util/Playback.h>
#include <core/debug.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
utf8 characters and ellipsizing */
size_t writePlayingFormat(
static size_t writePlayingFormat(
WINDOW *w,
std::string title,
std::string album,
@ -198,12 +199,19 @@ size_t writePlayingFormat(
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)
: Window(nullptr)
, playback(playback)
, transport(playback.GetTransport())
, focus(FocusNone)
{
, focus(FocusNone) {
this->SetFrameVisible(false);
this->playback.TrackChanged.connect(this, &TransportWindow::OnPlaybackServiceTrackChanged);
this->playback.ModeChanged.connect(this, &TransportWindow::OnPlaybackModeChanged);
@ -243,6 +251,31 @@ void TransportWindow::Show() {
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() {
this->SetFocus((FocusTarget)(((int) this->focus + 1) % 3));
return (this->focus != FocusNone);

View File

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