|
24 | 24 | (defvar *terse* nil "If t, this will supress messages that get shown on changes to volume.")
|
25 | 25 | (defvar *doas* nil "If t, this will use doas to run sndioctl.")
|
26 | 26 |
|
27 |
| -(defun call-sndioctl (args captive) |
| 27 | +(defun call-sndioctl (args) |
28 | 28 | "Calls sndioctl with the required arguments."
|
29 | 29 | (run-shell-command
|
30 | 30 | (format nil "~asndioctl ~a" (if *doas* "doas " "") args)
|
31 |
| - captive)) |
32 |
| - |
33 |
| -(defun make-step-cmd (direction) |
34 |
| - "Helpful wrapper for generating command strings for incrementing/decrementing volume." |
35 |
| - (cond |
36 |
| - ((string= "+" direction) |
37 |
| - (format nil "-q output.level=+~a" *step*)) |
38 |
| - ((string= "-" direction) |
39 |
| - (format nil "-q output.level=-~a" *step*)) |
40 |
| - (t (error "Not a valid step direction!")))) |
| 31 | + t)) |
41 | 32 |
|
42 | 33 | (defun get-mute-state-string ()
|
43 | 34 | "Returns a nicely formatted string containing the current mute state."
|
44 |
| - (let ((state (aref (call-sndioctl "-n output.mute" t) 0))) |
45 |
| - (cond |
46 |
| - ((string= "0" state) |
47 |
| - (format nil "Muted: No")) |
48 |
| - ((string= "1" state) |
49 |
| - (format nil "Muted: Yes")) |
50 |
| - (t (error "Unknown output from sndioctl -n output.mute"))))) |
| 35 | + (let* ((code-to-str |
| 36 | + (lambda (c) |
| 37 | + (cond |
| 38 | + ((string= "0" c) "No") |
| 39 | + ((string= "1" c) "Yes") |
| 40 | + (t "Err")))) |
| 41 | + (get-state |
| 42 | + (lambda (key) |
| 43 | + (handler-case |
| 44 | + (funcall code-to-str |
| 45 | + (aref (call-sndioctl (format nil "-n ~a" key)) 0)) |
| 46 | + (error (c) (declare (ignore c)) "N/A")) |
| 47 | + )) |
| 48 | + (in-state (funcall get-state "input.mute")) |
| 49 | + (out-state (funcall get-state "output.mute"))) |
| 50 | + (format nil "Muted in: ~a Muted out: ~a" in-state out-state))) |
51 | 51 |
|
52 | 52 | (defun get-volume-level-string ()
|
53 | 53 | "Returns a nicely formatted string containing the current volume level."
|
54 |
| - (let ((level |
55 |
| - (with-input-from-string (vol-str (call-sndioctl "-n output.level" t)) |
56 |
| - (read vol-str)))) |
57 |
| - (format nil "Volume: ~2$%" (* 100.0 level)))) |
| 54 | + (let* ((get-volume |
| 55 | + (lambda (key) |
| 56 | + (handler-case |
| 57 | + (format nil "~2$%" |
| 58 | + (* 100 |
| 59 | + (with-input-from-string |
| 60 | + (vol-str (call-sndioctl (format nil "-n ~a" key))) |
| 61 | + (read vol-str)))) |
| 62 | + (error (c) (declare (ignore c)) "N/A")))) |
| 63 | + (in-volume (funcall get-volume "input.level")) |
| 64 | + (out-volume (funcall get-volume "output.level"))) |
| 65 | + (format nil "Volume in: ~a Volume out: ~a" in-volume out-volume))) |
58 | 66 |
|
59 | 67 | (defun sndioctl-status-message ()
|
60 | 68 | "Returns a string indicating currrent sndioctl state."
|
61 | 69 | (format nil "~a ~a" (get-volume-level-string) (get-mute-state-string)))
|
62 | 70 |
|
63 | 71 | (defcommand volume-up () ()
|
64 | 72 | "Volume goes up"
|
65 |
| - (call-sndioctl (make-step-cmd "+") nil) |
| 73 | + (call-sndioctl (format nil "-q input.level=+~a" *step*)) |
| 74 | + (call-sndioctl (format nil "-q output.level=+~a" *step*)) |
66 | 75 | (if (not *terse*)
|
67 | 76 | (message (sndioctl-status-message))))
|
68 | 77 |
|
69 | 78 | (defcommand volume-down () ()
|
70 | 79 | "Volume goes down"
|
71 |
| - (call-sndioctl (make-step-cmd "-") nil) |
| 80 | + (call-sndioctl (format nil "-q input.level=-~a" *step*)) |
| 81 | + (call-sndioctl (format nil "-q output.level=-~a" *step*)) |
72 | 82 | (if (not *terse*)
|
73 | 83 | (message (sndioctl-status-message))))
|
74 | 84 |
|
75 | 85 | (defcommand toggle-mute () ()
|
76 | 86 | "Toggles mute"
|
77 |
| - (call-sndioctl "-q output.mute=!" nil) |
| 87 | + (call-sndioctl "-n input.mute=!") |
| 88 | + (call-sndioctl "-n output.mute=!") |
78 | 89 | (if (not *terse*)
|
79 | 90 | (message (sndioctl-status-message))))
|
80 | 91 |
|
81 | 92 | (defcommand set-mute () ()
|
82 | 93 | "Force sets mute to ON"
|
83 |
| - (call-sndioctl "-q output.mute=1" nil) |
| 94 | + (call-sndioctl "-q input.mute=1") |
| 95 | + (call-sndioctl "-q output.mute=1") |
84 | 96 | (if (not *terse*)
|
85 | 97 | (message (sndioctl-status-message))))
|
86 | 98 |
|
87 | 99 | (defcommand unset-mute () ()
|
88 | 100 | "Force sets mute to OFF"
|
89 |
| - (call-sndioctl "-q output.mute=0" nil) |
| 101 | + (call-sndioctl "-q inout.mute=0") |
| 102 | + (call-sndioctl "-q output.mute=0") |
90 | 103 | (if (not *terse*)
|
91 | 104 | (message (sndioctl-status-message))))
|
0 commit comments