summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--attic/jao-mpdn.el (renamed from lib/media/jao-mpdn.el)0
-rw-r--r--init.org4
-rw-r--r--lib/media/jao-mpc.el64
3 files changed, 63 insertions, 5 deletions
diff --git a/lib/media/jao-mpdn.el b/attic/jao-mpdn.el
index d707767..d707767 100644
--- a/lib/media/jao-mpdn.el
+++ b/attic/jao-mpdn.el
diff --git a/init.org b/init.org
index 04a3f8d..773b2fa 100644
--- a/init.org
+++ b/init.org
@@ -2970,10 +2970,6 @@
(defalias 'jao-player-echo 'jao-mpc-echo-current)
(defalias 'jao-player-list 'jao-mpc-show-playlist)
(defalias 'jao-player-browse 'jao-mpc-show-albums)
-
- (use-package elmpd :ensure t)
- (use-package jao-mpdn :demand t)
- (jao-mpdn-setup)
#+end_src
*** mopidy
#+begin_src emacs-lisp
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el
index 59021ca..669883c 100644
--- a/lib/media/jao-mpc.el
+++ b/lib/media/jao-mpc.el
@@ -41,6 +41,66 @@
(or jao-mpc--local-port jao-mpc-port)
cmd)))
+(defconst jao-mpc--fields
+ '(artist album composer originaldate genre title track position time name))
+
+(defconst jao-mpc--stfmt
+ (mapconcat (lambda (f) (format "%s:::%%%s%%" f f)) jao-mpc--fields "\n"))
+
+(defun jao-mpc--current ()
+ (let ((s (jao-mpc--cmd (format "-f '%s' current" jao-mpc--stfmt)))
+ (res))
+ (dolist (s (split-string s "\n" t " ") res)
+ (when (string-match "\\(.+\\):::\\(.+\\)" s)
+ (push (cons (intern (match-string 1 s)) (match-string 2 s)) res)))))
+
+(defun jao-mpc--current-str (&optional current len)
+ (let* ((current (or current (jao-mpc--current)))
+ (len (or len (jao-mpc--queue-len)))
+ (title (alist-get 'title current (alist-get 'name current "")))
+ (album (alist-get 'album current))
+ (artist (alist-get 'artist current))
+ (composer (alist-get 'composer current))
+ (no (string-to-number (alist-get 'track current "0")))
+ (time (alist-get 'time current "")))
+ (format " %s%s %s%s%s%s"
+ (jao--put-face (if (zerop no) "" (format "%02d/%s " no len))
+ 'jao-themes-f02)
+ (jao--put-face title 'jao-themes-f00)
+ (jao--put-face artist 'jao-themes-f01)
+ (jao--put-face (if composer (format " [%s]" composer) "")
+ 'jao-themes-f01)
+ (jao--put-face (if album (format " (%s)" album) "") 'jao-themes-f11)
+ (if (string-blank-p time)
+ ""
+ (jao--put-face (format " [%s]" time) 'jao-themes-dimm)))))
+
+(defvar jao-mpc-minibuffer-str "")
+
+(defun jao-mpc--playing-p ()
+ (not (string-blank-p (jao-mpc--cmd "status|grep '\\[playing\\]'"))))
+
+(defun jao-mpc--queue-len ()
+ (string-to-number (jao-mpc--cmd "playlist|wc -l")))
+
+(defun jao-mpc--set-current-str (&optional _proc _str)
+ (setq jao-mpc-minibuffer-str
+ (if (jao-mpc--playing-p)
+ (jao-mpc--current-str)
+ (when (and jao-random-album-p (not (jao-mpc--current)))
+ (jao-random-album-next))
+ "")))
+
+(defvar jao-mpc--idle-proc nil)
+
+(defun jao-mpc--idle-loop ()
+ (when jao-mpc--idle-proc (kill-process jao-mpc--idle-proc))
+ (setq jao-mpc--idle-proc
+ (make-process :name "jao-mpc-idleloop"
+ :buffer "*jao-mpc-idleloop*"
+ :command '("mpc" "idleloop" "player")
+ :filter #'jao-mpc--set-current-str)))
+
(define-derived-mode jao-mpc-albums-mode fundamental-mode "MPC Albums"
"Mode to display the list of albums known by mpd."
(read-only-mode -1)
@@ -167,7 +227,9 @@
(setq jao-lyrics-info-function #'jao-mpc-lyrics-track-data)
(jao-random-album-setup #'jao-mpc--album-buffer
#'jao-mpc--add-and-play
- #'jao-mpc-stop))
+ #'jao-mpc-stop)
+ (jao-mpc--idle-loop)
+ (jao-minibuffer-add-msg-variable 'jao-mpc-minibuffer-str 1))
(provide 'jao-mpc)
;;; jao-mpc.el ends here