From 7ddfda9b0af623d5039f7073f6c043f370c129cc Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 31 May 2021 05:21:13 +0100 Subject: jao-mpc: more fat trimming: mpdel to the attic --- attic/misc.org | 75 +++++++++++++++++++++++++++++++++++++++ init.org | 99 +++++++++++----------------------------------------- lib/media/jao-mpc.el | 81 +++++++++++++++++++++++++++++------------- 3 files changed, 151 insertions(+), 104 deletions(-) diff --git a/attic/misc.org b/attic/misc.org index 23336e0..7087111 100644 --- a/attic/misc.org +++ b/attic/misc.org @@ -1,5 +1,80 @@ #+title: Miscellaneous config bits that i don't use anymore +* mpdel + #+BEGIN_SRC emacs-lisp + (jao-load-path "libmpdel") + (jao-load-path "mpdel") + (jao-load-path "navigel") + + (use-package navigel + :init (setq navigel-display-messages nil)) + + (defun jao-mpdel-dup-dir-p (dir) + (and (libmpdel-directory-p dir) + (string-match-p "\\[.+\\]\\b" + (or (libmpdel--directory-path dir) "")))) + + (defun jao-mpdel--filter (dirs) + (cl-remove-if 'jao-mpdel-dup-dir-p dirs)) + + (use-package libmpdel + :init (setq libmpdel-port 6669)) + + (use-package mpdel + :diminish + :init + (setq mpdel-browser-list-clean-up-function 'identity + mpdel-browser-top-level-entries + '(directories + empty-line + stored-playlists current-playlist + empty-line + "Spotify/Top Lists/Top artists/Personal" + "Spotify/Playlists/Featured" + empty-line + search-album search-artist search-title)) + + (defun jao-mpdel--show-osd (data song ml) + (let* ((no (1+ (string-to-number (or (cdr (assq 'song data)) "0")))) + (to (or (cdr (assq 'playlistlength data)) "0")) + (album (or (libmpdel-album-name song) "")) + (artist (or (libmpdel-artist-name song) "")) + (tms (split-string (or (cdr (assq 'time data)) "0/0") ":")) + (tm (format "%s/%s" + (libmpdel-time-to-string (car tms)) + (libmpdel-time-to-string (cadr tms)))) + (title (format "%s %s/%s. %s" tm no to + (or (libmpdel-entity-name song) "")))) + (if ml + (message "%s %s - %s (%s)" tm title artist album) + (jao-notify (format "%s (%s)" artist album) + title + jao-notify-audio-icon)))) + + (defun jao-mpdel-show-osd (&optional ml) + (interactive "P") + (let ((song (libmpdel-current-song))) + (when song + (libmpdel-send-command "status" + `(lambda (data) + (jao-mpdel--show-osd data ,song ,ml)))))) + + (defun jao-mpdel-search (&optional type) + (interactive + (list (completing-read "Search by: " '("album" "artist" "title")))) + (let* ((func (cond ((string= type "album") 'mpdel-core-search-by-album) + ((string= type "artist") 'mpdel-core-search-by-artist) + ((string= type "title") 'mpdel-core-search-by-title))) + (thing (read-from-minibuffer (format "Search for %s: " type)))) + (mpdel-core-open (libmpdel-search-criteria-create :type type :what thing))))) + + (use-package mpdel-browser) + (defalias 'mpdel-pop-to-browser 'mpdel-browser-open) + + (mpdel-mode) + (define-key mpdel-browser-mode-map (kbd "n") #'next-line) + (define-key mpdel-browser-mode-map (kbd "p") #'previous-line) + #+END_SRC * emms *** configuration #+BEGIN_SRC emacs-lisp diff --git a/init.org b/init.org index 03cd9bc..d2dc404 100644 --- a/init.org +++ b/init.org @@ -2949,81 +2949,6 @@ (defalias 'jao-spotify-artist #'consult-spotify-artist) (defalias 'jao-spotify-playlist #'consult-spotify-playlist) #+end_src -*** mpdel - #+BEGIN_SRC emacs-lisp - (jao-load-path "libmpdel") - (jao-load-path "mpdel") - (jao-load-path "navigel") - - (use-package navigel - :init (setq navigel-display-messages nil)) - - (defun jao-mpdel-dup-dir-p (dir) - (and (libmpdel-directory-p dir) - (string-match-p "\\[.+\\]\\b" - (or (libmpdel--directory-path dir) "")))) - - (defun jao-mpdel--filter (dirs) - (cl-remove-if 'jao-mpdel-dup-dir-p dirs)) - - (use-package libmpdel - :init (setq libmpdel-port 6669)) - - (use-package mpdel - :diminish - :init - (setq mpdel-browser-list-clean-up-function 'identity - mpdel-browser-top-level-entries - '(directories - empty-line - stored-playlists current-playlist - empty-line - "Spotify/Top Lists/Top artists/Personal" - "Spotify/Playlists/Featured" - empty-line - search-album search-artist search-title)) - - (defun jao-mpdel--show-osd (data song ml) - (let* ((no (1+ (string-to-number (or (cdr (assq 'song data)) "0")))) - (to (or (cdr (assq 'playlistlength data)) "0")) - (album (or (libmpdel-album-name song) "")) - (artist (or (libmpdel-artist-name song) "")) - (tms (split-string (or (cdr (assq 'time data)) "0/0") ":")) - (tm (format "%s/%s" - (libmpdel-time-to-string (car tms)) - (libmpdel-time-to-string (cadr tms)))) - (title (format "%s %s/%s. %s" tm no to - (or (libmpdel-entity-name song) "")))) - (if ml - (message "%s %s - %s (%s)" tm title artist album) - (jao-notify (format "%s (%s)" artist album) - title - jao-notify-audio-icon)))) - - (defun jao-mpdel-show-osd (&optional ml) - (interactive "P") - (let ((song (libmpdel-current-song))) - (when song - (libmpdel-send-command "status" - `(lambda (data) - (jao-mpdel--show-osd data ,song ,ml)))))) - - (defun jao-mpdel-search (&optional type) - (interactive - (list (completing-read "Search by: " '("album" "artist" "title")))) - (let* ((func (cond ((string= type "album") 'mpdel-core-search-by-album) - ((string= type "artist") 'mpdel-core-search-by-artist) - ((string= type "title") 'mpdel-core-search-by-title))) - (thing (read-from-minibuffer (format "Search for %s: " type)))) - (mpdel-core-open (libmpdel-search-criteria-create :type type :what thing))))) - - (use-package mpdel-browser) - (defalias 'mpdel-pop-to-browser 'mpdel-browser-open) - - (mpdel-mode) - (define-key mpdel-browser-mode-map (kbd "n") #'next-line) - (define-key mpdel-browser-mode-map (kbd "p") #'previous-line) - #+END_SRC *** mpc #+begin_src emacs-lisp (use-package elmpd :ensure t) @@ -3046,6 +2971,23 @@ (defalias 'jao-player-list 'jao-mpc-show-playlist) (defalias 'jao-player-browse 'jao-mpc-show-albums) #+end_src +*** mopidy + #+begin_src emacs-lisp + (defvar jao-mopidy-port 6669) + (defvar jao-mopidy-conn + (let ((jao-mpc-port jao-mopidy-port)) (jao-mpc--connect "jao-mopidy"))) + + (defmacro jao-mopidy-def (name args &rest body) + `(defun ,name ,args + (interactive) + (let ((jao-mpc--connection jao-mopidy-conn) + (jao-mpc-port jao-mopidy-port)) + ,@body))) + + (jao-mopidy-def jao-mopidy-show-playlist () (jao-mpc-show-playlist)) + (jao-mopidy-def jao-mopidy-clear () (jao-mpc-clear)) + (jao-mopidy-def jao-mopidy-disconnect () (jao-mpc-disconnect)) + #+end_src *** hydras #+begin_src emacs-lisp (require 'jao-lyrics) @@ -3088,11 +3030,10 @@ (("s" espotify-play-pause "toggle") ("n" espotify-next "next") ("p" espotify-previous "previous") - ("w" jao-mpdel-show-osd "currently playing")) + ("w" jao-mpris-show-osd "currently playing")) "Browse" - (("b" mpdel-pop-to-browser "browser") - ("l" mpdel-playlist-open "playing list") - ("c" (mpdel-core-replace-current-playlist) "clear list" :color red) + (("l" jao-mopidy-show-playlist "playing list") + ("c" jao-mopidy-clear "clear list" :color red) ("s-s" jao-hydra-spotify/body nil)))) (pretty-hydra-define jao-hydra-media 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 () @@ -188,6 +211,11 @@ (interactive) (jao-mpc--send "previous" nil)) +;;;###autoload +(defun jao-mpc-clear () + (interactive) + (jao-mpc--send "clear" nil)) + ;;;###autoload (defun jao-mpc-echo-current () (interactive) @@ -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 () -- cgit v1.2.3