Browse Source

Add functions / hotkeys to control playback volume

pull/22/head
Leon Rische 1 year ago
parent
commit
f4e82107ed
2 changed files with 41 additions and 2 deletions
  1. +4
    -2
      README.org
  2. +37
    -0
      mpdel-core.el

+ 4
- 2
README.org View File

@ -94,8 +94,8 @@ buffer (e.g., press ~M-n~ in a playlist buffer to play the next song)
to do the same. Additionally, the following keybindings are available
in all MPDel buffers where they make sense:
| *Binding* | *Action* |
|---------+--------------------------------------|
| *Binding* | *Action* |
|-----------+--------------------------------------|
| ~a~ | add item to current playlist |
| ~A~ | add item to a stored playlist |
| ~r~ | replace current playlist with item |
@ -107,6 +107,8 @@ in all MPDel buffers where they make sense:
| ~C-x C-j~ | open a dired buffer on item at point |
| ~n~ | move to next line |
| ~p~ | move to previous line |
| ~+~ | increase playback volume |
| ~-~ | decrease playback volume |
Opening a dired buffer on the item at point requires configuring
~libmpdel-music-directory~ first.


+ 37
- 0
mpdel-core.el View File

@ -45,6 +45,11 @@
(navigel-method mpdel navigel-parent (entity)
(libmpdel-entity-parent entity))
(defcustom mpdel-core-volume-step 5
"Amount to increase / decrease the playback volume by."
:type 'integer
:group 'mpdel-core)
;;; Public functions
@ -154,6 +159,36 @@ Documentation: https://www.musicpd.org/doc/html/protocol.html#filters"
(interactive (list (read-from-minibuffer "Search with filter: ")))
(mpdel-core-open (libmpdel-filter-create :text filter)))
(defun mpdel-core-volume-adjust (amount)
"Adjust the playback volume by AMOUNT."
(let* ((volume (string-to-number (libmpdel-volume)))
(new-volume (max 0 (min 100 (+ volume amount)))))
(libmpdel-playback-set-volume new-volume)))
;;;###autoload
(defun mpdel-core-volume-increase (&optional amount)
"Increase the playback volume by AMOUNT.
If AMOUNT is nil, `mpdel-core-volume-step' is used instead.
Called interactively, AMOUNT can be passed as a prefix argument."
(interactive "P")
(cond
((null amount) (mpdel-core-volume-adjust mpdel-core-volume-step))
((listp amount)
(mpdel-core-volume-adjust (* (car amount) mpdel-core-volume-step)))
(t (mpdel-core-volume-adjust amount))))
;;;###autoload
(defun mpdel-core-volume-decrease (&optional amount)
"Decrease the playback volume by AMOUNT.
If AMOUNT is nil, `mpdel-core-volume-step' is used instead.
Called interactively, AMOUNT can be passed as a prefix argument."
(interactive "P")
(cond
((null amount) (mpdel-core-volume-adjust (- mpdel-core-volume-step)))
((listp amount)
(mpdel-core-volume-adjust (- (* (car amount) mpdel-core-volume-step))))
(t (mpdel-core-volume-adjust (- amount)))))
;;; Mode
@ -176,6 +211,8 @@ Documentation: https://www.musicpd.org/doc/html/protocol.html#filters"
(define-key map (kbd "^") #'navigel-open-parent)
(define-key map (kbd "n") #'next-line)
(define-key map (kbd "p") #'previous-line)
(define-key map (kbd "+") #'mpdel-core-volume-increase)
(define-key map (kbd "-") #'mpdel-core-volume-decrease)
map)
"Keybindings for all MPDel buffers.")


Loading…
Cancel
Save