Discussion:
[emms-help] [PATCH] PulseAudio cleanup
David Michael
2017-06-11 20:45:10 UTC
Permalink
* lisp/emms-volume.el (emms-volume-change-function): Fix typo.
* lisp/emms-volume-pulse.el: Limit default percents to range 0-100.

This fixes some typos, doc strings, and limits volume percentages
between 0 and 100 by default. At least with the Solaris sink,
attempting to set a volume outside this range will fail with a
"connection terminated" error from pactl.
---
lisp/emms-volume-pulse.el | 19 ++++++++-----------
lisp/emms-volume.el | 2 +-
2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/lisp/emms-volume-pulse.el b/lisp/emms-volume-pulse.el
index 8d95e30..7fc6de5 100644
--- a/lisp/emms-volume-pulse.el
+++ b/lisp/emms-volume-pulse.el
@@ -56,13 +56,9 @@ See full list of devices on your system by running
(string :tag "Sink symbolic name"))
:group 'emms-volume)

-(defcustom emms-volume-pulse-max-volume 150
- "The sink to use for volume adjustment.
-
-See full list of devices on your system by running
- pactl list short sinks"
- :type '(choice (number :tag "Sink number")
- (string :tag "Sink symbolic name"))
+(defcustom emms-volume-pulse-max-volume 100
+ "The maximum volume percentage."
+ :type 'integer
:group 'emms-volume)


@@ -73,7 +69,7 @@ See full list of devices on your system by running
(output
(shell-command-to-string
(concat "pactl list sinks" "|"
- "grep -E -e 'Sink' -e 'Name' -e '^[^a-zA-Z]*Volume'"))))
+ "grep -E -e 'Sink' -e 'Name' -e '^[^a-zA-Z]*Volume'"))))
(string-to-number
(car
(reverse
@@ -97,12 +93,13 @@ See full list of devices on your system by running

;;;###autoload
(defun emms-volume-pulse-change (amount)
- "Change amixer master volume by AMOUNT."
+ "Change PulseAudio volume by AMOUNT."
(message "Volume is %s%%"
(let ((pactl (or (executable-find "pactl")
(error "pactl is not in PATH")))
- (next-vol (min (+ (emms-volume--pulse-get-volume) amount)
- emms-volume-pulse-max-volume)))
+ (next-vol (max (min (+ (emms-volume--pulse-get-volume) amount)
+ emms-volume-pulse-max-volume)
+ 0)))
(when (zerop (shell-command
(format "%s set-sink-volume %s %s%%"
pactl emms-volume-pulse-sink next-vol)))
diff --git a/lisp/emms-volume.el b/lisp/emms-volume.el
index cca8d77..54eadd3 100644
--- a/lisp/emms-volume.el
+++ b/lisp/emms-volume.el
@@ -61,7 +61,7 @@
If you have your own functions for changing volume, set this."
:type '(choice (const :tag "Amixer" emms-volume-amixer-change)
(const :tag "MPD" emms-volume-mpd-change)
- (const :tag "Pulseaudio" emms-volume-pule-change)
+ (const :tag "PulseAudio" emms-volume-pulse-change)
(function :tag "Lisp function"))
:group 'emms-volume)
--
2.7.5
Yoni Rabkin
2017-06-19 18:59:29 UTC
Permalink
Applied.

Sorry for the delay, and thank you for the patch.
Post by David Michael
* lisp/emms-volume.el (emms-volume-change-function): Fix typo.
* lisp/emms-volume-pulse.el: Limit default percents to range 0-100.
This fixes some typos, doc strings, and limits volume percentages
between 0 and 100 by default. At least with the Solaris sink,
attempting to set a volume outside this range will fail with a
"connection terminated" error from pactl.
---
lisp/emms-volume-pulse.el | 19 ++++++++-----------
lisp/emms-volume.el | 2 +-
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/lisp/emms-volume-pulse.el b/lisp/emms-volume-pulse.el
index 8d95e30..7fc6de5 100644
--- a/lisp/emms-volume-pulse.el
+++ b/lisp/emms-volume-pulse.el
@@ -56,13 +56,9 @@ See full list of devices on your system by running
(string :tag "Sink symbolic name"))
:group 'emms-volume)
-(defcustom emms-volume-pulse-max-volume 150
- "The sink to use for volume adjustment.
-
-See full list of devices on your system by running
- pactl list short sinks"
- :type '(choice (number :tag "Sink number")
- (string :tag "Sink symbolic name"))
+(defcustom emms-volume-pulse-max-volume 100
+ "The maximum volume percentage."
+ :type 'integer
:group 'emms-volume)
@@ -73,7 +69,7 @@ See full list of devices on your system by running
(output
(shell-command-to-string
(concat "pactl list sinks" "|"
- "grep -E -e 'Sink' -e 'Name' -e '^[^a-zA-Z]*Volume'"))))
+ "grep -E -e 'Sink' -e 'Name' -e '^[^a-zA-Z]*Volume'"))))
(string-to-number
(car
(reverse
@@ -97,12 +93,13 @@ See full list of devices on your system by running
;;;###autoload
(defun emms-volume-pulse-change (amount)
- "Change amixer master volume by AMOUNT."
+ "Change PulseAudio volume by AMOUNT."
(message "Volume is %s%%"
(let ((pactl (or (executable-find "pactl")
(error "pactl is not in PATH")))
- (next-vol (min (+ (emms-volume--pulse-get-volume) amount)
- emms-volume-pulse-max-volume)))
+ (next-vol (max (min (+ (emms-volume--pulse-get-volume) amount)
+ emms-volume-pulse-max-volume)
+ 0)))
(when (zerop (shell-command
(format "%s set-sink-volume %s %s%%"
pactl emms-volume-pulse-sink next-vol)))
diff --git a/lisp/emms-volume.el b/lisp/emms-volume.el
index cca8d77..54eadd3 100644
--- a/lisp/emms-volume.el
+++ b/lisp/emms-volume.el
@@ -61,7 +61,7 @@
If you have your own functions for changing volume, set this."
:type '(choice (const :tag "Amixer" emms-volume-amixer-change)
(const :tag "MPD" emms-volume-mpd-change)
- (const :tag "Pulseaudio" emms-volume-pule-change)
+ (const :tag "PulseAudio" emms-volume-pulse-change)
(function :tag "Lisp function"))
:group 'emms-volume)
--
"Cut your own wood and it will warm you twice"
Loading...