Compare commits

...

3 Commits

3 changed files with 47 additions and 18 deletions

View File

@ -172,9 +172,13 @@ Note this interface may not work with all PipeWire versions.")
(pw-cli--parse-properties)))
(defun pw-cli--format-property-value (value)
(if (consp value)
(concat "[ " (mapconcat #'pw-cli--format-property-value value ", ") " ]")
value))
(cond
((consp value)
(concat "[ " (mapconcat #'pw-cli--format-property-value value ", ") " ]"))
((numberp value)
(number-to-string value))
(t
value)))
(defun pw-cli--format-property (property)
(format "%s: %s" (car property) (pw-cli--format-property-value (cdr property))))

View File

@ -198,9 +198,11 @@ rather than using cached data to obtain the result."
(cdr (assoc "volume" parameters))
(nth port-id (cdr (assoc (if monitor-p "monitorVolumes" "channelVolumes") parameters)))))))
(defun pw-lib-set-volume (volume object)
(defun pw-lib-set-volume (volume object &optional single-p)
"Set the volume of PipeWire OBJECT to VOLUME.
VOLUME must be an integer in the range 0-100."
VOLUME must be an integer in the range 0-100.
If SINGLE-P is non-nil, set the volume only for a single channel,
otherwise set the volume to the same value for all the related channels."
(cl-destructuring-bind (node-p parameters monitor-p node-id port-id)
(pw-lib--object-parameters object)
(let* ((property (cond
@ -211,8 +213,10 @@ VOLUME must be an integer in the range 0-100."
(value (if node-p
float-volume
(let ((orig-value (cdr (assoc property parameters))))
(if single-p
(cl-substitute float-volume nil orig-value
:test #'always :start port-id :count 1)))))
:test #'always :start port-id :count 1)
(make-list (length orig-value) float-volume))))))
(pw-access-set-properties pw-lib--accessor node-id (list (cons property value))))))
(defun pw-lib-set-default (object stored-p)

View File

@ -150,7 +150,7 @@ object. Otherwise apply it on the default audio sink."
(pw-ui--update (format "%s %s" (pw-ui--object-name object) (if muted-p "muted" "unmuted")))))
;;;###autoload
(defun pipewire-set-volume (volume &optional object)
(defun pipewire-set-volume (volume &optional object single-p)
"Set volume of an audio output or input.
VOLUME must be a number in the range 0-100.
If OBJECT is given (only Nodes and Ports are allowed) or if on a Node
@ -160,32 +160,52 @@ Otherwise apply it on the default audio sink."
(setq volume (max 0 (min 100 volume)))
(unless object
(setq object (pw-ui--current-object t '("Node" "Port"))))
(pw-lib-set-volume volume object)
(pw-lib-set-volume volume object single-p)
(pw-ui--update (format "Volume %s for %s" volume (pw-ui--object-name object))))
(defun pw-ui--change-volume (step)
(defun pw-ui--change-volume (step &optional single-p)
(let* ((object (pw-ui--current-object t '("Node" "Port")))
(volume (pw-lib-volume object))
(new-volume (max 0 (min 100 (+ volume step)))))
(pipewire-set-volume new-volume object)))
(pipewire-set-volume new-volume object single-p)))
;;;###autoload
(defun pipewire-increase-volume ()
(defun pipewire-increase-volume (&optional single-p)
"Increase volume of an audio output or input.
The volume is increased by `pipewire-volume-step'.
If on a Node or Port in a PipeWire buffer, apply it on all the
channels of the given object. Otherwise apply it on the default audio
sink."
(interactive)
(pw-ui--change-volume pipewire-volume-step single-p))
;;;###autoload
(defun pipewire-increase-volume-single ()
"Increase volume of an audio output or input.
The volume is increased by `pipewire-volume-step'.
If on a Node or Port in a PipeWire buffer, apply it on the given
object. Otherwise apply it on the default audio sink."
(interactive)
(pw-ui--change-volume pipewire-volume-step))
(pipewire-increase-volume t))
;;;###autoload
(defun pipewire-decrease-volume ()
(defun pipewire-decrease-volume (&optional single-p)
"Decrease volume of an audio output or input.
The volume is Decreased by `pipewire-volume-step'.
The volume is decreased by `pipewire-volume-step'.
If on a Node or Port in a PipeWire buffer, apply it on all the
channels of the given object. Otherwise apply it on the default audio
sink."
(interactive)
(pw-ui--change-volume (- pipewire-volume-step) single-p))
;;;###autoload
(defun pipewire-decrease-volume-single ()
"Decrease volume of an audio output or input.
The volume is decreased by `pipewire-volume-step'.
If on a Node or Port in a PipeWire buffer, apply it on the given
object. Otherwise apply it on the default audio sink."
(interactive)
(pw-ui--change-volume (- pipewire-volume-step)))
(pipewire-decrease-volume t))
;;;###autoload
(defun pipewire-set-default ()
@ -212,9 +232,10 @@ Otherwise ask for the Node to set as the default Node."
(define-key map "d" 'pipewire-set-default)
(define-key map "m" 'pipewire-toggle-muted)
(define-key map "v" 'pipewire-set-volume)
(define-key map "+" 'pipewire-increase-volume)
(define-key map "=" 'pipewire-increase-volume)
(define-key map "-" 'pipewire-decrease-volume)
(define-key map "+" 'pipewire-increase-volume-single)
(define-key map "_" 'pipewire-decrease-volume-single)
map))
(define-derived-mode pipewire-mode special-mode "PW"