Incremental work on the now playing list. It sort of works now, but

things are a bit goofy.
This commit is contained in:
casey 2016-06-02 23:01:22 -07:00
parent 535367d705
commit 40bc4d31ad
12 changed files with 310 additions and 130 deletions

View File

@ -42,7 +42,6 @@
#include <app/layout/ConsoleLayout.h>
#include <app/layout/LibraryLayout.h>
#include <app/layout/NowPlayingLayout.h>
#include <app/util/GlobalHotkeys.h>
#include <app/service/PlaybackService.h>
@ -238,7 +237,6 @@ int main(int argc, char* argv[])
GlobalHotkeys globalHotkeys(playback, library);
ILayoutPtr libraryLayout((ILayout *) new LibraryLayout(playback, library));
ILayoutPtr nowPlayingLayout((ILayout *) new NowPlayingLayout(playback, library));
ILayoutPtr consoleLayout((ILayout *) new ConsoleLayout(tp, library));
int64 ch;
@ -288,9 +286,6 @@ int main(int argc, char* argv[])
else if (ch == KEY_F(2)) {
changeLayout(state, libraryLayout);
}
else if (ch == KEY_F(3)) {
changeLayout(state, nowPlayingLayout);
}
else if (!globalHotkeys.Handle(kn)) {
if (state.input) {
state.input->Write(kn);

View File

@ -0,0 +1,134 @@
#include "stdafx.h"
#include <cursespp/Colors.h>
#include <cursespp/Screen.h>
#include <core/library/LocalLibraryConstants.h>
#include <app/query/CategoryTrackListQuery.h>
#include "BrowseLayout.h"
using namespace musik::core::library::constants;
#define CATEGORY_WIDTH 25
#define DEFAULT_CATEGORY constants::Track::ARTIST_ID
using namespace musik::core;
using namespace musik::core::audio;
using namespace musik::core::library;
using namespace musik::box;
using namespace cursespp;
BrowseLayout::BrowseLayout(
PlaybackService& playback,
LibraryPtr library)
: LayoutBase()
, playback(playback)
, parent(parent) {
this->library = library;
this->InitializeWindows();
}
BrowseLayout::~BrowseLayout() {
}
void BrowseLayout::Layout() {
size_t cx = this->GetWidth(), cy = this->GetHeight();
if (cx == 0 || cy == 0) {
return;
}
size_t x = this->GetX(), y = this->GetY();
this->MoveAndResize(x, y, cx, cy);
this->SetSize(cx, cy);
this->SetPosition(x, y);
this->categoryList->MoveAndResize(x, y, CATEGORY_WIDTH, cy);
this->trackList->MoveAndResize(
x + CATEGORY_WIDTH, y, cx - CATEGORY_WIDTH, cy);
this->categoryList->SetFocusOrder(0);
this->trackList->SetFocusOrder(1);
}
void BrowseLayout::InitializeWindows() {
this->categoryList.reset(new CategoryListView(this->library, DEFAULT_CATEGORY));
this->trackList.reset(new TrackListView(this->playback, this->library));
this->AddWindow(this->categoryList);
this->AddWindow(this->trackList);
this->categoryList->SelectionChanged.connect(
this, &BrowseLayout::OnCategoryViewSelectionChanged);
this->categoryList->Invalidated.connect(
this, &BrowseLayout::OnCategoryViewInvalidated);
this->Layout();
}
IWindowPtr BrowseLayout::GetFocus() {
return this->focused ? this->focused : LayoutBase::GetFocus();
}
void BrowseLayout::Show() {
LayoutBase::Show();
this->categoryList->Requery();
}
void BrowseLayout::RequeryTrackList(ListWindow *view) {
if (view == this->categoryList.get()) {
DBID selectedId = this->categoryList->GetSelectedId();
if (selectedId != -1) {
this->trackList->Requery(std::shared_ptr<TrackListQueryBase>(
new CategoryTrackListQuery(
this->library,
this->categoryList->GetFieldName(),
selectedId)));
}
}
}
void BrowseLayout::OnCategoryViewSelectionChanged(
ListWindow *view, size_t newIndex, size_t oldIndex) {
this->RequeryTrackList(view);
}
void BrowseLayout::OnCategoryViewInvalidated(
ListWindow *view, size_t selectedIndex) {
this->RequeryTrackList(view);
}
bool BrowseLayout::KeyPress(const std::string& key) {
if (key == "^M") { /* enter. play the selection */
auto tracks = this->trackList->GetTrackList();
auto focus = this->GetFocus();
size_t index = (focus == this->trackList)
? this->trackList->GetSelectedIndex() : 0;
this->playback.Play(*tracks, index);
return true;
}
if (key == "KEY_F(5)") {
this->categoryList->Requery();
return true;
}
else if (key == "ALT_1" || key == "M-1") {
this->categoryList->SetFieldName(constants::Track::ARTIST_ID);
return true;
}
else if (key == "ALT_2" || key == "M-2") {
this->categoryList->SetFieldName(constants::Track::ALBUM_ID);
return true;
}
else if (key == "ALT_3" || key == "M-3") {
this->categoryList->SetFieldName(constants::Track::GENRE_ID);
return true;
}
return LayoutBase::KeyPress(key);
}

View File

@ -0,0 +1,49 @@
#pragma once
#include <cursespp/LayoutBase.h>
#include <app/window/CategoryListView.h>
#include <app/window/TrackListView.h>
#include <app/window/TransportWindow.h>
#include <app/service/PlaybackService.h>
#include <core/playback/Transport.h>
#include <core/library/ILibrary.h>
#include <sigslot/sigslot.h>
namespace musik {
namespace box {
class BrowseLayout : public cursespp::LayoutBase, public sigslot::has_slots<> {
public:
BrowseLayout(
PlaybackService& playback,
musik::core::LibraryPtr library);
virtual ~BrowseLayout();
virtual void Layout();
virtual void Show();
virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(const std::string& key);
private:
void InitializeWindows();
void RequeryTrackList(ListWindow *view);
void OnCategoryViewSelectionChanged(
ListWindow *view, size_t newIndex, size_t oldIndex);
void OnCategoryViewInvalidated(
ListWindow *view, size_t selectedIndex);
PlaybackService& playback;
musik::core::LibraryPtr library;
std::shared_ptr<CategoryListView> categoryList;
std::shared_ptr<TrackListView> trackList;
cursespp::IWindowPtr focused;
cursespp::IWindowPtr parent;
};
}
}

View File

@ -40,108 +40,81 @@ LibraryLayout::~LibraryLayout() {
}
void LibraryLayout::Layout() {
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
int x = 0, y = 0;
int cx = Screen::GetWidth(), cy = Screen::GetHeight();
this->categoryList->MoveAndResize(
0,
0,
CATEGORY_WIDTH,
this->GetHeight() - TRANSPORT_HEIGHT);
this->MoveAndResize(x, y, cx, cy);
this->categoryList->SetFocusOrder(0);
this->trackList->MoveAndResize(
CATEGORY_WIDTH,
0,
this->GetWidth() - CATEGORY_WIDTH,
this->GetHeight() - TRANSPORT_HEIGHT);
this->trackList->SetFocusOrder(1);
this->browseLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
this->nowPlayingLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
this->transportView->MoveAndResize(
1,
this->GetHeight() - TRANSPORT_HEIGHT,
this->GetWidth() - 2,
cy - TRANSPORT_HEIGHT,
cx - 2,
TRANSPORT_HEIGHT);
this->transportView->Update();
this->ShowBrowse();
}
void LibraryLayout::ShowNowPlaying() {
if (this->focusedLayout != this->nowPlayingLayout) {
this->AddWindow(this->nowPlayingLayout);
this->RemoveWindow(this->browseLayout);
this->focusedLayout = this->nowPlayingLayout;
this->nowPlayingLayout->Layout();
this->nowPlayingLayout->Show();
this->BringToTop();
}
}
void LibraryLayout::ShowBrowse() {
if (this->focusedLayout != this->browseLayout) {
this->RemoveWindow(this->nowPlayingLayout);
this->AddWindow(this->browseLayout);
this->focusedLayout = this->browseLayout;
this->browseLayout->Layout();
this->BringToTop();
}
}
void LibraryLayout::InitializeWindows() {
this->categoryList.reset(new CategoryListView(this->library, DEFAULT_CATEGORY));
this->trackList.reset(new TrackListView(this->playback, this->library));
this->browseLayout.reset(new BrowseLayout(this->playback, this->library));
this->nowPlayingLayout.reset(new NowPlayingLayout(this->playback, this->library));
this->transportView.reset(new TransportWindow(this->playback));
this->AddWindow(this->categoryList);
this->AddWindow(this->trackList);
this->AddWindow(this->transportView);
this->categoryList->SelectionChanged.connect(
this, &LibraryLayout::OnCategoryViewSelectionChanged);
this->categoryList->Invalidated.connect(
this, &LibraryLayout::OnCategoryViewInvalidated);
this->Layout();
}
IWindowPtr LibraryLayout::GetFocus() {
return this->focused ? this->focused : LayoutBase::GetFocus();
}
void LibraryLayout::Show() {
LayoutBase::Show();
this->categoryList->Requery();
this->transportView->Update();
}
void LibraryLayout::RequeryTrackList(ListWindow *view) {
if (view == this->categoryList.get()) {
DBID selectedId = this->categoryList->GetSelectedId();
if (selectedId != -1) {
this->trackList->Requery(std::shared_ptr<TrackListQueryBase>(
new CategoryTrackListQuery(
this->library,
this->categoryList->GetFieldName(),
selectedId)));
}
}
IWindowPtr LibraryLayout::FocusNext() {
return this->focusedLayout->FocusNext();
}
void LibraryLayout::OnCategoryViewSelectionChanged(
ListWindow *view, size_t newIndex, size_t oldIndex) {
this->RequeryTrackList(view);
IWindowPtr LibraryLayout::FocusPrev() {
return this->focusedLayout->FocusPrev();
}
void LibraryLayout::OnCategoryViewInvalidated(
ListWindow *view, size_t selectedIndex) {
this->RequeryTrackList(view);
IWindowPtr LibraryLayout::GetFocus() {
return this->focusedLayout->GetFocus();
}
bool LibraryLayout::KeyPress(const std::string& key) {
if (key == "^M") { /* enter. play the selection */
auto tracks = this->trackList->GetTrackList();
auto focus = this->GetFocus();
size_t index = (focus == this->trackList)
? this->trackList->GetSelectedIndex() : 0;
this->playback.Play(*tracks, index);
}
else if (key == "ALT_1" || key == "M-1") {
this->categoryList->SetFieldName(constants::Track::ARTIST_ID);
if (key == "^N") {
this->ShowNowPlaying();
return true;
}
else if (key == "ALT_2" || key == "M-2") {
this->categoryList->SetFieldName(constants::Track::ALBUM_ID);
else if (key == "^[") {
this->ShowBrowse();
return true;
}
else if (key == "ALT_3" || key == "M-3") {
this->categoryList->SetFieldName(constants::Track::GENRE_ID);
return true;
}
else if (key == "KEY_F(5)") {
this->categoryList->Requery();
else if (this->focusedLayout && this->focusedLayout->KeyPress(key)) {
return true;
}
else if (key == " ") {

View File

@ -1,50 +1,49 @@
#pragma once
#pragma once
#include <cursespp/LayoutBase.h>
#include <cursespp/LayoutStack.h>
#include <app/layout/BrowseLayout.h>
#include <app/layout/NowPlayingLayout.h>
#include <app/window/TransportWindow.h>
#include <app/service/PlaybackService.h>
#include <core/playback/Transport.h>
#include <core/library/ILibrary.h>
#include <sigslot/sigslot.h>
namespace musik {
namespace box {
class LibraryLayout : public cursespp::LayoutBase, public sigslot::has_slots<> {
public:
LibraryLayout(
PlaybackService& playback,
musik::core::LibraryPtr library);
virtual ~LibraryLayout();
virtual void Layout();
#include <cursespp/LayoutBase.h>
#include <app/window/CategoryListView.h>
#include <app/window/TrackListView.h>
#include <app/window/TransportWindow.h>
#include <app/service/PlaybackService.h>
#include <core/playback/Transport.h>
#include <core/library/ILibrary.h>
#include <sigslot/sigslot.h>
namespace musik {
namespace box {
class LibraryLayout : public cursespp::LayoutBase, public sigslot::has_slots<> {
public:
LibraryLayout(
PlaybackService& playback,
musik::core::LibraryPtr library);
virtual ~LibraryLayout();
virtual void Layout();
virtual void Show();
virtual cursespp::IWindowPtr FocusNext();
virtual cursespp::IWindowPtr FocusPrev();
virtual cursespp::IWindowPtr GetFocus();
virtual void Show();
virtual bool KeyPress(const std::string& key);
private:
void InitializeWindows();
void RequeryTrackList(ListWindow *view);
void OnCategoryViewSelectionChanged(
ListWindow *view, size_t newIndex, size_t oldIndex);
void OnCategoryViewInvalidated(
ListWindow *view, size_t selectedIndex);
PlaybackService& playback;
musik::core::audio::Transport& transport;
musik::core::LibraryPtr library;
std::shared_ptr<CategoryListView> categoryList;
std::shared_ptr<TrackListView> trackList;
std::shared_ptr<TransportWindow> transportView;
cursespp::IWindowPtr focused;
};
}
}
void InitializeWindows();
void ShowNowPlaying();
void ShowBrowse();
PlaybackService& playback;
musik::core::audio::Transport& transport;
musik::core::LibraryPtr library;
std::shared_ptr<BrowseLayout> browseLayout;
std::shared_ptr<TransportWindow> transportView;
std::shared_ptr<NowPlayingLayout> nowPlayingLayout;
cursespp::ILayoutPtr focusedLayout;
};
}
}

View File

@ -31,16 +31,17 @@ NowPlayingLayout::~NowPlayingLayout() {
}
void NowPlayingLayout::Layout() {
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
size_t cx = this->GetWidth(), cy = this->GetHeight();
this->trackList->MoveAndResize(
0,
0,
this->GetWidth(),
this->GetHeight());
if (cx && cy) {
this->trackList->MoveAndResize(
0,
0,
this->GetWidth(),
this->GetHeight());
this->trackList->SetFocusOrder(1);
this->trackList->SetFocusOrder(1);
}
}
void NowPlayingLayout::InitializeWindows() {
@ -61,4 +62,13 @@ void NowPlayingLayout::Show() {
void NowPlayingLayout::RequeryTrackList() {
this->trackList->Requery(std::shared_ptr<TrackListQueryBase>(
new NowPlayingTrackListQuery(this->playback)));
}
bool NowPlayingLayout::KeyPress(const std::string& key) {
if (key == "^M") { /* enter. play the selection */
this->playback.Play(this->trackList->GetSelectedIndex());
return true;
}
return LayoutBase::KeyPress(key);
}

View File

@ -25,6 +25,7 @@ namespace musik {
virtual void Layout();
virtual void Show();
virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(const std::string& key);
private:
void InitializeWindows();

View File

@ -11,5 +11,6 @@ namespace cursespp {
virtual bool Pop(ILayoutPtr layout) = 0;
virtual bool BringToTop(ILayoutPtr layout) = 0;
virtual bool SendToBottom(ILayoutPtr layout) = 0;
virtual ILayoutPtr Top() = 0;
};
}

View File

@ -103,6 +103,14 @@ IWindowPtr LayoutStack::FocusNext() {
return this->layouts.front()->FocusNext();
}
ILayoutPtr LayoutStack::Top() {
if (this->layouts.size()) {
return this->layouts.front();
}
return ILayoutPtr();
}
IWindowPtr LayoutStack::FocusPrev() {
if (!this->layouts.size()) {
return IWindowPtr();

View File

@ -2,11 +2,12 @@
#include "ILayout.h"
#include "ILayoutStack.h"
#include "LayoutBase.h"
#include <memory>
namespace cursespp {
class LayoutStack : public ILayout, public ILayoutStack {
class LayoutStack : public LayoutBase, public ILayoutStack {
public:
LayoutStack();
virtual ~LayoutStack();
@ -41,6 +42,7 @@ namespace cursespp {
virtual bool Pop(ILayoutPtr layout);
virtual bool BringToTop(ILayoutPtr layout);
virtual bool SendToBottom(ILayoutPtr layout);
virtual ILayoutPtr Top();
private:
std::deque<ILayoutPtr> layouts;

View File

@ -115,6 +115,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="app\layout\BrowseLayout.cpp" />
<ClCompile Include="app\layout\LibraryLayout.cpp" />
<ClCompile Include="app\layout\ConsoleLayout.cpp" />
<ClCompile Include="app\layout\NowPlayingLayout.cpp" />
@ -155,6 +156,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="app\layout\BrowseLayout.h" />
<ClInclude Include="app\layout\LibraryLayout.h" />
<ClInclude Include="app\layout\ConsoleLayout.h" />
<ClInclude Include="app\layout\NowPlayingLayout.h" />

View File

@ -102,6 +102,9 @@
<ClCompile Include="app\layout\NowPlayingLayout.cpp">
<Filter>app\layout</Filter>
</ClCompile>
<ClCompile Include="app\layout\BrowseLayout.cpp">
<Filter>app\layout</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
@ -246,6 +249,9 @@
<ClInclude Include="app\layout\NowPlayingLayout.h">
<Filter>app\layout</Filter>
</ClInclude>
<ClInclude Include="app\layout\BrowseLayout.h">
<Filter>app\layout</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="cursespp">