diff --git a/Application/include/utils/NX.hpp b/Application/include/utils/NX.hpp index a269267..f20dc09 100644 --- a/Application/include/utils/NX.hpp +++ b/Application/include/utils/NX.hpp @@ -47,6 +47,9 @@ namespace Utils::NX { // Does nothing if state matches void setCPUBoost(bool); + // Enable/disable low fs priority + void setLowFsPriority(bool); + // Enable/disable 'media playing' flag // Does nothing if state matches void setPlayingMedia(bool); diff --git a/Application/source/Application.cpp b/Application/source/Application.cpp index 07d2bd4..4b38cfe 100644 --- a/Application/source/Application.cpp +++ b/Application/source/Application.cpp @@ -48,7 +48,7 @@ namespace Main { this->setHighlightAnimation(nullptr); this->display->setFadeIn(); this->display->setFadeOut(); - this->display->setShowFPS(true); + // this->display->setShowFPS(true); this->exitPrompt = nullptr; // Setup screens @@ -65,14 +65,14 @@ namespace Main { // Start checking for an update this->hasUpdate_ = false; this->updateThread = std::async(std::launch::async, [this]() { - // Updater updater = Updater(); - // if (updater.needsCheck(updateInterval)) { - // if (updater.checkForUpdate()) { - // this->hasUpdate_ = updater.availableUpdate(); - // } - // } else { - // this->hasUpdate_ = updater.availableUpdate(); - // } + Updater updater = Updater(); + if (updater.needsCheck(updateInterval)) { + if (updater.checkForUpdate()) { + this->hasUpdate_ = updater.availableUpdate(); + } + } else { + this->hasUpdate_ = updater.availableUpdate(); + } }); } diff --git a/Application/source/LibraryScanner.cpp b/Application/source/LibraryScanner.cpp index c3e9f35..c3c239a 100644 --- a/Application/source/LibraryScanner.cpp +++ b/Application/source/LibraryScanner.cpp @@ -4,9 +4,10 @@ #include "LibraryScanner.hpp" #include "Log.hpp" #include "Paths.hpp" -#include "utils/Fs.hpp" +#include "utils/FS.hpp" #include "utils/Image.hpp" #include "utils/MP3.hpp" +#include "utils/NX.hpp" #include "utils/Timer.hpp" #include "utils/Utils.hpp" @@ -101,15 +102,19 @@ LibraryScanner::Status LibraryScanner::parseFileUpdate(const FilePair & file) { LibraryScanner::Status LibraryScanner::processFiles() { // First get all paths within folder along with modified timestamp + Utils::NX::setLowFsPriority(true); std::vector files; - for (auto & entry: std::filesystem::recursive_directory_iterator(this->searchPath)) { - if (entry.path().extension() == ".mp3") { - // Why is this conversion so hard? - auto time = entry.last_write_time(); - auto clock = std::chrono::file_clock::to_sys(time); - unsigned int timestamp = (unsigned int)std::chrono::system_clock::to_time_t(clock); - - files.push_back(FilePair{entry.path().string(), timestamp}); + + if (Utils::Fs::fileExists(this->searchPath)) { + for (auto & entry: std::filesystem::recursive_directory_iterator(this->searchPath)) { + if (entry.path().extension() == ".mp3") { + // Why is this conversion so hard? + auto time = entry.last_write_time(); + auto clock = std::chrono::file_clock::to_sys(time); + unsigned int timestamp = (unsigned int)std::chrono::system_clock::to_time_t(clock); + + files.push_back(FilePair{entry.path().string(), timestamp}); + } } } Log::writeInfo("[SCAN] Found " + std::to_string(files.size()) + " files"); @@ -124,6 +129,7 @@ LibraryScanner::Status LibraryScanner::processFiles() { std::vector< std::pair > tmp = this->database->getAllSongFileInfo(dbOK); if (!dbOK) { Log::writeError("[SCAN] Couldn't read filesystem info from database"); + Utils::NX::setLowFsPriority(false); return Status::ErrDatabase; } for (size_t i = 0; i < tmp.size(); i++) { @@ -167,6 +173,7 @@ LibraryScanner::Status LibraryScanner::processFiles() { // Wait for threads to finish addThread.get(); updateThread.get(); + Utils::NX::setLowFsPriority(false); // Log status Log::writeInfo("[SCAN] Adding " + std::to_string(this->addFiles.size()) + " files"); diff --git a/Application/source/ui/frame/settings/About.cpp b/Application/source/ui/frame/settings/About.cpp index 8626ca0..4050513 100644 --- a/Application/source/ui/frame/settings/About.cpp +++ b/Application/source/ui/frame/settings/About.cpp @@ -57,6 +57,7 @@ namespace Frame::Settings { this->addComment("JSON for Modern C++\nCopyright © 2013-2020 Niels Lohmann\nMIT License\nhttps://github.com/nlohmann/json"); this->addComment("libcURL\nCopyright © 1996-2020 Daniel Stenberg\nMIT/X Derivate License\nhttps://curl.haxx.se"); this->addComment("libmpg123\nLGPL 2.1 License\nhttps://www.mpg123.de"); + this->addComment("libnx\nCopyright © 2017-2020 libnx Authors\nISC License\nhttps://github.com/switchbrew/libnx"); this->addComment("minIni\nCopyright © compuphase\nApache 2 License\nhttps://github.com/compuphase/minIni"); this->addComment("SDL2_gfx Extensions\nCopyright © 2018 Richard T. Russell\nzlib License\nhttps://github.com/rtrussell/BBCSDL"); this->addComment("Splash\nCopyright © 2020 Google\nApache 2 License\nhttps://github.com/tallbl0nde/Splash"); diff --git a/Application/source/ui/frame/settings/SysMP3.cpp b/Application/source/ui/frame/settings/SysMP3.cpp index b26e154..981280f 100644 --- a/Application/source/ui/frame/settings/SysMP3.cpp +++ b/Application/source/ui/frame/settings/SysMP3.cpp @@ -19,6 +19,7 @@ namespace Frame::Settings { this->addButton("Equalizer", [this]() { this->showEqualizer(); }); + this->addComment("Note: There may be a slight delay before any changes take effect."); // Setup overlay this->ovlEQ = new CustomOvl::Equalizer("Equalizer"); diff --git a/Application/source/ui/screen/Update.cpp b/Application/source/ui/screen/Update.cpp index 595bd16..34fc52d 100644 --- a/Application/source/ui/screen/Update.cpp +++ b/Application/source/ui/screen/Update.cpp @@ -300,7 +300,7 @@ namespace Screen { } else { this->presentInfo("Update installed!", "Both the sysmodule and this application will terminate.", [this]() { this->msgbox->close(); - // terminate services + this->app->sysmodule()->terminate(); this->app->exit(true); }); } @@ -347,6 +347,7 @@ namespace Screen { } void Update::onUnload() { + this->thread.get(); this->removeElement(this->bg); this->removeElement(this->icon); this->removeElement(this->container); diff --git a/Application/source/utils/NX.cpp b/Application/source/utils/NX.cpp index a97f9ec..f372f55 100644 --- a/Application/source/utils/NX.cpp +++ b/Application/source/utils/NX.cpp @@ -109,6 +109,10 @@ namespace Utils::NX { boost = enable; } + void setLowFsPriority(bool low) { + fsSetPriority(low ? FsPriority_Background : FsPriority_Normal); + } + static bool media = false; void setPlayingMedia(bool enable) { // Only set if different state diff --git a/Images/.gitignore b/Images/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/Images/screenshots.png b/Images/screenshots.png new file mode 100644 index 0000000..d9cc94d Binary files /dev/null and b/Images/screenshots.png differ diff --git a/Makefile b/Makefile index 5970fce..fac4a48 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ clean: @echo -e '\033[1m>> Application\033[0m' @$(MAKE) -s -C Application/ clean-all @echo -e '\033[1m>> Overlay\033[0m' - @$(MAKE) -C Overlay/ clean + @$(MAKE) -s -C Overlay/ clean @echo -e '\033[1m>> Sysmodule\033[0m' @$(MAKE) -s -C Sysmodule/ clean @echo -e '\033[1m>> SD Card\033[0m' diff --git a/Sysmodule/include/nx/NX.hpp b/Sysmodule/include/nx/NX.hpp index 318e2de..27a34b3 100644 --- a/Sysmodule/include/nx/NX.hpp +++ b/Sysmodule/include/nx/NX.hpp @@ -11,6 +11,11 @@ namespace NX { // Close any started services void stopServices(); + namespace Fs { + // Set whether or not to use a higher priority for fs operations + void setHighPriority(const bool); + }; + namespace Gpio { // Prepare gpio for use bool prepare(); diff --git a/Sysmodule/source/Service.cpp b/Sysmodule/source/Service.cpp index f5c2ca2..d2bf044 100644 --- a/Sysmodule/source/Service.cpp +++ b/Sysmodule/source/Service.cpp @@ -657,6 +657,9 @@ void MainService::ipcThread() { } void MainService::playbackThread() { + // Request a higher priority for FS access + NX::Fs::setHighPriority(true); + while (!this->exit_) { std::unique_lock sMtx(this->sMutex); std::unique_lock sqMtx(this->sqMutex); diff --git a/Sysmodule/source/main.cpp b/Sysmodule/source/main.cpp index 37a2bc4..fe41f08 100644 --- a/Sysmodule/source/main.cpp +++ b/Sysmodule/source/main.cpp @@ -8,7 +8,7 @@ // DB: ~0.5MB // IPC: ~0.2MB // Queue: ~0.2MB -// MP3: ~0.3MB +// MP3: ~0.5MB #define INNER_HEAP_SIZE (size_t)(2 * 1024 * 1024) // It hangs if I don't use C... I wish I knew why! diff --git a/Sysmodule/source/nx/Audio.cpp b/Sysmodule/source/nx/Audio.cpp index deb70a6..de0ac0d 100644 --- a/Sysmodule/source/nx/Audio.cpp +++ b/Sysmodule/source/nx/Audio.cpp @@ -5,8 +5,8 @@ #include "nx/NX.hpp" #include -constexpr size_t bufferSize = 0x3C00; // Size of each buffer (15kB) -constexpr size_t maxBuffers = 4; // Maximum number of buffer slots +constexpr size_t bufferSize = 0xC800; // Size of each buffer (50kB) +constexpr size_t maxBuffers = 6; // Maximum number of buffer slots (50KB * 6 = 300KB) constexpr size_t outputChannels = 2; // Number of channels to output (should always be 2) Audio * Audio::instance = nullptr; // Our singleton instance diff --git a/Sysmodule/source/nx/NX.cpp b/Sysmodule/source/nx/NX.cpp index 1e63076..68ef172 100644 --- a/Sysmodule/source/nx/NX.cpp +++ b/Sysmodule/source/nx/NX.cpp @@ -159,6 +159,12 @@ namespace NX { } } + namespace Fs { + void setHighPriority(const bool b) { + fsSetPriority(b ? FsPriority_Realtime : FsPriority_Normal); + } + }; + namespace Gpio { static bool gpioPrepared = false; // Set true if ready to poll pad static GpioPadSession gpioSession; // Current session used to read pad