>From a3c6fc729618dacb93aba0bcef09ccc8cd39c3d7 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Wed, 21 Sep 2022 11:13:31 -0400 Subject: [PATCH 1/2] Ask pactl for sink by name This allows us to ask for special names like @DEFAULT_SINK@ --- emms-volume-pulse.el | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/emms-volume-pulse.el b/emms-volume-pulse.el index 5211e69..504bb83 100644 --- a/emms-volume-pulse.el +++ b/emms-volume-pulse.el @@ -42,8 +42,6 @@ ;;; Code: -(require 'cl-lib) - ;; TODO: it would be great if custom could have ;; choices based on pactl list short sinks | cut -f1-2 @@ -61,34 +59,21 @@ See full list of devices on your system by running :type 'integer :group 'emms-volume) - (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'")))) - (string-to-number - (car - (reverse - (funcall - (if sink-number-p #'assq #'assoc) - emms-volume-pulse-sink - (mapcar (if sink-number-p 'identity 'cdr) - (cl-loop while - (string-match - (mapconcat #'identity - '(".*Sink[ \t]+\\#\\([0-9]+\\)" - ".*Name:[ \t]\\([^\n]+\\)" - ".*Volume:.*?\\([0-9]+\\)%.*\n?") - "\n") - output) - collect (list (string-to-number (match-string 1 output)) - (match-string 2 output) - (match-string 3 output)) - do (setq output (replace-match "" nil nil output)))))))))) - + (let* ((sink-string (if (numberp emms-volume-pulse-sink) + (number-to-string emms-volume-pulse-sink) + emms-volume-pulse-sink)) + (output + (shell-command-to-string + (concat "pactl get-sink-volume " sink-string)))) + (string-match + ".*Volume:.*?\\([0-9]+\\)%.*\n?" + output) + (let ((volume (match-string 1 output))) + (if volume + (string-to-number volume) + (error "Could not find pulse sink %s" sink-string))))) ;;;###autoload (defun emms-volume-pulse-change (amount) -- 2.37.3