[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
add emms-volume-sndioctl
From: |
Omar Polo |
Subject: |
add emms-volume-sndioctl |
Date: |
Thu, 09 Sep 2021 20:10:47 +0200 |
User-agent: |
mu4e 1.6.6; emacs 28.0.50 |
Hello,
Apologies if this isn't the correct mailing list to submit EMMS patches,
I couldn't find a better place to send this to.
The following patch adds another emms-volume backend for OpenBSD'
sndioctl(1). OpenBSD used to use mixerctl(8) to adjust the volume, but
with the previous release (or the one before? I don't remember)
sndioctl(1) was added and mixerctl(8) is something reserved for lower
level tasks and requires root now IIRC.
Note that I've added the check for the `sndioctl' executable before the
others: this is needed to prevent emms to automatically choose mixerctl
(or pactl since it's not unusual to have pulseaudio installed due to
some dependency.) Should I add a comment noting this?
I already did the copyright paperwork.
Thanks,
Omar Polo
>From 185ee21071ae01176ee0f984f6fafb2088f7da1a Mon Sep 17 00:00:00 2001
From: Omar Polo <op@omarpolo.com>
Date: Thu, 9 Sep 2021 20:06:45 +0200
Subject: [PATCH] Add emms-volume-sndioctl
sndioctl(1) is the utility to manipulate audio device controls on
OpenBSD.
---
emms-volume-sndioctl.el | 71 +++++++++++++++++++++++++++++++++++++++++
emms-volume.el | 3 ++
2 files changed, 74 insertions(+)
create mode 100644 emms-volume-sndioctl.el
diff --git a/emms-volume-sndioctl.el b/emms-volume-sndioctl.el
new file mode 100644
index 0000000..4bfb574
--- /dev/null
+++ b/emms-volume-sndioctl.el
@@ -0,0 +1,71 @@
+;;; emms-volume-sndioctl.el --- a mode for changing volume using sndioctl -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2006, 2007, 2008, 2009, 2019 Free Software Foundation, Inc.
+
+;; Authors: Omar Polo <op@omarpolo.com>
+
+;; This file is part of EMMS.
+
+;; EMMS is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+;;
+;; EMMS is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with EMMS; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file defines a few simple functions to raise or lower the
+;; volume using sndioctl. It can be used stand-alone, though it's
+;; meant for usage with EMMS, particularly with emms-volume.el
+
+;;; History:
+
+;; Sep 09 2021: Based on emms-volume-mixerctl.el by Omar Polo
+
+;;; Code:
+
+(defcustom emms-volume-sndioctl-stream "output"
+ "The stream to change the volume with.
+Usually it's the global \"output\". For a full list of available
+controls, run `sndioctl' in a shell."
+ :type '(choice (const :tag "output" "output")
+ (string :tag "Something else: "))
+ :group 'emms-volume)
+
+(defcustom emms-volume-sndioctl-device nil
+ "The card number to change volume.
+The card is identified by a number. For a full list run `ls
+/dev/mixer?*' in a shell."
+ :type '(choice (const :tag "none" nil)
+ (string :tag "Device: "))
+ :group 'emms-volume)
+
+;;;###autoload
+(defun emms-volume-sndioctl-change (amount)
+ "Change sndioctl level by AMOUNT."
+ (message "Playback channels: %s"
+ (with-temp-buffer
+ (when (zerop
+ (apply #'call-process
+ "sndioctl" nil (current-buffer) nil
+ `("-n"
+ ,@(when emms-volume-sndioctl-device
+ `("-f" ,emms-volume-sndioctl-device))
+ ,(format "%s.level=%s%f"
+ emms-volume-sndioctl-stream
+ (if (> amount 0) "+" "")
+ (/ (float amount) 100)))))
+ (string-trim-right (buffer-string))))))
+
+(provide 'emms-volume-sndioctl)
+
+;;; emms-volume-sndioctl.el ends here
diff --git a/emms-volume.el b/emms-volume.el
index bb92a31..3275e38 100644
--- a/emms-volume.el
+++ b/emms-volume.el
@@ -52,6 +52,7 @@
(require 'emms-volume-amixer)
(require 'emms-volume-pulse)
(require 'emms-volume-mixerctl)
+(require 'emms-volume-sndioctl)
;; Customize group
(defgroup emms-volume nil
@@ -61,6 +62,7 @@
;; General volume setting related code.
(defcustom emms-volume-change-function
(cond
+ ((executable-find "sndioctl") 'emms-volume-sndioctl-change)
((executable-find "amixer") 'emms-volume-amixer-change)
((executable-find "pactl") 'emms-volume-pulse-change)
((executable-find "mixerctl") 'emms-volume-mixerctl-change)
@@ -71,6 +73,7 @@ If you have your own functions for changing volume, set this."
(const :tag "MPD" emms-volume-mpd-change)
(const :tag "PulseAudio" emms-volume-pulse-change)
(const :tag "Mixerctl" emms-volume-mixerctl-change)
+ (const :tag "Sndioctl" emms-volume-sndioctl-change)
(function :tag "Lisp function")))
(defcustom emms-volume-change-amount 2
--
2.33.0
- add emms-volume-sndioctl,
Omar Polo <=