diff options
-rw-r--r-- | init.el | 4 | ||||
-rw-r--r-- | lib/media/jao-mpc.el | 24 |
2 files changed, 16 insertions, 12 deletions
@@ -3143,8 +3143,8 @@ (jao-mpc-setup jao-mopidy-port (if jao-modeline-in-minibuffer -10 70)) (defun jao-mpc-pport (&optional mop) - (cond ((or mop (jao-mpc--playing-p jao-mopidy-port)) jao-mopidy-port) - ((jao-mpc--playing-p) 6600) + (cond ((or mop (jao-mpc-playing-p jao-mopidy-port)) jao-mopidy-port) + ((jao-mpc-playing-p) 6600) (t jao-mpc-last-port))) (defmacro jao-defun-play (name &optional mpc-name) diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el index 88cde6f..9cdd5bd 100644 --- a/lib/media/jao-mpc.el +++ b/lib/media/jao-mpc.el @@ -67,10 +67,13 @@ (jao-mpc--parse-fields s res) (jao-mpc--parse-fields st res))) -(defun jao-mpc--playing-p (&optional port) - (string-prefix-p "playing" (jao-mpc--cmd "status %state%" port))) +(defsubst jao-mpc-status (&optional port) + (string-trim (jao-mpc--cmd "status %state%" port))) -(defun jao-mpc--queue-len (&optional port) +(defsubst jao-mpc-playing-p (&optional port) + (string-prefix-p "playing" (jao-mpc-status port))) + +(defsubst jao-mpc--queue-len (&optional port) (string-to-number (jao-mpc--cmd "status %length%" port))) (defsubst jao--put-face (str face) @@ -110,12 +113,13 @@ (defvar jao-mpc-minibuffer-str "") (defun jao-mpc--set-current-str (&optional port) - (setq jao-mpc-minibuffer-str - (if (jao-mpc--playing-p port) - (jao-mpc--current-str port) - (when (and jao-random-album-p (not (jao-mpc--current-str port))) - (let ((inhibit-message t)) (jao-random-album-next))) - "")) + (let ((status (or (jao-mpc-status port) ""))) + (setq jao-mpc-minibuffer-str + (if (string= "playing" status) (jao-mpc--current-str port) "")) + (when (and jao-random-album-p + (string= status "paused") + (string= "0\n" (jao-mpc--cmd "status %songpos%" port))) + (jao-random-album-next))) (jao-minibuffer-refresh)) (defvar jao-mpc--idle-procs nil) @@ -288,7 +292,7 @@ (defun jao-mpc-connect (&optional port) (interactive) (jao-mpc--idle-loop port) - (when (jao-mpc--playing-p port) (jao-mpc--set-current-str port))) + (when (jao-mpc-playing-p port) (jao-mpc--set-current-str port))) ;;;###autoload (defun jao-mpc-setup (&optional secondary-port priority) |