al-sound.el 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;; al-sound.el --- Playing audio and controlling sound parameters
  2. ;; Copyright © 2016 Alex Kost
  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. ;;; Code:
  16. ;;; Playing sound
  17. (defvar al/play-sound-program (executable-find "play")
  18. "Default program for playing a sound.
  19. Used by `al/play-sound'.
  20. If nil, use `play-sound-file'.")
  21. (defvar al/play-sound-args (and al/play-sound-program '("-q"))
  22. "List of default arguments for `al/play-sound-program'.")
  23. ;;;###autoload
  24. (defun al/play-sound (file)
  25. "Play audio FILE with `al/play-sound-program'."
  26. (if al/play-sound-program
  27. (apply #'start-process
  28. al/play-sound-program nil al/play-sound-program
  29. (append al/play-sound-args (list file)))
  30. (with-demoted-errors "ERROR during playing sound: %S"
  31. (play-sound-file file))))
  32. ;;; Setting sound
  33. ;; This following code is used to set sound parameters (volume and
  34. ;; muteness). It looks mostly like a wrapper around 'amixer' command,
  35. ;; except that 'osd-sound' is called instead.
  36. ;;
  37. ;; This 'osd-sound' is a simple shell script that sends some Guile
  38. ;; expression to Guile-Daemon <https://github.com/alezost/guile-daemon>.
  39. ;; 2 things eventually happen: amixer is called and the sound value is
  40. ;; displayed in OSD.
  41. ;;
  42. ;; 'osd-sound' script can be found in my Guile-Daemon config:
  43. ;; <https://github.com/alezost/guile-daemon-config/blob/master/scripts/osd-sound>.
  44. (defvar al/sound-program "osd-sound"
  45. "Name of a program to be called with amixer arguments.")
  46. (defun al/sound-call (&rest args)
  47. "Execute `al/sound-program' using amixer ARGS."
  48. (apply #'start-process
  49. al/sound-program nil al/sound-program args))
  50. ;;;###autoload
  51. (defun al/set-sound (&rest args)
  52. "Set sound value for 'Master' simple control.
  53. ARGS are the rest amixer arguments after 'sset Master'."
  54. (interactive
  55. (split-string (read-string (concat al/sound-program " sset Master "))
  56. " "))
  57. (apply #'al/sound-call "sset" "Master" args))
  58. (provide 'al-sound)
  59. ;;; al-sound.el ends here