aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharles kerr <charlesk@canonical.com>2015-12-19 17:56:59 -0600
committercharles kerr <charlesk@canonical.com>2015-12-19 17:56:59 -0600
commit6aa814370aab377943bd109875e8c0ae1bdcdab9 (patch)
treeb305d4784f5edf69dba328fb14c5a57f41e9e4a3
parent4b695bacf20b7247f6b16483ede5e5d8b51dd355 (diff)
downloadayatana-indicator-sound-6aa814370aab377943bd109875e8c0ae1bdcdab9.tar.gz
ayatana-indicator-sound-6aa814370aab377943bd109875e8c0ae1bdcdab9.tar.bz2
ayatana-indicator-sound-6aa814370aab377943bd109875e8c0ae1bdcdab9.zip
move loudness warning's enabled & decibels from volume-control-pulse to options
-rw-r--r--src/CMakeLists.txt8
-rw-r--r--src/options-gsettings.vala104
-rw-r--r--src/options.vala40
-rw-r--r--src/service.vala6
-rw-r--r--src/volume-control-pulse.vala37
-rw-r--r--src/volume-control.vala3
-rw-r--r--src/volume-warning.vala37
7 files changed, 175 insertions, 60 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4ff5646..a0f9d05 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -54,18 +54,22 @@ vala_add(indicator-sound-service
)
vala_add(indicator-sound-service
options.vala
+ DEPENDS
+ volume-control
+ volume-control-pulse
)
vala_add(indicator-sound-service
options-gsettings.vala
DEPENDS
options
+ volume-control-pulse
volume-control
- volume-control-pulse
)
vala_add(indicator-sound-service
volume-control.vala
DEPENDS
options
+ volume-control-pulse
)
vala_add(indicator-sound-service
volume-control-pulse.vala
@@ -77,6 +81,7 @@ vala_add(indicator-sound-service
volume-warning.vala
DEPENDS
options
+ volume-control-pulse
volume-control
)
vala_add(indicator-sound-service
@@ -127,6 +132,7 @@ vala_add(indicator-sound-service
media-player
volume-control
options
+ volume-control-pulse
)
vala_add(indicator-sound-service
accounts-service-user.vala
diff --git a/src/options-gsettings.vala b/src/options-gsettings.vala
new file mode 100644
index 0000000..a524390
--- /dev/null
+++ b/src/options-gsettings.vala
@@ -0,0 +1,104 @@
+/*
+ * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*-
+ * Copyright 2015 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+using PulseAudio;
+
+public class IndicatorSound.OptionsGSettings : Options
+{
+ public OptionsGSettings() {
+ init_max_volume();
+ init_loud_volume();
+ }
+
+ ~OptionsGSettings() {
+ }
+
+ private Settings _settings = new Settings ("com.canonical.indicator.sound");
+ private Settings _shared_settings = new Settings ("com.ubuntu.sound");
+
+ /** MAX VOLUME PROPERTY **/
+
+ private void init_max_volume() {
+ _settings.changed["normal-volume-decibels"].connect(() => update_max_volume());
+ _settings.changed["amplified-volume-decibels"].connect(() => update_max_volume());
+ _shared_settings.changed["allow-amplified-volume"].connect(() => update_max_volume());
+ update_max_volume();
+ }
+ private void update_max_volume () {
+ set_max_volume_(calculate_max_volume());
+ }
+ protected void set_max_volume_ (double vol) {
+ if (max_volume != vol) {
+ debug("changing max_volume from %f to %f", this.max_volume, vol);
+ max_volume = vol;
+ }
+ }
+ private double calculate_max_volume () {
+ unowned string decibel_key = _shared_settings.get_boolean("allow-amplified-volume")
+ ? "amplified-volume-decibels"
+ : "normal-volume-decibels";
+ var volume_dB = _settings.get_double(decibel_key);
+ var volume_sw = PulseAudio.Volume.sw_from_dB (volume_dB);
+ return VolumeControlPulse.volume_to_double (volume_sw);
+ }
+
+
+ /** LOUD VOLUME **/
+
+ private PulseAudio.Volume _loud_volume;
+
+ public override PulseAudio.Volume loud_volume() {
+ return _loud_volume;
+ }
+
+ private bool _loud_volume_warning_enabled;
+
+ public override bool loud_volume_warning_enabled() {
+ return _loud_volume_warning_enabled;
+ }
+
+ private string loud_enabled_key = "warning-volume-enabled";
+ private string loud_decibel_key = "warning-volume-decibels";
+
+ private void init_loud_volume() {
+ _settings.changed[loud_enabled_key].connect(() => update_loud_volume());
+ _settings.changed[loud_decibel_key].connect(() => update_loud_volume());
+ update_loud_volume();
+ }
+ private void update_loud_volume() {
+ var changed = false;
+ var vol = PulseAudio.Volume.sw_from_dB (_settings.get_double (loud_decibel_key));
+ var enabled = _settings.get_boolean(loud_enabled_key);
+
+ if (_loud_volume != vol) {
+ debug("updating loud_volume_sw to %d", (int)vol);
+ _loud_volume = vol;
+ changed = true;
+ }
+ if (_loud_volume_warning_enabled != enabled) {
+ debug("updating loud_volume_warning_enabled to %d", (int)enabled);
+ _loud_volume_warning_enabled = enabled;
+ changed = true;
+ }
+
+ if (changed)
+ loud_changed();
+ }
+}
diff --git a/src/options.vala b/src/options.vala
new file mode 100644
index 0000000..5e43025
--- /dev/null
+++ b/src/options.vala
@@ -0,0 +1,40 @@
+/*
+ * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*-
+ * Copyright 2015 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+public abstract class IndicatorSound.Options : Object
+{
+ // MAX VOLUME
+
+ public virtual double max_volume { get; protected set; }
+
+ // LOUD
+
+ public signal void loud_changed();
+ public abstract PulseAudio.Volume loud_volume();
+ public abstract bool loud_volume_warning_enabled();
+
+ public bool is_loud_pulse (PulseAudio.Volume volume) {
+ return loud_volume_warning_enabled() && (volume >= loud_volume());
+ }
+
+ public bool is_loud (VolumeControl.Volume volume) {
+ return is_loud_pulse(VolumeControlPulse.double_to_volume(volume.volume));
+ }
+}
diff --git a/src/service.vala b/src/service.vala
index 3ff7ffb..c94deb2 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -620,10 +620,10 @@ public class IndicatorSound.Service: Object {
&& this.notify_server_supports_actions
&& !this.volume_control.high_volume_approved
&& !ignore_warning_this_time;
- if (waiting_user_approve_warn && volume_control.below_warning_volume) {
+ if (waiting_user_approve_warn && !_options.is_loud(volume_control.volume)) {
volume_control.set_warning_volume();
close_notification(warn_notification);
- }
+ }
if (warn) {
close_notification(info_notification);
if (_pre_warn_volume == null) {
@@ -641,7 +641,7 @@ public class IndicatorSound.Service: Object {
vol.reason = VolumeControl.VolumeReasons.USER_KEYPRESS;
_pre_warn_volume = null;
volume_control.volume = vol;
-
+
waiting_user_approve_warn = false;
});
warn_notification.add_action ("cancel", _("Cancel"), (n, a) => {
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index 6c3ef17..25ba32f 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -723,40 +723,24 @@ public class VolumeControlPulse : VolumeControl
/** HIGH VOLUME PROPERTY **/
- private bool _warning_volume_enabled;
- private double _warning_volume_norms; /* 1.0 == PA_VOLUME_NORM */
private bool _high_volume = false;
- public override bool ignore_high_volume {
- get {
+ public override bool ignore_high_volume {
+ get {
if (_ignore_warning_this_time) {
warning("Ignore");
_ignore_warning_this_time = false;
return true;
}
- return false;
- }
+ return false;
+ }
set { }
}
public override bool high_volume {
get { return this._high_volume; }
private set { this._high_volume = value; }
}
- public override bool below_warning_volume {
- get { return this._volume.volume < this._warning_volume_norms; }
- private set { }
- }
private void init_high_volume() {
- _settings.changed["warning-volume-enabled"].connect(() => update_high_volume_cache());
- _settings.changed["warning-volume-decibels"].connect(() => update_high_volume_cache());
- update_high_volume_cache();
- }
- private void update_high_volume_cache() {
- var volume_dB = _settings.get_double ("warning-volume-decibels");
- var volume_sw = PulseAudio.Volume.sw_from_dB (volume_dB);
- var volume_norms = volume_to_double (volume_sw);
- _warning_volume_norms = volume_norms;
- _warning_volume_enabled = _settings.get_boolean("warning-volume-enabled");
- debug("updating high volume cache... enabled %d dB %f sw %lu norm %f", (int)_warning_volume_enabled, volume_dB, volume_sw, volume_norms);
+ _options.loud_changed.connect(() => update_high_volume());
update_high_volume();
}
private void update_high_volume() {
@@ -771,15 +755,14 @@ public class VolumeControlPulse : VolumeControl
}
private bool calculate_high_volume_from_volume(double volume) {
return _active_port_headphone
- && _warning_volume_enabled
- && volume > _warning_volume_norms
+ && _options.is_loud(_volume)
&& (stream == "multimedia");
}
public override void clamp_to_high_volume() {
- if (_high_volume && (_volume.volume > _warning_volume_norms)) {
+ if (_high_volume && _options.is_loud(_volume)) {
var vol = new VolumeControl.Volume();
- vol.volume = _volume.volume.clamp(0, _warning_volume_norms);
+ vol.volume = _volume.volume.clamp(0, volume_to_double(_options.loud_volume()));
vol.reason = _volume.reason;
debug("Clamping from %f down to %f", _volume.volume, vol.volume);
volume = vol;
@@ -788,10 +771,10 @@ public class VolumeControlPulse : VolumeControl
public override void set_warning_volume() {
var vol = new VolumeControl.Volume();
- vol.volume = _warning_volume_norms;
+ vol.volume = volume_to_double(_options.loud_volume());
vol.reason = _volume.reason;
debug("Setting warning level volume from %f down to %f", _volume.volume, vol.volume);
- volume = vol;
+ volume = vol;
}
/** HIGH VOLUME APPROVED PROPERTY **/
diff --git a/src/volume-control.vala b/src/volume-control.vala
index f33ae18..62655be 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -45,7 +45,7 @@ public abstract class VolumeControl : Object
public VolumeReasons reason;
}
- private IndicatorSound.Options _options = null;
+ protected IndicatorSound.Options _options = null;
public VolumeControl(IndicatorSound.Options options) {
_options = options;
@@ -56,7 +56,6 @@ public abstract class VolumeControl : Object
public virtual bool active_mic { get { return false; } set { } }
public virtual bool high_volume { get { return false; } protected set { } }
public virtual bool ignore_high_volume { get { return false; } protected set { } }
- public virtual bool below_warning_volume { get { return false; } protected set { } }
public virtual bool mute { get { return false; } }
public virtual bool is_playing { get { return false; } }
public virtual VolumeControl.ActiveOutput active_output { get { return VolumeControl.ActiveOutput.SPEAKERS; } }
diff --git a/src/volume-warning.vala b/src/volume-warning.vala
index b511856..01ddeff 100644
--- a/src/volume-warning.vala
+++ b/src/volume-warning.vala
@@ -650,40 +650,24 @@ public class VolumeWarning : VolumeControl
/** HIGH VOLUME PROPERTY **/
- private bool _warning_volume_enabled;
- private double _warning_volume_norms; /* 1.0 == PA_VOLUME_NORM */
private bool _high_volume = false;
- public override bool ignore_high_volume {
- get {
+ public override bool ignore_high_volume {
+ get {
if (_ignore_warning_this_time) {
warning("Ignore");
_ignore_warning_this_time = false;
return true;
}
- return false;
- }
+ return false;
+ }
set { }
}
public override bool high_volume {
get { return this._high_volume; }
private set { this._high_volume = value; }
}
- public override bool below_warning_volume {
- get { return this._volume.volume < this._warning_volume_norms; }
- private set { }
- }
private void init_high_volume() {
- _settings.changed["warning-volume-enabled"].connect(() => update_high_volume_cache());
- _settings.changed["warning-volume-decibels"].connect(() => update_high_volume_cache());
- update_high_volume_cache();
- }
- private void update_high_volume_cache() {
- var volume_dB = _settings.get_double ("warning-volume-decibels");
- var volume_sw = PulseAudio.Volume.sw_from_dB (volume_dB);
- var volume_norms = volume_to_double (volume_sw);
- _warning_volume_norms = volume_norms;
- _warning_volume_enabled = _settings.get_boolean("warning-volume-enabled");
- debug("updating high volume cache... enabled %d dB %f sw %lu norm %f", (int)_warning_volume_enabled, volume_dB, volume_sw, volume_norms);
+ _options.loud_changed.connect(() => update_high_volume());
update_high_volume();
}
private void update_high_volume() {
@@ -698,15 +682,14 @@ public class VolumeWarning : VolumeControl
}
private bool calculate_high_volume_from_volume(double volume) {
return _active_port_headphone
- && _warning_volume_enabled
- && volume > _warning_volume_norms
+ && _options.is_loud(_volume)
&& (stream == "multimedia");
}
public override void clamp_to_high_volume() {
- if (_high_volume && (_volume.volume > _warning_volume_norms)) {
+ if (_high_volume && _options.is_loud(_volume)) {
var vol = new VolumeControl.Volume();
- vol.volume = _volume.volume.clamp(0, _warning_volume_norms);
+ vol.volume = _volume.volume.clamp(0, volume_to_double(_options.loud_volume()));
vol.reason = _volume.reason;
debug("Clamping from %f down to %f", _volume.volume, vol.volume);
volume = vol;
@@ -715,10 +698,10 @@ public class VolumeWarning : VolumeControl
public override void set_warning_volume() {
var vol = new VolumeControl.Volume();
- vol.volume = _warning_volume_norms;
+ vol.volume = volume_to_double(_options.loud_volume());
vol.reason = _volume.reason;
debug("Setting warning level volume from %f down to %f", _volume.volume, vol.volume);
- volume = vol;
+ volume = vol;
}
/** HIGH VOLUME APPROVED PROPERTY **/