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
=== modified file 'data/com.canonical.indicator.sound.gschema.xml'
--- data/com.canonical.indicator.sound.gschema.xml 2013-07-19 08:05:31 +0000
+++ data/com.canonical.indicator.sound.gschema.xml 2014-02-20 17:44:22 +0000
@@ -48,5 +48,9 @@
48 Whether or not to show the sound indicator in the menu bar.48 Whether or not to show the sound indicator in the menu bar.
49 </description>49 </description>
50 </key>50 </key>
51 <key name="allow-amplified-volume" type="b">
52 <default>false</default>
53 <summary>Whether the volume slider allows setting the volume above 100%</summary>
54 </key>
51 </schema>55 </schema>
52</schemalist>56</schemalist>
5357
=== modified file 'src/service.vala'
--- src/service.vala 2014-01-22 17:37:20 +0000
+++ src/service.vala 2014-02-20 17:44:22 +0000
@@ -17,7 +17,7 @@
17 * Lars Uebernickel <lars.uebernickel@canonical.com>17 * Lars Uebernickel <lars.uebernickel@canonical.com>
18 */18 */
1919
20public class IndicatorSound.Service {20public class IndicatorSound.Service: Object {
21 public Service () {21 public Service () {
22 this.settings = new Settings ("com.canonical.indicator.sound");22 this.settings = new Settings ("com.canonical.indicator.sound");
2323
@@ -54,6 +54,8 @@
54 this.notification.set_hint_string ("x-canonical-private-synchronous", "indicator-sound");54 this.notification.set_hint_string ("x-canonical-private-synchronous", "indicator-sound");
55 }55 }
56 }56 }
57
58 settings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET);
57 }59 }
5860
59 public int run () {61 public int run () {
@@ -71,6 +73,25 @@
71 return 0;73 return 0;
72 }74 }
7375
76 public bool allow_amplified_volume {
77 get {
78 return this.max_volume > 1.0;
79 }
80
81 set {
82 if (value) {
83 /* from pulse/volume.h: #define PA_VOLUME_UI_MAX (pa_sw_volume_from_dB(+11.0)) */
84 this.max_volume = (double)PulseAudio.Volume.sw_from_dB(11.0) / PulseAudio.Volume.NORM;
85 }
86 else {
87 this.max_volume = 1.0;
88 }
89
90 /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
91 this.actions.change_action_state ("volume", this.volume_control.get_volume () / this.max_volume);
92 }
93 }
94
74 const ActionEntry[] action_entries = {95 const ActionEntry[] action_entries = {
75 { "root", null, null, "@a{sv} {}", null },96 { "root", null, null, "@a{sv} {}", null },
76 { "scroll", activate_scroll_action, "i", null, null },97 { "scroll", activate_scroll_action, "i", null, null },
@@ -88,13 +109,18 @@
88 Notify.Notification notification;109 Notify.Notification notification;
89 bool syncing_preferred_players = false;110 bool syncing_preferred_players = false;
90111
112 /* Maximum volume as a scaling factor between the volume action's state and the value in
113 * this.volume_control. See create_volume_action().
114 */
115 double max_volume = 1.0;
116
91 const double volume_step_percentage = 0.06;117 const double volume_step_percentage = 0.06;
92118
93 void activate_scroll_action (SimpleAction action, Variant? param) {119 void activate_scroll_action (SimpleAction action, Variant? param) {
94 int delta = param.get_int32(); /* positive for up, negative for down */120 int delta = param.get_int32(); /* positive for up, negative for down */
95121
96 double v = this.volume_control.get_volume () + volume_step_percentage * delta;122 double v = this.volume_control.get_volume () + volume_step_percentage * delta;
97 this.volume_control.set_volume (v.clamp (0.0, 1.0));123 this.volume_control.set_volume (v.clamp (0.0, this.max_volume));
98124
99 if (this.notification != null) {125 if (this.notification != null) {
100 string icon;126 string icon;
@@ -201,22 +227,35 @@
201227
202 void volume_changed (double volume) {228 void volume_changed (double volume) {
203 var volume_action = this.actions.lookup_action ("volume") as SimpleAction;229 var volume_action = this.actions.lookup_action ("volume") as SimpleAction;
204 volume_action.set_state (new Variant.double (volume));230
231 /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
232 volume_action.set_state (new Variant.double (volume / this.max_volume));
205233
206 this.update_root_icon ();234 this.update_root_icon ();
207 }235 }
208236
209 Action create_volume_action () {237 Action create_volume_action () {
210 var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (this.volume_control.get_volume ()));238 /* The action's state is between be in [0.0, 1.0] instead of [0.0,
239 * max_volume], so that we don't need to update the slider menu item
240 * every time allow-amplified-volume is changed. Convert between the
241 * two here, so that we always pass the full range into
242 * volume_control.set_volume().
243 */
244
245 double volume = this.volume_control.get_volume () / this.max_volume;
246
247 var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (volume));
211248
212 volume_action.change_state.connect ( (action, val) => {249 volume_action.change_state.connect ( (action, val) => {
213 volume_control.set_volume (val.get_double ());250 double v = val.get_double () * this.max_volume;
251 volume_control.set_volume (v.clamp (0.0, this.max_volume));
214 });252 });
215253
216 /* activating this action changes the volume by the amount given in the parameter */254 /* activating this action changes the volume by the amount given in the parameter */
217 volume_action.activate.connect ( (action, param) => {255 volume_action.activate.connect ( (action, param) => {
218 double v = volume_control.get_volume () + volume_step_percentage * param.get_int32 ();256 int delta = param.get_int32 ();
219 volume_control.set_volume (v.clamp (0.0, 1.0));257 double v = volume_control.get_volume () + volume_step_percentage * delta;
258 volume_control.set_volume (v.clamp (0.0, this.max_volume));
220 });259 });
221260
222 this.volume_control.volume_changed.connect (volume_changed);261 this.volume_control.volume_changed.connect (volume_changed);

Subscribers

People subscribed via source and target branches