From dda9044eb9740ca995139711cd8318815bf88e2a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 20:47:52 -0500 Subject: fix clang++ warning about unused private field in snap.cpp's Sound class --- src/snap.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/snap.cpp') diff --git a/src/snap.cpp b/src/snap.cpp index 25632e9..4a19d6e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -60,7 +60,6 @@ public: m_clock(clock), m_filename(filename), m_volume(volume), - m_duration_minutes(duration_minutes), m_loop(loop), m_canberra_id(get_next_canberra_id()), m_loop_end_time(clock->localtime().add_full(0, 0, 0, 0, duration_minutes, 0.0)) @@ -184,7 +183,6 @@ private: const std::shared_ptr m_clock; const std::string m_filename; const AlarmVolume m_volume; - const int m_duration_minutes; const bool m_loop; const int32_t m_canberra_id; const DateTime m_loop_end_time; -- cgit v1.2.3 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. --- data/com.canonical.indicator.datetime.gschema.xml | 12 +++------- include/datetime/settings-shared.h | 10 -------- include/datetime/settings.h | 2 +- src/exporter.cpp | 26 +------------------- src/settings-live.cpp | 6 ++--- src/snap.cpp | 29 +++++++++++------------ tests/manual-test-snap.cpp | 22 ++++++++++++++++- tests/test-exporter.cpp | 4 ++-- tests/test-settings.cpp | 26 +------------------- 9 files changed, 46 insertions(+), 91 deletions(-) (limited to 'src/snap.cpp') diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index 3e0082d..17a38ed 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -5,13 +5,6 @@ - - - - - - - true @@ -137,8 +130,9 @@ If an alarm doesn't specify its own sound file, this file will be used as the fallback sound. - - 'normal' + + + 50 The alarm's default volume level. The volume at which alarms will be played. diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index bfddd88..23d2e1c 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -30,16 +30,6 @@ typedef enum } TimeFormatMode; -typedef enum -{ - ALARM_VOLUME_VERY_QUIET, - ALARM_VOLUME_QUIET, - ALARM_VOLUME_NORMAL, - ALARM_VOLUME_LOUD, - ALARM_VOLUME_VERY_LOUD -} -AlarmVolume; - #define SETTINGS_INTERFACE "com.canonical.indicator.datetime" #define SETTINGS_SHOW_CLOCK_S "show-clock" #define SETTINGS_TIME_FORMAT_S "time-format" diff --git a/include/datetime/settings.h b/include/datetime/settings.h index a941f05..26d4ed0 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -57,7 +57,7 @@ public: core::Property time_format_mode; core::Property timezone_name; core::Property alarm_sound; - core::Property alarm_volume; + core::Property alarm_volume; core::Property alarm_duration; }; 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; }; diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 90dbe08..cc24a67 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -41,10 +41,29 @@ namespace g_main_loop_quit(static_cast(gloop)); return G_SOURCE_REMOVE; }; + + int volume = 50; + + GOptionEntry entries[] = + { + { "volume", 'v', 0, G_OPTION_ARG_INT, &volume, "Volume level [1..100]", "volume" }, + { NULL } + }; } -int main() +int main(int argc, const char* argv[]) { + GError* error = nullptr; + GOptionContext* context = g_option_context_new(nullptr); + g_option_context_add_main_entries(context, entries, nullptr); + if (!g_option_context_parse(context, &argc, (gchar***)&argv, &error)) + { + g_print("option parsing failed: %s\n", error->message); + exit(1); + } + g_option_context_free(context); + volume = CLAMP(volume, 1, 100); + Appointment a; a.color = "green"; a.summary = "Alarm"; @@ -74,6 +93,7 @@ int main() g_debug("SCHEMA_DIR is %s", SCHEMA_DIR); auto settings = std::make_shared(); + settings->alarm_volume.set(volume); auto timezones = std::make_shared(settings, TIMEZONE_FILE); auto clock = std::make_shared(timezones); Snap snap (clock, settings); diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index 3f502cf..e947740 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -183,7 +183,7 @@ TEST_F(ExporterFixture, AlarmProperties) **** Try changing the Settings -- do the DBus properties change to match it? ***/ - auto expected_volume = ALARM_VOLUME_VERY_LOUD; + auto expected_volume = 1; int expected_duration = 60; const char * expected_sound = "/tmp/foo.wav"; settings->alarm_volume.set(expected_volume); @@ -210,7 +210,7 @@ TEST_F(ExporterFixture, AlarmProperties) **** Try chaning the DBus properties -- do the Settings change to match it? ***/ - expected_volume = ALARM_VOLUME_VERY_QUIET; + expected_volume = 100; expected_duration = 30; expected_sound = "/tmp/bar.wav"; g_object_set(proxy, SOUND_PROP, expected_sound, diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 2b500b2..e4aeef7 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -151,6 +151,7 @@ TEST_F(SettingsFixture, BoolProperties) TEST_F(SettingsFixture, IntProperties) { TestIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); + TestIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); } TEST_F(SettingsFixture, StringProperties) @@ -181,31 +182,6 @@ TEST_F(SettingsFixture, TimeFormatMode) } } -TEST_F(SettingsFixture, AlarmVolume) -{ - const auto key = SETTINGS_ALARM_VOLUME_S; - const AlarmVolume volumes[] = { ALARM_VOLUME_VERY_QUIET, - ALARM_VOLUME_QUIET, - ALARM_VOLUME_NORMAL, - ALARM_VOLUME_LOUD, - ALARM_VOLUME_VERY_LOUD }; - - for(const auto& val : volumes) - { - g_settings_set_enum(m_gsettings, key, val); - EXPECT_EQ(val, m_settings->alarm_volume.get()); - EXPECT_EQ(val, g_settings_get_enum(m_gsettings, key)); - } - - for(const auto& val : volumes) - { - m_settings->alarm_volume.set(val); - EXPECT_EQ(val, m_settings->alarm_volume.get()); - EXPECT_EQ(val, g_settings_get_enum(m_gsettings, key)); - } -} - - namespace { std::vector strv_to_vector(const gchar** strv) -- cgit v1.2.3 From eebf8f911cedf5124ada2f91576f821da6f421b0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 27 Jun 2014 09:46:21 -0500 Subject: use unsigned ints for the alarm volume, duration properties --- ...com.canonical.indicator.datetime.gschema.xml.in | 4 ++-- include/datetime/settings.h | 4 ++-- src/exporter.cpp | 24 ++++++++++++---------- src/settings-live.cpp | 12 +++++------ src/snap.cpp | 18 ++++++++-------- tests/CMakeLists.txt | 4 ++-- tests/test-settings.cpp | 22 ++++++++++---------- 7 files changed, 45 insertions(+), 43 deletions(-) (limited to 'src/snap.cpp') diff --git a/data/com.canonical.indicator.datetime.gschema.xml.in b/data/com.canonical.indicator.datetime.gschema.xml.in index 776f6c7..62b42c1 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml.in +++ b/data/com.canonical.indicator.datetime.gschema.xml.in @@ -130,7 +130,7 @@ If an alarm doesn't specify its own sound file, this file will be used as the fallback sound. - + 50 <_summary>The alarm's default volume level. @@ -138,7 +138,7 @@ The volume at which alarms will be played. - + 30 <_summary>The alarm's duration. diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 26d4ed0..e5f885e 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -57,8 +57,8 @@ public: core::Property time_format_mode; core::Property timezone_name; core::Property alarm_sound; - core::Property alarm_volume; - core::Property alarm_duration; + core::Property alarm_volume; + core::Property alarm_duration; }; } // namespace datetime diff --git a/src/exporter.cpp b/src/exporter.cpp index a5a059d..e2b60f2 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -107,20 +107,22 @@ private: G_CALLBACK(on_gobject_notify_string), &p); // when the Settings changes, update the GObject - p.changed().connect([o, propname](const std::string& s){ - g_object_set(o, propname, s.c_str(), nullptr); + p.changed().connect([o, propname](const std::string& val){ + g_object_set(o, propname, val.c_str(), nullptr); }); } static void - on_gobject_notify_int(GObject* o, GParamSpec* pspec, gpointer p) + on_gobject_notify_uint(GObject* o, GParamSpec* pspec, gpointer p) { - int val = 0; + uint val = 0; g_object_get (o, pspec->name, &val, nullptr); - static_cast*>(p)->set(val); + static_cast*>(p)->set(val); } - void bind_int_property(gpointer o, const char* propname, core::Property& p) + void bind_uint_property(gpointer o, + const char* propname, + core::Property& p) { // initialize the GObject property from the Settings g_object_set(o, propname, p.get(), nullptr); @@ -128,19 +130,19 @@ private: // 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_int), &p); + G_CALLBACK(on_gobject_notify_uint), &p); // when the Settings changes, update the GObject - p.changed().connect([o, propname](int i){ - g_object_set(o, propname, i, nullptr); + p.changed().connect([o, propname](unsigned int val){ + g_object_set(o, propname, val, nullptr); }); } void alarm_properties_init() { - bind_int_property(m_alarm_props, "duration", m_settings->alarm_duration); - bind_int_property(m_alarm_props, "default-volume", m_settings->alarm_volume); + bind_uint_property(m_alarm_props, "duration", m_settings->alarm_duration); + bind_uint_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 369d2d6..71bbd96 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -123,12 +123,12 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str()); }); - alarm_volume.changed().connect([this](int value){ - g_settings_set_int(m_settings, SETTINGS_ALARM_VOLUME_S, value); + alarm_volume.changed().connect([this](unsigned int value){ + g_settings_set_uint(m_settings, SETTINGS_ALARM_VOLUME_S, value); }); - alarm_duration.changed().connect([this](int value){ - g_settings_set_int(m_settings, SETTINGS_ALARM_DURATION_S, value); + alarm_duration.changed().connect([this](unsigned int value){ + g_settings_set_uint(m_settings, SETTINGS_ALARM_DURATION_S, value); }); } @@ -229,12 +229,12 @@ void LiveSettings::update_alarm_sound() void LiveSettings::update_alarm_volume() { - alarm_volume.set(g_settings_get_int(m_settings, SETTINGS_ALARM_VOLUME_S)); + alarm_volume.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_VOLUME_S)); } void LiveSettings::update_alarm_duration() { - alarm_duration.set(g_settings_get_int(m_settings, SETTINGS_ALARM_DURATION_S)); + alarm_duration.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_DURATION_S)); } /*** diff --git a/src/snap.cpp b/src/snap.cpp index 40fd541..eab7001 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -54,8 +54,8 @@ public: Sound(const std::shared_ptr& clock, const std::string& filename, - int volume, - int duration_minutes, + unsigned int volume, + unsigned int duration_minutes, bool loop): m_clock(clock), m_filename(filename), @@ -132,9 +132,9 @@ private: g_clear_pointer(&props, ca_proplist_destroy); } - static float get_gain_level(int volume) + static float get_gain_level(unsigned int volume) { - const int clamped_volume = CLAMP(volume, 1, 100); + const unsigned int clamped_volume = CLAMP(volume, 1, 100); /* This range isn't set in stone -- arrived at from manual tests on Nextus 4 */ @@ -181,7 +181,7 @@ private: const std::shared_ptr m_clock; const std::string m_filename; - const int m_volume; + const unsigned int m_volume; const bool m_loop; const int32_t m_canberra_id; const DateTime m_loop_end_time; @@ -194,8 +194,8 @@ 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 int v) {m_volume = v;} - void set_duration_minutes(int i) {m_duration_minutes=i;} + void set_volume(const unsigned int v) {m_volume = v;} + void set_duration_minutes(int unsigned i) {m_duration_minutes=i;} void set_looping(bool b) {m_looping=b;} Sound* operator()() { @@ -209,8 +209,8 @@ public: private: std::shared_ptr m_clock; std::string m_filename; - int m_volume = 50; - int m_duration_minutes = 30; + unsigned int m_volume = 50; + unsigned int m_duration_minutes = 30; bool m_looping = true; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 26b326d..958e1cc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,8 +21,8 @@ execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compil OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_command (OUTPUT gschemas.compiled - DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.gschema.xml - COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.datetime.gschema.xml + COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) # look for headers in our src dir, and also in the directories where we autogenerate files... diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index e4aeef7..44a0252 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -101,26 +101,26 @@ protected: g_clear_pointer(&tmp, g_free); } - void TestIntProperty(core::Property& property, const gchar* key) + void TestUIntProperty(core::Property& property, const gchar* key) { - EXPECT_EQ(g_settings_get_int(m_gsettings, key), property.get()); + EXPECT_EQ(g_settings_get_uint(m_gsettings, key), property.get()); - int expected_values[] = { 1, 2, 3 }; + unsigned int expected_values[] = { 1, 2, 3 }; // modify GSettings and confirm that the new value is propagated - for(const int& expected_value : expected_values) + for(const auto& expected_value : expected_values) { - g_settings_set_int(m_gsettings, key, expected_value); + g_settings_set_uint(m_gsettings, key, expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); } // modify the property and confirm that the new value is propagated - for(const int& expected_value : expected_values) + for(const auto& expected_value : expected_values) { property.set(expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); } } }; @@ -148,10 +148,10 @@ TEST_F(SettingsFixture, BoolProperties) TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S); } -TEST_F(SettingsFixture, IntProperties) +TEST_F(SettingsFixture, UIntProperties) { - TestIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); - TestIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); + TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); + TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); } TEST_F(SettingsFixture, StringProperties) -- cgit v1.2.3