emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/emms 88cbd8c8fa: * emms-volume-pulse.el: Try to find th


From: ELPA Syncer
Subject: [elpa] externals/emms 88cbd8c8fa: * emms-volume-pulse.el: Try to find the default sink
Date: Sun, 2 Oct 2022 08:01:49 -0400 (EDT)

branch: externals/emms
commit 88cbd8c8fae985f077418647a5cb1b69f8b6d18b
Author: Yoni Rabkin <yrk@gnu.org>
Commit: Yoni Rabkin <yrk@gnu.org>

    * emms-volume-pulse.el: Try to find the default sink
    
    emms-volume-pulse.el
    (emms-volume-pulse-sink): Add nil as an option and set as default
    (emms-volume--pulse-get-volume): Use default sink if emms-volume-pulse-sink 
isn't set
    (emms-volume-pulse-change): Likewise
    
    Patch submitted by Morgan Smith
---
 AUTHORS              |  1 +
 emms-volume-pulse.el | 32 ++++++++++++++++++++++----------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index d52009354a..94d4d1e7f5 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -23,6 +23,7 @@ Mario Lang             <mlang@delYsid.org>
 Martin Schoenmakers     <aiviru@diamond-age.net>
 Matthew Kennedy                 <mkennedy@gentoo.org>
 Michael Olson           <mwolson@gnu.org>
+Morgan Smith             <Morgan.J.Smith@outlook.com>
 Nick Alcock             <nix@esperi.org.uk>
 Omar Polo                <op@omarpolo.com>
 Petteri Hintsanen        <petterih@iki.fi>
diff --git a/emms-volume-pulse.el b/emms-volume-pulse.el
index 5211e69acb..4a33b037bc 100644
--- a/emms-volume-pulse.el
+++ b/emms-volume-pulse.el
@@ -47,13 +47,16 @@
 ;; TODO: it would be great if custom could have
 ;; choices based on pactl list short sinks | cut -f1-2
 
-(defcustom emms-volume-pulse-sink 0
+(defcustom emms-volume-pulse-sink nil
   "The sink to use for volume adjustment.
 
+If nil try to use the default sink.
+
 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"))
+                 (string :tag "Sink symbolic name")
+                 (const :tag "Default sink" nil))
   :group 'emms-volume)
 
 (defcustom emms-volume-pulse-max-volume 100
@@ -61,14 +64,22 @@ See full list of devices on your system by running
   :type 'integer
   :group 'emms-volume)
 
-
+;; 'pactl get-sink-volume' was only added recently (version 14.1).
+;; When that version is more widespread this function can be
+;; simplified
 (defun emms-volume--pulse-get-volume ()
   "Return `emms-volume-pulse-sink' volume."
-  (let ((sink-number-p (numberp emms-volume-pulse-sink))
-        (output
-         (shell-command-to-string
-          (concat "pactl list sinks" "|"
-                  "grep -E -e 'Sink' -e 'Name' -e '^[^a-zA-Z]*Volume'"))))
+  (let* ((emms-volume-pulse-sink
+          (if emms-volume-pulse-sink
+              emms-volume-pulse-sink
+            (string-trim
+             (shell-command-to-string
+              "pactl info | grep 'Default Sink: ' | cut -d ' ' -f3-"))))
+         (sink-number-p (numberp emms-volume-pulse-sink))
+         (output
+          (shell-command-to-string
+           (concat "pactl list sinks" "|"
+                   "grep -E -e 'Sink' -e 'Name' -e '^[^a-zA-Z]*Volume'"))))
     (string-to-number
      (car
       (reverse
@@ -89,7 +100,6 @@ See full list of devices on your system by running
                                       (match-string 3 output))
                         do (setq output (replace-match "" nil nil 
output))))))))))
 
-
 ;;;###autoload
 (defun emms-volume-pulse-change (amount)
   "Change PulseAudio volume by AMOUNT."
@@ -101,7 +111,9 @@ See full list of devices on your system by running
                                 0)))
              (when (zerop (shell-command
                            (format "%s set-sink-volume %s %s%%"
-                                   pactl emms-volume-pulse-sink next-vol)))
+                                   pactl
+                                   (or emms-volume-pulse-sink "@DEFAULT_SINK@")
+                                   next-vol)))
                next-vol))))
 
 (provide 'emms-volume-pulse)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]