From 66c19c2123571cef9261fa2ee8d06c42b76f10be Mon Sep 17 00:00:00 2001 From: casey Date: Thu, 12 May 2016 02:31:44 -0700 Subject: [PATCH] More improvements to layouts and stuff. Need to figure out scroll focus situation soon. --- src/core/library/LibraryFactory.cpp | 1 + src/musikbox/CategoryListQuery.cpp | 9 +++--- src/musikbox/CategoryListView.cpp | 44 ++++++++++++++++++++++++--- src/musikbox/CategoryListView.h | 33 ++++++++++++++++---- src/musikbox/CommandWindow.cpp | 14 ++------- src/musikbox/CommandWindow.h | 9 +++--- src/musikbox/IScrollAdapter.h | 2 ++ src/musikbox/LibraryLayout.cpp | 21 +++++++++---- src/musikbox/LibraryLayout.h | 10 ++++-- src/musikbox/Main.cpp | 10 ++++-- src/musikbox/MainLayout.cpp | 6 ++-- src/musikbox/MainLayout.h | 2 +- src/musikbox/ScrollAdapterBase.cpp | 6 ++++ src/musikbox/ScrollableWindow.cpp | 4 +++ src/musikbox/ScrollableWindow.h | 3 ++ src/musikbox/SingleLineEntry.cpp | 2 ++ src/musikbox/TrackListView.cpp | 13 ++++++++ src/musikbox/TrackListView.h | 12 ++++++++ src/musikbox/musikbox.vcxproj | 2 ++ src/musikbox/musikbox.vcxproj.filters | 6 ++++ 20 files changed, 166 insertions(+), 43 deletions(-) create mode 100755 src/musikbox/TrackListView.cpp create mode 100755 src/musikbox/TrackListView.h diff --git a/src/core/library/LibraryFactory.cpp b/src/core/library/LibraryFactory.cpp index 372399fc3..980650561 100644 --- a/src/core/library/LibraryFactory.cpp +++ b/src/core/library/LibraryFactory.cpp @@ -33,6 +33,7 @@ // POSSIBILITY OF SUCH DAMAGE. // ////////////////////////////////////////////////////////////////////////////// + #include "pch.hpp" #include #include diff --git a/src/musikbox/CategoryListQuery.cpp b/src/musikbox/CategoryListQuery.cpp index 351351159..beb17a729 100755 --- a/src/musikbox/CategoryListQuery.cpp +++ b/src/musikbox/CategoryListQuery.cpp @@ -26,9 +26,10 @@ bool CategoryListQuery::OnRun(Connection& db) { } std::string query = - "SELECT DISTINCT artists.name " - "FROM artists, tracks " - "WHERE artists.id = tracks.visual_artist_id;"; + "SELECT DISTINCT albums.name " + "FROM albums, tracks " + "WHERE albums.id = tracks.album_id " + "ORDER BY albums.sort_order;"; Statement stmt(query.c_str(), db); @@ -36,5 +37,5 @@ bool CategoryListQuery::OnRun(Connection& db) { result->push_back(stmt.ColumnText(0)); } - return false; + return true; } \ No newline at end of file diff --git a/src/musikbox/CategoryListView.cpp b/src/musikbox/CategoryListView.cpp index 25568a93d..b1460d1a1 100755 --- a/src/musikbox/CategoryListView.cpp +++ b/src/musikbox/CategoryListView.cpp @@ -1,20 +1,56 @@ #pragma once #include "stdafx.h" +#include "Colors.h" #include "CategoryListView.h" +#include "SingleLineEntry.h" +#include "MultiLineEntry.h" +#include "CategoryListQuery.h" -CategoryListView::CategoryListView() { +using musik::core::LibraryPtr; +using musik::core::IQuery; +CategoryListView::CategoryListView(LibraryPtr library) +: ScrollableWindow() { + this->library = library; + this->adapter = new Adapter(*this); + this->activeQuery = QueryPtr(new CategoryListQuery()); + this->library->Enqueue(activeQuery); } CategoryListView::~CategoryListView() { + delete adapter; +} +void CategoryListView::OnIdle() { + if (activeQuery && activeQuery->GetStatus() == IQuery::Finished) { + /* need to make better use of smart pointers here... there should + be a way to "cast" smart_ptr to smart_ptr. */ + CategoryListQuery *clq = (CategoryListQuery *) activeQuery.get(); + this->metadata = clq->GetResult(); + activeQuery.reset(); + this->OnAdapterChanged(); + } } IScrollAdapter& CategoryListView::GetScrollAdapter() { - return adapter; + return *adapter; } -void CategoryListView::OnQueryCompleted(QueryPtr query) { - +CategoryListView::Adapter::Adapter(CategoryListView &parent) +: parent(parent) { } + +size_t CategoryListView::Adapter::GetEntryCount() { + return parent.metadata ? parent.metadata->size() : 0; +} + +IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) { + this->spos = this->parent.GetScrollPosition(); + int64 attrs = index == this->spos.logicalIndex ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1; + + IScrollAdapter::EntryPtr entry(new SingleLineEntry(parent.metadata->at(index))); + entry->SetAttrs(attrs); + + return entry; +} \ No newline at end of file diff --git a/src/musikbox/CategoryListView.h b/src/musikbox/CategoryListView.h index 0f7a6573f..deab3317c 100755 --- a/src/musikbox/CategoryListView.h +++ b/src/musikbox/CategoryListView.h @@ -1,21 +1,42 @@ #pragma once +#include + #include "ScrollableWindow.h" -#include "SimpleScrollAdapter.h" +#include "ScrollAdapterBase.h" + #include +#include using musik::core::QueryPtr; +using musik::core::LibraryPtr; -class CategoryListView : public ScrollableWindow { +class CategoryListView : public ScrollableWindow, public sigslot::has_slots<> { public: - CategoryListView(); + CategoryListView(LibraryPtr library); ~CategoryListView(); /* non-virtual for now*/ + void OnIdle(); + protected: virtual IScrollAdapter& GetScrollAdapter(); - private: - void OnQueryCompleted(QueryPtr query); + class Adapter : public ScrollAdapterBase { + public: + Adapter(CategoryListView &parent); - SimpleScrollAdapter adapter; + virtual size_t GetEntryCount(); + virtual EntryPtr GetEntry(size_t index); + + private: + CategoryListView &parent; + IScrollAdapter::ScrollPosition spos; + }; + + private: + LibraryPtr library; + QueryPtr activeQuery; + Adapter *adapter; + + boost::shared_ptr> metadata; }; \ No newline at end of file diff --git a/src/musikbox/CommandWindow.cpp b/src/musikbox/CommandWindow.cpp index 1235b0b03..aa844ef33 100755 --- a/src/musikbox/CommandWindow.cpp +++ b/src/musikbox/CommandWindow.cpp @@ -32,17 +32,15 @@ bool tostr(T& t, const std::string& s) { return !(iss >> t).fail(); } -CommandWindow::CommandWindow(Transport& transport, OutputWindow& output) +CommandWindow::CommandWindow(Transport& transport, LibraryPtr library, OutputWindow& output) : Window() { this->transport = &transport; + this->library = library; this->buffer = new char[BUFFER_SIZE]; this->bufferPosition = 0; this->output = &output; this->paused = false; - this->library = LibraryFactory::Libraries().at(0); this->output->WriteLine("type 'h' or 'help'\n", BOX_COLOR_BLACK_ON_GREY); - - this->library->QueryCompleted.connect(this, &CommandWindow::OnQueryCompleted); } CommandWindow::~CommandWindow() { @@ -111,11 +109,6 @@ void CommandWindow::SetVolume(float volume) { transport->SetVolume(volume); } -void CommandWindow::OnQueryCompleted(QueryPtr query) { - CategoryListQuery *result = (CategoryListQuery *) query.get(); - CategoryListQuery::Result data = result->GetResult(); -} - void CommandWindow::Help() { int64 s = -1; this->output->WriteLine("help:\n", s); @@ -144,9 +137,6 @@ bool CommandWindow::ProcessCommand(const std::string& cmd) { if (name == "plugins") { this->ListPlugins(); } - if (name == "artists") { - this->artistQueryId = this->library->Enqueue(QueryPtr(new CategoryListQuery())); - } else if (name == "play" || name == "pl" || name == "p") { return this->PlayFile(args); } diff --git a/src/musikbox/CommandWindow.h b/src/musikbox/CommandWindow.h index c33fbd4ef..e825e14dd 100755 --- a/src/musikbox/CommandWindow.h +++ b/src/musikbox/CommandWindow.h @@ -13,7 +13,11 @@ using namespace musik::core::audio; class CommandWindow : public Window, public IInput, public sigslot::has_slots<> { public: - CommandWindow(Transport& transport, OutputWindow& output); + CommandWindow( + Transport& transport, + LibraryPtr library, + OutputWindow& output); + ~CommandWindow(); virtual void WriteChar(int ch); @@ -31,13 +35,10 @@ class CommandWindow : public Window, public IInput, public sigslot::has_slots<> void SetVolume(float volume); void Help(); - void OnQueryCompleted(QueryPtr query); - char* buffer; int bufferPosition; OutputWindow* output; Transport* transport; LibraryPtr library; bool paused; - int artistQueryId; }; \ No newline at end of file diff --git a/src/musikbox/IScrollAdapter.h b/src/musikbox/IScrollAdapter.h index 0aa4d954b..10aa3ec65 100755 --- a/src/musikbox/IScrollAdapter.h +++ b/src/musikbox/IScrollAdapter.h @@ -10,6 +10,7 @@ class IScrollAdapter { firstVisibleEntryIndex = 0; visibleEntryCount = 0; lineCount = 0; + logicalIndex = 0; totalEntries = 0; } @@ -17,6 +18,7 @@ class IScrollAdapter { size_t visibleEntryCount; size_t lineCount; size_t totalEntries; + size_t logicalIndex; }; class IEntry { diff --git a/src/musikbox/LibraryLayout.cpp b/src/musikbox/LibraryLayout.cpp index 0797375be..7e0fba7b7 100755 --- a/src/musikbox/LibraryLayout.cpp +++ b/src/musikbox/LibraryLayout.cpp @@ -1,8 +1,11 @@ #include "stdafx.h" +#include "Screen.h" #include "LibraryLayout.h" -LibraryLayout::LibraryLayout() { - +LibraryLayout::LibraryLayout(LibraryPtr library) { + this->albumList.reset(new CategoryListView(library)); + this->trackList.reset(new TrackListView()); + this->Layout(); } LibraryLayout::~LibraryLayout() { @@ -10,21 +13,27 @@ LibraryLayout::~LibraryLayout() { } IWindow* LibraryLayout::FocusNext() { - return NULL; + return this->GetFocus(); } IWindow* LibraryLayout::FocusPrev() { - return NULL; + return this->GetFocus(); } IWindow* LibraryLayout::GetFocus() { - return NULL; + return this->albumList.get(); } void LibraryLayout::Layout() { + this->albumList->SetPosition(0, 0); + this->albumList->SetSize(20, Screen::GetHeight()); + this->albumList->Create(); + this->trackList->SetPosition(20, 0); + this->trackList->SetSize(Screen::GetWidth() - 20, Screen::GetHeight()); + this->trackList->Create(); } void LibraryLayout::OnIdle() { - + this->albumList->OnIdle(); } \ No newline at end of file diff --git a/src/musikbox/LibraryLayout.h b/src/musikbox/LibraryLayout.h index eb1d750d9..947c14066 100755 --- a/src/musikbox/LibraryLayout.h +++ b/src/musikbox/LibraryLayout.h @@ -2,10 +2,15 @@ #include "ILayout.h" #include "CategoryListView.h" +#include "TrackListView.h" + +#include + +using musik::core::LibraryPtr; class LibraryLayout : public ILayout { public: - LibraryLayout(); + LibraryLayout(LibraryPtr library); ~LibraryLayout(); /* not virtual */ virtual IWindow* FocusNext(); @@ -15,5 +20,6 @@ class LibraryLayout : public ILayout { virtual void OnIdle(); private: - CategoryListView albumList; + boost::shared_ptr albumList; + boost::shared_ptr trackList; }; \ No newline at end of file diff --git a/src/musikbox/Main.cpp b/src/musikbox/Main.cpp index 940fb47c2..56ba5dff3 100644 --- a/src/musikbox/Main.cpp +++ b/src/musikbox/Main.cpp @@ -48,6 +48,8 @@ #include #include +#include + #ifdef WIN32 #undef MOUSE_MOVED @@ -83,6 +85,7 @@ int main(int argc, char* argv[]) start_color(); use_default_colors(); refresh(); + curs_set(0); #ifdef __PDCURSES__ PDC_set_title("musikbox ♫"); @@ -94,8 +97,11 @@ int main(int argc, char* argv[]) Transport tp; tp.SetVolume(0.01); - MainLayout mainLayout(tp); - LibraryLayout library; + using musik::core::LibraryFactory; + LibraryPtr library = LibraryFactory::Libraries().at(0); + + MainLayout mainLayout(tp, library); + //LibraryLayout libraryLayout(library); int ch; timeout(IDLE_TIMEOUT_MS); diff --git a/src/musikbox/MainLayout.cpp b/src/musikbox/MainLayout.cpp index d36503f1b..9a777e2e5 100755 --- a/src/musikbox/MainLayout.cpp +++ b/src/musikbox/MainLayout.cpp @@ -4,6 +4,8 @@ #include "MainLayout.h" #include "Screen.h" +/* most top-level layouts are going to want this functionality. it +should probably live someplace shared. */ static inline IWindow* adjustFocus(IWindow* oldFocus, IWindow* newFocus) { if (oldFocus) { oldFocus->SetFrameColor(BOX_COLOR_WHITE_ON_BLACK); @@ -16,11 +18,11 @@ static inline IWindow* adjustFocus(IWindow* oldFocus, IWindow* newFocus) { return newFocus; } -MainLayout::MainLayout(Transport& transport) { +MainLayout::MainLayout(Transport& transport, LibraryPtr library) { this->logs.reset(new LogWindow()); this->output.reset(new OutputWindow()); this->resources.reset(new ResourcesWindow()); - this->commands.reset(new CommandWindow(transport, *this->output)); + this->commands.reset(new CommandWindow(transport, library, *this->output)); this->transport.reset(new TransportWindow(transport)); this->focusOrder.push_back(commands.get()); diff --git a/src/musikbox/MainLayout.h b/src/musikbox/MainLayout.h index 1c81740fa..5c5558851 100755 --- a/src/musikbox/MainLayout.h +++ b/src/musikbox/MainLayout.h @@ -16,7 +16,7 @@ using musik::core::audio::Transport; class MainLayout : public ILayout { public: - MainLayout(Transport& transport); + MainLayout(Transport& transport, LibraryPtr library); ~MainLayout(); virtual IWindow* FocusNext(); diff --git a/src/musikbox/ScrollAdapterBase.cpp b/src/musikbox/ScrollAdapterBase.cpp index 068fe6afd..4179e1a54 100755 --- a/src/musikbox/ScrollAdapterBase.cpp +++ b/src/musikbox/ScrollAdapterBase.cpp @@ -73,6 +73,7 @@ void ScrollAdapterBase::DrawPage(WINDOW* window, size_t index, ScrollPosition *r result->firstVisibleEntryIndex = 0; result->lineCount = 0; result->totalEntries = 0; + result->logicalIndex = 0; } wclear(window); @@ -85,6 +86,10 @@ void ScrollAdapterBase::DrawPage(WINDOW* window, size_t index, ScrollPosition *r index = GetEntryCount() - 1; } + /* unfortunately this needs to go here so the GetEntry() method knows + what the the implied focus is */ + result->logicalIndex = index; + std::deque visible; size_t topIndex; /* calculated by GetVisibleItems */ GetVisibleItems(index, visible, topIndex); @@ -121,5 +126,6 @@ void ScrollAdapterBase::DrawPage(WINDOW* window, size_t index, ScrollPosition *r result->firstVisibleEntryIndex = topIndex; result->lineCount = drawnLines; result->totalEntries = GetEntryCount(); + result->logicalIndex = index; } } \ No newline at end of file diff --git a/src/musikbox/ScrollableWindow.cpp b/src/musikbox/ScrollableWindow.cpp index efe9fec4e..eea2da13c 100755 --- a/src/musikbox/ScrollableWindow.cpp +++ b/src/musikbox/ScrollableWindow.cpp @@ -19,6 +19,10 @@ void ScrollableWindow::SetSize(int width, int height) { GetScrollAdapter().SetDisplaySize(GetContentWidth(), GetContentHeight()); } +IScrollAdapter::ScrollPosition ScrollableWindow::GetScrollPosition() { + return this->scrollPosition; +} + void ScrollableWindow::OnAdapterChanged() { IScrollAdapter *adapter = &GetScrollAdapter(); if (IsLastItemVisible()) { diff --git a/src/musikbox/ScrollableWindow.h b/src/musikbox/ScrollableWindow.h index b18997e6f..3fe029d41 100755 --- a/src/musikbox/ScrollableWindow.h +++ b/src/musikbox/ScrollableWindow.h @@ -23,6 +23,9 @@ class ScrollableWindow : public IScrollable, public Window { protected: virtual IScrollAdapter& GetScrollAdapter() = 0; + + IScrollAdapter::ScrollPosition GetScrollPosition(); + void OnAdapterChanged(); private: diff --git a/src/musikbox/SingleLineEntry.cpp b/src/musikbox/SingleLineEntry.cpp index fd9a979f1..34fc8abef 100755 --- a/src/musikbox/SingleLineEntry.cpp +++ b/src/musikbox/SingleLineEntry.cpp @@ -4,6 +4,7 @@ SingleLineEntry::SingleLineEntry(const std::string& value) { this->value = value; + this->attrs = -1; } size_t SingleLineEntry::GetIndex() { @@ -33,6 +34,7 @@ size_t SingleLineEntry::GetLineCount() { std::string SingleLineEntry::GetLine(size_t line) { return u8substr(this->value, 0, this->width > 0 ? this->width : 0); } + std::string SingleLineEntry::GetValue() { return this->value; } \ No newline at end of file diff --git a/src/musikbox/TrackListView.cpp b/src/musikbox/TrackListView.cpp new file mode 100755 index 000000000..fc0782b53 --- /dev/null +++ b/src/musikbox/TrackListView.cpp @@ -0,0 +1,13 @@ +#pragma once + +#include "stdafx.h" +#include "TrackListView.h" + +TrackListView::TrackListView() +: Window() { + +} + +TrackListView::~TrackListView() { + +} diff --git a/src/musikbox/TrackListView.h b/src/musikbox/TrackListView.h new file mode 100755 index 000000000..512ef7f72 --- /dev/null +++ b/src/musikbox/TrackListView.h @@ -0,0 +1,12 @@ +#pragma once + +#include "curses_config.h" +#include "Window.h" + +class TrackListView : public Window { + public: + TrackListView(); + ~TrackListView(); + + private: +}; \ No newline at end of file diff --git a/src/musikbox/musikbox.vcxproj b/src/musikbox/musikbox.vcxproj index ccb9e8a81..24889923b 100755 --- a/src/musikbox/musikbox.vcxproj +++ b/src/musikbox/musikbox.vcxproj @@ -123,6 +123,7 @@ + @@ -151,6 +152,7 @@ + diff --git a/src/musikbox/musikbox.vcxproj.filters b/src/musikbox/musikbox.vcxproj.filters index 2a5114842..758402690 100755 --- a/src/musikbox/musikbox.vcxproj.filters +++ b/src/musikbox/musikbox.vcxproj.filters @@ -63,6 +63,9 @@ curses + + view + @@ -132,6 +135,9 @@ curses + + view +