M module-apps/Application.cpp => module-apps/Application.cpp +8 -14
@@ 101,17 101,6 @@ namespace app
std::chrono::milliseconds{key_timer_ms},
[this](sys::Timer &) { longPressTimerCallback(); });
- phoneModeObserver->connect(this);
- phoneModeObserver->subscribe(
- [=](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) {
- using namespace gui::popup;
- if (getCurrentWindow()->getName() == window::phone_modes_window) {
- updateWindow(window::phone_modes_window, std::make_unique<gui::ModesPopupData>(phoneMode));
- }
- else {
- switchWindow(window::phone_modes_window, std::make_unique<gui::ModesPopupData>(phoneMode));
- }
- });
connect(typeid(AppRefreshMessage),
[this](sys::Message *msg) -> sys::MessagePointer { return handleAppRefresh(msg); });
connect(sevm::BatteryStatusChangeMessage(), [&](sys::Message *) { return handleBatteryStatusChange(); });
@@ 121,7 110,6 @@ namespace app
[&](sys::Message *msg) -> sys::MessagePointer { return handleUpdateWindow(msg); });
// handle phone mode changes
- bus.channels.push_back(sys::BusChannel::PhoneModeChanges);
phoneModeObserver->connect(this);
phoneModeObserver->subscribe(
[&](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) {
@@ 552,7 540,7 @@ namespace app
{
using namespace gui::popup;
const auto msg = static_cast<AudioKeyPressedResponse *>(msgl);
- if (!msg->muted) {
+ if (msg->showPopup == AudioKeyPressedResponse::ShowPopup::True) {
LOG_INFO("Playback: %s, volume: %s",
audio::str(msg->context.second).c_str(),
std::to_string(msg->volume).c_str());
@@ 691,7 679,13 @@ namespace app
return;
}
- refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
+ using namespace gui::popup;
+ if (getCurrentWindow()->getName() == window::phone_modes_window) {
+ updateWindow(window::phone_modes_window, std::make_unique<gui::ModesPopupData>(mode));
+ }
+ else {
+ switchWindow(window::phone_modes_window, std::make_unique<gui::ModesPopupData>(mode));
+ }
}
void Application::attachPopups(const std::vector<gui::popup::ID> &popupsList)
M module-apps/application-meditation/windows/MeditationTimerWindow.cpp => module-apps/application-meditation/windows/MeditationTimerWindow.cpp +19 -18
@@ 59,27 59,28 @@ void MeditationTimerWindow::destroyInterface()
void MeditationTimerWindow::onBeforeShow(ShowMode mode, SwitchData *data)
{
auto timerData = dynamic_cast<MeditationTimerData *>(data);
- assert(timerData);
- setVisiblePreparation();
- meditationTime = timerData->getMeditationTime();
- meditationIntervalPeriod = timerData->getMeditationIntervals();
-
- auto onPreparation = [&]() -> void {
- setVisibleRunning();
- auto onMeditationEnd = [&]() -> void {
- setVisibleMeditationEnd();
+ if (timerData != nullptr) {
+ setVisiblePreparation();
+ meditationTime = timerData->getMeditationTime();
+ meditationIntervalPeriod = timerData->getMeditationIntervals();
+
+ auto onPreparation = [&]() -> void {
+ setVisibleRunning();
+ auto onMeditationEnd = [&]() -> void {
+ setVisibleMeditationEnd();
+ application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
+ };
+ timer->registerTimeoutCallback(onMeditationEnd);
+ timer->reset(meditationTime, meditationIntervalPeriod);
+ timer->start();
application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
};
- timer->registerTimeoutCallback(onMeditationEnd);
- timer->reset(meditationTime, meditationIntervalPeriod);
- timer->start();
- application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
- };
- timer->registerTimeoutCallback(onPreparation);
- timer->setCounterVisible(timerData->isCounterEnabled());
- timer->reset(timerData->getPreparationTime());
- timer->start();
+ timer->registerTimeoutCallback(onPreparation);
+ timer->setCounterVisible(timerData->isCounterEnabled());
+ timer->reset(timerData->getPreparationTime());
+ timer->start();
+ }
}
auto MeditationTimerWindow::onInput(const InputEvent &inputEvent) -> bool
M module-audio/Audio/Audio.cpp => module-audio/Audio/Audio.cpp +2 -0
@@ 124,6 124,7 @@ namespace audio
LOG_ERROR("Operation STOP failure: %s", audio::str(retStop).c_str());
}
+ muted = Muted::False;
auto ret = Operation::Create(Operation::Type::Idle);
if (ret) {
currentState = State::Idle;
@@ 154,6 155,7 @@ namespace audio
audio::RetCode Audio::Mute()
{
+ muted = Muted::True;
return SetOutputVolume(0);
}
M module-audio/Audio/Audio.hpp => module-audio/Audio/Audio.hpp +12 -0
@@ 19,6 19,12 @@ namespace audio
class Audio
{
+ enum class Muted : bool
+ {
+ True,
+ False
+ };
+
public:
enum class State
{
@@ 61,6 67,11 @@ namespace audio
return currentOperation->GetInputGain();
}
+ [[nodiscard]] auto IsMuted() const noexcept
+ {
+ return muted == Muted::True;
+ }
+
const Operation &GetCurrentOperation() const
{
// currentOperation always exists - null pattern design
@@ 103,6 114,7 @@ namespace audio
private:
void UpdateProfiles();
+ Muted muted = Muted::False;
AudioSinkState audioSinkState;
std::shared_ptr<BluetoothStreamData> btData;
M module-services/service-audio/ServiceAudio.cpp => module-services/service-audio/ServiceAudio.cpp +18 -19
@@ 410,8 410,7 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleSendEvent(std::shared_
}
std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector<audio::PlaybackType> &stopTypes,
- const Token &token,
- bool &muted)
+ const Token &token)
{
std::vector<std::pair<Token, audio::RetCode>> retCodes;
@@ 439,7 438,6 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector
for (auto &input : audioMux.GetAllInputs()) {
const auto ¤tOperation = input.audio->GetCurrentOperation();
if (std::find(stopTypes.begin(), stopTypes.end(), currentOperation.GetPlaybackType()) != stopTypes.end()) {
- muted = true;
auto t = input.token;
retCodes.emplace_back(t, stopInput(&input));
}
@@ 464,19 462,15 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector
return std::make_unique<AudioStopResponse>(audio::RetCode::Success, token);
}
-std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector<audio::PlaybackType> &stopTypes,
- const Token &token)
-{
- bool muted = false;
- return HandleStop(stopTypes, token, muted);
-}
-
void ServiceAudio::HandleNotification(const AudioNotificationMessage::Type &type, const Token &token)
{
if (type == AudioNotificationMessage::Type::EndOfFile) {
auto input = audioMux.GetInput(token);
if (input && ShouldLoop((*input)->audio->GetCurrentOperationPlaybackType())) {
(*input)->audio->Start();
+ if ((*input)->audio->IsMuted()) {
+ (*input)->audio->Mute();
+ }
}
else {
auto newMsg = std::make_shared<AudioStopRequest>(token);
@@ 492,9 486,6 @@ void ServiceAudio::HandleNotification(const AudioNotificationMessage::Type &type
auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr<AudioKeyPressedResponse>
{
-
- // mute if 0 and return with parameter shouldn't popup
- bool muted = false;
auto context = getCurrentContext();
const auto currentVolume =
@@ 503,13 494,13 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr<AudioKeyP
if (isSystemSound(context.second)) {
// active system sounds can be only muted, no volume control is possible
if (step < 0) {
- HandleStop({context.second}, Token(), muted);
- if (muted) {
- return std::make_unique<AudioKeyPressedResponse>(audio::RetCode::Success, 0, muted, context);
- }
+ MuteCurrentOperation();
+ return std::make_unique<AudioKeyPressedResponse>(
+ audio::RetCode::Success, 0, AudioKeyPressedResponse::ShowPopup::False, context);
}
else {
- return std::make_unique<AudioKeyPressedResponse>(audio::RetCode::Success, currentVolume, muted, context);
+ return std::make_unique<AudioKeyPressedResponse>(
+ audio::RetCode::Success, currentVolume, AudioKeyPressedResponse::ShowPopup::False, context);
}
}
@@ 524,7 515,8 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr<AudioKeyP
// update volume of currently active sound
setSetting(Setting::Volume, std::to_string(newVolume));
}
- return std::make_unique<AudioKeyPressedResponse>(audio::RetCode::Success, newVolume, muted, context);
+ return std::make_unique<AudioKeyPressedResponse>(
+ audio::RetCode::Success, newVolume, AudioKeyPressedResponse::ShowPopup::True, context);
}
void ServiceAudio::HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode,
@@ 547,6 539,13 @@ void ServiceAudio::HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode,
}
}
+void ServiceAudio::MuteCurrentOperation()
+{
+ for (auto &input : audioMux.GetAllInputs()) {
+ input.audio->Mute();
+ }
+}
+
bool ServiceAudio::IsBusy()
{
for (auto &input : audioMux.GetAllInputs()) {
M module-services/service-audio/service-audio/AudioMessage.hpp => module-services/service-audio/service-audio/AudioMessage.hpp +9 -4
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 262,14 262,19 @@ class AudioKeyPressedRequest : public AudioMessage
class AudioKeyPressedResponse : public sys::DataMessage
{
public:
+ enum class ShowPopup : bool
+ {
+ True,
+ False
+ };
AudioKeyPressedResponse(audio::RetCode retCode,
const audio::Volume &volume,
- const bool muted,
+ const ShowPopup showPopup,
const std::pair<audio::Profile::Type, audio::PlaybackType> &context)
- : sys::DataMessage(MessageType::AudioMessage), volume(volume), muted(muted), context(context)
+ : sys::DataMessage(MessageType::AudioMessage), volume(volume), showPopup(showPopup), context(context)
{}
const audio::Volume volume{};
- const bool muted = false;
+ const ShowPopup showPopup = ShowPopup::False;
std::pair<audio::Profile::Type, audio::PlaybackType> context;
};
M module-services/service-audio/service-audio/ServiceAudio.hpp => module-services/service-audio/service-audio/ServiceAudio.hpp +1 -2
@@ 72,8 72,6 @@ class ServiceAudio : public sys::Service
const std::string = "",
const audio::PlaybackType &playbackType = audio::PlaybackType::None)
-> std::unique_ptr<AudioResponseMessage>;
- auto HandleStop(const std::vector<audio::PlaybackType> &stopTypes, const audio::Token &token, bool &muted)
- -> std::unique_ptr<AudioResponseMessage>;
auto HandleStop(const std::vector<audio::PlaybackType> &stopTypes, const audio::Token &token)
-> std::unique_ptr<AudioResponseMessage>;
auto HandleSendEvent(std::shared_ptr<audio::Event> evt) -> std::unique_ptr<AudioResponseMessage>;
@@ 84,6 82,7 @@ class ServiceAudio : public sys::Service
void HandleNotification(const AudioNotificationMessage::Type &type, const audio::Token &token);
auto HandleKeyPressed(const int step) -> std::unique_ptr<AudioKeyPressedResponse>;
void HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode);
+ void MuteCurrentOperation();
void VibrationUpdate(const audio::PlaybackType &type = audio::PlaybackType::None,
std::optional<audio::AudioMux::Input *> input = std::nullopt);
auto GetVibrationType(const audio::PlaybackType &type) -> VibrationType;