From 8bb09ca0225886c18e351d3c6156521ed479edd1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 22:13:13 -0500 Subject: Design prefers to have a volume slider instead of presets, so remove the AlarmVolume enum and replace it with an int range. --- src/exporter.cpp | 26 +------------------------- src/settings-live.cpp | 6 +++--- src/snap.cpp | 29 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/exporter.cpp b/src/exporter.cpp index 3ba95bf..a5a059d 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -137,34 +137,10 @@ private: } - static void - on_gobject_notify_volume(GObject* o, GParamSpec* pspec, gpointer p) - { - int val = 0; - g_object_get (o, pspec->name, &val, nullptr); - static_cast*>(p)->set(AlarmVolume(val)); - } - void bind_volume_property(gpointer o, const char* propname, core::Property& p) - { - // initialize the GObject property from the Settings - g_object_set(o, propname, (int)p.get(), nullptr); - - // when the GObject changes, update the Settings - const std::string notify_propname = std::string("notify::") + propname; - g_signal_connect(o, notify_propname.c_str(), - G_CALLBACK(on_gobject_notify_volume), &p); - - // when the Settings changes, update the GObject - p.changed().connect([o, propname](AlarmVolume i){ - g_object_set(o, propname, (int)i, nullptr); - }); - } - - void alarm_properties_init() { bind_int_property(m_alarm_props, "duration", m_settings->alarm_duration); - bind_volume_property(m_alarm_props, "default-volume", m_settings->alarm_volume); + bind_int_property(m_alarm_props, "default-volume", m_settings->alarm_volume); bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound); } diff --git a/src/settings-live.cpp b/src/settings-live.cpp index e34ace1..369d2d6 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -123,8 +123,8 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str()); }); - alarm_volume.changed().connect([this](AlarmVolume value){ - g_settings_set_enum(m_settings, SETTINGS_ALARM_VOLUME_S, gint(value)); + alarm_volume.changed().connect([this](int value){ + g_settings_set_int(m_settings, SETTINGS_ALARM_VOLUME_S, value); }); alarm_duration.changed().connect([this](int value){ @@ -229,7 +229,7 @@ void LiveSettings::update_alarm_sound() void LiveSettings::update_alarm_volume() { - alarm_volume.set((AlarmVolume)g_settings_get_enum(m_settings, SETTINGS_ALARM_VOLUME_S)); + alarm_volume.set(g_settings_get_int(m_settings, SETTINGS_ALARM_VOLUME_S)); } void LiveSettings::update_alarm_duration() diff --git a/src/snap.cpp b/src/snap.cpp index 4a19d6e..40fd541 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -54,7 +54,7 @@ public: Sound(const std::shared_ptr& clock, const std::string& filename, - AlarmVolume volume, + int volume, int duration_minutes, bool loop): m_clock(clock), @@ -132,18 +132,17 @@ private: g_clear_pointer(&props, ca_proplist_destroy); } - static float get_gain_level(const AlarmVolume volume) + static float get_gain_level(int volume) { - /* These values aren't set in stone -- - arrived at from from manual tests on Nexus 4 */ - switch (volume) - { - case ALARM_VOLUME_VERY_QUIET: return -8; - case ALARM_VOLUME_QUIET: return -4; - case ALARM_VOLUME_LOUD: return 4; - case ALARM_VOLUME_VERY_LOUD: return 8; - default: return 0; - } + const int clamped_volume = CLAMP(volume, 1, 100); + + /* This range isn't set in stone -- + arrived at from manual tests on Nextus 4 */ + constexpr float gain_low = -10; + constexpr float gain_high = 10; + + constexpr float gain_range = gain_high - gain_low; + return gain_low + (gain_range * (clamped_volume / 100.0f)); } static void on_done_playing(ca_context*, uint32_t, int rv, void* gself) @@ -182,7 +181,7 @@ private: const std::shared_ptr m_clock; const std::string m_filename; - const AlarmVolume m_volume; + const int m_volume; const bool m_loop; const int32_t m_canberra_id; const DateTime m_loop_end_time; @@ -195,7 +194,7 @@ class SoundBuilder public: void set_clock(const std::shared_ptr& c) {m_clock = c;} void set_filename(const std::string& s) {m_filename = s;} - void set_volume(const AlarmVolume v) {m_volume = v;} + void set_volume(const int v) {m_volume = v;} void set_duration_minutes(int i) {m_duration_minutes=i;} void set_looping(bool b) {m_looping=b;} @@ -210,7 +209,7 @@ public: private: std::shared_ptr m_clock; std::string m_filename; - AlarmVolume m_volume = ALARM_VOLUME_NORMAL; + int m_volume = 50; int m_duration_minutes = 30; bool m_looping = true; }; -- cgit v1.2.3