summaryrefslogtreecommitdiffhomepage
path: root/emms
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-10-23 01:40:37 +0100
committerjao <jao@gnu.org>2020-10-23 01:40:37 +0100
commita6b0ff6304ee71d4148ec86ed726f5be56f70fe9 (patch)
tree6d0156f104b8671606abe4f6a51f66af7457f452 /emms
parentf7dd6221829a1efb0445da28114a1481ae3c6aa0 (diff)
downloadelibs-a6b0ff6304ee71d4148ec86ed726f5be56f70fe9.tar.gz
elibs-a6b0ff6304ee71d4148ec86ed726f5be56f70fe9.tar.bz2
jao-emms using jao-minibuffer if requested to
Diffstat (limited to 'emms')
-rw-r--r--emms/jao-emms-info-track.el80
-rw-r--r--emms/jao-emms-random-album.el4
2 files changed, 61 insertions, 23 deletions
diff --git a/emms/jao-emms-info-track.el b/emms/jao-emms-info-track.el
index 98056e4..f0cdd0f 100644
--- a/emms/jao-emms-info-track.el
+++ b/emms/jao-emms-info-track.el
@@ -1,4 +1,4 @@
-;; jao-emms-info-track.el -- utilities to show tracks
+;; jao-emms-info-track.el -- utilities to show tracks -*- lexical-binding:t; -*-
;; Copyright (C) 2009, 2010, 2013, 2017, 2020 Jose Antonio Ortega Ruiz
@@ -24,6 +24,7 @@
(require 'emms-tag-editor)
(require 'jao-osd)
(require 'jao-emms)
+(require 'jao-minibuffer)
(defgroup jao-emms-faces nil "Faces"
:group 'faces
@@ -62,16 +63,23 @@
(put-text-property 0 (length str) 'face face str)
str)
-(defun jao-emms-info-track-file (track &optional lapsed titlesep)
+(defun jao-emms--to-number (x)
+ (or (and (numberp x) x)
+ (and (stringp x)
+ (string-match "\\`\\(:?[0-9]+\\)" x)
+ (string-to-number (match-string 1 x)))))
+
+(defun jao-emms-info-track-file (track &optional lapsed plen titlesep)
"Return a description of the current track."
- (let ((no (string-to-number (emms-track-get track 'info-tracknumber "0")))
+ (let ((no (jao-emms--to-number (emms-track-get track 'info-tracknumber "0")))
(time (emms-track-get track 'info-playing-time))
(artist (emms-track-get track 'info-artist ""))
(composer (emms-track-get track 'info-composer nil))
(title (emms-track-get track 'info-title ""))
(album (emms-track-get track 'info-album))
(last-played (or (emms-track-get track 'last-played) '(0 0 0)))
- (play-count (or (emms-track-get track 'play-count) 0)))
+ (play-count (or (emms-track-get track 'play-count) 0))
+ (playlength (if plen (format "/%02d" (string-to-number plen)) "")))
(if (or (not title) (not album))
(emms-track-simple-description track)
(format "♪ [%s%s] %s%s%s%s%s%s"
@@ -82,45 +90,52 @@
'jao-emms-font-lock-artist)
(jao--put-face (if album (format " (%s)" album) " *")
'jao-emms-font-lock-album)
- (or titlesep " ")
- (jao--put-face (if (zerop no) "" (format " %02d · " no))
+ (or titlesep "")
+ (jao--put-face (if (zerop no) "" (format " %02d%s " no playlength))
'jao-emms-font-lock-track)
(jao--put-face title
'jao-emms-font-lock-title)))))
-(defun jao-emms-info-track-description (track &optional lapsed tsep)
+;;;###autoload
+(defun jao-emms-info-track-description (track &optional lapsed plen tsep)
(if (memq (emms-track-type track) '(streamlist url))
(jao-emms-info-track-stream track)
- (jao-emms-info-track-file track lapsed tsep)))
+ (jao-emms-info-track-file track lapsed plen tsep)))
+;;;###autoload
(defun jao-emms-toggle-osd ()
(interactive)
(setq jao-emms-show-osd-p (not jao-emms-show-osd-p))
(message "Emms OSD %s" (if jao-emms-show-osd-p "enabled" "disabled")))
-(defsubst jao-emms-current-track-str (&optional lapsed tsep)
- (substring-no-properties
- (jao-emms-info-track-description (emms-playlist-current-selected-track)
- lapsed tsep)))
-
(defvar jao-emms-show-icon nil)
+(defun jao-emms--with-mpd-track (callback)
+ (emms-player-mpd-get-status
+ nil
+ (lambda (_ st)
+ (let* ((lapsed (jao-emms--to-number (cdr (assoc "time" st))))
+ (plen (cdr (assoc "playlistlength" st)))
+ (song (jao-emms--to-number (cdr (assoc "song" st))))
+ (track (emms-playlist-current-selected-track)))
+ (when (and track song)
+ (emms-track-set track 'info-tracknumber (1+ song)))
+ (funcall callback track lapsed plen)))))
+
;;;###autoload
(defun jao-emms-show-osd ()
(interactive)
- (emms-player-mpd-get-playing-time
- nil
- (lambda (v l)
+ (jao-emms--with-mpd-track
+ (lambda (track lapsed play-len)
(let* ((sep "~~~~~")
- (s (substring (jao-emms-current-track-str l sep) 2))
+ (s (jao-emms-info-track-description track lapsed play-len sep))
+ (s (substring-no-properties s 2))
(cs (split-string s sep)))
- (jao-notify (cadr cs) (car cs) jao-emms-show-icon))
- t)))
+ (jao-notify (cadr cs) (car cs) jao-emms-show-icon)))))
(defun jao-emms-show-osd-hook ()
(interactive)
- (when jao-emms-show-osd-p (jao-emms-show-osd))
- t)
+ (when jao-emms-show-osd-p (jao-emms-show-osd)))
(defun jao-emms-install-i3dv2 ()
(add-to-list 'emms-tag-editor-tagfile-functions
@@ -133,11 +148,32 @@
(info-composer . "-TCOM")
(info-note . "c")))))
+(defvar jao-emms-echo-string "")
+(defun jao-emms-update-echo-string ()
+ (if (and emms-player-playing-p (not emms-player-paused-p))
+ (jao-emms--with-mpd-track
+ (lambda (track _ play-len)
+ (setq jao-emms-echo-string
+ (jao-emms-info-track-description track nil play-len))
+ (jao-minibuffer-refresh)))
+ (setq jao-emms-echo-string "")
+ (jao-minibuffer-refresh)))
+
+(defun jao-emms-enable-minibuffer ()
+ (jao-minibuffer-add-variable 'jao-emms-echo-string t)
+ (dolist (h '(emms-track-updated-functions
+ emms-player-finished-hook
+ emms-player-stopped-hook
+ emms-player-started-hook
+ emms-player-paused-hook))
+ (add-hook h #'jao-emms-update-echo-string)))
+
;;;###autoload
-(defun jao-emms-info-setup (&optional show-osd show-echo-line no-id3)
+(defun jao-emms-info-setup (&optional show-mini show-osd show-echo-line no-id3)
(setq emms-track-description-function 'jao-emms-info-track-description)
(setq jao-emms-show-osd-p show-osd)
(add-hook 'emms-player-started-hook 'jao-emms-show-osd-hook)
+ (when show-mini (jao-emms-enable-minibuffer))
(unless show-echo-line
(eval-after-load 'emms-player-mpd
'(remove-hook 'emms-player-started-hook 'emms-player-mpd-show)))
diff --git a/emms/jao-emms-random-album.el b/emms/jao-emms-random-album.el
index 9c3246d..72e056b 100644
--- a/emms/jao-emms-random-album.el
+++ b/emms/jao-emms-random-album.el
@@ -20,6 +20,7 @@
(require 'emms)
+(require 'jao-minibuffer)
(defvar jao-emms-random-album-p t)
(defvar jao-emms-random-lines nil)
@@ -101,7 +102,8 @@
(emms-browser-add-tracks-and-play)
(when jao-emms-random-album-notify-p
(jao-notify album "Next album" jao-emms-random-album-notify-icon)))
- (emms-browser-bury-buffer)))
+ (emms-browser-bury-buffer)
+ (jao-minibuffer-refresh)))
;;;###autoload
(defun jao-emms-random-album-reset ()