diff --git a/src/musikbox/CMakeLists.txt b/src/musikbox/CMakeLists.txt index 465aa7e79..521a399a3 100644 --- a/src/musikbox/CMakeLists.txt +++ b/src/musikbox/CMakeLists.txt @@ -21,12 +21,10 @@ set (BOX_SRCS ./app/util/GlobalHotkeys.cpp ./app/util/Playback.cpp ./app/util/PreferenceKeys.cpp - ./app/util/SystemInfo.cpp ./app/window/CategoryListView.cpp ./app/window/EntryWithHeader.cpp ./app/window/LogWindow.cpp ./app/window/OutputWindow.cpp - ./app/window/ResourcesWindow.cpp ./app/window/ShortcutsWindow.cpp ./app/window/TrackListView.cpp ./app/window/TransportWindow.cpp diff --git a/src/musikbox/app/layout/ConsoleLayout.cpp b/src/musikbox/app/layout/ConsoleLayout.cpp index c3ac2483b..46b2c98c1 100755 --- a/src/musikbox/app/layout/ConsoleLayout.cpp +++ b/src/musikbox/app/layout/ConsoleLayout.cpp @@ -46,9 +46,6 @@ #include -#define MESSAGE_TYPE_UPDATE 1001 -#define UPDATE_INTERVAL_MS 1000 - template bool tostr(T& t, const std::string& s) { std::istringstream iss(s); @@ -68,7 +65,6 @@ ConsoleLayout::ConsoleLayout(ITransport& transport, LibraryPtr library) this->logs.reset(new LogWindow(this)); this->output.reset(new OutputWindow(this)); - this->resources.reset(new ResourcesWindow(this)); this->commands.reset(new cursespp::TextInput()); this->commands->SetFocusOrder(0); @@ -78,7 +74,6 @@ ConsoleLayout::ConsoleLayout(ITransport& transport, LibraryPtr library) this->AddWindow(this->commands); this->AddWindow(this->logs); this->AddWindow(this->output); - this->AddWindow(this->resources); this->commands->EnterPressed.connect(this, &ConsoleLayout::OnEnterPressed); @@ -101,11 +96,8 @@ void ConsoleLayout::Layout() { /* bottom left */ this->commands->MoveAndResize(x, cy - 3, cx / 2, 3); - /* top right */ - this->logs->MoveAndResize(cx / 2, 0, cx / 2, cy - 3); - - /* bottom right */ - this->resources->MoveAndResize(cx / 2, cy - 3, cx / 2, 3); + /* right */ + this->logs->MoveAndResize(cx / 2, 0, cx / 2, cy); } void ConsoleLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { @@ -134,30 +126,6 @@ void ConsoleLayout::OnEnterPressed(TextInput *input) { } } -void ConsoleLayout::OnVisibilityChanged(bool visible) { - LayoutBase::OnVisibilityChanged(visible); - - if (visible) { - this->UpdateWindows(); - this->RemoveMessage(MESSAGE_TYPE_UPDATE); - this->PostMessage(MESSAGE_TYPE_UPDATE, 0, 0, UPDATE_INTERVAL_MS); - } - else { - this->RemoveMessage(MESSAGE_TYPE_UPDATE); - } -} - -void ConsoleLayout::ProcessMessage(IMessage &message) { - if (message.Type() == MESSAGE_TYPE_UPDATE) { - this->UpdateWindows(); - this->PostMessage(MESSAGE_TYPE_UPDATE, 0, 0, UPDATE_INTERVAL_MS); - } -} - -void ConsoleLayout::UpdateWindows() { - this->logs->Update(); - this->resources->Update(); -} void ConsoleLayout::Seek(const std::vector& args) { if (args.size() > 0) { diff --git a/src/musikbox/app/layout/ConsoleLayout.h b/src/musikbox/app/layout/ConsoleLayout.h index 5e85b9a43..b37562a3c 100755 --- a/src/musikbox/app/layout/ConsoleLayout.h +++ b/src/musikbox/app/layout/ConsoleLayout.h @@ -40,7 +40,6 @@ #include #include #include -#include #include #include @@ -66,14 +65,9 @@ namespace musik { ~ConsoleLayout(); virtual void Layout(); - virtual void ProcessMessage(cursespp::IMessage &message); - virtual void OnVisibilityChanged(bool visible); - - void SetShortcutsWindow(ShortcutsWindow* shortcuts); + virtual void SetShortcutsWindow(ShortcutsWindow* shortcuts); private: - void UpdateWindows(); - void OnEnterPressed(cursespp::TextInput* input); void ListPlugins() const; @@ -89,7 +83,6 @@ namespace musik { std::shared_ptr logs; std::shared_ptr commands; std::shared_ptr output; - std::shared_ptr resources; musik::core::audio::ITransport& transport; musik::core::LibraryPtr library; }; diff --git a/src/musikbox/app/util/SystemInfo.cpp b/src/musikbox/app/util/SystemInfo.cpp deleted file mode 100755 index 8d5e2bf25..000000000 --- a/src/musikbox/app/util/SystemInfo.cpp +++ /dev/null @@ -1,187 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2016 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. -// -////////////////////////////////////////////////////////////////////////////// - -#include "stdafx.h" - -#include "SystemInfo.h" - -using namespace musik::box; - -#ifdef WIN32 - -#include "windows.h" -#include "psapi.h" -#include "pdh.h" - -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); - - ULONGLONG diff = now.QuadPart - lastCpu.QuadPart; - diff = std::max((ULONGLONG) 1, diff); - - percent /= diff; - percent /= processorCount; - - lastCpu = now; - lastUserCpu = user; - lastSysCpu = sys; - - return (percent * 100.0f); -} -#endif diff --git a/src/musikbox/app/util/SystemInfo.h b/src/musikbox/app/util/SystemInfo.h deleted file mode 100755 index 413968716..000000000 --- a/src/musikbox/app/util/SystemInfo.h +++ /dev/null @@ -1,54 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2016 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. -// -////////////////////////////////////////////////////////////////////////////// - -#include "stdafx.h" - -namespace musik { - namespace box { - class SystemInfo { - public: - static SystemInfo* Create(); - virtual ~SystemInfo(); - - virtual int64 GetTotalVirtualMemory(); - virtual int64 GetUsedVirtualMemory(); - virtual int64 GetTotalPhysicalMemory(); - virtual int64 GetUsedPhysicalMemory(); - virtual double GetCpuUsage(); - - protected: - SystemInfo(); - }; - } -} diff --git a/src/musikbox/app/window/LogWindow.cpp b/src/musikbox/app/window/LogWindow.cpp index 47b66af94..aa864f78a 100755 --- a/src/musikbox/app/window/LogWindow.cpp +++ b/src/musikbox/app/window/LogWindow.cpp @@ -45,6 +45,12 @@ using namespace cursespp; typedef IScrollAdapter::IEntry IEntry; +#define REFRESH 1000 + +#define DEBOUNCE_REFRESH() \ + this->RemoveMessage(REFRESH); \ + this->PostMessage(REFRESH, 0, 0, 250); + LogWindow::LogWindow(IWindow *parent) : ScrollableWindow(parent) { this->adapter = new SimpleScrollAdapter(); @@ -66,6 +72,23 @@ void LogWindow::ClearContents() { this->OnAdapterChanged(); } +void LogWindow::ProcessMessage(IMessage &message) { + if (message.Type() == REFRESH) { + this->Update(); + } + else { + ScrollableWindow::ProcessMessage(message); + } +} + +void LogWindow::OnVisibilityChanged(bool visible) { + ScrollableWindow::OnVisibilityChanged(visible); + + if (visible) { + DEBOUNCE_REFRESH(); + } +} + void LogWindow::Update() { boost::mutex::scoped_lock lock(pendingMutex); @@ -73,8 +96,6 @@ void LogWindow::Update() { return; } - WINDOW* contents = this->GetContent(); - for (size_t i = 0; i < pending.size(); i++) { int64 attrs = COLOR_PAIR(CURSESPP_TEXT_DEFAULT); @@ -116,4 +137,6 @@ void LogWindow::OnLogged( /* from a background thread */ entry->tag = tag; entry->message = message; pending.push_back(entry); + + DEBOUNCE_REFRESH(); } diff --git a/src/musikbox/app/window/LogWindow.h b/src/musikbox/app/window/LogWindow.h index 434bf8f7b..7e467b018 100755 --- a/src/musikbox/app/window/LogWindow.h +++ b/src/musikbox/app/window/LogWindow.h @@ -57,12 +57,16 @@ namespace musik { virtual ~LogWindow(); void ClearContents(); - void Update(); + + virtual void ProcessMessage(cursespp::IMessage &message); + virtual void OnVisibilityChanged(bool visible); protected: virtual cursespp::IScrollAdapter& GetScrollAdapter(); private: + void Update(); + void OnLogged( musik::debug::log_level level, std::string tag, diff --git a/src/musikbox/app/window/ResourcesWindow.cpp b/src/musikbox/app/window/ResourcesWindow.cpp deleted file mode 100755 index cfe99d9a7..000000000 --- a/src/musikbox/app/window/ResourcesWindow.cpp +++ /dev/null @@ -1,75 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2016 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. -// -////////////////////////////////////////////////////////////////////////////// - -#include "stdafx.h" - -#include "ResourcesWindow.h" - -#include -#include - -#include - -#include - -using namespace musik::box; -using namespace cursespp; - -#define BYTES_PER_MEGABYTE 1048576.0f - -ResourcesWindow::ResourcesWindow(IWindow *parent) -: Window(parent) { - this->systemInfo = SystemInfo::Create(); -} - -ResourcesWindow::~ResourcesWindow() { - delete this->systemInfo; -} - -void ResourcesWindow::Update() { - this->Clear(); - - double virtualMemoryUsed = (double) systemInfo->GetUsedVirtualMemory() / BYTES_PER_MEGABYTE; - double physicalMemoryUsed = (double) systemInfo->GetUsedPhysicalMemory() / BYTES_PER_MEGABYTE; - double cpuUsage = (double) systemInfo->GetCpuUsage(); - - wprintw( - this->GetContent(), - "cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)", - cpuUsage, - virtualMemoryUsed, - physicalMemoryUsed); - - this->Repaint(); -} diff --git a/src/musikbox/app/window/ResourcesWindow.h b/src/musikbox/app/window/ResourcesWindow.h deleted file mode 100755 index 98004db25..000000000 --- a/src/musikbox/app/window/ResourcesWindow.h +++ /dev/null @@ -1,60 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2016 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. -// -////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include -#include - -#include - -namespace musik { - namespace box { - class ResourcesWindow : - public cursespp::Window -#if (__clang_major__ == 7 && __clang_minor__ == 3) - , public std::enable_shared_from_this -#endif - { - public: - ResourcesWindow(cursespp::IWindow *parent = NULL); - virtual ~ResourcesWindow(); - - virtual void Update(); - - private: - SystemInfo* systemInfo; - }; - } -} diff --git a/src/musikbox/musikbox.vcxproj b/src/musikbox/musikbox.vcxproj index 564335587..4e2737933 100755 --- a/src/musikbox/musikbox.vcxproj +++ b/src/musikbox/musikbox.vcxproj @@ -135,12 +135,10 @@ - - @@ -192,12 +190,10 @@ - - @@ -248,4 +244,4 @@ - \ No newline at end of file +