mirror of
https://github.com/stumpwm/stumpwm-contrib.git
synced 2026-09-10 07:26:25 -04:00
add a module for FreeBSD's audio mixer
This commit is contained in:
parent
36f43af312
commit
0e776696d7
15
media/stumpwm-mixer/README.md
Normal file
15
media/stumpwm-mixer/README.md
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# stumpwm-mixer
|
||||
|
||||
This is a StumpWM interface to FreeBSD's built-in `mixer` command so
|
||||
that you can control the volume from StumpWM and get some visual
|
||||
feedback when the volume changes. It's deliberately designed to have a
|
||||
similar interface to the `stumpwm-sndioctl` module.
|
||||
|
||||
Add something like this to your config to bind its commands to the
|
||||
media buttons:
|
||||
|
||||
```
|
||||
(define-key *top-map* (kbd "XF86AudioMute") "toggle-mute")
|
||||
(define-key *top-map* (kbd "XF86AudioLowerVolume") "volume-down")
|
||||
(define-key *top-map* (kbd "XF86AudioRaiseVolume") "volume-up")
|
||||
```
|
||||
51
media/stumpwm-mixer/mixer.lisp
Normal file
51
media/stumpwm-mixer/mixer.lisp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
(in-package #:stumpwm-mixer)
|
||||
|
||||
(defun mixer-output ()
|
||||
(let ((output (run-shell-command "mixer" t)))
|
||||
(loop for line in (uiop:split-string output :separator '(#\newline))
|
||||
collect (uiop:split-string line :separator '(#\space)))))
|
||||
|
||||
(defun parse-mixer ()
|
||||
(let ((output (mixer-output))
|
||||
(rem '("" "Mixer" "is" "currently" "set" "to")))
|
||||
(loop for line in output
|
||||
collect (remove-if
|
||||
(lambda (x)
|
||||
(member x rem :test #'equalp))
|
||||
line))))
|
||||
|
||||
(defun print-audio ()
|
||||
(let* ((output (parse-mixer))
|
||||
(volume (car (cdr (assoc "pcm" output :test #'equalp))))
|
||||
(muted (car (cdr (assoc "vol" output :test #'equalp)))))
|
||||
(message
|
||||
(format nil "Volume: ~a~:[~; (muted)~]" volume
|
||||
(string= "0:0" muted)))))
|
||||
|
||||
(defcommand volume-up () ()
|
||||
(run-shell-command
|
||||
"mixer pcm +5")
|
||||
(print-audio))
|
||||
|
||||
(defcommand volume-down () ()
|
||||
(run-shell-command
|
||||
"mixer pcm -5")
|
||||
(print-audio))
|
||||
|
||||
(defcommand toggle-mute () ()
|
||||
(let ((vol (assoc "vol" (parse-mixer)
|
||||
:test #'equalp)))
|
||||
(if (equalp (cadr vol) "0:0")
|
||||
(run-shell-command
|
||||
"mixer vol 100")
|
||||
(run-shell-command
|
||||
"mixer vol 0"))
|
||||
(print-audio)))
|
||||
|
||||
(defcommand set-mute () ()
|
||||
(run-shell-command
|
||||
"mixer vol 0"))
|
||||
|
||||
(defcommand unset-mute () ()
|
||||
(run-shell-command
|
||||
"mixer vol 100"))
|
||||
7
media/stumpwm-mixer/package.lisp
Normal file
7
media/stumpwm-mixer/package.lisp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(defpackage #:stumpwm-mixer
|
||||
(:use :cl :stumpwm)
|
||||
(:export :volume-up
|
||||
:volume-down
|
||||
:toggle-mute
|
||||
:set-mute
|
||||
:unset-mute))
|
||||
8
media/stumpwm-mixer/stumpwm-mixer.asd
Normal file
8
media/stumpwm-mixer/stumpwm-mixer.asd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(defsystem "stumpwm-mixer"
|
||||
:description "Interface to FreeBSD's built-in sound mixer"
|
||||
:author "Nyx <n1x@riseup.net>"
|
||||
:license "ISC"
|
||||
:serial t
|
||||
:depends-on ("stumpwm")
|
||||
:components ((:file "package")
|
||||
(:file "mixer")))
|
||||
Loading…
Reference in a new issue