Merge lp:~larsu/indicator-sound/allow-amplified-volume into lp:indicator-sound/14.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Charles Kerr
Approved revision: 412
Merged at revision: 414
Proposed branch: lp:~larsu/indicator-sound/allow-amplified-volume
Merge into: lp:indicator-sound/14.04
Diff against target: 122 lines (+50/-7)
2 files modified
data/com.canonical.indicator.sound.gschema.xml (+4/-0)
src/service.vala (+46/-7)
To merge this branch: bzr merge lp:~larsu/indicator-sound/allow-amplified-volume
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Charles Kerr (community) Approve
Ted Gould (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+207492@code.launchpad.net

Commit message

Add support for amplified volumes

Add a settings key "allow-amplified-volume" which controls whether the volume slider stops at 100% or PA_VOLUME_UI_MAX. unity-control-center will provide a ui for this key.

Description of the change

Add support for amplified volumes

Add a settings key "allow-amplified-volume" which controls whether the volume slider stops at 100% or PA_VOLUME_UI_MAX. unity-control-center will provide a ui for this key.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) :
review: Approve
413. By Lars Karlitski

Clamp volume when in the action's change_state handler

414. By Lars Karlitski

Add comments explaining max_volume a bit better

Revision history for this message
Charles Kerr (charlesk) wrote :

nice & simple.

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

looks good, works fine!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/com.canonical.indicator.sound.gschema.xml'
2--- data/com.canonical.indicator.sound.gschema.xml 2013-07-19 08:05:31 +0000
3+++ data/com.canonical.indicator.sound.gschema.xml 2014-02-20 17:44:22 +0000
4@@ -48,5 +48,9 @@
5 Whether or not to show the sound indicator in the menu bar.
6 </description>
7 </key>
8+ <key name="allow-amplified-volume" type="b">
9+ <default>false</default>
10+ <summary>Whether the volume slider allows setting the volume above 100%</summary>
11+ </key>
12 </schema>
13 </schemalist>
14
15=== modified file 'src/service.vala'
16--- src/service.vala 2014-01-22 17:37:20 +0000
17+++ src/service.vala 2014-02-20 17:44:22 +0000
18@@ -17,7 +17,7 @@
19 * Lars Uebernickel <lars.uebernickel@canonical.com>
20 */
21
22-public class IndicatorSound.Service {
23+public class IndicatorSound.Service: Object {
24 public Service () {
25 this.settings = new Settings ("com.canonical.indicator.sound");
26
27@@ -54,6 +54,8 @@
28 this.notification.set_hint_string ("x-canonical-private-synchronous", "indicator-sound");
29 }
30 }
31+
32+ settings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET);
33 }
34
35 public int run () {
36@@ -71,6 +73,25 @@
37 return 0;
38 }
39
40+ public bool allow_amplified_volume {
41+ get {
42+ return this.max_volume > 1.0;
43+ }
44+
45+ set {
46+ if (value) {
47+ /* from pulse/volume.h: #define PA_VOLUME_UI_MAX (pa_sw_volume_from_dB(+11.0)) */
48+ this.max_volume = (double)PulseAudio.Volume.sw_from_dB(11.0) / PulseAudio.Volume.NORM;
49+ }
50+ else {
51+ this.max_volume = 1.0;
52+ }
53+
54+ /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
55+ this.actions.change_action_state ("volume", this.volume_control.get_volume () / this.max_volume);
56+ }
57+ }
58+
59 const ActionEntry[] action_entries = {
60 { "root", null, null, "@a{sv} {}", null },
61 { "scroll", activate_scroll_action, "i", null, null },
62@@ -88,13 +109,18 @@
63 Notify.Notification notification;
64 bool syncing_preferred_players = false;
65
66+ /* Maximum volume as a scaling factor between the volume action's state and the value in
67+ * this.volume_control. See create_volume_action().
68+ */
69+ double max_volume = 1.0;
70+
71 const double volume_step_percentage = 0.06;
72
73 void activate_scroll_action (SimpleAction action, Variant? param) {
74 int delta = param.get_int32(); /* positive for up, negative for down */
75
76 double v = this.volume_control.get_volume () + volume_step_percentage * delta;
77- this.volume_control.set_volume (v.clamp (0.0, 1.0));
78+ this.volume_control.set_volume (v.clamp (0.0, this.max_volume));
79
80 if (this.notification != null) {
81 string icon;
82@@ -201,22 +227,35 @@
83
84 void volume_changed (double volume) {
85 var volume_action = this.actions.lookup_action ("volume") as SimpleAction;
86- volume_action.set_state (new Variant.double (volume));
87+
88+ /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
89+ volume_action.set_state (new Variant.double (volume / this.max_volume));
90
91 this.update_root_icon ();
92 }
93
94 Action create_volume_action () {
95- var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (this.volume_control.get_volume ()));
96+ /* The action's state is between be in [0.0, 1.0] instead of [0.0,
97+ * max_volume], so that we don't need to update the slider menu item
98+ * every time allow-amplified-volume is changed. Convert between the
99+ * two here, so that we always pass the full range into
100+ * volume_control.set_volume().
101+ */
102+
103+ double volume = this.volume_control.get_volume () / this.max_volume;
104+
105+ var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (volume));
106
107 volume_action.change_state.connect ( (action, val) => {
108- volume_control.set_volume (val.get_double ());
109+ double v = val.get_double () * this.max_volume;
110+ volume_control.set_volume (v.clamp (0.0, this.max_volume));
111 });
112
113 /* activating this action changes the volume by the amount given in the parameter */
114 volume_action.activate.connect ( (action, param) => {
115- double v = volume_control.get_volume () + volume_step_percentage * param.get_int32 ();
116- volume_control.set_volume (v.clamp (0.0, 1.0));
117+ int delta = param.get_int32 ();
118+ double v = volume_control.get_volume () + volume_step_percentage * delta;
119+ volume_control.set_volume (v.clamp (0.0, this.max_volume));
120 });
121
122 this.volume_control.volume_changed.connect (volume_changed);

Subscribers

People subscribed via source and target branches