summaryrefslogtreecommitdiffhomepage
path: root/lib/media
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-05-31 05:21:13 +0100
committerjao <jao@gnu.org>2021-05-31 06:22:47 +0100
commit7ddfda9b0af623d5039f7073f6c043f370c129cc (patch)
tree74828b5d5c1353110852d97908f853f8979c8891 /lib/media
parentd5fa86062b31179c268cb914266f0e646a244229 (diff)
downloadelibs-7ddfda9b0af623d5039f7073f6c043f370c129cc.tar.gz
elibs-7ddfda9b0af623d5039f7073f6c043f370c129cc.tar.bz2
jao-mpc: more fat trimming: mpdel to the attic
Diffstat (limited to 'lib/media')
-rw-r--r--lib/media/jao-mpc.el81
1 files changed, 56 insertions, 25 deletions
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el
index 512d21b..9004920 100644
--- a/lib/media/jao-mpc.el
+++ b/lib/media/jao-mpc.el
@@ -20,7 +20,7 @@
;;; Commentary:
-;; Simple mpd control using mpc commands.
+;; Simple mpd control using elmpd and mpc.
;;; Code:
@@ -29,6 +29,9 @@
(require 'jao-lyrics)
(defvar jao-mpc--connection nil)
+(defvar-local jao-mpc--local-connecton nil)
+(defvar-local jao-mpc--local-port nil)
+
(defvar jao-mpc-host "localhost")
(defvar jao-mpc-port 6600)
@@ -38,15 +41,18 @@
(delete-process (elmpd-connection--fd jao-mpc--connection))
(setq jao-mpc--connection nil)))
+(defun jao-mpc--connect (name &optional cb)
+ (elmpd-connect :name name
+ :host jao-mpc-host
+ :port jao-mpc-port
+ :subsystems
+ (when cb `((player) . ,cb))))
+
(defun jao-mpc-connect (&optional force)
(interactive)
(when force (jao-mpc-disconnect))
(unless jao-mpc--connection
- (setq jao-mpc--connection
- (elmpd-connect :name "jao-mpc"
- :host jao-mpc-host
- :port jao-mpc-port
- :subsystems '((player) . jao-mpc--watcher)))
+ (setq jao-mpc--connection (jao-mpc--connect "jao-mpc" 'jao-mpc--watcher))
(jao-mpc--watcher jao-mpc--connection 'player))
jao-mpc--connection)
@@ -57,14 +63,17 @@
(defvar jao-mpc--current '())
(defvar jao-mpc-minibuffer-str "")
+(defun jao-mpc--parse-retort (txt)
+ (let (res)
+ (dolist (e (split-string txt "\n" t " ") res)
+ (let ((e (split-string e ": " t " ")))
+ (when (and (car e) (cadr e))
+ (push (cons (car e) (cadr e)) res))))))
+
(defun jao-mpc--update-status (next)
(let ((cb (lambda (_c ok txt)
(when ok
- (setq jao-mpc--play-status '())
- (dolist (e (split-string txt "\n" t " "))
- (let ((e (split-string e ": " t " ")))
- (when (and (car e) (cadr e))
- (push (cons (car e) (cadr e)) jao-mpc--play-status))))
+ (setq jao-mpc--play-status (jao-mpc--parse-retort txt))
(when next (funcall next))))))
(jao-mpc--send "status" cb)))
@@ -98,15 +107,12 @@
(if (jao-mpc--playing-p) (jao-mpc--current-str) ""))
(jao-minibuffer-refresh))
-(defun jao-mpc--update-current ()
+(defun jao-mpc--update-current (&optional next)
(let ((cb (lambda (_c ok txt)
(when ok
- (setq jao-mpc--current '())
- (dolist (e (split-string txt "\n" t " "))
- (let ((e (split-string e ": " t " ")))
- (when (and (car e) (cadr e))
- (push (cons (car e) (cadr e)) jao-mpc--current))))
- (jao-mpc--update-minibuffer)))))
+ (setq jao-mpc--current (jao-mpc--parse-retort txt))
+ (jao-mpc--update-minibuffer)
+ (when next (funcall next))))))
(jao-mpc--send "currentsong" cb)))
(defun jao-mpc--watcher (_conn _subsys)
@@ -148,20 +154,37 @@
"Mode to display the list of playlist known by mpd."
(read-only-mode -1)
(delete-region (point-min) (point-max))
- (insert (shell-command-to-string "mpc playlist"))
+ (insert (shell-command-to-string (format "mpc -p %s playlist" jao-mpc-port)))
(goto-char (point-min))
+ (display-line-numbers-mode)
(read-only-mode 1))
+(defun jao-mpc--playlist-goto-current ()
+ (interactive)
+ (let ((jao-mpc--connection
+ (or jao-mpc--local-connecton jao-mpc--local-connecton)))
+ (jao-mpc--update-current
+ (lambda ()
+ (when-let (no (string-to-number (jao-mpc--current-get "Pos")))
+ (goto-char (point-min))
+ (forward-line no))))))
+
+(defun jao-mpc--playlist-play ()
+ (interactive)
+ (shell-command-to-string (format "mpc -p %s play %s"
+ (or jao-mpc--local-port jao-mpc-port)
+ (line-number-at-pos))))
+
(define-key jao-mpc-playlist-mode-map (kbd "n") #'next-line)
(define-key jao-mpc-playlist-mode-map (kbd "p") #'previous-line)
(define-key jao-mpc-playlist-mode-map (kbd "q") #'bury-buffer)
+(define-key jao-mpc-playlist-mode-map (kbd ".") #'jao-mpc--playlist-goto-current)
+(define-key jao-mpc-playlist-mode-map (kbd "RET") #'jao-mpc--playlist-play)
(defun jao-mpc--playlist-buffer ()
- (if-let (b (get-buffer jao-mpc--playlist))
- b
- (with-current-buffer (get-buffer-create jao-mpc--playlist)
- (jao-mpc-playlist-mode)
- (current-buffer))))
+ (with-current-buffer (get-buffer-create jao-mpc--playlist)
+ (jao-mpc-playlist-mode)
+ (current-buffer)))
;;;###autoload
(defun jao-mpc-stop ()
@@ -189,6 +212,11 @@
(jao-mpc--send "previous" nil))
;;;###autoload
+(defun jao-mpc-clear ()
+ (interactive)
+ (jao-mpc--send "clear" nil))
+
+;;;###autoload
(defun jao-mpc-echo-current ()
(interactive)
(jao-notify (jao-mpc--current-str)))
@@ -203,7 +231,10 @@
(defun jao-mpc-show-playlist ()
"Show current playlist."
(interactive)
- (pop-to-buffer (jao-mpc--playlist-buffer)))
+ (pop-to-buffer (jao-mpc--playlist-buffer))
+ (setq-local jao-mpc--local-connecton jao-mpc--connection
+ jao-mpc--local-port jao-mpc-port)
+ (jao-mpc--playlist-goto-current))
;;;###autoload
(defun jao-mpc-lyrics-track-data ()