* emms-volume-amixer.el: implement `emms-volume-amixer-get' - emms.git - EMMS, The Emacs Multimedia System.

index : emms.git
EMMS, The Emacs Multimedia System.
summary refs log tree commit diff
diff options
context:
space:
mode:
authorYoni Rabkin <yrk@gnu.org>2023年03月02日 13:07:06 -0500
committerYoni Rabkin <yrk@gnu.org>2023年03月02日 13:07:06 -0500
commit4136e8bbfa2d676b5ab2df0d5450048299429e9a (patch)
treeb00cc03fd15a0f2ee9f70f665f58dc8ecfdb6314
parentd45fd671d2be07fd56db251a0fa8835e8f31ef26 (diff)
downloademms-volume.tar.gz
* emms-volume-amixer.el: implement `emms-volume-amixer-get'volume
Diffstat
-rw-r--r--emms-volume-amixer.el 32
1 files changed, 25 insertions, 7 deletions
diff --git a/emms-volume-amixer.el b/emms-volume-amixer.el
index b799822..9cde1a9 100644
--- a/emms-volume-amixer.el
+++ b/emms-volume-amixer.el
@@ -32,14 +32,8 @@
;; May 30 2006: First cleanup and collation of amixer functions into a
;; separate file for releasability.
-;;; Todo:
-
-;; There probably needs to be more configurability, which may in turn
-;; mean adding some more functions.
-;; Some of this could benefit from adding customize interfaces.
;;; Code:
-
(defcustom emms-volume-amixer-control "Master"
"The control to change the volume with.
Controls includes \"Master\", \"PCM\", etc. For a full list of available
@@ -56,6 +50,10 @@ The card is identified by a number. For a full list run `cat
:type 'integer
:group 'emms-volume)
+(defvar emms-volume-amixer-volume-regexp
+ "\\[\\([0-9]+\\)%\\]"
+ "Regexp to capture the volume from amixer output.")
+
;;;###autoload
(defun emms-volume-amixer-change (amount)
"Change amixer master volume by AMOUNT."
@@ -68,9 +66,29 @@ The card is identified by a number. For a full list run `cat
"sset" emms-volume-amixer-control
(format "%d%%%s" (abs amount)
(if (< amount 0) "-" "+"))))
- (if (re-search-backward "\\[\\([0-9]+%\\)\\]" nil t)
+ (if (re-search-backward emms-volume-amixer-volume-regexp nil t)
(match-string 1))))))
+(defun emms-volume-amixer-get ()
+ "Return the amixer volume.
+
+Number is limited to the range [0-100]."
+ (let ((v (with-temp-buffer
+ (when (zerop
+ (call-process "amixer" nil (current-buffer) nil
+ "-c"
+ (format "%d" emms-volume-amixer-card)
+ "sget" emms-volume-amixer-control))
+ (if (re-search-backward
+ emms-volume-amixer-volume-regexp nil t)
+ (match-string 1)
+ nil)))))
+ (if v
+ (max (min (string-to-number v) 100) 0)
+ (error "could not get volume from amixer backend"))))
+
+
+
(provide 'emms-volume-amixer)
;;; emms-volume-amixer.el ends here
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月02日 22:22:22 +0000

AltStyle によって変換されたページ (->オリジナル) /