fordon_greeman / voidfiles

Branch: main
Switch branches/tags
main
theidioticdev add emacs 2079ec5 1d ago
80 lines · 2.8 KB Raw Blame History
1 ;;; emms-volume-mixerctl.el --- a mode for changing volume using mixerctl -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2019 Free Software Foundation, Inc.
4
5 ;; Authors: Martin Schoenmakers <aiviru@diamond-age.net>
6 ;; Bruno Félix Rezende Ribeiro <oitofelix@gnu.org>
7
8 ;; This file is part of EMMS.
9
10 ;; EMMS is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
14 ;;
15 ;; EMMS is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with EMMS; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; This file defines a few simple functions to raise or lower the volume
28 ;; using mixerctl. It can be used stand-alone, though it's meant for usage
29 ;; with EMMS, particularly with emms-volume.el
30
31 ;;; History:
32
33 ;; Jul 06 2019: Based on emms-volume-amixer.el by Martin Schoenmakers
34
35 ;;; Todo:
36
37 ;; There probably needs to be more configurability, which may in turn
38 ;; mean adding some more functions.
39 ;; Some of this could benefit from adding customize interfaces.
40
41 ;;; Code:
42
43 (defcustom emms-volume-mixerctl-control "master"
44 "The control to change the volume with.
45 Controls includes \"master\", \"mono\", etc. For a full list of available
46 controls, run `mixerctl -a' in a shell."
47 :type '(choice (const :tag "master" "master")
48 (const :tag "mono" "mono")
49 (string :tag "Something else: "))
50 :group 'emms-volume)
51
52 (defcustom emms-volume-mixerctl-card 0
53 "The card number to change volume.
54 The card is identified by a number. For a full list run `ls
55 /dev/mixer?*' in a shell."
56 :type 'integer
57 :group 'emms-volume)
58
59 ;;;###autoload
60 (defun emms-volume-mixerctl-change (amount)
61 "Change mixerctl master volume by AMOUNT."
62 (message "Playback channels: %s"
63 (with-temp-buffer
64 (when (zerop
65 (call-process "mixerctl" nil (current-buffer) nil
66 "-f"
67 (format "/dev/mixer%d" emms-volume-mixerctl-card)
68 (let ((amount-str
69 (format "%s%d" (if (< amount 0) "-" "+")
70 (abs amount))))
71 (format "outputs.%s=%s,%s"
72 emms-volume-mixerctl-control
73 amount-str amount-str))))
74 (if (and (forward-line -1)
75 (re-search-forward "^\\(.*\\):.*->.*,\\(.*\\)$" nil t))
76 (format "%s -> %s" (match-string 1) (match-string 2)))))))
77
78 (provide 'emms-volume-mixerctl)
79
80 ;;; emms-volume-mixerctl.el ends here