~aleteoryx/muditaos

2ee37c8f0875f7d2a7e5bcaf4713da4253001f31 — Lefucjusz 1 year, 7 months ago 70d3ba4
[BH-1934] Add different sound for the end of meditation

Added different sound for the end of
meditation session than the one played
at the beginning and at fixed intervals.
M harmony_changelog.md => harmony_changelog.md +1 -0
@@ 7,6 7,7 @@

### Added
* Added custom alarms functionality
* Added unique sound to indicate the meditation session has ended.

### Changed / Improved
* Updated button handling during pre-wake up

M products/BellHybrid/CMakeLists.txt => products/BellHybrid/CMakeLists.txt +2 -2
@@ 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.23
                            0.0.25
                            ${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.23
                            0.0.25
                            ${MUDITA_CACHE_DIR}
    )
download_asset_json(json-rt1051-target

M products/BellHybrid/apps/application-bell-meditation-timer/MeditationTimer.cpp => products/BellHybrid/apps/application-bell-meditation-timer/MeditationTimer.cpp +1 -1
@@ 78,7 78,7 @@ namespace app
    void MeditationTimer::createUserInterface()
    {
        windowsFactory.attach(meditation::MeditationMainWindow::defaultName,
                              [this](ApplicationCommon *app, const std::string &name) {
                              [](ApplicationCommon *app, const std::string &name) {
                                  return std::make_unique<meditation::MeditationMainWindow>(app);
                              });


M products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp => products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp +7 -3
@@ 14,13 14,17 @@ namespace app::meditation
        inline constexpr auto meditationCountdown  = "MeditationCountdown";
        inline constexpr auto meditationProgress   = "MeditationProgress";
        inline constexpr auto meditationLowBattery = "MeditationLowBatteryWindow";
    }; // namespace windows
    } // namespace windows

    constexpr auto meditationDBRecordName = "MeditationTimer";
    inline constexpr auto meditationDBRecordName = "MeditationTimer";

    inline std::filesystem::path getMeditationAudioPath()
    inline std::filesystem::path getMeditationGongSoundPath()
    {
        return paths::audio::proprietary() / paths::audio::meditation() / "Meditation_Gong.mp3";
    }

    inline std::filesystem::path getMeditationEndSoundPath()
    {
        return paths::audio::proprietary() / paths::audio::meditation() / "Meditation_End.mp3";
    }
} // namespace app::meditation

M products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.cpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.cpp +29 -12
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "MeditationTimer.hpp"


@@ 10,13 10,15 @@
#include <common/LanguageUtils.hpp>
#include <common/models/TimeModel.hpp>
#include <common/windows/BellFinishedWindow.hpp>
#include <audio/AudioMessage.hpp>
#include <service-db/Settings.hpp>

namespace
{
    constexpr std::chrono::minutes emptyValue{0};
    constexpr std::chrono::seconds endWindowTimeout{6};

    std::chrono::seconds to_interval(const double ratio, std::chrono::minutes total_duration)
    std::chrono::seconds to_interval(double ratio, std::chrono::minutes total_duration)
    {
        const long interval = std::chrono::seconds{total_duration}.count() * ratio;
        return std::chrono::seconds{interval};


@@ 36,7 38,7 @@ namespace app::meditation
        duration = std::chrono::minutes{
            utils::getNumericValue<int>(settings->getValue(meditationDBRecordName, settings::SettingsScope::AppLocal))};

        interval = to_interval(chimeIntervalModel.getValue().to_double(), duration);
        interval = to_interval(this->chimeIntervalModel.getValue().to_double(), duration);
    }

    void MeditationProgressPresenter::setTimer(std::unique_ptr<app::TimerWithCallbacks> &&_timer)


@@ 53,6 55,11 @@ namespace app::meditation
        getView()->setTime(timeModel->getCurrentTime());
    }

    bool MeditationProgressPresenter::isTimerStopped()
    {
        return timer->isStopped();
    }

    void MeditationProgressPresenter::start()
    {
        static_cast<app::Application *>(app)->suspendIdleTimer();


@@ 65,11 72,6 @@ namespace app::meditation
        finish();
    }

    bool MeditationProgressPresenter::isTimerStopped()
    {
        return timer->isStopped();
    }

    void MeditationProgressPresenter::pause()
    {
        timer->stop();


@@ 118,6 120,25 @@ namespace app::meditation
                                                         endWindowTimeout));
    }

    void MeditationProgressPresenter::onBeforeShow()
    {
        getView()->setTimeFormat(timeModel->getTimeFormat());
    }

    void MeditationProgressPresenter::playGongSound()
    {
        auto msg = std::make_shared<service::AudioStartPlaybackRequest>(app::meditation::getMeditationGongSoundPath(),
                                                                        audio::PlaybackType::Meditation);
        app->bus.sendUnicast(std::move(msg), service::audioServiceName);
    }

    void MeditationProgressPresenter::playEndSound()
    {
        auto msg = std::make_shared<service::AudioStartPlaybackRequest>(app::meditation::getMeditationEndSoundPath(),
                                                                        audio::PlaybackType::Meditation);
        app->bus.sendUnicast(std::move(msg), service::audioServiceName);
    }

    void MeditationProgressPresenter::onProgressFinished()
    {
        getView()->progressFinished();


@@ 131,10 152,6 @@ namespace app::meditation
        }
    }

    void MeditationProgressPresenter::onBeforeShow()
    {
        getView()->setTimeFormat(timeModel->getTimeFormat());
    }
    void MeditationProgressPresenter::addMeditationEntry(const std::chrono::minutes elapsed)
    {
        if (elapsed > std::chrono::minutes::zero()) {

M products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.hpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.hpp +21 -18
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 48,6 48,7 @@ namespace app::meditation
            virtual void pause()                                            = 0;
            virtual void resume()                                           = 0;
        };

        class Presenter : public BasePresenter<MeditationProgressContract::View>
        {
          public:


@@ 61,28 62,13 @@ namespace app::meditation
            virtual void abandon()                                                  = 0;
            virtual void finish()                                                   = 0;
            virtual void onBeforeShow()                                             = 0;
            virtual void playGongSound()                                            = 0;
            virtual void playEndSound()                                             = 0;
        };
    };

    class MeditationProgressPresenter : public MeditationProgressContract::Presenter
    {
      private:
        app::ApplicationCommon *app  = nullptr;
        settings::Settings *settings = nullptr;
        std::unique_ptr<app::TimerWithCallbacks> timer;
        std::unique_ptr<AbstractTimeModel> timeModel;
        models::ChimeInterval &chimeIntervalModel;
        models::Statistics &statisticsModel;
        std::chrono::minutes duration;
        std::chrono::seconds interval;

        static constexpr auto endWindowTimeout = std::chrono::seconds{5};

        void onProgressFinished();
        void onIntervalReached();

        void addMeditationEntry(std::chrono::minutes elapsed);

      public:
        MeditationProgressPresenter(app::ApplicationCommon *app,
                                    settings::Settings *settings,


@@ 100,5 86,22 @@ namespace app::meditation
        void abandon() override;
        void finish() override;
        void onBeforeShow() override;
        void playGongSound() override;
        void playEndSound() override;

      private:
        app::ApplicationCommon *app{nullptr};
        settings::Settings *settings{nullptr};
        std::unique_ptr<app::TimerWithCallbacks> timer;
        std::unique_ptr<AbstractTimeModel> timeModel;
        models::ChimeInterval &chimeIntervalModel;
        models::Statistics &statisticsModel;
        std::chrono::minutes duration;
        std::chrono::seconds interval;

        void onProgressFinished();
        void onIntervalReached();

        void addMeditationEntry(std::chrono::minutes elapsed);
    };
} // namespace app::meditation

M products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp +1 -1
@@ 87,7 87,7 @@ namespace app::meditation

        auto playSound = [this, chimeVolume]() {
            this->audioModel.setVolume(chimeVolume->value(), AbstractAudioModel::PlaybackType::Meditation);
            this->audioModel.play(getMeditationAudioPath(), AbstractAudioModel::PlaybackType::Meditation, {});
            this->audioModel.play(getMeditationGongSoundPath(), AbstractAudioModel::PlaybackType::Meditation, {});
        };

        chimeVolume->onEnter = playSound;

M products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.cpp => products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.cpp +7 -13
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "MeditationTimer.hpp"


@@ 6,10 6,11 @@
#include "MeditationRunningWindow.hpp"
#include "MeditationStyle.hpp"

#include <audio/AudioMessage.hpp>
#include <apps-common/widgets/BellBaseLayout.hpp>
#include <apps-common/widgets/ProgressTimerWithBarGraphAndCounter.hpp>
#include <purefs/filesystem_paths.hpp>
#include <apps-common/widgets/BarGraph.hpp>
#include <common/widgets/BellStatusClock.hpp>
#include <gui/widgets/Icon.hpp>

namespace
{


@@ 95,7 96,7 @@ namespace gui
        updateTime();

        if (mode == ShowMode::GUI_SHOW_INIT) {
            playGong();
            presenter->playGongSound();
            presenter->start();
        }
    }


@@ 174,18 175,11 @@ namespace gui

    void MeditationRunningWindow::intervalTimeout()
    {
        playGong();
        presenter->playGongSound();
    }

    void MeditationRunningWindow::endSession()
    {
        playGong();
    }

    void MeditationRunningWindow::playGong()
    {
        auto msg = std::make_shared<service::AudioStartPlaybackRequest>(app::meditation::getMeditationAudioPath(),
                                                                        audio::PlaybackType::Meditation);
        application->bus.sendUnicast(std::move(msg), service::audioServiceName);
        presenter->playEndSound();
    }
} // namespace gui

M products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.hpp => products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.hpp +12 -16
@@ 1,21 1,19 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Application.hpp>
#include <AppWindow.hpp>
#include <InputEvent.hpp>
#include <Text.hpp>
#include <apps-common/widgets/BarGraph.hpp>
#include <apps-common/widgets/TimeFixedWidget.hpp>
#include <common/widgets/BellStatusClock.hpp>
#include <gui/widgets/Icon.hpp>

#include "MeditationProgressPresenter.hpp"

namespace gui
{
    class ArcProgressBar;
    class BellStatusClock;
    class Icon;
    class TimeFixedWidget;

    class MeditationRunningWindow : public AppWindow, public app::meditation::MeditationProgressContract::View
    {
      public:


@@ 23,7 21,6 @@ namespace gui
            app::ApplicationCommon *app,
            std::unique_ptr<app::meditation::MeditationProgressContract::Presenter> &&windowPresenter);

        // virtual methods
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        bool onInput(const InputEvent &inputEvent) override;
        void buildInterface() override;


@@ 34,11 31,11 @@ namespace gui

      private:
        std::unique_ptr<app::meditation::MeditationProgressContract::Presenter> presenter;
        gui::VBox *mainVBox           = nullptr;
        gui::ArcProgressBar *progress = nullptr;
        gui::TimeFixedWidget *timer   = nullptr;
        gui::Icon *icon               = nullptr;
        gui::BellStatusClock *clock   = nullptr;
        VBox *mainVBox{nullptr};
        ArcProgressBar *progress{nullptr};
        TimeFixedWidget *timer{nullptr};
        Icon *icon{nullptr};
        gui::BellStatusClock *clock{nullptr};

        void setTime(std::time_t newTime) override;
        void setTimeFormat(utils::time::Locale::TimeFormat fmt) override;


@@ 47,8 44,7 @@ namespace gui
        void buildLayout();
        void configureTimer();

        void endSession();
        void intervalTimeout();
        void playGong();
        void endSession();
    };
} // namespace gui

M products/BellHybrid/assets/assets_common.json => products/BellHybrid/assets/assets_common.json +1 -0
@@ 85,6 85,7 @@
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/bg_sounds/Under_the_Water.mp3", "output": "assets/audio/relaxation/Under_the_Water.mp3"},
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/bg_sounds/Woodland_Ambiance.mp3", "output": "assets/audio/relaxation/Woodland_Ambiance.mp3"},
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/meditation/Meditation_Gong.mp3", "output": "assets/audio/meditation/Meditation_Gong.mp3"},
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/meditation/Meditation_End.mp3", "output": "assets/audio/meditation/Meditation_End.mp3"},
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/prewakeup/Joyful_Awakening.mp3", "output": "assets/audio/prewakeup/Joyful_Awakening.mp3"},
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/prewakeup/Morning_Spirit.mp3", "output": "assets/audio/prewakeup/Morning_Spirit.mp3"},
        {"name": "release_audio.tgz", "tarfile" :"./image/assets/audio/bell/prewakeup/Radiant_Morning.mp3", "output": "assets/audio/prewakeup/Radiant_Morning.mp3"},