From 45cdeb96952f2b5ca8488a7c0a817813bd5ce3ca Mon Sep 17 00:00:00 2001 From: Lukasz Mastalerz Date: Wed, 29 Nov 2023 12:30:17 +0100 Subject: [PATCH] [BH-1795] Add noises to relaxation Adding color of noises to Relaxation --- harmony_changelog.md | 1 + image/system_a/data/lang/Deutsch.json | 1 + image/system_a/data/lang/English.json | 1 + image/system_a/data/lang/Espanol.json | 1 + image/system_a/data/lang/Francais.json | 1 + image/system_a/data/lang/Polski.json | 1 + products/BellHybrid/CMakeLists.txt | 4 +-- .../ApplicationBellRelaxation.cpp | 1 + .../data/RelaxationCommon.hpp | 1 + .../model/RelaxationSongsModel.cpp | 32 ++++++++++++------- .../model/RelaxationSongsModel.hpp | 4 +++ .../model/RelaxationSongsRepository.cpp | 3 ++ .../widgets/RelaxationItem.hpp | 2 ++ .../widgets/RelaxationListView.cpp | 14 +++++--- products/BellHybrid/assets/assets_common.json | 8 ++++- products/BellHybrid/paths/Paths.cpp | 4 +++ products/BellHybrid/paths/Paths.hpp | 1 + 17 files changed, 61 insertions(+), 19 deletions(-) diff --git a/harmony_changelog.md b/harmony_changelog.md index afff2a5aef166e531f87f0fc262d24abfa257b9c..be59d5c9b6730584e0f9c34dd90ed9039e54d487 100644 --- a/harmony_changelog.md +++ b/harmony_changelog.md @@ -13,6 +13,7 @@ * Added brightness fade in functionality * Added labels to Relaxation * Added date format setting +* Added colors of noise to Relaxation ### Changed / Improved * Optimize the way Relaxation is loading music files diff --git a/image/system_a/data/lang/Deutsch.json b/image/system_a/data/lang/Deutsch.json index 490997d4b10fb283d60072f15bca6ce3c34148f1..f17c5feef89831a591368ce52cb046d4762074c4 100644 --- a/image/system_a/data/lang/Deutsch.json +++ b/image/system_a/data/lang/Deutsch.json @@ -60,6 +60,7 @@ "app_bell_relaxation_once_description": "das Lied wird einmal abgespielt", "app_bell_relaxation_timer_title": "Timer", "app_bell_relaxation_sounds": "Entspannende Sounds", + "app_bell_relaxation_noises": "Farben des Rauschens", "app_bell_relaxation_uploaded_sounds": "Hochgeladene Sounds", "app_bell_settings_about": "Information", "app_bell_settings_about_info_text": "www.mudita.com", diff --git a/image/system_a/data/lang/English.json b/image/system_a/data/lang/English.json index 40b0343199eb4db4a558377f1fb640861d5204a6..7fc33c44760ebf1578497aa76e06e20748169748 100644 --- a/image/system_a/data/lang/English.json +++ b/image/system_a/data/lang/English.json @@ -93,6 +93,7 @@ "app_bell_relaxation_once_description": "the song will play one time", "app_bell_relaxation_timer_title": "Relaxation time", "app_bell_relaxation_sounds": "Relaxation sounds", + "app_bell_relaxation_noises": "Colors of noise", "app_bell_relaxation_uploaded_sounds": "Uploaded sounds", "app_bell_reset_message": "Resetting Mudita
Harmony
", "app_bell_settings_about": "About", diff --git a/image/system_a/data/lang/Espanol.json b/image/system_a/data/lang/Espanol.json index ed3009251a2afcd68fb4d08896bd804f1c5b3e21..a81cb59ef42cf9943fcccdc1b74acf90ccc4ac58 100644 --- a/image/system_a/data/lang/Espanol.json +++ b/image/system_a/data/lang/Espanol.json @@ -59,6 +59,7 @@ "app_bell_relaxation_once_description": "la canci\u00f3n se reproducir\u00e1 una vez", "app_bell_relaxation_timer_title": "Temporizador", "app_bell_relaxation_sounds": "Sonidos de relajaci\u00f3n", + "app_bell_relaxation_noises": "Colores de ruido", "app_bell_relaxation_uploaded_sounds": "Sonidos subidos", "app_bell_settings_about": "Informaci\u00f3n", "app_bell_settings_about_info_text": "www.mudita.com", diff --git a/image/system_a/data/lang/Francais.json b/image/system_a/data/lang/Francais.json index 53e66a41ce42ae7b89bc43adfbd08ad123e4a5ad..c6547198ab4105df144d81c8860377b52f647e8d 100644 --- a/image/system_a/data/lang/Francais.json +++ b/image/system_a/data/lang/Francais.json @@ -61,6 +61,7 @@ "app_bell_relaxation_once_description": "le morceau sera lu une fois", "app_bell_relaxation_timer_title": "Minuterie", "app_bell_relaxation_sounds": "Sons de relaxation", + "app_bell_relaxation_noises": "Couleurs du bruit", "app_bell_relaxation_uploaded_sounds": "Sons t\u00e9l\u00e9charg\u00e9s", "app_bell_settings_about": "\u00c0 propos", "app_bell_settings_about_info_text": "www.mudita.com", diff --git a/image/system_a/data/lang/Polski.json b/image/system_a/data/lang/Polski.json index 522063df700d938e54f42621b7d24ea72e88de42..cd8e2410c144ea02db5b999d7337d8240f399ca0 100644 --- a/image/system_a/data/lang/Polski.json +++ b/image/system_a/data/lang/Polski.json @@ -60,6 +60,7 @@ "app_bell_relaxation_once_description": "utw\u00f3r zostanie odtworzony jeden raz", "app_bell_relaxation_timer_title": "Wy\u0142\u0105cznik czasowy", "app_bell_relaxation_sounds": "D\u017Awi\u0119ki relaksacji", + "app_bell_relaxation_noises": "Kolory szum\u00f3w", "app_bell_relaxation_uploaded_sounds": "Przes\u0142ane d\u017awi\u0119ki", "app_bell_settings_about": "O produkcie", "app_bell_settings_about_info_text": "www.mudita.com", diff --git a/products/BellHybrid/CMakeLists.txt b/products/BellHybrid/CMakeLists.txt index 0db747951ca97b1c4c390daeeb286aef88920f74..d099dd1b6471b0ff9f003df6f8a3ec7e21973cca 100644 --- a/products/BellHybrid/CMakeLists.txt +++ b/products/BellHybrid/CMakeLists.txt @@ -143,14 +143,14 @@ download_asset_release_json(json-common-target ${CMAKE_CURRENT_SOURCE_DIR}/assets/assets_common.json ${SYSROOT_PATH}/system_a/ MuditaOSPublicAssets - 0.0.18 + 0.0.19 ${MUDITA_CACHE_DIR} ) download_asset_release_json(json-community-target ${CMAKE_CURRENT_SOURCE_DIR}/assets/assets_community.json ${SYSROOT_PATH}/system_a/ MuditaOSPublicAssets - 0.0.18 + 0.0.19 ${MUDITA_CACHE_DIR} ) download_asset_json(json-rt1051-target diff --git a/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp b/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp index 298d5eb96284ac433443016644847a0e59961b95..ebc9a7ecc46d49f7999c56d221ac809a712d755e 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp @@ -80,6 +80,7 @@ namespace app windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) { const auto paths = std::map{ {relaxation::MusicType::Relaxation, paths::audio::proprietary() / paths::audio::relaxation()}, + {relaxation::MusicType::ColorsOfNoise, paths::audio::proprietary() / paths::audio::colorOfNoises()}, {relaxation::MusicType::User, paths::audio::userApp() / paths::audio::relaxation()}}; auto soundsRepository = std::make_unique(app, paths); diff --git a/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationCommon.hpp b/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationCommon.hpp index 5a58bb609efca500db66682f638c7e99c8bc27b6..eebf3f48a51d658a2a17a1a240a8847065076269 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationCommon.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationCommon.hpp @@ -10,6 +10,7 @@ namespace app::relaxation enum class MusicType { Relaxation, + ColorsOfNoise, User, Undefined }; diff --git a/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.cpp b/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.cpp index 8de40d3395700e1e05298e7042f9305f3a0aecc5..55a89aa354e0725e46462036b97f990bc86910ab 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.cpp @@ -20,7 +20,6 @@ namespace } // namespace namespace app::relaxation { - RelaxationSongsProvider::RelaxationSongsProvider(ApplicationCommon *app) : DatabaseModel(app) {} @@ -49,24 +48,33 @@ namespace app::relaxation { return style::bell_options::h + 2 * style::bell_options::option_margin; } + bool RelaxationSongsModel::nextRecordExist(gui::Order order) + { + const auto getOppositeOrder = [order]() { + return order == gui::Order::Next ? gui::Order::Previous : gui::Order::Next; + }; + + auto exist = getRecord(order) != nullptr; + getRecord(getOppositeOrder()); + return exist; + } gui::ListItem *RelaxationSongsModel::getItem(gui::Order order) { const auto sound = getRecord(order); if (!sound) { return nullptr; } + auto item = + gui::option::RelaxationOption{getTypeFromPath(sound->fileInfo.path, songsRepository->getPathPrefixes()), + sound->tags.title, + [=]([[maybe_unused]] gui::Item &item) { + activateCallback(*sound); + return true; + }, + [=]([[maybe_unused]] gui::Item &item) { return true; }, + nullptr}; - auto item = new gui::option::RelaxationOption( - getTypeFromPath(sound->fileInfo.path, songsRepository->getPathPrefixes()), - sound->tags.title, - [=]([[maybe_unused]] gui::Item &item) { - activateCallback(*sound); - return true; - }, - [=]([[maybe_unused]] gui::Item &item) { return true; }, - nullptr); - - return item->build(); + return item.build(); } void RelaxationSongsModel::requestRecords(std::uint32_t offset, std::uint32_t limit) { diff --git a/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.hpp b/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.hpp index 79779716fa07456fc4c02c6196978d204ca957c5..5565b35cae21d82ab1191a5278140209754f4b03 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.hpp @@ -14,6 +14,7 @@ namespace app::relaxation public gui::ListItemProvider { public: + virtual ~RelaxationSongsProvider() = default; using OnActivateCallback = std::function; explicit RelaxationSongsProvider(ApplicationCommon *application); @@ -32,6 +33,8 @@ namespace app::relaxation [[nodiscard]] bool updateRecords(std::vector records) override; public: + virtual ~RelaxationSongsModel() = default; + explicit RelaxationSongsModel(ApplicationCommon *application, std::unique_ptr soundsRepository); @@ -45,5 +48,6 @@ namespace app::relaxation void createData(OnActivateCallback activateCallback) override; void updateRecordsCount(); + bool nextRecordExist(gui::Order order); }; } // namespace app::relaxation diff --git a/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.cpp b/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.cpp index c8649de871bdbf610a977940b30e1dc277736011..47c2f19e86296236589af26ec4bb6acbcc27366f 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.cpp @@ -118,6 +118,9 @@ namespace app::relaxation } for (const auto &[type, filesCount] : filesPerType) { + if (filesCount == 0) { + continue; + } totalFilesCount += filesCount; if (const auto newOffset = calculateOffset(offset, filesCount); newOffset != offset) { offset = newOffset; diff --git a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationItem.hpp b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationItem.hpp index 409985e3dd380dae06c5bfdd4d2032512f0feab1..c3bd44d5bcafa10377dbc7806303cb3c422bd3fb 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationItem.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationItem.hpp @@ -15,6 +15,7 @@ namespace gui public: explicit RelaxationItem(app::relaxation::MusicType musicType); + virtual ~RelaxationItem() = default; app::relaxation::MusicType getMusicType(); }; @@ -22,5 +23,6 @@ namespace gui { public: explicit RelaxationMarkerItem(const UTF8 &labelText); + virtual ~RelaxationMarkerItem() = default; }; } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationListView.cpp b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationListView.cpp index 1c7f9d2efb029bedd8b9821ebc38af3d8ce99779..59fefa96a0db7d7d6d50168622a10e504f4a8aad 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationListView.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationListView.cpp @@ -3,6 +3,7 @@ #include "RelaxationListView.hpp" #include "widgets/RelaxationOption.hpp" +#include "model/RelaxationSongsModel.hpp" #include "RelaxationItem.hpp" #include @@ -13,6 +14,7 @@ namespace const std::map typeToLabel{ {app::relaxation::MusicType::Relaxation, "app_bell_relaxation_sounds"}, + {app::relaxation::MusicType::ColorsOfNoise, "app_bell_relaxation_noises"}, {app::relaxation::MusicType::User, "app_bell_relaxation_uploaded_sounds"}}; gui::RelaxationMarkerItem *createMarkerItem(app::relaxation::MusicType musicType) @@ -41,7 +43,6 @@ namespace gui currentPageSize = 0; itemsOnPage = 0; labelAdded = false; - getSlotsLeft(); ListItem *item = nullptr; while ((item = provider->getItem(getOrderFromDirection())) != nullptr) { @@ -56,6 +57,9 @@ namespace gui itemsOnPage++; } else { + // Add invisible item to list to avoid memory leak + item->setVisible(false); + body->addWidget(item); break; } /* If direction is bottom-to-top, add label mark after adding relaxation item. */ @@ -108,13 +112,15 @@ namespace gui } } else { - const auto nextItemExist = provider->getItem(getOrderFromDirection()) != nullptr; + const auto relaxationProvider = dynamic_cast(provider.get()); + if (relaxationProvider == nullptr) { + break; + } + const auto nextItemExist = relaxationProvider->nextRecordExist(getOrderFromDirection()); if (!nextItemExist && getSlotsLeft() == 1) { body->addWidget(createMarkerItem(currentType)); updateState(currentType); } - // Setting back iterator to proper position - provider->getItem(getOppositeOrderFromDirection()); } break; } diff --git a/products/BellHybrid/assets/assets_common.json b/products/BellHybrid/assets/assets_common.json index 46d41f98585b67d1bd3803232faf3391777c1d7b..a342761747314c456a66f9600b1fedc33e6d61f1 100644 --- a/products/BellHybrid/assets/assets_common.json +++ b/products/BellHybrid/assets/assets_common.json @@ -105,6 +105,12 @@ {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/evening_reminder/Evening_Horizon.mp3", "output": "assets/audio/evening_reminder/Evening_Horizon.mp3"}, {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/evening_reminder/Evolving_Dusk.mp3", "output": "assets/audio/evening_reminder/Evolving_Dusk.mp3"}, {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/evening_reminder/Melodic_Mirth.mp3", "output": "assets/audio/evening_reminder/Melodic_Mirth.mp3"}, - {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/evening_reminder/Twilight_Gleam.mp3", "output": "assets/audio/evening_reminder/Twilight_Gleam.mp3"} + {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/evening_reminder/Twilight_Gleam.mp3", "output": "assets/audio/evening_reminder/Twilight_Gleam.mp3"}, + + {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/noises/Brown_Noise.mp3", "output": "assets/audio/noises/Brown_Noise.mp3"}, + {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/noises/Pink_Noise.mp3", "output": "assets/audio/noises/Pink_Noise.mp3"}, + {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/noises/White_Noise.mp3", "output": "assets/audio/noises/White_Noise.mp3"}, + {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/noises/Grey_Noise.mp3", "output": "assets/audio/noises/Grey_Noise.mp3"}, + {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/noises/Ultra_Noise.mp3", "output": "assets/audio/noises/Ultra_Noise.mp3"} ] } diff --git a/products/BellHybrid/paths/Paths.cpp b/products/BellHybrid/paths/Paths.cpp index 589cefc4935c745688ad26c41768dc78ecc6a49c..be2c41d933a24cd48ccfb2ffe5bb6ce0ff499678 100644 --- a/products/BellHybrid/paths/Paths.cpp +++ b/products/BellHybrid/paths/Paths.cpp @@ -36,3 +36,7 @@ std::filesystem::path paths::audio::meditation() noexcept { return "meditation"; } +std::filesystem::path paths::audio::colorOfNoises() noexcept +{ + return "noises"; +} diff --git a/products/BellHybrid/paths/Paths.hpp b/products/BellHybrid/paths/Paths.hpp index 6ec1e33a31ff9cb2e8fdb7621871f174b7a64690..368df087267ace5438cc190734fcd79b3d47fa0b 100644 --- a/products/BellHybrid/paths/Paths.hpp +++ b/products/BellHybrid/paths/Paths.hpp @@ -17,6 +17,7 @@ namespace paths std::filesystem::path bedtimeReminder() noexcept; std::filesystem::path relaxation() noexcept; std::filesystem::path meditation() noexcept; + std::filesystem::path colorOfNoises() noexcept; } // namespace audio } // namespace paths