Tab selection and some other minor bug fixes.

This commit is contained in:
casey 2016-05-08 02:56:05 -07:00
parent e3af440479
commit 2fe495cb2b
10 changed files with 82 additions and 52 deletions

View File

@ -85,7 +85,12 @@ static int getTrackNumber(const char* uri) {
if (lastDot != std::string::npos) {
/* always in the format F:\Track01.cda */
std::string number = filename.substr(lastDot - 2, 2);
return stoi(number);
try {
return stoi(number);
}
catch (...) {
return 1;
}
}
return 1;

View File

@ -54,6 +54,8 @@ Player::Player(std::string &url, OutputPtr *output)
, currentPosition(0)
, setPosition(-1)
{
musik::debug::info(TAG, "new instance created");
if (*output) {
this->output = *output;
}
@ -65,6 +67,7 @@ Player::Player(std::string &url, OutputPtr *output)
IOutput, musik::core::PluginFactory::DestroyDeleter<IOutput>>("GetAudioOutput");
if (!outputs.empty()) {
musik::debug::info(TAG, "found an IOutput device!");
this->output = outputs.front();
}
}

View File

@ -64,23 +64,22 @@ void Transport::PrepareNextTrack(std::string trackUrl){
}
void Transport::Start(std::string url){
musik::debug::info(TAG, "start");
musik::debug::info(TAG, "we were asked to start the track at " + url);
// Check if this is already Prepared
PlayerPtr player = this->nextPlayer;
this->nextPlayer.reset();
musik::debug::info(TAG, "next player reset");
musik::debug::info(TAG, "creating a Player...");
// If the nextPlayer wasn't the same as the one started, lets create a new one
if(!player || player->url!=url){
if(!player || player->url != url){
Player::OutputPtr output;
musik::debug::info(TAG, "created output device");
player = Player::Create(url, &output);
player->SetVolume(this->volume);
musik::debug::info(TAG, "created player");
musik::debug::info(TAG, "Player created successfully");
}
// Add to the players

View File

@ -40,8 +40,7 @@ CommandWindow::CommandWindow(Transport& transport, OutputWindow& output) {
this->output = &output;
this->paused = false;
this->ListPlugins();
this->ListPlugins();
this->output->WriteLine("hello! type 'h' or 'help'");
}
CommandWindow::~CommandWindow() {
@ -105,7 +104,7 @@ void CommandWindow::SetVolume(float volume) {
}
void CommandWindow::Help() {
this->output->WriteLine("\n\nhelp:");
this->output->WriteLine("\nhelp:");
this->output->WriteLine(" pl [file]: play file at path");
this->output->WriteLine(" pa: toggle pause/resume");
this->output->WriteLine(" st: stop playing");

View File

@ -10,7 +10,9 @@ LogWindow::LogWindow() {
this->SetColor(BOX_COLOR_WHITE_ON_BLUE);
this->SetSize(Screen::GetWidth() / 2, Screen::GetHeight());
this->SetPosition(Screen::GetWidth() / 2, 0);
this->SetScrollable(true);
this->adapter = new SimpleScrollAdapter();
this->adapter->SetDisplaySize(this->GetContentWidth(), this->GetContentHeight());
this->Create();
@ -21,40 +23,43 @@ LogWindow::LogWindow() {
LogWindow::~LogWindow() {
}
IScrollAdapter& LogWindow::GetScrollAdapter() {
return (IScrollAdapter&) *this->adapter;
}
void LogWindow::Update() {
boost::mutex::scoped_lock lock(pendingMutex);
WINDOW* contents = this->GetContents();
if (contents) {
for (size_t i = 0; i < pending.size(); i++) {
LogEntry* entry = pending[i];
int64 attrs = COLOR_PAIR(BOX_COLOR_WHITE_ON_BLUE);
int64 color = COLOR_PAIR(BOX_COLOR_WHITE_ON_BLUE);
for (size_t i = 0; i < pending.size(); i++) {
LogEntry* entry = pending[i];
switch (entry->level) {
case musik::debug::level_error:
color = COLOR_PAIR(BOX_COLOR_RED_ON_BLUE) | A_BOLD;
break;
case musik::debug::level_warning:
color = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLUE) | A_BOLD;
switch (entry->level) {
case musik::debug::level_error: {
attrs = COLOR_PAIR(BOX_COLOR_RED_ON_BLUE) | A_BOLD;
break;
}
wattron(contents, color);
wprintw(contents, "[%s] %s\n", entry->tag.c_str(), entry->message.c_str());
wattroff(contents, color);
wrefresh(contents);
delete entry;
case musik::debug::level_warning: {
attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLUE) | A_BOLD;
break;
}
}
std::string s = boost::str(boost::format(
"[%1%] %2%") % entry->tag % entry->message);
this->adapter->AddLine(s, attrs);
}
this->OnAdapterChanged();
pending.clear();
}
void LogWindow::OnLogged(
void LogWindow::OnLogged( /* from a background thread */
musik::debug::log_level level,
std::string tag,
std::string message)

View File

@ -4,15 +4,19 @@
#include <core/debug.h>
#include <boost/thread/mutex.hpp>
#include "BorderedWindow.h"
#include "ScrollableWindow.h"
#include "SimpleScrollAdapter.h"
class LogWindow : public BorderedWindow, public sigslot::has_slots<> {
class LogWindow : public ScrollableWindow, public sigslot::has_slots<> {
public:
LogWindow();
~LogWindow();
void Update();
protected:
virtual IScrollAdapter& GetScrollAdapter();
private:
void OnLogged(
musik::debug::log_level level,
@ -27,4 +31,5 @@ class LogWindow : public BorderedWindow, public sigslot::has_slots<> {
boost::mutex pendingMutex;
std::vector<LogEntry*> pending;
SimpleScrollAdapter* adapter;
};

View File

@ -1,5 +1,5 @@
//////////////////////////////////////////////////////////////////////////////
// Copyright © 2007, Björn Olievier
// Copyright © 2007, Björn Olievier
//
// All rights reserved.
//
@ -82,7 +82,7 @@ int main(int argc, char* argv[])
curs_set(0);
#ifdef __PDCURSES__
PDC_set_title("musikbox");
PDC_set_title("♫ rect");
#endif
{
@ -95,7 +95,12 @@ int main(int argc, char* argv[])
CommandWindow command(tp, output);
TransportWindow transport(tp);
int f1 = KEY_F(2);
std::vector<ScrollableWindow*> order;
order.push_back(&logs);
order.push_back(&output);
int index = 0;
ScrollableWindow *scrollable = order.at(index);
int ch;
timeout(500);
@ -103,19 +108,26 @@ int main(int argc, char* argv[])
if (ch == -1) { /* timeout */
logs.Update();
}
else if (ch == 9) { /* tab */
index++;
if (index >= order.size()) {
index = 0;
}
scrollable = order.at(index);
}
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
}
else if (ch == KEY_NPAGE) {
output.PageDown();
scrollable->PageDown();
}
else if (ch == KEY_PPAGE) {
output.PageUp();
scrollable->PageUp();
}
else if (ch == KEY_DOWN) {
output.ScrollDown();
scrollable->ScrollDown();
}
else if (ch == KEY_UP) {
output.ScrollUp();
scrollable->ScrollUp();
}
else {
command.WriteChar(ch);

View File

@ -31,6 +31,10 @@ size_t SimpleScrollAdapter::GetEntryCount() {
void SimpleScrollAdapter::DrawPage(WINDOW* window, size_t lineNumber) {
wclear(window);
if (this->lineCount <= 0) {
return;
}
/* binary search to find where we need to start */
size_t offset = this->FindEntryIndex(lineNumber);
@ -47,23 +51,21 @@ void SimpleScrollAdapter::DrawPage(WINDOW* window, size_t lineNumber) {
do {
size_t count = (*it)->GetLineCount();
int64 attrs = (*it)->GetAttrs();
if (attrs != 0) {
wattron(window, attrs);
}
for (size_t i = c; i < count && remaining != 0; i++) {
int64 attrs = (*it)->GetAttrs();
if (attrs != 0) {
wattron(window, attrs);
}
std::string line = (*it)->GetLine(i).c_str();
wprintw(window, "%s\n", line.c_str());
if (attrs != 0) {
wattroff(window, attrs);
}
--remaining;
}
if (attrs != 0) {
wattroff(window, attrs);
}
++it;
c = 0;
} while (it != end && remaining != 0);
@ -190,7 +192,7 @@ inline static void breakIntoSubLines(
std::string word = words.at(i);
int len = std::distance(word.begin(), word.end());
/* this string is fine, it'll easily fit on its own line of necessary */
/* this word is fine, it'll easily fit on its own line of necessary */
if (width >= len) {
sanitizedWords.push_back(word);
@ -204,7 +206,7 @@ inline static void breakIntoSubLines(
/* ugh, we gotta split on UTF8 characters, not actual characters.
this makes things a bit more difficult... we iterate over the string
one displayable character at a time, and break it apart into separate
lines. */
lines as necessary. */
std::string::iterator begin = word.begin();
std::string::iterator end = word.begin();

View File

@ -38,7 +38,7 @@ void TransportWindow::Repaint() {
WINDOW *c = this->GetContents();
std::string volume = boost::str(boost::format(
"volume: %1%\n") % this->transport->Volume());
"volume: %1%\n") % this->transport->Volume());
wprintw(c, volume.c_str());
wprintw(c, "filename: ");

View File

@ -11,7 +11,7 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>square</ProjectName>
<ProjectName>rect</ProjectName>
<ProjectGuid>{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}</ProjectGuid>
<RootNamespace>square</RootNamespace>
<Keyword>Win32Proj</Keyword>