sound.lisp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ;;; sound.lisp --- Set sound parameters and show them in OSD
  2. ;; Copyright © 2013-2016 Alex Kost <alezost@gmail.com>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This file provides a couple of commands to set sound parameters
  17. ;; (volume and muteness). It looks mostly like a wrapper around
  18. ;; 'amixer' command, except that 'osd-sound' is called instead.
  19. ;;
  20. ;; This 'osd-sound' is a simple shell script that sends some Guile
  21. ;; expression to Guile-Daemon <https://github.com/alezost/guile-daemon>.
  22. ;; 2 things eventually happen: amixer is called and the sound value is
  23. ;; displayed in OSD.
  24. ;;
  25. ;; 'osd-sound' script can be found in my Guile-Daemon config:
  26. ;; <https://github.com/alezost/guile-daemon-config/blob/master/scripts/osd-sound>.
  27. ;;; Code:
  28. (in-package :stumpwm)
  29. (defvar *al/sound-program* "osd-sound"
  30. "Name of a program to be called with amixer arguments.")
  31. (defvar *al/sound-scontrols* '("Master" "Line")
  32. "List of simple controls for managing.")
  33. (defvar *al/sound-current-scontrol-num* 0
  34. "The number of the currently used simple control.")
  35. (defun al/sound-get-current-scontrol ()
  36. "Return the current simple control from `*al/sound-scontrols*'."
  37. (nth *al/sound-current-scontrol-num* *al/sound-scontrols*))
  38. (defun al/sound-get-next-scontrol ()
  39. "Return next simple control from `*al/sound-scontrols*'."
  40. (setq *al/sound-current-scontrol-num*
  41. (if (>= *al/sound-current-scontrol-num*
  42. (- (length *al/sound-scontrols*) 1))
  43. 0
  44. (+ 1 *al/sound-current-scontrol-num*)))
  45. (al/sound-get-current-scontrol))
  46. (defun al/sound-call (&rest args)
  47. "Execute `*al/sound-program*' using amixer ARGS."
  48. (run-prog *al/sound-program*
  49. :args args :wait nil :search t))
  50. (defcommand al/sound-set-current-scontrol (&rest args) (:rest)
  51. "Set sound value for the current simple control.
  52. ARGS are the rest amixer arguments after 'sset CONTROL'."
  53. (apply #'al/sound-call "sset" (al/sound-get-current-scontrol) args))
  54. (defcommand al/sound-current-scontrol () ()
  55. "Show sound value of the current simple control."
  56. (al/sound-call "sget" (al/sound-get-current-scontrol)))
  57. (defcommand al/sound-next-scontrol () ()
  58. "Switch simple control and show its sound value."
  59. (al/sound-call "sget" (al/sound-get-next-scontrol)))
  60. ;;; sound.lisp ends here