cursespp and musikbox are compiling! not running though.

This commit is contained in:
Casey Langen 2016-05-25 23:31:15 -07:00
parent e33f9928fb
commit d12eae819d
53 changed files with 290 additions and 225 deletions

View File

@ -48,10 +48,11 @@ set (musikbox_LINK_LIBS
include_directories (
"${musikbox_SOURCE_DIR}/src"
"${musikbox_SOURCE_DIR}/src/core"
"${musikbox_SOURCE_DIR}/src/musikbox"
"${musikbox_SOURCE_DIR}/src/3rdparty/include"
)
add_subdirectory(src/3rdparty)
add_subdirectory(src/core)
#add_subdirectory(src/contrib)
#add_subdirectory(src/musikbox)
add_subdirectory(src/musikbox)

View File

@ -1,20 +1,84 @@
set (SQUARE_SRCS
stdafx.cpp
player.cpp
DummyAudioEventHandler.cpp
ConsoleUI.cpp
set (BOX_SRCS
./Main.cpp
./stdafx.cpp
./app/layout/LibraryLayout.cpp
./app/layout/MainLayout.cpp
./app/query/CategoryListViewQuery.cpp
./app/query/SingleTrackQuery.cpp
./app/query/TrackListViewQuery.cpp
./app/service/PlaybackService.cpp
./app/util/GlobalHotkeys.cpp
./app/util/SystemInfo.cpp
./app/util/Text.cpp
./app/window/CategoryListView.cpp
./app/window/CommandWindow.cpp
./app/window/LogWindow.cpp
./app/window/OutputWindow.cpp
./app/window/ResourcesWindow.cpp
./app/window/TrackListView.cpp
./app/window/TransportWindow.cpp
./cursespp/Colors.cpp
./cursespp/LayoutBase.cpp
./cursespp/LayoutStack.cpp
./cursespp/ListWindow.cpp
./cursespp/Message.cpp
./cursespp/MessageQueue.cpp
./cursespp/MultiLineEntry.cpp
./cursespp/Screen.cpp
./cursespp/ScrollableWindow.cpp
./cursespp/ScrollAdapterBase.cpp
./cursespp/SimpleScrollAdapter.cpp
./cursespp/SingleLineEntry.cpp
./cursespp/Window.cpp
./cursespp/WindowLayout.cpp
)
set (SQUARE_HEADERS
config.h
ConsoleUI.h
DummyAudioEventHandler.h
memtrace.h
stdafx.h
set (BOX_HEADERS
./stdafx.h
./app/layout/LibraryLayout.h
./app/layout/MainLayout.h
./app/query/CategoryListViewQuery.h
./app/query/SingleTrackQuery.h
./app/query/TrackListViewQuery.h
./app/service/PlaybackService.h
./app/util/GlobalHotkeys.h
./app/util/SystemInfo.h
./app/util/Text.h
./app/window/CategoryListView.h
./app/window/CommandWindow.h
./app/window/LogWindow.h
./app/window/OutputWindow.h
./app/window/ResourcesWindow.h
./app/window/TrackListView.h
./app/window/TransportWindow.h
./cursespp/Colors.h
./cursespp/curses_config.h
./cursespp/IDisplayable.h
./cursespp/IInput.h
./cursespp/IKeyHandler.h
./cursespp/ILayout.h
./cursespp/ILayoutStack.h
./cursespp/IMessage.h
./cursespp/IMessageTarget.h
./cursespp/IOrderable.h
./cursespp/IScrollable.h
./cursespp/IScrollAdapter.h
./cursespp/IWindow.h
./cursespp/IWindowGroup.h
./cursespp/LayoutBase.h
./cursespp/LayoutStack.h
./cursespp/ListWindow.h
./cursespp/Message.h
./cursespp/MessageQueue.h
./cursespp/MultiLineEntry.h
./cursespp/Screen.h
./cursespp/ScrollableWindow.h
./cursespp/ScrollAdapterBase.h
./cursespp/SimpleScrollAdapter.h
./cursespp/SingleLineEntry.h
./cursespp/Window.h
./cursespp/WindowLayout.h
)
SOURCE_GROUP ("Source Files" FILES ${SQUARE_SRCS})
SOURCE_GROUP ("Header Files" FILES ${SQUARE_HEADERS})
add_executable(square ${SQUARE_SRCS} ${SQUARE_HEADERS})
target_link_libraries(square ${musikCube_LINK_LIBS} musik)
add_executable(musikbox ${BOX_SRCS} ${BOX_HEADERS})
target_link_libraries(musikbox ${musikbox_LINK_LIBS} curses panel musikcore)

View File

@ -3,31 +3,31 @@
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
@ -95,7 +95,7 @@ static void changeLayout(WindowState& current, ILayoutPtr newLayout) {
if (current.layout) {
current.layout->Hide();
current.layout = { 0 };
current.layout.reset();
}
if (newLayout) {
@ -149,7 +149,7 @@ int main(int argc, char* argv[])
std::locale locale = std::locale();
std::locale utf8Locale(locale, new boost::filesystem::detail::utf8_codecvt_facet);
boost::filesystem::path::imbue(utf8Locale);
musik::debug::init();
ttytype[0] = 30; /* min height */
@ -184,14 +184,17 @@ int main(int argc, char* argv[])
GlobalHotkeys globalHotkeys(playback, library);
ILayoutPtr libraryLayout(new LibraryLayout(playback, library));
ILayoutPtr consoleLayout(new MainLayout(tp, library));
ILayoutPtr libraryLayout((ILayout *) new LibraryLayout(playback, library));
ILayoutPtr consoleLayout((ILayout *) new MainLayout(tp, library));
int64 ch;
timeout(IDLE_TIMEOUT_MS);
bool quit = false;
WindowState state = { 0 };
WindowState state;
state.input = NULL;
state.keyHandler = NULL;
changeLayout(state, libraryLayout);
while (!quit) {
@ -249,4 +252,3 @@ int main(int argc, char* argv[])
return 0;
}

View File

@ -136,4 +136,4 @@ bool LibraryLayout::KeyPress(int64 ch) {
}
return LayoutBase::KeyPress(ch);
}
}

View File

@ -17,16 +17,16 @@ namespace musik {
class LibraryLayout : public cursespp::LayoutBase, public sigslot::has_slots<> {
public:
LibraryLayout(
PlaybackService& playback,
PlaybackService& playback,
musik::core::LibraryPtr library);
virtual ~LibraryLayout();
virtual void Layout();
virtual void Show();
virtual bool LibraryLayout::KeyPress(int64 ch);
virtual cursespp::IWindowPtr GetFocus();
virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(int64 ch);
private:
void InitializeWindows();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "MainLayout.h"
#include <cursespp/Screen.h>
@ -73,4 +71,4 @@ void MainLayout::ProcessMessage(IMessage &message) {
void MainLayout::UpdateWindows() {
this->logs->Update();
this->resources->Update();
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "CategoryListViewQuery.h"
@ -17,7 +15,7 @@ using namespace musik::core::db;
using namespace musik::core::library::constants;
using namespace musik::box;
#define reset(x) x.reset(new std::vector<std::shared_ptr<Result>>);
#define reset(x) x.reset(new std::vector<std::shared_ptr<Result> >);
static const std::string ALBUM_QUERY =
"SELECT DISTINCT albums.id, albums.name "
@ -41,9 +39,9 @@ static boost::mutex QUERY_MAP_MUTEX;
static std::map<std::string, std::string> FIELD_TO_QUERY_MAP;
static void initFieldToQueryMap() {
FIELD_TO_QUERY_MAP.emplace(Track::ALBUM_ID, ALBUM_QUERY);
FIELD_TO_QUERY_MAP.emplace(Track::ARTIST_ID, ARTIST_QUERY);
FIELD_TO_QUERY_MAP.emplace(Track::GENRE_ID, GENRE_QUERY);
FIELD_TO_QUERY_MAP[Track::ALBUM_ID] = ALBUM_QUERY;
FIELD_TO_QUERY_MAP[Track::ARTIST_ID] = ARTIST_QUERY;
FIELD_TO_QUERY_MAP[Track::GENRE_ID] = GENRE_QUERY;
}
CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) {
@ -77,7 +75,7 @@ bool CategoryListViewQuery::OnRun(Connection& db) {
std::string query = FIELD_TO_QUERY_MAP[this->trackField];
Statement stmt(query.c_str(), db);
while (stmt.Step() == Row) {
std::shared_ptr<Result> row(new Result());
row->id = stmt.ColumnInt64(0);
@ -86,4 +84,4 @@ bool CategoryListViewQuery::OnRun(Connection& db) {
}
return true;
}
}

View File

@ -14,7 +14,7 @@ namespace musik {
};
typedef std::shared_ptr<std::vector<
std::shared_ptr<Result>>> ResultList;
std::shared_ptr<Result> > > ResultList;
CategoryListViewQuery(const std::string& trackField);
virtual ~CategoryListViewQuery();
@ -30,4 +30,4 @@ namespace musik {
ResultList result;
};
}
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "SingleTrackQuery.h"
@ -32,4 +30,4 @@ bool SingleTrackQuery::OnRun(Connection& db) {
result.reset(new LibraryTrack());
result->SetValue("filename", filename.c_str());
return LibraryTrack::Load(result.get(), db);
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "TrackListViewQuery.h"
@ -66,4 +64,4 @@ bool TrackListViewQuery::OnRun(Connection& db) {
}
return true;
}
}

View File

@ -10,10 +10,10 @@ namespace musik {
class TrackListViewQuery : public musik::core::query::QueryBase {
public:
typedef std::shared_ptr<
std::vector<musik::core::TrackPtr>> Result;
std::vector<musik::core::TrackPtr> > Result;
TrackListViewQuery(
musik::core::LibraryPtr library,
musik::core::LibraryPtr library,
const std::string& column, DBID id);
virtual ~TrackListViewQuery();

View File

@ -2,13 +2,14 @@
#include "SystemInfo.h"
using namespace musik::box;
#ifdef WIN32
#include "windows.h"
#include "psapi.h"
#include "pdh.h"
using namespace musik::box;
#ifdef WIN32
class WindowsSystemInfo : public SystemInfo {
public:
WindowsSystemInfo();
@ -125,15 +126,15 @@ double WindowsSystemInfo::GetCpuUsage() {
FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user;
double percent;
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
percent =
percent =
(double) (sys.QuadPart - lastSysCpu.QuadPart) +
(double) (user.QuadPart - lastUserCpu.QuadPart);
@ -142,11 +143,11 @@ double WindowsSystemInfo::GetCpuUsage() {
percent /= diff;
percent /= processorCount;
lastCpu = now;
lastUserCpu = user;
lastSysCpu = sys;
return (percent * 100.0f);
}
#endif
#endif

View File

@ -16,12 +16,13 @@ namespace musik {
size_t c = 0;
while (c < len && it != str.end()) {
try {
utf8::next(it++, end);
utf8::next(it, end);
}
catch (...) {
it++; /* invalid encoding, just treat as a single char */
/* invalid encoding, just treat as a single char */
}
++it;
++c;
}
@ -52,4 +53,4 @@ namespace musik {
}
}
}
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include <cursespp/Colors.h>
@ -84,7 +82,7 @@ IScrollAdapter& CategoryListView::GetScrollAdapter() {
return *adapter;
}
CategoryListView::Adapter::Adapter(CategoryListView &parent)
CategoryListView::Adapter::Adapter(CategoryListView &parent)
: parent(parent) {
}
@ -100,4 +98,4 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) {
IScrollAdapter::EntryPtr entry(new SingleLineEntry(value));
entry->SetAttrs(attrs);
return entry;
}
}

View File

@ -20,7 +20,11 @@ using cursespp::ScrollAdapterBase;
namespace musik {
namespace box {
class CategoryListView : public ListWindow, public sigslot::has_slots<> {
class CategoryListView :
public ListWindow,
public std::enable_shared_from_this<CategoryListView>,
public sigslot::has_slots<>
{
public:
CategoryListView(LibraryPtr library, const std::string& fieldName);
virtual ~CategoryListView();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include <cursespp/Screen.h>
@ -41,8 +39,8 @@ bool tostr(T& t, const std::string& s) {
CommandWindow::CommandWindow(
IWindow *parent,
Transport& transport,
LibraryPtr library,
OutputWindow& output)
LibraryPtr library,
OutputWindow& output)
: Window(parent) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->transport = &transport;
@ -232,7 +230,7 @@ void CommandWindow::ListPlugins() const {
using musik::core::IPlugin;
using musik::core::PluginFactory;
typedef std::vector<std::shared_ptr<IPlugin>> PluginList;
typedef std::vector<std::shared_ptr<IPlugin> > PluginList;
typedef PluginFactory::NullDeleter<IPlugin> Deleter;
PluginList plugins = PluginFactory::Instance()
@ -248,4 +246,4 @@ void CommandWindow::ListPlugins() const {
this->output->WriteLine(format, BOX_COLOR_RED_ON_BLUE);
}
}
}

View File

@ -9,10 +9,11 @@
namespace musik {
namespace box {
class CommandWindow :
public cursespp::Window,
public cursespp::IInput,
public sigslot::has_slots<>
class CommandWindow :
public cursespp::Window,
public cursespp::IInput,
public std::enable_shared_from_this<CommandWindow>,
public sigslot::has_slots<>
{
public:
CommandWindow(
@ -21,7 +22,7 @@ namespace musik {
musik::core::LibraryPtr library,
OutputWindow& output);
~CommandWindow();
virtual ~CommandWindow();
virtual void WriteChar(int64 ch);
virtual void Focus();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "LogWindow.h"
@ -13,7 +11,7 @@ using namespace cursespp;
typedef IScrollAdapter::IEntry IEntry;
LogWindow::LogWindow(IWindow *parent)
LogWindow::LogWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLUE);
@ -81,4 +79,4 @@ void LogWindow::OnLogged( /* from a background thread */
entry->tag = tag;
entry->message = message;
pending.push_back(entry);
}
}

View File

@ -11,10 +11,14 @@
namespace musik {
namespace box {
class LogWindow : public cursespp::ScrollableWindow, public sigslot::has_slots<> {
class LogWindow :
public cursespp::ScrollableWindow,
public std::enable_shared_from_this<LogWindow>,
public sigslot::has_slots<>
{
public:
LogWindow(cursespp::IWindow *parent = NULL);
~LogWindow();
virtual ~LogWindow();
void Update();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "OutputWindow.h"
@ -13,7 +11,7 @@ using namespace cursespp;
typedef IScrollAdapter::EntryPtr EntryPtr;
OutputWindow::OutputWindow(IWindow *parent)
OutputWindow::OutputWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->SetContentColor(BOX_COLOR_BLACK_ON_GREY);
this->adapter = new SimpleScrollAdapter();
@ -32,4 +30,4 @@ IScrollAdapter& OutputWindow::GetScrollAdapter() {
void OutputWindow::WriteLine(const std::string& text, int64 attrs) {
this->adapter->AddEntry(EntryPtr(new MultiLineEntry(text, attrs)));
this->OnAdapterChanged();
}
}

View File

@ -7,16 +7,19 @@
namespace musik {
namespace box {
class OutputWindow : public cursespp::ScrollableWindow {
public:
OutputWindow(cursespp::IWindow *parent = NULL);
~OutputWindow();
class OutputWindow :
public cursespp::ScrollableWindow,
public std::enable_shared_from_this<OutputWindow>
{
public:
OutputWindow(cursespp::IWindow *parent = NULL);
virtual ~OutputWindow();
void WriteLine(const std::string& line, int64 attrs = -1);
virtual cursespp::IScrollAdapter& GetScrollAdapter();
void WriteLine(const std::string& line, int64 attrs = -1);
virtual cursespp::IScrollAdapter& GetScrollAdapter();
private:
cursespp::SimpleScrollAdapter* adapter;
private:
cursespp::SimpleScrollAdapter* adapter;
};
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "ResourcesWindow.h"
@ -16,7 +14,7 @@ using namespace cursespp;
#define BYTES_PER_MEGABYTE 1048576.0f
ResourcesWindow::ResourcesWindow(IWindow *parent)
ResourcesWindow::ResourcesWindow(IWindow *parent)
: Window(parent) {
this->systemInfo = SystemInfo::Create();
}
@ -33,11 +31,11 @@ void ResourcesWindow::Update() {
double cpuUsage = (double) systemInfo->GetCpuUsage();
wprintw(
this->GetContent(),
"cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)",
this->GetContent(),
"cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)",
cpuUsage,
virtualMemoryUsed,
physicalMemoryUsed);
this->Repaint();
}
}

View File

@ -7,7 +7,10 @@
namespace musik {
namespace box {
class ResourcesWindow : public cursespp::Window {
class ResourcesWindow :
public cursespp::Window,
public std::enable_shared_from_this<ResourcesWindow>
{
public:
ResourcesWindow(cursespp::IWindow *parent = NULL);
virtual ~ResourcesWindow();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include <cursespp/Colors.h>
@ -132,7 +130,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
duration = text::Duration(duration);
std::string text = boost::str(
boost::format("%s %s %s %s %s")
boost::format("%s %s %s %s %s")
% group(setw(column0Width), setfill(' '), trackNum)
% group(setw(column1Width), setiosflags(std::ios::left), setfill(' '), title)
% group(setw(column2Width), setiosflags(std::ios::right), setfill(' '), duration)
@ -144,4 +142,4 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
entry->SetAttrs(attrs);
return entry;
}
}

View File

@ -13,13 +13,17 @@
namespace musik {
namespace box {
class TrackListView : public cursespp::ListWindow, public sigslot::has_slots<> {
class TrackListView :
public cursespp::ListWindow,
public std::enable_shared_from_this<TrackListView>,
public sigslot::has_slots<>
{
public:
TrackListView(
PlaybackService& playback,
PlaybackService& playback,
musik::core::LibraryPtr library);
~TrackListView();
virtual ~TrackListView();
virtual void ProcessMessage(cursespp::IMessage &message);
virtual bool KeyPress(int64 ch);
@ -44,7 +48,7 @@ namespace musik {
private:
std::shared_ptr<TrackListViewQuery> query;
std::shared_ptr<std::vector<TrackPtr>> metadata;
std::shared_ptr<std::vector<TrackPtr> > metadata;
Adapter* adapter;
PlaybackService& playback;
musik::core::LibraryPtr library;

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h"
#include "TransportWindow.h"
@ -18,6 +16,8 @@
#include <boost/algorithm/string.hpp>
#include <boost/chrono.hpp>
#include <algorithm>
using namespace musik::core;
using namespace musik::core::audio;
using namespace musik::core::library;
@ -56,9 +56,9 @@ void TransportWindow::Show() {
}
void TransportWindow::ProcessMessage(IMessage &message) {
int type = message.Type();
if (type == REFRESH_TRANSPORT_READOUT) {
int type = message.Type();
if (type == REFRESH_TRANSPORT_READOUT) {
this->Update();
DEBOUNCE_REFRESH(REFRESH_INTERVAL_MS)
}
@ -102,19 +102,19 @@ void TransportWindow::Update() {
WINDOW *c = this->GetContent();
bool paused = (transport->GetPlaybackState() == Transport::PlaybackPaused);
int64 gb = COLOR_PAIR(this->focused
? BOX_COLOR_RED_ON_BLACK
int64 gb = COLOR_PAIR(this->focused
? BOX_COLOR_RED_ON_BLACK
: BOX_COLOR_GREEN_ON_BLACK);
/* playing SONG TITLE from ALBUM NAME */
std::string duration = "0";
if (transport->GetPlaybackState() == Transport::PlaybackStopped) {
if (transport->GetPlaybackState() == Transport::PlaybackStopped) {
wattron(c, gb);
wprintw(c, "playback is stopped");
wattroff(c, gb);
}
}
else {
std::string title, album;
@ -144,9 +144,9 @@ void TransportWindow::Update() {
/* volume slider */
wprintw(c, "\n");
int volumePercent = (size_t) round(this->transport->Volume() * 100.0f) - 1;
int thumbOffset = min(9, (volumePercent * 10) / 100);
int thumbOffset = std::min(9, (volumePercent * 10) / 100);
std::string volume = "vol ";
@ -190,7 +190,7 @@ void TransportWindow::Update() {
if (secondsTotal) {
size_t progress = (secondsCurrent * 100) / secondsTotal;
thumbOffset = min(timerWidth - 1, (progress * timerWidth) / 100);
thumbOffset = std::min(timerWidth - 1, (progress * timerWidth) / 100);
}
std::string timerTrack = "";
@ -202,9 +202,9 @@ void TransportWindow::Update() {
wprintw(c, currentTime.c_str());
wattroff(c, timerAttrs);
wprintw(c, " %s %s",
timerTrack.c_str(),
wprintw(c, " %s %s",
timerTrack.c_str(),
totalTime.c_str());
this->Repaint();
}
}

View File

@ -10,10 +10,14 @@
namespace musik {
namespace box {
class TransportWindow : public cursespp::Window, public sigslot::has_slots<> {
class TransportWindow :
public cursespp::Window,
public std::enable_shared_from_this<TransportWindow>,
public sigslot::has_slots<>
{
public:
TransportWindow(
musik::core::LibraryPtr library,
musik::core::LibraryPtr library,
musik::core::audio::Transport& transport);
~TransportWindow();

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h>
#include "Colors.h"
@ -20,4 +18,4 @@ void Colors::Init() {
init_pair(BOX_COLOR_RED_ON_GREY, COLOR_RED, COLOR_WHITE);
init_pair(BOX_COLOR_GREEN_ON_BLACK, COLOR_GREEN, COLOR_BLACK);
init_pair(BOX_COLOR_BLACK_ON_BLACK, COLOR_BLACK, COLOR_BLACK);
}
}

View File

@ -3,9 +3,8 @@
namespace cursespp {
class IDisplayable {
public:
virtual ~IDisplayable() = 0 { }
virtual ~IDisplayable() { }
virtual void Show() = 0;
virtual void Hide() = 0;
};
}

View File

@ -5,7 +5,7 @@
namespace cursespp {
class IInput {
public:
virtual ~IInput() = 0 { }
virtual ~IInput() { }
virtual void WriteChar(int64 ch) = 0;
};
}
}

View File

@ -5,7 +5,7 @@
namespace cursespp {
class IKeyHandler {
public:
virtual ~IKeyHandler() = 0 { }
virtual ~IKeyHandler() { }
virtual bool KeyPress(int64 ch) = 0;
};
}
}

View File

@ -10,7 +10,7 @@ namespace cursespp {
class ILayout : public IWindowGroup, public IKeyHandler, public IOrderable, public IDisplayable {
public:
virtual ~ILayout() = 0 { }
virtual ~ILayout() { }
virtual IWindowPtr FocusNext() = 0;
virtual IWindowPtr FocusPrev() = 0;
virtual IWindowPtr GetFocus() = 0;
@ -20,4 +20,4 @@ namespace cursespp {
};
typedef std::shared_ptr<ILayout> ILayoutPtr;
}
}

View File

@ -6,10 +6,10 @@
namespace cursespp {
class ILayoutStack {
public:
virtual ~ILayoutStack() = 0 { }
virtual ~ILayoutStack() { }
virtual bool Push(ILayoutPtr layout) = 0;
virtual bool Pop(ILayoutPtr layout) = 0;
virtual bool BringToTop(ILayoutPtr layout) = 0;
virtual bool SendToBottom(ILayoutPtr layout) = 0;
};
}
}

View File

@ -9,7 +9,7 @@ namespace cursespp {
class IMessage {
public:
virtual ~IMessage() = 0 { }
virtual ~IMessage() { }
virtual IMessageTarget* Target() = 0;
virtual int Type() = 0;
virtual int64 UserData1() = 0;
@ -17,4 +17,4 @@ namespace cursespp {
};
typedef std::shared_ptr<IMessage> IMessagePtr;
}
}

View File

@ -5,7 +5,8 @@
namespace cursespp {
class IMessageTarget {
public:
virtual ~IMessageTarget() { }
virtual bool IsAcceptingMessages() = 0;
virtual void ProcessMessage(IMessage &message) = 0;
};
}
}

View File

@ -3,8 +3,8 @@
namespace cursespp {
class IOrderable {
public:
virtual ~IOrderable() = 0 { }
virtual ~IOrderable() { }
virtual void BringToTop() = 0;
virtual void SendToBottom() = 0;
};
}
}

View File

@ -5,7 +5,7 @@
namespace cursespp {
class IScrollAdapter {
public:
virtual ~IScrollAdapter() = 0 { }
virtual ~IScrollAdapter() { }
struct ScrollPosition {
ScrollPosition() {
@ -25,7 +25,7 @@ namespace cursespp {
class IEntry {
public:
virtual ~IEntry() = 0 { }
virtual ~IEntry() { }
virtual size_t GetLineCount() = 0;
virtual std::string GetLine(size_t line) = 0;
virtual std::string GetValue() = 0;
@ -42,4 +42,3 @@ namespace cursespp {
virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) = 0;
};
}

View File

@ -3,7 +3,7 @@
namespace cursespp {
class IScrollable {
public:
virtual ~IScrollable() = 0 { }
virtual ~IScrollable() { }
virtual void ScrollToTop() = 0;
virtual void ScrollToBottom() = 0;
virtual void ScrollUp(int delta = 1) = 0;
@ -11,4 +11,4 @@ namespace cursespp {
virtual void PageUp() = 0;
virtual void PageDown() = 0;
};
}
}

View File

@ -10,7 +10,7 @@ namespace cursespp {
class IWindow : public IOrderable, public IDisplayable, public IMessageTarget {
public:
virtual ~IWindow() = 0 { }
virtual ~IWindow() { }
virtual void Repaint() = 0;
virtual void SetParent(IWindow* parent) = 0;
virtual void Show() = 0;
@ -35,4 +35,4 @@ namespace cursespp {
};
typedef std::shared_ptr<IWindow> IWindowPtr;
}
}

View File

@ -5,10 +5,10 @@
namespace cursespp {
class IWindowGroup {
public:
virtual ~IWindowGroup() = 0 { }
virtual ~IWindowGroup() { }
virtual bool AddWindow(IWindowPtr window) = 0;
virtual bool RemoveWindow(IWindowPtr window) = 0;
virtual size_t GetWindowCount() = 0;
virtual IWindowPtr GetWindowAt(size_t position) = 0;
};
}
}

View File

@ -7,7 +7,7 @@ using namespace cursespp;
template <typename T> static int find(std::vector<T>& haystack, T& needle) {
int i = 0;
std::vector<T>::iterator it = haystack.begin();
typename std::vector<T>::iterator it = haystack.begin();
for (; it != haystack.end(); it++, i++) {
if ((*it) == needle) {
return i;
@ -42,7 +42,7 @@ static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
return newFocus;
}
LayoutBase::LayoutBase(IWindow* parent)
LayoutBase::LayoutBase(IWindow* parent)
: Window(parent) {
this->focused = -1;
this->layoutStack = 0;
@ -229,4 +229,4 @@ ILayoutStack* LayoutBase::GetLayoutStack() {
void LayoutBase::SetLayoutStack(ILayoutStack* stack) {
this->layoutStack = stack;
}
}

View File

@ -50,4 +50,4 @@ namespace cursespp {
std::vector<IWindowPtr> focusable;
int focused;
};
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h>
#include "LayoutStack.h"
@ -40,19 +38,19 @@ static inline bool erase(std::deque<ILayoutPtr>& group, ILayoutPtr ptr) {
}
bool LayoutStack::AddWindow(IWindowPtr window) {
throw std::exception("AddWindow() not supported in LayoutStack. Use Push()");
throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()");
}
bool LayoutStack::RemoveWindow(IWindowPtr window) {
throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()");
throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()");
}
size_t LayoutStack::GetWindowCount() {
throw std::exception("GetWindowCount() not supported in LayoutStack.");
throw std::runtime_error("GetWindowCount() not supported in LayoutStack.");
}
IWindowPtr LayoutStack::GetWindowAt(size_t position) {
throw std::exception("GetWindowAt() not supported in LayoutStack.");
throw std::runtime_error("GetWindowAt() not supported in LayoutStack.");
}
ILayoutStack* LayoutStack::GetLayoutStack() {

View File

@ -1,4 +1,5 @@
#include <stdafx.h>
#include <algorithm>
#include "ListWindow.h"
using namespace cursespp;
@ -7,7 +8,7 @@ typedef IScrollAdapter::ScrollPosition ScrollPos;
size_t ListWindow::NO_SELECTION = (size_t) -1;
ListWindow::ListWindow(IWindow *parent)
ListWindow::ListWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->selectedIndex = (size_t) -1;
}
@ -24,15 +25,15 @@ void ListWindow::ScrollToTop() {
void ListWindow::ScrollToBottom() {
IScrollAdapter& adapter = this->GetScrollAdapter();
this->SetSelectedIndex(max(0, adapter.GetEntryCount() - 1));
this->SetSelectedIndex(std::max(0UL, adapter.GetEntryCount() - 1));
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
this->Repaint();
}
void ListWindow::Focus() {
GetScrollAdapter().DrawPage(
this->GetContent(),
this->scrollPosition.firstVisibleEntryIndex,
this->GetContent(),
this->scrollPosition.firstVisibleEntryIndex,
&this->scrollPosition);
}
@ -46,13 +47,13 @@ void ListWindow::ScrollUp(int delta) {
int minIndex = 0;
int newIndex = this->selectedIndex - delta;
newIndex = max(newIndex, minIndex);
newIndex = std::max(newIndex, minIndex);
if (newIndex < (int) first + 1) {
drawIndex = newIndex - 1;
}
drawIndex = max(0, drawIndex);
drawIndex = std::max(0, drawIndex);
this->SetSelectedIndex(newIndex);
@ -75,7 +76,7 @@ void ListWindow::ScrollDown(int delta) {
size_t maxIndex = adapter.GetEntryCount() - 1;
size_t newIndex = this->selectedIndex + delta;
newIndex = min(newIndex, maxIndex);
newIndex = std::min(newIndex, maxIndex);
if (newIndex >= last - 1) {
drawIndex = drawIndex + delta;
@ -92,7 +93,7 @@ void ListWindow::PageUp() {
IScrollAdapter &adapter = this->GetScrollAdapter();
ScrollPos spos = this->GetScrollPosition();
int target = (int) this->GetPreviousPageEntryIndex();
/* if the target position is zero, let it be so the user can see
the top of the list. otherwise, scroll down by one to give indication
there is more to see. */
@ -112,7 +113,7 @@ void ListWindow::PageDown() {
ScrollPos spos = this->GetScrollPosition();
size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1;
this->SetSelectedIndex(min(adapter.GetEntryCount() - 1, lastVisible + 1));
this->SetSelectedIndex(std::min(adapter.GetEntryCount() - 1, lastVisible + 1));
adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition);
this->Repaint();
@ -160,4 +161,4 @@ void ListWindow::OnAdapterChanged() {
IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() {
return this->scrollPosition;
}
}

View File

@ -1,4 +1,5 @@
#include <stdafx.h>
#include <algorithm>
#include "MessageQueue.h"
using namespace boost::chrono;
@ -81,7 +82,7 @@ void MessageQueue::Remove(IMessageTarget *target, int type) {
void MessageQueue::Post(IMessagePtr message, int64 delayMs) {
boost::recursive_mutex::scoped_lock lock(this->queueMutex);
delayMs = max(0, delayMs);
delayMs = std::max(0LL, delayMs);
milliseconds now = duration_cast<milliseconds>(
system_clock::now().time_since_epoch());

View File

@ -1,6 +1,8 @@
#include <stdafx.h>
#include "MultiLineEntry.h"
#include <math.h>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include "MultiLineEntry.h"
using namespace cursespp;
@ -12,7 +14,7 @@ MultiLineEntry::MultiLineEntry(const std::string& value, int64 attrs) {
}
size_t MultiLineEntry::GetLineCount() {
return max(1, this->lines.size());
return std::max(1UL, this->lines.size());
}
std::string MultiLineEntry::GetLine(size_t n) {

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h>
#include "Screen.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdafx.h>
#include <algorithm>
#include "ScrollableWindow.h"
#include "Screen.h"
#include "Colors.h"
@ -52,8 +52,8 @@ void ScrollableWindow::OnAdapterChanged() {
ScrollPos &pos = this->GetScrollPosition();
adapter->DrawPage(
this->GetContent(),
pos.firstVisibleEntryIndex,
this->GetContent(),
pos.firstVisibleEntryIndex,
&pos);
this->Repaint();
@ -72,7 +72,7 @@ void ScrollableWindow::ScrollToTop() {
void ScrollableWindow::ScrollToBottom() {
GetScrollAdapter().DrawPage(
this->GetContent(),
this->GetContent(),
GetScrollAdapter().GetEntryCount(),
&this->GetScrollPosition());
@ -122,7 +122,7 @@ size_t ScrollableWindow::GetPreviousPageEntryIndex() {
remaining -= count;
}
return max(0, i);
return std::max(0, i);
}
void ScrollableWindow::PageUp() {
@ -144,4 +144,4 @@ bool ScrollableWindow::IsLastItemVisible() {
size_t firstVisible = pos.firstVisibleEntryIndex;
size_t lastVisible = firstVisible + pos.visibleEntryCount;
return lastIndex >= firstVisible && lastIndex <= lastVisible;
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h>
#include "Window.h"
#include "IWindowGroup.h"
@ -45,7 +43,7 @@ int Window::GetId() const {
}
void Window::ProcessMessage(IMessage &message) {
}
bool Window::IsAcceptingMessages() {
@ -79,9 +77,9 @@ void Window::SendToBottom() {
void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay) {
MessageQueue::Instance().Post(
Message::Create(
this,
messageType,
user1,
this,
messageType,
user1,
user2),
delay);
}
@ -215,14 +213,14 @@ void Window::Create() {
this->frame = (this->parent == NULL)
? newwin(
this->height,
this->width,
this->y,
this->height,
this->width,
this->y,
this->x)
: newwin(
this->height,
this->width,
this->parent->GetY() + this->y,
this->height,
this->width,
this->parent->GetY() + this->y,
this->parent->GetX() + this->x);
this->framePanel = new_panel(this->frame);

View File

@ -71,4 +71,4 @@ namespace cursespp {
int64 contentColor, frameColor;
int width, height, x, y;
};
}
}

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h>
#include "WindowLayout.h"
#include "LayoutStack.h"
@ -15,19 +13,19 @@ WindowLayout::~WindowLayout() {
}
bool WindowLayout::AddWindow(IWindowPtr window) {
throw std::exception("AddWindow() not supported in LayoutStack. Use Push()");
throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()");
}
bool WindowLayout::RemoveWindow(IWindowPtr window) {
throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()");
throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()");
}
size_t WindowLayout::GetWindowCount() {
throw std::exception("GetWindowCount() not supported in LayoutStack.");
throw std::runtime_error("GetWindowCount() not supported in LayoutStack.");
}
IWindowPtr WindowLayout::GetWindowAt(size_t position) {
throw std::exception("GetWindowAt() not supported in LayoutStack.");
throw std::runtime_error("GetWindowAt() not supported in LayoutStack.");
}
void WindowLayout::Show() {
@ -71,4 +69,4 @@ ILayoutStack* WindowLayout::GetLayoutStack() {
void WindowLayout::SetLayoutStack(ILayoutStack* stack) {
this->stack = stack;
}
}