#include <sound_manager.h>
-#define RETURN_ON_ERROR(status) do { \
- if (status != SOUND_MANAGER_ERROR_NONE) { \
- ERROR("Sound manager error %d", status); \
- return true; \
- } \
+#define RETURN_ON_ERROR(status) do { \
+ if (status != SOUND_MANAGER_ERROR_NONE) { \
+ ERROR("Sound manager error %d", status); \
+ return true; \
+ } \
} while (false)
-template <typename DerivedType>
-class VolumeControlActivity : public Activity, private RegisterActivity<DerivedType>
+#define RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(status) do { \
+ if (status != SOUND_MANAGER_ERROR_NONE) { \
+ if (status == SOUND_MANAGER_ERROR_NO_PLAYING_SOUND) \
+ DEBUG("Sound isn't playing on any channel"); \
+ else \
+ ERROR("sound_manager_get_current_sound_type error: %d", status); \
+ return soundType; \
+ } \
+ } while (false)
+
+template <typename DerivedType, bool bindable>
+class VolumeControlActivity : public Activity, private RegisterActivity<DerivedType, bindable>
{
public:
constexpr static const char *activityType = DerivedType::activityType;
int volume = 0;
int maxVolume = 0;
int minVolume = 0;
+ sound_type_e soundType = getSoundType();
- RETURN_ON_ERROR(sound_manager_get_max_volume(DerivedType::soundType, &maxVolume));
- RETURN_ON_ERROR(sound_manager_get_volume(DerivedType::soundType, &volume));
+ RETURN_ON_ERROR(sound_manager_get_max_volume(soundType, &maxVolume));
+ RETURN_ON_ERROR(sound_manager_get_volume(soundType, &volume));
volume = utils::clamp(volume + DerivedType::step, minVolume, maxVolume);
- RETURN_ON_ERROR(sound_manager_set_volume(DerivedType::soundType, volume));
+ RETURN_ON_ERROR(sound_manager_set_volume(soundType, volume));
return true;
}
+ virtual sound_type_e getSoundType() const
+ {
+ return DerivedType::soundType;
+ }
+
};
-class IncreaseMediaVolumeActivity : public VolumeControlActivity<IncreaseMediaVolumeActivity>
+class IncreaseMediaVolumeActivity : public VolumeControlActivity<IncreaseMediaVolumeActivity, false>
{
public:
static constexpr const char *activityType = "INCREASE_MEDIA_VOLUME";
static constexpr const sound_type_e soundType = SOUND_TYPE_MEDIA;
};
-class DecreaseMediaVolumeActivity : public VolumeControlActivity<DecreaseMediaVolumeActivity>
+class DecreaseMediaVolumeActivity : public VolumeControlActivity<DecreaseMediaVolumeActivity, false>
{
public:
static constexpr const char *activityType = "DECREASE_MEDIA_VOLUME";
static constexpr const sound_type_e soundType = SOUND_TYPE_MEDIA;
};
-class IncreaseRingtoneVolumeActivity : public VolumeControlActivity<IncreaseRingtoneVolumeActivity>
+class IncreaseRingtoneVolumeActivity : public VolumeControlActivity<IncreaseRingtoneVolumeActivity, false>
{
public:
static constexpr const char *activityType = "INCREASE_RINGTONE_VOLUME";
static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
};
-class DecreaseRingtoneVolumeActivity : public VolumeControlActivity<DecreaseRingtoneVolumeActivity>
+class DecreaseRingtoneVolumeActivity : public VolumeControlActivity<DecreaseRingtoneVolumeActivity, false>
{
public:
static constexpr const char *activityType = "DECREASE_RINGTONE_VOLUME";
static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
};
-class IncreaseNotificationsVolumeActivity : public VolumeControlActivity<IncreaseNotificationsVolumeActivity>
+class IncreaseNotificationsVolumeActivity : public VolumeControlActivity<IncreaseNotificationsVolumeActivity, false>
{
public:
static constexpr const char *activityType = "INCREASE_NOTIFICATIONS_VOLUME";
static constexpr const sound_type_e soundType = SOUND_TYPE_NOTIFICATION;
};
-class DecreaseNotificationsVolumeActivity : public VolumeControlActivity<DecreaseNotificationsVolumeActivity>
+class DecreaseNotificationsVolumeActivity : public VolumeControlActivity<DecreaseNotificationsVolumeActivity, false>
{
public:
static constexpr const char *activityType = "DECREASE_NOTIFICATIONS_VOLUME";
static constexpr const int step = -1;
static constexpr const sound_type_e soundType = SOUND_TYPE_NOTIFICATION;
+};
+
+class IncreaseVolumeActivity : public VolumeControlActivity<IncreaseVolumeActivity, true>
+{
+public:
+ sound_type_e getSoundType() const override
+ {
+ sound_type_e type;
+ RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(sound_manager_get_current_sound_type(&type));
+ return type;
+ }
+
+ static constexpr const char *activityType = "INCREASE_VOLUME";
+ static constexpr const int step = 1;
+ static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
+};
+
+class DecreaseVolumeActivity : public VolumeControlActivity<DecreaseVolumeActivity, true>
+{
+public:
+ sound_type_e getSoundType() const override
+ {
+ sound_type_e type;
+ RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(sound_manager_get_current_sound_type(&type));
+ return type;
+ }
+
+ static constexpr const char *activityType = "DECREASE_VOLUME";
+ static constexpr const int step = -1;
+ static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
};
\ No newline at end of file