mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
More improvements to layouts and stuff. Need to figure out scroll focus
situation soon.
This commit is contained in:
parent
2de2a21291
commit
66c19c2123
@ -33,6 +33,7 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pch.hpp"
|
||||
#include <core/library/LibraryFactory.h>
|
||||
#include <core/library/LocalLibrary.h>
|
||||
|
@ -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;
|
||||
}
|
@ -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<Query> to smart_ptr<FooQuery>. */
|
||||
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;
|
||||
}
|
@ -1,21 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <sigslot/sigslot.h>
|
||||
|
||||
#include "ScrollableWindow.h"
|
||||
#include "SimpleScrollAdapter.h"
|
||||
#include "ScrollAdapterBase.h"
|
||||
|
||||
#include <core/library/IQuery.h>
|
||||
#include <core/library/ILibrary.h>
|
||||
|
||||
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<std::vector<std::string>> metadata;
|
||||
};
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
@ -2,10 +2,15 @@
|
||||
|
||||
#include "ILayout.h"
|
||||
#include "CategoryListView.h"
|
||||
#include "TrackListView.h"
|
||||
|
||||
#include <core/library/ILibrary.h>
|
||||
|
||||
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<CategoryListView> albumList;
|
||||
boost::shared_ptr<TrackListView> trackList;
|
||||
};
|
@ -48,6 +48,8 @@
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
|
||||
|
||||
#include <core/library/LibraryFactory.h>
|
||||
|
||||
#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);
|
||||
|
@ -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());
|
||||
|
@ -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();
|
||||
|
@ -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<EntryPtr> 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;
|
||||
}
|
||||
}
|
@ -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()) {
|
||||
|
@ -23,6 +23,9 @@ class ScrollableWindow : public IScrollable, public Window {
|
||||
|
||||
protected:
|
||||
virtual IScrollAdapter& GetScrollAdapter() = 0;
|
||||
|
||||
IScrollAdapter::ScrollPosition GetScrollPosition();
|
||||
|
||||
void OnAdapterChanged();
|
||||
|
||||
private:
|
||||
|
@ -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;
|
||||
}
|
13
src/musikbox/TrackListView.cpp
Executable file
13
src/musikbox/TrackListView.cpp
Executable file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TrackListView.h"
|
||||
|
||||
TrackListView::TrackListView()
|
||||
: Window() {
|
||||
|
||||
}
|
||||
|
||||
TrackListView::~TrackListView() {
|
||||
|
||||
}
|
12
src/musikbox/TrackListView.h
Executable file
12
src/musikbox/TrackListView.h
Executable file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "curses_config.h"
|
||||
#include "Window.h"
|
||||
|
||||
class TrackListView : public Window {
|
||||
public:
|
||||
TrackListView();
|
||||
~TrackListView();
|
||||
|
||||
private:
|
||||
};
|
@ -123,6 +123,7 @@
|
||||
<ClCompile Include="MultiLineEntry.cpp" />
|
||||
<ClCompile Include="ScrollableWindow.cpp" />
|
||||
<ClCompile Include="SingleLineEntry.cpp" />
|
||||
<ClCompile Include="TrackListView.cpp" />
|
||||
<ClCompile Include="Window.cpp" />
|
||||
<ClCompile Include="Colors.cpp" />
|
||||
<ClCompile Include="CommandWindow.cpp" />
|
||||
@ -151,6 +152,7 @@
|
||||
<ClInclude Include="MultiLineEntry.h" />
|
||||
<ClInclude Include="ScrollableWindow.h" />
|
||||
<ClInclude Include="SingleLineEntry.h" />
|
||||
<ClInclude Include="TrackListView.h" />
|
||||
<ClInclude Include="Window.h" />
|
||||
<ClInclude Include="Colors.h" />
|
||||
<ClInclude Include="CommandWindow.h" />
|
||||
|
@ -63,6 +63,9 @@
|
||||
<ClCompile Include="ScrollableWindow.cpp">
|
||||
<Filter>curses</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TrackListView.cpp">
|
||||
<Filter>view</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -132,6 +135,9 @@
|
||||
<ClInclude Include="ScrollableWindow.h">
|
||||
<Filter>curses</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TrackListView.h">
|
||||
<Filter>view</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="curses">
|
||||
|
Loading…
x
Reference in New Issue
Block a user