mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 21:40:20 +00:00
- Added SystemInfo and ResourcesWindow for real-time resource usage monitoring
- Renamed GenericTrack -> InMemoryTrack - A few other random cleanups
This commit is contained in:
parent
0639b3f0c2
commit
4d279004c7
@ -101,7 +101,7 @@
|
||||
<ClCompile Include="Library\query\SortTracksWithDataQuery.cpp" />
|
||||
<ClCompile Include="Library\query\TrackListQueryBase.cpp" />
|
||||
<ClCompile Include="Library\query\TrackMetadataQuery.cpp" />
|
||||
<ClCompile Include="library\track\GenericTrack.cpp" />
|
||||
<ClCompile Include="library\track\InMemoryTrack.cpp" />
|
||||
<ClCompile Include="library\track\IndexerTrack.cpp" />
|
||||
<ClCompile Include="library\track\LibraryTrack.cpp" />
|
||||
<ClCompile Include="library\track\Track.cpp" />
|
||||
@ -145,7 +145,7 @@
|
||||
<ClInclude Include="Library\query\SortTracksWithDataQuery.h" />
|
||||
<ClInclude Include="Library\query\TrackListQueryBase.h" />
|
||||
<ClInclude Include="Library\query\TrackMetadataQuery.h" />
|
||||
<ClInclude Include="library\track\GenericTrack.h" />
|
||||
<ClInclude Include="library\track\InMemoryTrack.h" />
|
||||
<ClInclude Include="library\track\IndexerTrack.h" />
|
||||
<ClInclude Include="library\track\LibraryTrack.h" />
|
||||
<ClInclude Include="library\track\Track.h" />
|
||||
|
@ -124,9 +124,6 @@
|
||||
<ClCompile Include="library\LocalLibrary.cpp">
|
||||
<Filter>src\library</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="library\track\GenericTrack.cpp">
|
||||
<Filter>src\library\track</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="library\track\IndexerTrack.cpp">
|
||||
<Filter>src\library\track</Filter>
|
||||
</ClCompile>
|
||||
@ -157,6 +154,9 @@
|
||||
<ClCompile Include="debug.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="library\track\InMemoryTrack.cpp">
|
||||
<Filter>src\library\track</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.hpp">
|
||||
@ -273,9 +273,6 @@
|
||||
<ClInclude Include="library\LocalLibrary.h">
|
||||
<Filter>src\library</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="library\track\GenericTrack.h">
|
||||
<Filter>src\library\track</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="library\track\IndexerTrack.h">
|
||||
<Filter>src\library\track</Filter>
|
||||
</ClInclude>
|
||||
@ -321,5 +318,8 @@
|
||||
<ClInclude Include="debug.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="library\track\InMemoryTrack.h">
|
||||
<Filter>src\library\track</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -386,7 +386,7 @@ void Indexer::SyncDirectory(
|
||||
stmt.BindInt(2, parentDirId);
|
||||
stmt.BindText(3, relativePath);
|
||||
|
||||
if (!stmt.Step() == db::Done) {
|
||||
if (stmt.Step() != db::Done) {
|
||||
return; /* ugh, failed? */
|
||||
}
|
||||
|
||||
@ -822,8 +822,6 @@ void Indexer::SyncOptimize() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
@ -978,7 +976,7 @@ void Indexer::RunAnalyzers() {
|
||||
}
|
||||
}
|
||||
|
||||
if(this->Exited() || this->Restarted()){
|
||||
if (this->Exited() || this->Restarted()){
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace musik { namespace core {
|
||||
std::string path;
|
||||
};
|
||||
|
||||
typedef std::vector<boost::shared_ptr<metadata::IMetadataReader> > MetadataReaderList;
|
||||
typedef std::vector<boost::shared_ptr<metadata::IMetadataReader>> MetadataReaderList;
|
||||
|
||||
std::deque<AddRemoveContext> addRemoveQueue;
|
||||
|
||||
|
@ -36,32 +36,32 @@
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include <core/library/track/GenericTrack.h>
|
||||
#include <core/library/track/InMemoryTrack.h>
|
||||
#include <core/playback/NonLibraryTrackHelper.h>
|
||||
|
||||
using namespace musik::core;
|
||||
|
||||
TrackPtr GenericTrack::Create(const char *uri) {
|
||||
GenericTrack *newTrack = new GenericTrack(uri);
|
||||
TrackPtr InMemoryTrack::Create(const char *uri) {
|
||||
InMemoryTrack *newTrack = new InMemoryTrack(uri);
|
||||
TrackPtr track(newTrack);
|
||||
newTrack->selfPtr = track; /* used to make another shared_ptr */
|
||||
NonLibraryTrackHelper::Instance().ReadTrack(track);
|
||||
return track;
|
||||
}
|
||||
|
||||
GenericTrack::GenericTrack() {
|
||||
InMemoryTrack::InMemoryTrack() {
|
||||
}
|
||||
|
||||
GenericTrack::GenericTrack(const char *uri) {
|
||||
InMemoryTrack::InMemoryTrack(const char *uri) {
|
||||
if (uri) {
|
||||
this->uri = uri;
|
||||
}
|
||||
}
|
||||
|
||||
GenericTrack::~GenericTrack() {
|
||||
InMemoryTrack::~InMemoryTrack() {
|
||||
}
|
||||
|
||||
std::string GenericTrack::GetValue(const char* metakey) {
|
||||
std::string InMemoryTrack::GetValue(const char* metakey) {
|
||||
if (metakey) {
|
||||
std::string metaKey(metakey);
|
||||
|
||||
@ -99,44 +99,44 @@ std::string GenericTrack::GetValue(const char* metakey) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void GenericTrack::SetValue(const char* metakey, const char* value){
|
||||
void InMemoryTrack::SetValue(const char* metakey, const char* value){
|
||||
if (metakey && value) {
|
||||
boost::mutex::scoped_lock lock(this->metadataMutex);
|
||||
this->metadata.insert(std::pair<std::string, std::string>(metakey,value));
|
||||
}
|
||||
}
|
||||
|
||||
void GenericTrack::ClearValue(const char* metakey) {
|
||||
void InMemoryTrack::ClearValue(const char* metakey) {
|
||||
boost::mutex::scoped_lock lock(this->metadataMutex);
|
||||
this->metadata.erase(metakey);
|
||||
}
|
||||
|
||||
void GenericTrack::SetThumbnail(const char *data,long size) {
|
||||
void InMemoryTrack::SetThumbnail(const char *data,long size) {
|
||||
}
|
||||
|
||||
std::string GenericTrack::URI() {
|
||||
std::string InMemoryTrack::URI() {
|
||||
return this->uri;
|
||||
}
|
||||
|
||||
std::string GenericTrack::URL() {
|
||||
std::string InMemoryTrack::URL() {
|
||||
return this->uri;
|
||||
}
|
||||
|
||||
Track::MetadataIteratorRange GenericTrack::GetValues(const char* metakey) {
|
||||
Track::MetadataIteratorRange InMemoryTrack::GetValues(const char* metakey) {
|
||||
boost::mutex::scoped_lock lock(this->metadataMutex);
|
||||
return this->metadata.equal_range(metakey);
|
||||
}
|
||||
|
||||
Track::MetadataIteratorRange GenericTrack::GetAllValues() {
|
||||
Track::MetadataIteratorRange InMemoryTrack::GetAllValues() {
|
||||
return Track::MetadataIteratorRange(this->metadata.begin(),this->metadata.end());
|
||||
}
|
||||
|
||||
TrackPtr GenericTrack::Copy() {
|
||||
TrackPtr InMemoryTrack::Copy() {
|
||||
TrackPtr trackCopy;
|
||||
if (trackCopy = this->selfPtr.lock()) {
|
||||
return trackCopy;
|
||||
}
|
||||
|
||||
return GenericTrack::Create(this->uri.c_str());
|
||||
return InMemoryTrack::Create(this->uri.c_str());
|
||||
}
|
||||
|
@ -46,18 +46,18 @@ namespace musik { namespace core {
|
||||
|
||||
//////////////////////////////////////////
|
||||
///\brief
|
||||
///A GenericTrack is not related to any library. It must contain a URI
|
||||
///A InMemoryTrack is not related to any library. It must contain a URI
|
||||
//////////////////////////////////////////
|
||||
class GenericTrack : public Track {
|
||||
class InMemoryTrack : public Track {
|
||||
public:
|
||||
static TrackPtr Create(const char *uri);
|
||||
|
||||
protected:
|
||||
GenericTrack();
|
||||
GenericTrack(const char *uri);
|
||||
InMemoryTrack();
|
||||
InMemoryTrack(const char *uri);
|
||||
|
||||
public:
|
||||
virtual ~GenericTrack();
|
||||
virtual ~InMemoryTrack();
|
||||
|
||||
virtual std::string GetValue(const char* metakey);
|
||||
virtual void SetValue(const char* metakey,const char* value);
|
@ -37,7 +37,7 @@
|
||||
#include "pch.hpp"
|
||||
#include <core/library/track/TrackFactory.h>
|
||||
#include <core/library/track/LibraryTrack.h>
|
||||
#include <core/library/track/GenericTrack.h>
|
||||
#include <core/library/track/InMemoryTrack.h>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
@ -54,7 +54,7 @@ TrackPtr TrackFactory::CreateTrack(const std::string& uri) {
|
||||
}
|
||||
}
|
||||
|
||||
return GenericTrack::Create(uri.c_str());
|
||||
return InMemoryTrack::Create(uri.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,9 +149,10 @@ double Transport::Volume(){
|
||||
}
|
||||
|
||||
void Transport::SetVolume(double volume){
|
||||
musik::debug::info("transport", boost::str(boost::format("set volume %d%%") % (volume * 100)));
|
||||
musik::debug::info(TAG, boost::str(boost::format("set volume %d%%") % round(volume * 100)));
|
||||
|
||||
this->volume = volume;
|
||||
volume = max(0, min(1.0, volume));
|
||||
this->volume = volume;
|
||||
if(this->currentPlayer){
|
||||
for(PlayerList::iterator player=this->players.begin();player!=this->players.end();++player){
|
||||
(*player)->SetVolume(volume);
|
||||
|
@ -9,7 +9,8 @@ BorderedWindow::BorderedWindow() {
|
||||
this->width = 0;
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->color = -1;
|
||||
this->contentColor = -1;
|
||||
this->borderColor = -1;
|
||||
this->scrollable = false;
|
||||
}
|
||||
|
||||
@ -51,8 +52,22 @@ int BorderedWindow::GetY() const {
|
||||
return this->y;
|
||||
}
|
||||
|
||||
void BorderedWindow::SetColor(int color) {
|
||||
this->color = color;
|
||||
void BorderedWindow::SetContentColor(int color) {
|
||||
this->contentColor = color;
|
||||
|
||||
if (this->contentColor != -1 && this->contents) {
|
||||
wbkgd(this->contents, COLOR_PAIR(this->contentColor));
|
||||
this->Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
void BorderedWindow::SetBorderColor(int color) {
|
||||
this->borderColor = color;
|
||||
|
||||
if (this->borderColor != -1 && this->border) {
|
||||
wbkgd(this->border, COLOR_PAIR(this->borderColor));
|
||||
this->Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
void BorderedWindow::SetScrollable(bool scrollable) {
|
||||
@ -83,8 +98,12 @@ void BorderedWindow::Create() {
|
||||
|
||||
scrollok(this->contents, this->scrollable);
|
||||
|
||||
if (this->color != -1) {
|
||||
wbkgd(this->contents, COLOR_PAIR(this->color));
|
||||
if (this->contentColor != -1) {
|
||||
wbkgd(this->contents, COLOR_PAIR(this->contentColor));
|
||||
}
|
||||
|
||||
if (this->borderColor != -1) {
|
||||
wbkgd(this->border, COLOR_PAIR(this->borderColor));
|
||||
}
|
||||
|
||||
touchwin(this->contents);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <curses.h>
|
||||
#include "curses_config.h"
|
||||
|
||||
class BorderedWindow {
|
||||
public:
|
||||
@ -11,11 +11,14 @@ class BorderedWindow {
|
||||
void Destroy();
|
||||
virtual void Repaint();
|
||||
|
||||
virtual void SetContentColor(int color);
|
||||
virtual void SetBorderColor(int color);
|
||||
|
||||
protected:
|
||||
WINDOW* GetContents() const;
|
||||
void SetSize(int width, int height);
|
||||
void SetPosition(int x, int y);
|
||||
void SetColor(int color);
|
||||
|
||||
void SetScrollable(bool scrollable);
|
||||
void Clear();
|
||||
int GetWidth() const;
|
||||
@ -29,6 +32,6 @@ class BorderedWindow {
|
||||
private:
|
||||
WINDOW* border;
|
||||
WINDOW* contents;
|
||||
int width, height, x, y, color;
|
||||
int width, height, x, y, contentColor, borderColor;
|
||||
bool scrollable;
|
||||
};
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Colors.h"
|
||||
#include <curses.h>
|
||||
|
||||
Colors::Colors() {
|
||||
}
|
||||
@ -13,4 +12,7 @@ void Colors::Init() {
|
||||
init_pair(BOX_COLOR_YELLOW_ON_BLUE, COLOR_YELLOW, COLOR_BLUE);
|
||||
init_pair(BOX_COLOR_BLACK_ON_GREY, COLOR_BLACK, COLOR_WHITE);
|
||||
init_pair(BOX_COLOR_BLACK_ON_GREEN, COLOR_BLACK, COLOR_GREEN);
|
||||
init_pair(BOX_COLOR_YELLOW_ON_BLACK, COLOR_YELLOW, COLOR_BLACK);
|
||||
init_pair(BOX_COLOR_WHITE_ON_BLACK, COLOR_WHITE, COLOR_BLACK);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "curses_config.h"
|
||||
|
||||
#define BOX_COLOR_WHITE_ON_BLUE 1
|
||||
#define BOX_COLOR_RED_ON_BLUE 2
|
||||
#define BOX_COLOR_YELLOW_ON_BLUE 3
|
||||
#define BOX_COLOR_BLACK_ON_GREY 4
|
||||
#define BOX_COLOR_BLACK_ON_GREEN 5
|
||||
#define BOX_COLOR_YELLOW_ON_BLACK 6
|
||||
#define BOX_COLOR_WHITE_ON_BLACK 7
|
||||
|
||||
class Colors {
|
||||
private:
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "curses_config.h"
|
||||
#include "BorderedWindow.h"
|
||||
#include "OutputWindow.h"
|
||||
#include <core/playback/Transport.h>
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <curses.h>
|
||||
|
||||
class IScrollAdapter {
|
||||
public:
|
||||
@ -10,3 +9,4 @@ class IScrollAdapter {
|
||||
virtual size_t GetEntryCount() = 0;
|
||||
virtual void DrawPage(WINDOW* window, size_t index) = 0;
|
||||
};
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <curses.h>
|
||||
|
||||
LogWindow::LogWindow() {
|
||||
this->SetColor(BOX_COLOR_WHITE_ON_BLUE);
|
||||
this->SetSize(Screen::GetWidth() / 2, Screen::GetHeight());
|
||||
this->SetContentColor(BOX_COLOR_WHITE_ON_BLUE);
|
||||
this->SetSize(Screen::GetWidth() / 2, Screen::GetHeight() - 3);
|
||||
this->SetPosition(Screen::GetWidth() / 2, 0);
|
||||
|
||||
this->adapter = new SimpleScrollAdapter();
|
||||
|
@ -38,8 +38,7 @@
|
||||
#include "CommandWindow.h"
|
||||
#include "OutputWindow.h"
|
||||
#include "TransportWindow.h"
|
||||
|
||||
#include <curses.h>
|
||||
#include "ResourcesWindow.h"
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
@ -82,7 +81,7 @@ int main(int argc, char* argv[])
|
||||
curs_set(0);
|
||||
|
||||
#ifdef __PDCURSES__
|
||||
PDC_set_title("♫ rect");
|
||||
PDC_set_title("musikbox ♫");
|
||||
#endif
|
||||
|
||||
{
|
||||
@ -92,6 +91,7 @@ int main(int argc, char* argv[])
|
||||
Colors::Init();
|
||||
LogWindow logs;
|
||||
OutputWindow output;
|
||||
ResourcesWindow resources;
|
||||
CommandWindow command(tp, output);
|
||||
TransportWindow transport(tp);
|
||||
|
||||
@ -99,21 +99,28 @@ int main(int argc, char* argv[])
|
||||
order.push_back(&logs);
|
||||
order.push_back(&output);
|
||||
|
||||
int index = 0;
|
||||
size_t index = 0;
|
||||
ScrollableWindow *scrollable = order.at(index);
|
||||
scrollable->SetBorderColor(BOX_COLOR_YELLOW_ON_BLACK);
|
||||
|
||||
int ch;
|
||||
timeout(500);
|
||||
while (ch = getch()) {
|
||||
if (ch == -1) { /* timeout */
|
||||
logs.Update();
|
||||
transport.Repaint();
|
||||
resources.Repaint();
|
||||
}
|
||||
else if (ch == 9) { /* tab */
|
||||
scrollable->SetBorderColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||
|
||||
index++;
|
||||
if (index >= order.size()) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
scrollable = order.at(index);
|
||||
scrollable->SetBorderColor(BOX_COLOR_YELLOW_ON_BLACK);
|
||||
}
|
||||
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
|
||||
}
|
||||
@ -132,8 +139,6 @@ int main(int argc, char* argv[])
|
||||
else {
|
||||
command.WriteChar(ch);
|
||||
}
|
||||
|
||||
transport.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ OutputWindow::OutputWindow()
|
||||
{
|
||||
this->SetSize(Screen::GetWidth() / 2, Screen::GetHeight() - 3 - 4);
|
||||
this->SetPosition(0, 4);
|
||||
this->SetColor(BOX_COLOR_BLACK_ON_GREY);
|
||||
this->SetContentColor(BOX_COLOR_BLACK_ON_GREY);
|
||||
|
||||
this->adapter = new SimpleScrollAdapter();
|
||||
this->adapter->SetDisplaySize(this->GetContentWidth(), this->GetContentHeight());
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "curses_config.h"
|
||||
#include "ScrollableWindow.h"
|
||||
#include "SimpleScrollAdapter.h"
|
||||
|
||||
|
44
src/square/ResourcesWindow.cpp
Executable file
44
src/square/ResourcesWindow.cpp
Executable file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ResourcesWindow.h"
|
||||
#include "Screen.h"
|
||||
#include "Colors.h"
|
||||
|
||||
#include <core/debug.h>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
|
||||
ResourcesWindow::ResourcesWindow() {
|
||||
|
||||
this->SetSize(Screen::GetWidth() / 2, 3);
|
||||
|
||||
this->SetPosition(
|
||||
Screen::GetWidth() / 2,
|
||||
Screen::GetHeight() - this->GetHeight());
|
||||
|
||||
this->systemInfo = SystemInfo::Create();
|
||||
this->Create();
|
||||
}
|
||||
|
||||
ResourcesWindow::~ResourcesWindow() {
|
||||
delete this->systemInfo;
|
||||
}
|
||||
|
||||
#define BYTES_PER_MEGABYTE 1048576.0f
|
||||
|
||||
void ResourcesWindow::Repaint() {
|
||||
this->Clear();
|
||||
|
||||
float virtualMemoryUsed = (float) systemInfo->GetUsedVirtualMemory() / BYTES_PER_MEGABYTE;
|
||||
float physicalMemoryUsed = (float) systemInfo->GetUsedPhysicalMemory() / BYTES_PER_MEGABYTE;
|
||||
|
||||
wprintw(
|
||||
this->GetContents(),
|
||||
"cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)",
|
||||
systemInfo->GetCpuUsage(),
|
||||
virtualMemoryUsed,
|
||||
physicalMemoryUsed);
|
||||
|
||||
BorderedWindow::Repaint();
|
||||
}
|
17
src/square/ResourcesWindow.h
Executable file
17
src/square/ResourcesWindow.h
Executable file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "curses_config.h"
|
||||
#include "BorderedWindow.h"
|
||||
#include "SystemInfo.h"
|
||||
|
||||
class ResourcesWindow : public BorderedWindow {
|
||||
public:
|
||||
ResourcesWindow();
|
||||
virtual ~ResourcesWindow();
|
||||
|
||||
virtual void Repaint();
|
||||
|
||||
private:
|
||||
|
||||
SystemInfo* systemInfo;
|
||||
};
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Screen.h"
|
||||
#include <curses.h>
|
||||
|
||||
Screen::Screen() {
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "curses_config.h"
|
||||
|
||||
class Screen {
|
||||
private:
|
||||
|
@ -32,7 +32,7 @@ size_t ScrollableWindow::GetFirstVisible() {
|
||||
}
|
||||
|
||||
size_t ScrollableWindow::GetLastVisible() {
|
||||
int total = GetScrollAdapter().GetLineCount(this->GetContentWidth());
|
||||
size_t total = GetScrollAdapter().GetLineCount(this->GetContentWidth());
|
||||
return min(scrollPosition + this->GetContentHeight(), total);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "curses_config.h"
|
||||
#include "BorderedWindow.h"
|
||||
#include "IScrollAdapter.h"
|
||||
|
||||
|
@ -81,7 +81,7 @@ void SimpleScrollAdapter::AddLine(const std::string& str, int64 attrs) {
|
||||
this->lineCount += entry->GetLineCount();
|
||||
}
|
||||
|
||||
size_t SimpleScrollAdapter::FindEntryIndex(int lineNumber) {
|
||||
size_t SimpleScrollAdapter::FindEntryIndex(size_t lineNumber) {
|
||||
if (lineCount == -1) {
|
||||
Reindex();
|
||||
}
|
||||
@ -190,7 +190,7 @@ inline static void breakIntoSubLines(
|
||||
std::vector<std::string> sanitizedWords;
|
||||
for (size_t i = 0; i < words.size(); i++) {
|
||||
std::string word = words.at(i);
|
||||
int len = std::distance(word.begin(), word.end());
|
||||
size_t len = std::distance(word.begin(), word.end());
|
||||
|
||||
/* this word is fine, it'll easily fit on its own line of necessary */
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "curses_config.h"
|
||||
#include "IScrollAdapter.h";
|
||||
|
||||
class SimpleScrollAdapter : public IScrollAdapter {
|
||||
@ -44,8 +43,8 @@ class SimpleScrollAdapter : public IScrollAdapter {
|
||||
|
||||
|
||||
void Reindex();
|
||||
size_t FindEntryIndex(int index);
|
||||
size_t FindEntryIndex(size_t index);
|
||||
|
||||
EntryList entries;
|
||||
size_t lineCount, width, height;
|
||||
};
|
||||
};
|
||||
|
147
src/square/SystemInfo.cpp
Executable file
147
src/square/SystemInfo.cpp
Executable file
@ -0,0 +1,147 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "SystemInfo.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "psapi.h"
|
||||
#include "pdh.h"
|
||||
|
||||
#ifdef WIN32
|
||||
class WindowsSystemInfo : public SystemInfo {
|
||||
public:
|
||||
WindowsSystemInfo();
|
||||
virtual ~WindowsSystemInfo();
|
||||
|
||||
virtual int64 GetTotalVirtualMemory();
|
||||
virtual int64 GetUsedVirtualMemory();
|
||||
virtual int64 GetTotalPhysicalMemory();
|
||||
virtual int64 GetUsedPhysicalMemory();
|
||||
virtual double GetCpuUsage();
|
||||
|
||||
private:
|
||||
ULARGE_INTEGER lastCpu, lastSysCpu, lastUserCpu;
|
||||
int processorCount;
|
||||
HANDLE self;
|
||||
PDH_HQUERY cpuQuery;
|
||||
PDH_HCOUNTER cpuTotal;
|
||||
};
|
||||
#endif
|
||||
|
||||
SystemInfo* SystemInfo::Create() {
|
||||
#ifdef WIN32
|
||||
return new WindowsSystemInfo();
|
||||
#else
|
||||
return new SystemInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
SystemInfo::SystemInfo() {
|
||||
|
||||
}
|
||||
|
||||
SystemInfo::~SystemInfo() {
|
||||
|
||||
}
|
||||
|
||||
int64 SystemInfo::GetTotalVirtualMemory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64 SystemInfo::GetUsedVirtualMemory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64 SystemInfo::GetTotalPhysicalMemory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64 SystemInfo::GetUsedPhysicalMemory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double SystemInfo::GetCpuUsage() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define GET_MEMORY_STATUS \
|
||||
MEMORYSTATUSEX memInfo; \
|
||||
memInfo.dwLength = sizeof(MEMORYSTATUSEX); \
|
||||
GlobalMemoryStatusEx(&memInfo); \
|
||||
|
||||
#define GET_PROCESS_MEMORY_COUNTERS \
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc; \
|
||||
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)); \
|
||||
|
||||
WindowsSystemInfo::WindowsSystemInfo() {
|
||||
PdhOpenQuery(NULL, NULL, &cpuQuery);
|
||||
PdhAddCounter(cpuQuery, "\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal);
|
||||
PdhCollectQueryData(cpuQuery);
|
||||
|
||||
SYSTEM_INFO sysInfo;
|
||||
FILETIME ftime, fsys, fuser;
|
||||
|
||||
GetSystemInfo(&sysInfo);
|
||||
processorCount = sysInfo.dwNumberOfProcessors;
|
||||
|
||||
GetSystemTimeAsFileTime(&ftime);
|
||||
memcpy(&lastCpu, &ftime, sizeof(FILETIME));
|
||||
|
||||
self = GetCurrentProcess();
|
||||
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
|
||||
memcpy(&lastSysCpu, &fsys, sizeof(FILETIME));
|
||||
memcpy(&lastUserCpu, &fuser, sizeof(FILETIME));
|
||||
}
|
||||
|
||||
WindowsSystemInfo::~WindowsSystemInfo() {
|
||||
PdhCloseQuery(cpuQuery);
|
||||
}
|
||||
|
||||
int64 WindowsSystemInfo::GetTotalVirtualMemory() {
|
||||
GET_MEMORY_STATUS
|
||||
return memInfo.ullTotalPageFile;
|
||||
}
|
||||
|
||||
int64 WindowsSystemInfo::GetUsedVirtualMemory() {
|
||||
GET_PROCESS_MEMORY_COUNTERS
|
||||
return pmc.PrivateUsage;
|
||||
}
|
||||
|
||||
int64 WindowsSystemInfo::GetTotalPhysicalMemory() {
|
||||
GET_MEMORY_STATUS
|
||||
return memInfo.ullTotalPhys;
|
||||
}
|
||||
|
||||
int64 WindowsSystemInfo::GetUsedPhysicalMemory() {
|
||||
GET_PROCESS_MEMORY_COUNTERS
|
||||
return pmc.WorkingSetSize;
|
||||
}
|
||||
|
||||
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 =
|
||||
(double) (sys.QuadPart - lastSysCpu.QuadPart) +
|
||||
(double) (user.QuadPart - lastUserCpu.QuadPart);
|
||||
|
||||
percent /= (now.QuadPart - lastCpu.QuadPart);
|
||||
percent /= processorCount;
|
||||
|
||||
lastCpu = now;
|
||||
lastUserCpu = user;
|
||||
lastSysCpu = sys;
|
||||
|
||||
return percent * 100;
|
||||
}
|
||||
#endif
|
18
src/square/SystemInfo.h
Executable file
18
src/square/SystemInfo.h
Executable file
@ -0,0 +1,18 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
class SystemInfo {
|
||||
public:
|
||||
static SystemInfo* Create();
|
||||
|
||||
virtual ~SystemInfo();
|
||||
|
||||
protected:
|
||||
SystemInfo();
|
||||
|
||||
public:
|
||||
virtual int64 GetTotalVirtualMemory();
|
||||
virtual int64 GetUsedVirtualMemory();
|
||||
virtual int64 GetTotalPhysicalMemory();
|
||||
virtual int64 GetUsedPhysicalMemory();
|
||||
virtual double GetCpuUsage();
|
||||
};
|
@ -33,7 +33,6 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TransportEvents.h"
|
||||
|
||||
#include <core/debug.h>
|
||||
|
||||
using namespace musik::square;
|
||||
|
@ -34,7 +34,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "config.h"
|
||||
#include <vector>
|
||||
#include <sigslot/sigslot.h>
|
||||
|
||||
|
@ -24,7 +24,7 @@ using musik::core::audio::Transport;
|
||||
TransportWindow::TransportWindow(Transport& transport) {
|
||||
this->SetSize(Screen::GetWidth() / 2, 4);
|
||||
this->SetPosition(0, 0);
|
||||
this->SetColor(BOX_COLOR_BLACK_ON_GREEN);
|
||||
this->SetContentColor(BOX_COLOR_BLACK_ON_GREEN);
|
||||
this->transport = &transport;
|
||||
this->paused = false;
|
||||
this->Create();
|
||||
@ -37,10 +37,10 @@ void TransportWindow::Repaint() {
|
||||
this->Clear();
|
||||
WINDOW *c = this->GetContents();
|
||||
|
||||
std::string volume = boost::str(boost::format(
|
||||
"volume: %1%\n") % this->transport->Volume());
|
||||
int volume = (int) round(this->transport->Volume() * 100);
|
||||
|
||||
wprintw(c, volume.c_str());
|
||||
wprintw(c, "volume %d%%\n", volume);
|
||||
wprintw(c, "filename: ");
|
||||
|
||||
BorderedWindow::Repaint();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "curses_config.h"
|
||||
#include "BorderedWindow.h"
|
||||
#include "OutputWindow.h"
|
||||
#include <core/playback/Transport.h>
|
||||
|
8
src/square/Ui.h
Executable file
8
src/square/Ui.h
Executable file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#define PDC_WIDE
|
||||
#include <curses.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#undef MOUSE_MOVE
|
||||
#endif
|
@ -1,42 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License Agreement:
|
||||
//
|
||||
// The following are Copyright © 2008, musikCube team
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// 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
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SQUARE_CONFIG_H
|
||||
#define SQUARE_CONFIG_H
|
||||
|
||||
#include <core/config.h>
|
||||
|
||||
#endif // SQUARE_CONFIG_H
|
8
src/square/curses_config.h
Executable file
8
src/square/curses_config.h
Executable file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
#define PDC_WIDE
|
||||
#undef MOUSE_MOVED
|
||||
#endif
|
||||
|
||||
#include <curses.h>
|
@ -11,7 +11,7 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectName>rect</ProjectName>
|
||||
<ProjectName>musikbox</ProjectName>
|
||||
<ProjectGuid>{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}</ProjectGuid>
|
||||
<RootNamespace>square</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@ -20,7 +20,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
@ -78,7 +78,8 @@
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<ImportLibrary>../../bin/$(Configuration)/mC2.lib</ImportLibrary>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<AdditionalDependencies>pdcursesd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>pdcursesd.lib;pdh.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy "$(SolutionDir)\src\3rdparty\vld\*.*" "$(TargetDir)" </Command>
|
||||
@ -108,7 +109,8 @@
|
||||
<ImportLibrary>
|
||||
</ImportLibrary>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<AdditionalDependencies>pdcurses.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>pdcurses.lib;pdh.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ImageHasSafeExceptionHandlers>true</ImageHasSafeExceptionHandlers>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
@ -118,9 +120,11 @@
|
||||
<ClCompile Include="IScrollAdapter.h" />
|
||||
<ClCompile Include="LogWindow.cpp" />
|
||||
<ClCompile Include="OutputWindow.cpp" />
|
||||
<ClCompile Include="ResourcesWindow.cpp" />
|
||||
<ClCompile Include="Screen.cpp" />
|
||||
<ClCompile Include="ScrollableWindow.cpp" />
|
||||
<ClCompile Include="SimpleScrollAdapter.cpp" />
|
||||
<ClCompile Include="SystemInfo.cpp" />
|
||||
<ClCompile Include="TransportEvents.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@ -132,13 +136,15 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="BorderedWindow.h" />
|
||||
<ClInclude Include="Colors.h" />
|
||||
<ClInclude Include="config.h" />
|
||||
<ClInclude Include="CommandWindow.h" />
|
||||
<ClInclude Include="curses_config.h" />
|
||||
<ClInclude Include="LogWindow.h" />
|
||||
<ClInclude Include="OutputWindow.h" />
|
||||
<ClInclude Include="ResourcesWindow.h" />
|
||||
<ClInclude Include="Screen.h" />
|
||||
<ClInclude Include="ScrollableWindow.h" />
|
||||
<ClInclude Include="SimpleScrollAdapter.h" />
|
||||
<ClInclude Include="SystemInfo.h" />
|
||||
<ClInclude Include="TransportEvents.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="TransportWindow.h" />
|
||||
|
@ -56,14 +56,17 @@
|
||||
<ClCompile Include="ScrollableWindow.cpp">
|
||||
<Filter>Source Files\curses</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SystemInfo.cpp">
|
||||
<Filter>Source Files\windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ResourcesWindow.cpp">
|
||||
<Filter>Source Files\windows</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="config.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TransportEvents.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
@ -94,5 +97,14 @@
|
||||
<ClInclude Include="ScrollableWindow.h">
|
||||
<Filter>Source Files\curses</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="curses_config.h">
|
||||
<Filter>Source Files\curses</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SystemInfo.h">
|
||||
<Filter>Source Files\windows</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ResourcesWindow.h">
|
||||
<Filter>Source Files\windows</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,13 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include "config.h"
|
||||
#define PDC_WIDE
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
typedef __int64 int64;
|
||||
#include <core/config.h>
|
||||
#include "curses_config.h"
|
||||
|
||||
typedef __int64 int64;
|
Loading…
x
Reference in New Issue
Block a user