M products/BellHybrid/apps/application-bell-meditation-timer/MeditationTimer.cpp => products/BellHybrid/apps/application-bell-meditation-timer/MeditationTimer.cpp +4 -2
@@ 18,6 18,7 @@
#include "presenter/StatisticsPresenter.hpp"
#include <common/models/TimeModel.hpp>
+#include <common/models/AudioModel.hpp>
#include <common/windows/BellFinishedWindow.hpp>
#include <common/windows/SessionPausedWindow.hpp>
@@ 38,8 39,9 @@ namespace app
return ret;
}
+ audioModel = std::make_unique<AudioModel>(this);
chimeIntervalModel = std::make_unique<meditation::models::ChimeInterval>(this);
- chimeVolumeModel = std::make_unique<meditation::models::ChimeVolume>(this);
+ chimeVolumeModel = std::make_unique<meditation::models::ChimeVolume>(*audioModel);
startDelayModel = std::make_unique<meditation::models::StartDelay>(this);
createUserInterface();
@@ 58,7 60,7 @@ namespace app
windowsFactory.attach(meditation::SettingsWindow::name,
[this](ApplicationCommon *app, const std::string &name) {
auto presenter = std::make_unique<app::meditation::SettingsPresenter>(
- app, *chimeIntervalModel, *chimeVolumeModel, *startDelayModel);
+ app, *chimeIntervalModel, *chimeVolumeModel, *startDelayModel, *audioModel);
return std::make_unique<meditation::SettingsWindow>(app, std::move(presenter));
});
M products/BellHybrid/apps/application-bell-meditation-timer/data/Contract.hpp => products/BellHybrid/apps/application-bell-meditation-timer/data/Contract.hpp +1 -0
@@ 23,5 23,6 @@ namespace app::meditation::contract
virtual void saveData() = 0;
virtual void eraseProviderData() = 0;
virtual void handleEnter() = 0;
+ virtual void exitWithoutSave() = 0;
};
} // namespace app::meditation::contract
M products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp => products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp +1 -0
@@ 13,4 13,5 @@ namespace app::meditation
}; // namespace windows
constexpr auto meditationDBRecordName = "MeditationTimer";
+ inline constexpr auto meditationAudioPath = "assets/audio/meditation/Meditation_Gong.mp3";
} // namespace app::meditation
M products/BellHybrid/apps/application-bell-meditation-timer/include/application-bell-meditation-timer/MeditationTimer.hpp => products/BellHybrid/apps/application-bell-meditation-timer/include/application-bell-meditation-timer/MeditationTimer.hpp +2 -0
@@ 4,6 4,7 @@
#pragma once
#include <Application.hpp>
+#include <common/models/AbstractAudioModel.hpp>
namespace app::meditation::models
{
@@ 43,6 44,7 @@ namespace app
std::unique_ptr<app::meditation::models::ChimeInterval> chimeIntervalModel;
std::unique_ptr<app::meditation::models::ChimeVolume> chimeVolumeModel;
std::unique_ptr<app::meditation::models::StartDelay> startDelayModel;
+ std::unique_ptr<AbstractAudioModel> audioModel;
};
template <> struct ManifestTraits<MeditationTimer>
M products/BellHybrid/apps/application-bell-meditation-timer/models/ChimeVolume.cpp => products/BellHybrid/apps/application-bell-meditation-timer/models/ChimeVolume.cpp +12 -3
@@ 8,11 8,20 @@ namespace app::meditation::models
void ChimeVolume::setValue(std::uint8_t value)
{
- /// Dummy implementation.
+ audioModel.setVolume(value, AbstractAudioModel::PlaybackType::Meditation, {});
}
std::uint8_t ChimeVolume::getValue() const
{
- /// Dummy implementation
- return 5;
+ return defaultValue;
+ }
+
+ void ChimeVolume::restoreDefault()
+ {
+ setValue(defaultValue);
+ }
+
+ ChimeVolume::ChimeVolume(AbstractAudioModel &audioModel) : audioModel{audioModel}
+ {
+ defaultValue = audioModel.getVolume(AbstractAudioModel::PlaybackType::Meditation).value_or(0);
}
} // namespace app::meditation::models
M products/BellHybrid/apps/application-bell-meditation-timer/models/ChimeVolume.hpp => products/BellHybrid/apps/application-bell-meditation-timer/models/ChimeVolume.hpp +8 -2
@@ 4,15 4,21 @@
#pragma once
#include <common/models/SettingsModel.hpp>
+#include <common/models/AudioModel.hpp>
namespace app::meditation::models
{
- class ChimeVolume : public gui::SettingsModel<std::uint8_t>
+ class ChimeVolume : public gui::AbstractSettingsModel<std::uint8_t>
{
public:
- using SettingsModel::SettingsModel;
+ explicit ChimeVolume(AbstractAudioModel &audioModel);
void setValue(std::uint8_t value) override;
std::uint8_t getValue() const override;
+ void restoreDefault() override;
+
+ private:
+ AbstractAudioModel &audioModel;
+ std::uint8_t defaultValue;
};
} // namespace app::meditation::models
M products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp +33 -2
@@ 3,6 3,7 @@
#include "SettingsPresenter.hpp"
#include "MeditationMainWindow.hpp"
+#include "MeditationCommon.hpp"
#include "models/ChimeInterval.hpp"
#include "models/ChimeVolume.hpp"
@@ 60,10 61,12 @@ namespace app::meditation
SettingsPresenter::SettingsPresenter(app::ApplicationCommon *app,
models::ChimeInterval &chimeIntervalModel,
models::ChimeVolume &chimeVolumeModel,
- models::StartDelay &startDelayModel)
+ models::StartDelay &startDelayModel,
+ AbstractAudioModel &audioModel)
: application{app}, chimeIntervalModel{chimeIntervalModel}, chimeVolumeModel{chimeVolumeModel},
- startDelayModel{startDelayModel}
+ startDelayModel{startDelayModel}, audioModel{audioModel}
{
+
auto chimeInterval =
new list_items::Fraction{list_items::Fraction::spinner_type::range{{1, 1}, {1, 2}, {1, 3}, {1, 4}},
chimeIntervalModel,
@@ 82,6 85,23 @@ namespace app::meditation
listItemsProvider =
std::make_shared<BellListItemProvider>(BellListItemProvider::Items{startDelay, chimeInterval, chimeVolume});
+ chimeVolume->onEnter = [this]() {
+ this->audioModel.play(purefs::dir::getCurrentOSPath() / meditationAudioPath,
+ AbstractAudioModel::PlaybackType::Meditation,
+ {});
+ };
+
+ chimeVolume->onExit = [this]() { stopSound(); };
+
+ chimeVolume->set_on_value_change_cb([this](const auto &val) {
+ this->audioModel.setVolume(val, AbstractAudioModel::PlaybackType::Meditation, {});
+ if (this->audioModel.hasPlaybackFinished()) {
+ this->audioModel.play(purefs::dir::getCurrentOSPath() / meditationAudioPath,
+ AbstractAudioModel::PlaybackType::Meditation,
+ {});
+ }
+ });
+
for (auto &item : listItemsProvider->getListItems()) {
item->setValue();
}
@@ 94,6 114,7 @@ namespace app::meditation
}
void SettingsPresenter::saveData()
{
+ stopSound();
for (auto &item : listItemsProvider->getListItems()) {
item->getValue();
}
@@ 114,4 135,14 @@ namespace app::meditation
BellFinishedWindowData::Factory::create("circle_success_big", MeditationMainWindow::defaultName));
}
+ void SettingsPresenter::stopSound()
+ {
+ audioModel.stopPlayedByThis({});
+ }
+
+ void SettingsPresenter::exitWithoutSave()
+ {
+ chimeVolumeModel.restoreDefault();
+ }
+
} // namespace app::meditation
M products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.hpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.hpp +7 -1
@@ 5,6 5,8 @@
#include "data/Contract.hpp"
#include <common/BellListItemProvider.hpp>
+#include <common/models/AbstractAudioModel.hpp>
+#include <common/SoundsRepository.hpp>
#include <memory>
namespace app
@@ 27,18 29,22 @@ namespace app::meditation
SettingsPresenter(app::ApplicationCommon *app,
models::ChimeInterval &chimeIntervalModel,
models::ChimeVolume &chimeVolumeModel,
- models::StartDelay &startDelayModel);
+ models::StartDelay &startDelayModel,
+ AbstractAudioModel &audioModel);
void loadData() override;
void saveData() override;
auto getPagesProvider() const -> std::shared_ptr<gui::ListItemProvider> override;
void eraseProviderData() override;
void handleEnter() override;
+ void exitWithoutSave() override;
private:
+ void stopSound();
ApplicationCommon *application{};
models::ChimeInterval &chimeIntervalModel;
models::ChimeVolume &chimeVolumeModel;
models::StartDelay &startDelayModel;
+ AbstractAudioModel &audioModel;
std::shared_ptr<BellListItemProvider> listItemsProvider;
};
} // namespace app::meditation
M products/BellHybrid/apps/application-bell-meditation-timer/presenter/StatisticsPresenter.cpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/StatisticsPresenter.cpp +3 -0
@@ 19,4 19,7 @@ namespace app::meditation
}
void StatisticsPresenter::handleEnter()
{}
+
+ void StatisticsPresenter::exitWithoutSave()
+ {}
} // namespace app::meditation
M products/BellHybrid/apps/application-bell-meditation-timer/presenter/StatisticsPresenter.hpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/StatisticsPresenter.hpp +1 -0
@@ 17,6 17,7 @@ namespace app::meditation
void saveData() override;
void eraseProviderData() override;
void handleEnter() override;
+ void exitWithoutSave() override;
private:
};
M products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.cpp => products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.cpp +1 -2
@@ 16,7 16,6 @@ namespace
inline constexpr auto meditationProgressTimerName = "MeditationProgressTimer";
inline constexpr std::chrono::seconds baseTick{1};
inline constexpr auto meditationProgressMode = app::ProgressCountdownMode::Increasing;
- inline constexpr auto meditationAudioPath = "assets/audio/meditation/Meditation_Gong.mp3";
using namespace app::meditationStyle;
@@ 187,7 186,7 @@ namespace gui
void MeditationRunningWindow::playGong()
{
auto msg = std::make_shared<service::AudioStartPlaybackRequest>(
- purefs::dir::getCurrentOSPath() / meditationAudioPath, audio::PlaybackType::Meditation);
+ purefs::dir::getCurrentOSPath() / app::meditation::meditationAudioPath, audio::PlaybackType::Meditation);
application->bus.sendUnicast(std::move(msg), service::audioServiceName);
}
} // namespace gui
M products/BellHybrid/apps/application-bell-meditation-timer/windows/SettingsWindow.cpp => products/BellHybrid/apps/application-bell-meditation-timer/windows/SettingsWindow.cpp +3 -0
@@ 56,6 56,9 @@ namespace app::meditation
presenter->handleEnter();
return true;
}
+ if (inputEvent.isShortRelease(KeyCode::KEY_RF)) {
+ presenter->exitWithoutSave();
+ }
return AppWindow::onInput(inputEvent);
}
M products/BellHybrid/apps/common/include/common/models/AbstractAudioModel.hpp => products/BellHybrid/apps/common/include/common/models/AbstractAudioModel.hpp +2 -1
@@ 28,7 28,8 @@ namespace app
Snooze,
Alarm,
PreWakeup,
- Bedtime
+ Bedtime,
+ Meditation
};
virtual ~AbstractAudioModel() noexcept = default;
M products/BellHybrid/apps/common/src/AudioModel.cpp => products/BellHybrid/apps/common/src/AudioModel.cpp +2 -0
@@ 22,6 22,8 @@ namespace
return audio::PlaybackType::PreWakeUp;
case Type::Bedtime:
return audio::PlaybackType::Bedtime;
+ case Type::Meditation:
+ return audio::PlaybackType::Meditation;
default:
return audio::PlaybackType::Alarm;
}