fordon_greeman / voidfiles

Branch: main
Switch branches/tags
main
theidioticdev add emacs 2079ec5 23h ago
72 lines · 2.6 KB Raw Blame History
1 ;;; emms-volume-sndioctl.el --- a mode for changing volume using sndioctl -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2019 Free Software Foundation, Inc.
4
5 ;; Authors: Omar Polo <op@omarpolo.com>
6
7 ;; This file is part of EMMS.
8
9 ;; EMMS is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13 ;;
14 ;; EMMS is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18 ;;
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with EMMS; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Commentary:
25
26 ;; This file defines a few simple functions to raise or lower the
27 ;; volume using sndioctl. It can be used stand-alone, though it's
28 ;; meant for usage with EMMS, particularly with emms-volume.el
29
30 ;;; History:
31
32 ;; Sep 09 2021: Based on emms-volume-mixerctl.el by Omar Polo
33
34 ;;; Code:
35 (require 'subr-x)
36
37 (defcustom emms-volume-sndioctl-stream "output"
38 "The stream to change the volume with.
39 Usually it's the global \"output\". For a full list of available
40 controls, run `sndioctl' in a shell."
41 :type '(choice (const :tag "output" "output")
42 (string :tag "Something else: "))
43 :group 'emms-volume)
44
45 (defcustom emms-volume-sndioctl-device nil
46 "The card number to change volume.
47 The card is identified by a number. For a full list run `ls
48 /dev/mixer?*' in a shell."
49 :type '(choice (const :tag "none" nil)
50 (string :tag "Device: "))
51 :group 'emms-volume)
52
53 ;;;###autoload
54 (defun emms-volume-sndioctl-change (amount)
55 "Change sndioctl level by AMOUNT."
56 (message "Playback channels: %s"
57 (with-temp-buffer
58 (when (zerop
59 (apply #'call-process
60 "sndioctl" nil (current-buffer) nil
61 `("-n"
62 ,@(when emms-volume-sndioctl-device
63 `("-f" ,emms-volume-sndioctl-device))
64 ,(format "%s.level=%s%f"
65 emms-volume-sndioctl-stream
66 (if (> amount 0) "+" "")
67 (/ (float amount) 100)))))
68 (string-trim-right (buffer-string))))))
69
70 (provide 'emms-volume-sndioctl)
71
72 ;;; emms-volume-sndioctl.el ends here