author | Yoni Rabkin <yrk@gnu.org> | 2023年03月02日 13:07:06 -0500 |
---|---|---|
committer | Yoni Rabkin <yrk@gnu.org> | 2023年03月02日 13:07:06 -0500 |
commit | 4136e8bbfa2d676b5ab2df0d5450048299429e9a (patch) | |
tree | b00cc03fd15a0f2ee9f70f665f58dc8ecfdb6314 | |
parent | d45fd671d2be07fd56db251a0fa8835e8f31ef26 (diff) | |
download | emms-volume.tar.gz |
-rw-r--r-- | emms-volume-amixer.el | 32 |
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 |