From d5fa86062b31179c268cb914266f0e646a244229 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 31 May 2021 04:43:10 +0100 Subject: losing weight: elmpd instead of emms not only simpler, but also asynchronous --- attic/jao-emms-info-track.el | 214 +++++++++++++++++++++++++++++++++++ attic/jao-emms-lyrics.el | 41 +++++++ attic/jao-emms-random-album.el | 118 +++++++++++++++++++ attic/jao-emms.el | 27 +++++ attic/misc.org | 133 ++++++++++++++++++++++ init.org | 166 +++++---------------------- lib/media/jao-emms-info-track.el | 214 ----------------------------------- lib/media/jao-emms-lyrics.el | 41 ------- lib/media/jao-emms-random-album.el | 118 ------------------- lib/media/jao-emms.el | 27 ----- lib/media/jao-mpc.el | 224 +++++++++++++++++++++++++++++++++++++ lib/media/jao-random-album.el | 14 +-- 12 files changed, 789 insertions(+), 548 deletions(-) create mode 100644 attic/jao-emms-info-track.el create mode 100644 attic/jao-emms-lyrics.el create mode 100644 attic/jao-emms-random-album.el create mode 100644 attic/jao-emms.el delete mode 100644 lib/media/jao-emms-info-track.el delete mode 100644 lib/media/jao-emms-lyrics.el delete mode 100644 lib/media/jao-emms-random-album.el delete mode 100644 lib/media/jao-emms.el create mode 100644 lib/media/jao-mpc.el diff --git a/attic/jao-emms-info-track.el b/attic/jao-emms-info-track.el new file mode 100644 index 0000000..cf93625 --- /dev/null +++ b/attic/jao-emms-info-track.el @@ -0,0 +1,214 @@ +;; jao-emms-info-track.el -- utilities to show tracks -*- lexical-binding:t; -*- + +;; Copyright (C) 2009, 2010, 2013, 2017, 2020, 2021 Jose Antonio Ortega Ruiz + +;; Author: Jose Antonio Ortega Ruiz +;; Start date: Sat Jul 04, 2009 13:47 + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'emms) +(require 'emms-tag-editor) +(require 'emms-player-mpd) +(require 'jao-emms) +(require 'jao-minibuffer) + +(defgroup jao-emms-faces nil "Faces" + :group 'faces + :group 'jao-emms) + +(defface jao-emms-font-lock-album '((t (:foreground "lightgoldenrod2"))) + "Album name in EMMS track message." + :group 'jao-emms-faces) + +(defface jao-emms-font-lock-track '((t (:bold t))) + "Track number in EMMS track message." + :group 'jao-emms-faces) + +(defface jao-emms-font-lock-title '((t (:foreground "dodgerblue2"))) + "Track title in EMMS track message." + :group 'jao-emms-faces) + +(defface jao-emms-font-lock-artist '((t (:foreground "dodgerblue3"))) + "Artist name in EMMS track message." + :group 'jao-emms-faces) + +(defcustom jao-emms-show-osd-p nil + "Whether to show osd notices on track change" + :group 'jao-emms) + + + +(defun jao-emms-info-track-stream (track) + "Return track info for streams" + (let* ((name (emms-track-name track)) + (title (or (emms-track-get track 'title nil) + (car (emms-track-get track 'metadata nil)) + (car (split-string (shell-command-to-string "mpc status") + "\n")))) + (title (if (string-match "https?://\\([^/]+\\)/.+" (or title "")) + (match-string 1 title) + title))) + (format " %s (%s)" (or title "") (if title (emms-track-type track) name)))) + +(defsubst jao--put-face (str face) + (put-text-property 0 (length str) 'face face str) + str) + +(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--fmt-time (x suffix) + (if x (format "%02d:%02d%s" (/ x 60) (mod x 60) (or suffix "")) "")) + +(defun jao-emms--fmt-song-times (track lapsed pre post) + (if lapsed + (let ((time (when track (emms-track-get track 'info-playing-time)))) + (format "%s%s%s%s" + (or pre "") + (jao-emms--fmt-time lapsed (when time "/")) + (jao-emms--fmt-time time "") + (or post ""))) + "")) + +(defun jao-emms-info-track-file (track &optional lapsed plen titlesep) + "Return a description of the current track." + (let* ((no (jao-emms--to-number (emms-track-get track 'info-tracknumber "0"))) + (time (emms-track-get track 'info-playing-time)) + (year (emms-track-get track 'info-year)) + (year (if year (format " (%s)" year) "")) + (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)) + (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" + (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) + (or titlesep " ") + (jao-emms--fmt-song-times track lapsed "[" "] ") + (jao--put-face artist 'jao-emms-font-lock-artist) + (jao--put-face (if composer (format " [%s]" composer) "") + 'jao-emms-font-lock-artist) + (jao--put-face (if album + (format " (%s%s)" album year) + (format "%s *") year) + 'jao-emms-font-lock-album))))) + +;;;###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 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"))) + +(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 (format "%d" (1+ song)))) + (funcall callback track lapsed plen))))) + +;;;###autoload +(defun jao-emms-show-osd () + (interactive) + (jao-emms--with-mpd-track + (lambda (track lapsed play-len) + (let* ((sep "~~~~~") + (s (jao-emms-info-track-description track lapsed play-len sep)) + (s (substring-no-properties s 2)) + (cs (split-string s sep))) + (jao-notify (car cs) (cadr cs) jao-emms-show-icon))))) + +(defun jao-emms-show-osd-hook () + (interactive) + (when jao-emms-show-osd-p (jao-emms-show-osd))) + +(defun jao-emms-install-id3v2 () + (add-to-list 'emms-tag-editor-tagfile-functions + '("mp3" "id3v2" ((info-artist . "-a") + (info-title . "-t") + (info-album . "-A") + (info-tracknumber . "-T") + (info-year . "-y") + (info-genre . "-g") + (info-composer . "--TCOM") + (info-note . "-c"))))) + +(defvar jao-emms-echo-string "") + +(defun jao-emms--echo-string (v) + (setq jao-emms-echo-string v) + (jao-minibuffer-refresh)) + +(defun jao-emms-update-echo-string (&optional existing-track) + (if emms-player-playing-p + (jao-emms--with-mpd-track + (lambda (track lapsed play-len) + (jao-emms--echo-string + (cond ((and emms-player-paused-p existing-track) + (format "(%s/%s)" + (emms-track-get existing-track 'info-tracknumber) + play-len)) + (emms-player-paused-p "") + (t (jao-emms-info-track-description track nil play-len)))))) + (jao-emms--echo-string ""))) + +(defun jao-emms-enable-minibuffer (minibuffer-order) + (jao-minibuffer-add-msg-variable 'jao-emms-echo-string minibuffer-order) + (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 minibuffer show-osd show-echo-line 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 minibuffer (jao-emms-enable-minibuffer minibuffer)) + (unless show-echo-line + (eval-after-load 'emms-player-mpd + '(remove-hook 'emms-player-started-hook 'emms-player-mpd-show))) + (when id3 (jao-emms-install-id3v2)) + (ignore-errors (emms-player-mpd-connect))) + + +(provide 'jao-emms-info-track) +;;; jao-emms-info-track.el ends here diff --git a/attic/jao-emms-lyrics.el b/attic/jao-emms-lyrics.el new file mode 100644 index 0000000..0ea52e0 --- /dev/null +++ b/attic/jao-emms-lyrics.el @@ -0,0 +1,41 @@ +;; jao-emms-lyrics.el -- simple show lyrics in emms + +;; Copyright (C) 2009, 2010, 2017, 2019, 2020 Jose Antonio Ortega Ruiz + +;; Author: Jose Antonio Ortega Ruiz +;; Start date: Sat Jul 04, 2009 13:41 + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'emms) +(require 'jao-lyrics) + +;;;###autoload +(defun jao-emms-lyrics-track-data () + (let ((track (or (emms-playlist-current-selected-track) + (error "No playing track")))) + (cons (or (emms-track-get track 'info-artist nil) + (error "No artist")) + (or (emms-track-get track 'info-title nil) + (error "No artist"))))) + +;;;###autoload +(defun jao-emms-show-lyrics (&optional force) + (let ((jao-lyrics-info-function 'jao-emms-lyrics-track-data)) + (jao-show-lyrics force))) + +(provide 'jao-emms-lyrics) +;;; jao-emms-lyrics.el ends here diff --git a/attic/jao-emms-random-album.el b/attic/jao-emms-random-album.el new file mode 100644 index 0000000..72e056b --- /dev/null +++ b/attic/jao-emms-random-album.el @@ -0,0 +1,118 @@ +;; jao-emms-random-album.el -- play random albums in emms + +;; Copyright (C) 2009, 2010, 2017, 2018, 2020 Jose Antonio Ortega Ruiz + +;; Author: Jose Antonio Ortega Ruiz +;; Start date: Sat Jul 04, 2009 13:06 + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + + +(require 'emms) +(require 'jao-minibuffer) + +(defvar jao-emms-random-album-p t) +(defvar jao-emms-random-lines nil) +(defvar jao-emms-random-lines-file + (expand-file-name "~/.emacs.d/random-lines")) +(defvar jao-emms-random-album-notify-p t) +(defvar jao-emms-random-album-notify-icon nil) + +(defun jao-emms-random-lines () + (or jao-emms-random-lines + (and (file-exists-p jao-emms-random-lines-file) + (with-current-buffer + (find-file-noselect jao-emms-random-lines-file) + (goto-char (point-min)) + (setq jao-emms-random-lines (read (current-buffer))))) + (dotimes (n (1- (line-number-at-pos (point-max))) + jao-emms-random-lines) + (push (1+ n) jao-emms-random-lines)))) + +(defun jao-emms-random-lines-save () + (with-current-buffer (find-file-noselect jao-emms-random-lines-file) + (delete-region (point-min) (point-max)) + (insert (format "%s\n" jao-emms-random-lines)) + (save-buffer))) + +(defun jao-emms-goto-random-album () + (let* ((pos (random (length (jao-emms-random-lines)))) + (line (nth pos jao-emms-random-lines))) + (setq jao-emms-random-lines (remove line jao-emms-random-lines)) + (jao-emms-random-lines-save) + (goto-line line))) + +(defun jao-emms-next-noerror () + (interactive) + (when emms-player-playing-p + (error "A track is already being played")) + (cond (emms-repeat-track + (emms-start)) + ((condition-case nil + (progn + (emms-playlist-current-select-next) + t) + (error nil)) + (emms-start)) + (t + (if jao-emms-random-album-p + (jao-emms-random-album-next) + (message "No next track in playlist"))))) + + +;; User interface +;;;###autoload +(defun jao-emms-random-album-start () + (interactive) + (setq jao-emms-random-album-p t) + (jao-emms-random-album-next)) + +;;;###autoload +(defun jao-emms-random-album-stop () + (interactive) + (setq jao-emms-random-album-p nil) + (emms-stop)) + +;;;###autoload +(defun jao-emms-random-album-toggle () + (interactive) + (setq jao-emms-random-album-p (not jao-emms-random-album-p)) + (message "Random album %s" + (if jao-emms-random-album-p "enabled" "disabled"))) + +;;;###autoload +(defun jao-emms-random-album-next () + (interactive) + (save-excursion + (ignore-errors (emms-browser-clear-playlist)) + (emms-browse-by-album) + (jao-emms-goto-random-album) + (let ((album (substring-no-properties (thing-at-point 'line) 0 -1))) + (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) + (jao-minibuffer-refresh))) + +;;;###autoload +(defun jao-emms-random-album-reset () + (interactive) + (setq jao-emms-random-lines nil) + (jao-emms-random-lines-save)) + +(setq emms-player-next-function 'jao-emms-next-noerror) + + +(provide 'jao-emms-random-album) +;;; jao-emms-random-album.el ends here diff --git a/attic/jao-emms.el b/attic/jao-emms.el new file mode 100644 index 0000000..53b3513 --- /dev/null +++ b/attic/jao-emms.el @@ -0,0 +1,27 @@ +;; jao-emms.el -- shared bits + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; Author: Jose Antonio Ortega Ruiz +;; Start date: Sat Jul 04, 2009 13:51 + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(defgroup jao-emms nil "Emms extensions" :group 'emms) + + +(provide 'jao-emms) +;;; jao-emms.el ends here diff --git a/attic/misc.org b/attic/misc.org index 3a4df37..23336e0 100644 --- a/attic/misc.org +++ b/attic/misc.org @@ -1,5 +1,138 @@ #+title: Miscellaneous config bits that i don't use anymore +* emms +*** configuration + #+BEGIN_SRC emacs-lisp + (use-package emms + :pin gnu + :ensure t + :init + (setq emms-score-file "~/.emacs.d/score" + emms-stream-bookmarks-file "~/.emacs.d/streams" + emms-history-file "~/.emacs.d/cache/emms-history" + emms-cache-file "~/.emacs.d/cache/emms-cache" + emms-show-format "%s") + + (setq emms-source-file-default-directory "~/var/lib/music/" + emms-player-list '(emms-player-mpd) + emms-player-mpd-server-name "localhost" + emms-player-mpd-server-port "6600" + emms-player-mpd-music-directory emms-source-file-default-directory) + + (setq emms-volume-change-function 'emms-volume-mpd-change + emms-volume-change-amount 10 + emms-info-ogginfo-coding-system 'utf-8) + + ;; from http://www.shellarchive.co.uk/index.html#%20Prettify%20emms + (setq emms-browser-info-genre-format "%i· %n" + emms-browser-info-artist-format "%i· %n" + emms-browser-info-album-format "%i◨ %n" + emms-browser-info-title-format "%i♪ %n") + + (setq emms-last-played-format-alist + '(((emms-last-played-seconds-today) . "Today at %H:%M") + (604800 . "%a at %H:%M") + ((emms-last-played-seconds-month) . "%d") + ((emms-last-played-seconds-year) . "%m-%d") + (t . ""))) + + :hook ((emms-player-started . emms-player-mpd-show)) + + :config + (eval-after-load "emms-info" + '(add-to-list 'emms-info-functions 'emms-info-mpd))) + + (emms-all) + (emms-mode-line -1) + (emms-playing-time 1) + (emms-playing-time-disable-display) + + (use-package jao-emms-random-album + :after emms + :commands (jao-emms-random-album-next) + :init (setq jao-emms-random-album-notify-icon jao-notify-audio-icon)) + + (use-package jao-emms-info-track + :after emms + :init (setq jao-emms-show-icon jao-notify-audio-icon) + :config (jao-emms-info-setup 50)) + + (use-package jao-emms-lyrics + :after emms + :init (setq jao-lyrics-info-function 'jao-emms-lyrics-track-data)) + + (defvar jao-emms-random-album-notify--pause-icon + "/usr/share/icons/Tango/scalable/actions/media-playback-pause.svg") + + (defun jao-emms--show-status (s status) + (jao-notify (format "%s%s%s" + (cadr s) + (cdr (assoc (car s) status)) + (caddr s)) + "emms" + (if (string= "pause" (cdr (assoc "state" status))) + jao-emms-random-album-notify--pause-icon + jao-notify-audio-icon))) + + (defun jao-emms--osd-status (s &optional pref suff) + (emms-player-mpd-get-status (list s (or pref "") (or suff "")) + 'jao-emms--show-status)) + + #+END_SRC +*** helper functions + #+begin_src emacs-lisp + (defun jao-emms-volume-delta (d) + (funcall emms-volume-change-function d)) + + (defun jao-emms-show-volume () + (jao-emms--osd-status "volume" "Volume " "%")) + + (defalias 'jao-emms-update-cache 'emms-player-mpd-update-all-reset-cache) + + (defun jao-emms-load-streams () + (interactive) + (emms-play-playlist (expand-file-name "~/var/lib/music/streams.list"))) + + (defun jao-emms-search () + (interactive) + (let ((by (completing-read "Search by: " + '("artist" + "composer" + "performer" + "title" + "album" + "names")))) + (if (string= "names" by) + (emms-browser-search-by-names) + (emms-browser-search (list (intern (concat "info-" by))))))) + + (defun jao-emms-echo () + (interactive) + (emms-show) + (jao-emms-update-echo-string) + (emms-show)) + #+end_src +*** Media global aliases + #+begin_src emacs-lisp + (defalias 'jao-player-connect 'emms-player-mpd-connect) + (defalias 'jao-player-toggle 'emms-pause) + (defalias 'jao-player-next 'emms-next) + (defalias 'jao-player-previous 'emms-previous) + (defalias 'jao-player-stop 'emms-stop) + (defalias 'jao-player-start 'emms-start) + (defalias 'jao-player-seek-forward 'emms-seek-forward) + (defalias 'jao-player-seek-backward 'emms-seek-backward) + (defalias 'jao-player-play 'emms-start) + (defalias 'jao-player-search 'jao-emms-search) + (defalias 'jao-player-vol-delta 'jao-emms-volume-delta) + (defalias 'jao-player-volume 'jao-emms-show-volume) + (defalias 'jao-player-osd 'jao-emms-show-osd) + (defalias 'jao-player-echo 'jao-emms-echo) + (defalias 'jao-player-list 'emms-playlist-mode-go) + (defalias 'jao-player-browse 'emms-browser) + (defalias 'jao-player-random-album 'jao-emms-random-album-next) + #+end_src + * enwc #+BEGIN_SRC emacs-lisp (use-package enwc diff --git a/init.org b/init.org index 41936d9..03cd9bc 100644 --- a/init.org +++ b/init.org @@ -2927,138 +2927,6 @@ (global-set-key (kbd "") #'jao-toggle-audio-applet) #+end_src -*** emms -***** configuration - #+BEGIN_SRC emacs-lisp - (use-package emms - :pin gnu - :ensure t - :init - (setq emms-score-file "~/.emacs.d/score" - emms-stream-bookmarks-file "~/.emacs.d/streams" - emms-history-file "~/.emacs.d/cache/emms-history" - emms-cache-file "~/.emacs.d/cache/emms-cache" - emms-show-format "%s") - - (setq emms-source-file-default-directory "~/var/lib/music/" - emms-player-list '(emms-player-mpd) - emms-player-mpd-server-name "localhost" - emms-player-mpd-server-port "6600" - emms-player-mpd-music-directory emms-source-file-default-directory) - - (setq emms-volume-change-function 'emms-volume-mpd-change - emms-volume-change-amount 10 - emms-info-ogginfo-coding-system 'utf-8) - - ;; from http://www.shellarchive.co.uk/index.html#%20Prettify%20emms - (setq emms-browser-info-genre-format "%i· %n" - emms-browser-info-artist-format "%i· %n" - emms-browser-info-album-format "%i◨ %n" - emms-browser-info-title-format "%i♪ %n") - - (setq emms-last-played-format-alist - '(((emms-last-played-seconds-today) . "Today at %H:%M") - (604800 . "%a at %H:%M") - ((emms-last-played-seconds-month) . "%d") - ((emms-last-played-seconds-year) . "%m-%d") - (t . ""))) - - :hook ((emms-player-started . emms-player-mpd-show)) - - :config - (eval-after-load "emms-info" - '(add-to-list 'emms-info-functions 'emms-info-mpd))) - - (emms-all) - (emms-mode-line -1) - (emms-playing-time 1) - (emms-playing-time-disable-display) - - (use-package jao-emms-random-album - :after emms - :commands (jao-emms-random-album-next) - :init (setq jao-emms-random-album-notify-icon jao-notify-audio-icon)) - - (use-package jao-emms-info-track - :after emms - :init (setq jao-emms-show-icon jao-notify-audio-icon) - :config (jao-emms-info-setup 50)) - - (use-package jao-emms-lyrics - :after emms - :init (setq jao-lyrics-info-function 'jao-emms-lyrics-track-data)) - - (defvar jao-emms-random-album-notify--pause-icon - "/usr/share/icons/Tango/scalable/actions/media-playback-pause.svg") - - (defun jao-emms--show-status (s status) - (jao-notify (format "%s%s%s" - (cadr s) - (cdr (assoc (car s) status)) - (caddr s)) - "emms" - (if (string= "pause" (cdr (assoc "state" status))) - jao-emms-random-album-notify--pause-icon - jao-notify-audio-icon))) - - (defun jao-emms--osd-status (s &optional pref suff) - (emms-player-mpd-get-status (list s (or pref "") (or suff "")) - 'jao-emms--show-status)) - - #+END_SRC -***** helper functions - #+begin_src emacs-lisp - (defun jao-emms-volume-delta (d) - (funcall emms-volume-change-function d)) - - (defun jao-emms-show-volume () - (jao-emms--osd-status "volume" "Volume " "%")) - - (defalias 'jao-emms-update-cache 'emms-player-mpd-update-all-reset-cache) - - (defun jao-emms-load-streams () - (interactive) - (emms-play-playlist (expand-file-name "~/var/lib/music/streams.list"))) - - (defun jao-emms-search () - (interactive) - (let ((by (completing-read "Search by: " - '("artist" - "composer" - "performer" - "title" - "album" - "names")))) - (if (string= "names" by) - (emms-browser-search-by-names) - (emms-browser-search (list (intern (concat "info-" by))))))) - - (defun jao-emms-echo () - (interactive) - (emms-show) - (jao-emms-update-echo-string) - (emms-show)) - #+end_src -***** Media global aliases - #+begin_src emacs-lisp - (defalias 'jao-player-connect 'emms-player-mpd-connect) - (defalias 'jao-player-toggle 'emms-pause) - (defalias 'jao-player-next 'emms-next) - (defalias 'jao-player-previous 'emms-previous) - (defalias 'jao-player-stop 'emms-stop) - (defalias 'jao-player-start 'emms-start) - (defalias 'jao-player-seek-forward 'emms-seek-forward) - (defalias 'jao-player-seek-backward 'emms-seek-backward) - (defalias 'jao-player-play 'emms-start) - (defalias 'jao-player-search 'jao-emms-search) - (defalias 'jao-player-vol-delta 'jao-emms-volume-delta) - (defalias 'jao-player-volume 'jao-emms-show-volume) - (defalias 'jao-player-osd 'jao-emms-show-osd) - (defalias 'jao-player-echo 'jao-emms-echo) - (defalias 'jao-player-list 'emms-playlist-mode-go) - (defalias 'jao-player-browse 'emms-browser) - (defalias 'jao-player-random-album 'jao-emms-random-album-next) - #+end_src *** mpris #+begin_src emacs-lisp (use-package jao-mpris @@ -3156,6 +3024,28 @@ (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) + + (use-package jao-mpc + :demand t + :commands jao-mpc-setup) + + (jao-mpc-setup) + + (defalias 'jao-player-connect 'jao-mpc-connect) + (defalias 'jao-player-toggle 'jao-mpc-toggle) + (defalias 'jao-player-next 'jao-mpc-next) + (defalias 'jao-player-previous 'jao-mpc-previous) + (defalias 'jao-player-stop 'jao-mpc-stop) + (defalias 'jao-player-seek-forward 'jao-mpc-seek-forward) + (defalias 'jao-player-seek-backward 'jao-mpc-seek-backward) + (defalias 'jao-player-play 'jao-mpc-play) + (defalias 'jao-player-echo 'jao-mpc-echo-current) + (defalias 'jao-player-list 'jao-mpc-show-playlist) + (defalias 'jao-player-browse 'jao-mpc-show-albums) + #+end_src *** hydras #+begin_src emacs-lisp (require 'jao-lyrics) @@ -3163,7 +3053,7 @@ (defun jao-show-some-lyrics (arg) (interactive "P") (if (string-blank-p (or jao-mpris-track-string "")) - (jao-show-lyrics arg 'jao-emms-lyrics-track-data) + (jao-show-lyrics arg 'jao-mpc-lyrics-track-data) (jao-show-lyrics arg 'jao-mpris-artist-title))) (defalias 'jao-player-show-lyrics 'jao-show-some-lyrics) @@ -3185,7 +3075,7 @@ (interactive) (jao-notify "Volume" (format "%s%%" (jao-player-volume)))) - (use-package jao-emms-random-album) + (use-package jao-random-album :demand t) (pretty-hydra-define jao-hydra-spotify (global-map "s-s" :color blue :quit-key "q") @@ -3202,7 +3092,6 @@ "Browse" (("b" mpdel-pop-to-browser "browser") ("l" mpdel-playlist-open "playing list") - ;; ("m" jao-counsel-spotify-change-mpris "change mpris provider") ("c" (mpdel-core-replace-current-playlist) "clear list" :color red) ("s-s" jao-hydra-spotify/body nil)))) @@ -3230,11 +3119,8 @@ ("U" jao-mixer-capture-up "capture up" :color red) ("V" (jao-mixer-get-level "Capture") "show")) "Utilities" - (("C" jao-emms-update-cache "refresh cache") - ("c" jao-player-connect "reconnect to mpd") - ("r" jao-emms-random-album-toggle "toggle random album" - :toggle jao-emms-random-album-p) - ("N" jao-player-random-album "random album") + (("c" jao-player-connect "reconnect to mpd") + ("N" jao-random-album-next "random album") ("s-m" jao-hydra-media/body nil)))) #+end_src diff --git a/lib/media/jao-emms-info-track.el b/lib/media/jao-emms-info-track.el deleted file mode 100644 index cf93625..0000000 --- a/lib/media/jao-emms-info-track.el +++ /dev/null @@ -1,214 +0,0 @@ -;; jao-emms-info-track.el -- utilities to show tracks -*- lexical-binding:t; -*- - -;; Copyright (C) 2009, 2010, 2013, 2017, 2020, 2021 Jose Antonio Ortega Ruiz - -;; Author: Jose Antonio Ortega Ruiz -;; Start date: Sat Jul 04, 2009 13:47 - -;; This file is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3 of the License, or -;; (at your option) any later version. - -;; This file is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Code: - -(require 'emms) -(require 'emms-tag-editor) -(require 'emms-player-mpd) -(require 'jao-emms) -(require 'jao-minibuffer) - -(defgroup jao-emms-faces nil "Faces" - :group 'faces - :group 'jao-emms) - -(defface jao-emms-font-lock-album '((t (:foreground "lightgoldenrod2"))) - "Album name in EMMS track message." - :group 'jao-emms-faces) - -(defface jao-emms-font-lock-track '((t (:bold t))) - "Track number in EMMS track message." - :group 'jao-emms-faces) - -(defface jao-emms-font-lock-title '((t (:foreground "dodgerblue2"))) - "Track title in EMMS track message." - :group 'jao-emms-faces) - -(defface jao-emms-font-lock-artist '((t (:foreground "dodgerblue3"))) - "Artist name in EMMS track message." - :group 'jao-emms-faces) - -(defcustom jao-emms-show-osd-p nil - "Whether to show osd notices on track change" - :group 'jao-emms) - - - -(defun jao-emms-info-track-stream (track) - "Return track info for streams" - (let* ((name (emms-track-name track)) - (title (or (emms-track-get track 'title nil) - (car (emms-track-get track 'metadata nil)) - (car (split-string (shell-command-to-string "mpc status") - "\n")))) - (title (if (string-match "https?://\\([^/]+\\)/.+" (or title "")) - (match-string 1 title) - title))) - (format " %s (%s)" (or title "") (if title (emms-track-type track) name)))) - -(defsubst jao--put-face (str face) - (put-text-property 0 (length str) 'face face str) - str) - -(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--fmt-time (x suffix) - (if x (format "%02d:%02d%s" (/ x 60) (mod x 60) (or suffix "")) "")) - -(defun jao-emms--fmt-song-times (track lapsed pre post) - (if lapsed - (let ((time (when track (emms-track-get track 'info-playing-time)))) - (format "%s%s%s%s" - (or pre "") - (jao-emms--fmt-time lapsed (when time "/")) - (jao-emms--fmt-time time "") - (or post ""))) - "")) - -(defun jao-emms-info-track-file (track &optional lapsed plen titlesep) - "Return a description of the current track." - (let* ((no (jao-emms--to-number (emms-track-get track 'info-tracknumber "0"))) - (time (emms-track-get track 'info-playing-time)) - (year (emms-track-get track 'info-year)) - (year (if year (format " (%s)" year) "")) - (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)) - (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" - (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) - (or titlesep " ") - (jao-emms--fmt-song-times track lapsed "[" "] ") - (jao--put-face artist 'jao-emms-font-lock-artist) - (jao--put-face (if composer (format " [%s]" composer) "") - 'jao-emms-font-lock-artist) - (jao--put-face (if album - (format " (%s%s)" album year) - (format "%s *") year) - 'jao-emms-font-lock-album))))) - -;;;###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 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"))) - -(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 (format "%d" (1+ song)))) - (funcall callback track lapsed plen))))) - -;;;###autoload -(defun jao-emms-show-osd () - (interactive) - (jao-emms--with-mpd-track - (lambda (track lapsed play-len) - (let* ((sep "~~~~~") - (s (jao-emms-info-track-description track lapsed play-len sep)) - (s (substring-no-properties s 2)) - (cs (split-string s sep))) - (jao-notify (car cs) (cadr cs) jao-emms-show-icon))))) - -(defun jao-emms-show-osd-hook () - (interactive) - (when jao-emms-show-osd-p (jao-emms-show-osd))) - -(defun jao-emms-install-id3v2 () - (add-to-list 'emms-tag-editor-tagfile-functions - '("mp3" "id3v2" ((info-artist . "-a") - (info-title . "-t") - (info-album . "-A") - (info-tracknumber . "-T") - (info-year . "-y") - (info-genre . "-g") - (info-composer . "--TCOM") - (info-note . "-c"))))) - -(defvar jao-emms-echo-string "") - -(defun jao-emms--echo-string (v) - (setq jao-emms-echo-string v) - (jao-minibuffer-refresh)) - -(defun jao-emms-update-echo-string (&optional existing-track) - (if emms-player-playing-p - (jao-emms--with-mpd-track - (lambda (track lapsed play-len) - (jao-emms--echo-string - (cond ((and emms-player-paused-p existing-track) - (format "(%s/%s)" - (emms-track-get existing-track 'info-tracknumber) - play-len)) - (emms-player-paused-p "") - (t (jao-emms-info-track-description track nil play-len)))))) - (jao-emms--echo-string ""))) - -(defun jao-emms-enable-minibuffer (minibuffer-order) - (jao-minibuffer-add-msg-variable 'jao-emms-echo-string minibuffer-order) - (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 minibuffer show-osd show-echo-line 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 minibuffer (jao-emms-enable-minibuffer minibuffer)) - (unless show-echo-line - (eval-after-load 'emms-player-mpd - '(remove-hook 'emms-player-started-hook 'emms-player-mpd-show))) - (when id3 (jao-emms-install-id3v2)) - (ignore-errors (emms-player-mpd-connect))) - - -(provide 'jao-emms-info-track) -;;; jao-emms-info-track.el ends here diff --git a/lib/media/jao-emms-lyrics.el b/lib/media/jao-emms-lyrics.el deleted file mode 100644 index 0ea52e0..0000000 --- a/lib/media/jao-emms-lyrics.el +++ /dev/null @@ -1,41 +0,0 @@ -;; jao-emms-lyrics.el -- simple show lyrics in emms - -;; Copyright (C) 2009, 2010, 2017, 2019, 2020 Jose Antonio Ortega Ruiz - -;; Author: Jose Antonio Ortega Ruiz -;; Start date: Sat Jul 04, 2009 13:41 - -;; This file is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3 of the License, or -;; (at your option) any later version. - -;; This file is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Code: - -(require 'emms) -(require 'jao-lyrics) - -;;;###autoload -(defun jao-emms-lyrics-track-data () - (let ((track (or (emms-playlist-current-selected-track) - (error "No playing track")))) - (cons (or (emms-track-get track 'info-artist nil) - (error "No artist")) - (or (emms-track-get track 'info-title nil) - (error "No artist"))))) - -;;;###autoload -(defun jao-emms-show-lyrics (&optional force) - (let ((jao-lyrics-info-function 'jao-emms-lyrics-track-data)) - (jao-show-lyrics force))) - -(provide 'jao-emms-lyrics) -;;; jao-emms-lyrics.el ends here diff --git a/lib/media/jao-emms-random-album.el b/lib/media/jao-emms-random-album.el deleted file mode 100644 index 72e056b..0000000 --- a/lib/media/jao-emms-random-album.el +++ /dev/null @@ -1,118 +0,0 @@ -;; jao-emms-random-album.el -- play random albums in emms - -;; Copyright (C) 2009, 2010, 2017, 2018, 2020 Jose Antonio Ortega Ruiz - -;; Author: Jose Antonio Ortega Ruiz -;; Start date: Sat Jul 04, 2009 13:06 - -;; This file is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3 of the License, or -;; (at your option) any later version. - -;; This file is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - - -(require 'emms) -(require 'jao-minibuffer) - -(defvar jao-emms-random-album-p t) -(defvar jao-emms-random-lines nil) -(defvar jao-emms-random-lines-file - (expand-file-name "~/.emacs.d/random-lines")) -(defvar jao-emms-random-album-notify-p t) -(defvar jao-emms-random-album-notify-icon nil) - -(defun jao-emms-random-lines () - (or jao-emms-random-lines - (and (file-exists-p jao-emms-random-lines-file) - (with-current-buffer - (find-file-noselect jao-emms-random-lines-file) - (goto-char (point-min)) - (setq jao-emms-random-lines (read (current-buffer))))) - (dotimes (n (1- (line-number-at-pos (point-max))) - jao-emms-random-lines) - (push (1+ n) jao-emms-random-lines)))) - -(defun jao-emms-random-lines-save () - (with-current-buffer (find-file-noselect jao-emms-random-lines-file) - (delete-region (point-min) (point-max)) - (insert (format "%s\n" jao-emms-random-lines)) - (save-buffer))) - -(defun jao-emms-goto-random-album () - (let* ((pos (random (length (jao-emms-random-lines)))) - (line (nth pos jao-emms-random-lines))) - (setq jao-emms-random-lines (remove line jao-emms-random-lines)) - (jao-emms-random-lines-save) - (goto-line line))) - -(defun jao-emms-next-noerror () - (interactive) - (when emms-player-playing-p - (error "A track is already being played")) - (cond (emms-repeat-track - (emms-start)) - ((condition-case nil - (progn - (emms-playlist-current-select-next) - t) - (error nil)) - (emms-start)) - (t - (if jao-emms-random-album-p - (jao-emms-random-album-next) - (message "No next track in playlist"))))) - - -;; User interface -;;;###autoload -(defun jao-emms-random-album-start () - (interactive) - (setq jao-emms-random-album-p t) - (jao-emms-random-album-next)) - -;;;###autoload -(defun jao-emms-random-album-stop () - (interactive) - (setq jao-emms-random-album-p nil) - (emms-stop)) - -;;;###autoload -(defun jao-emms-random-album-toggle () - (interactive) - (setq jao-emms-random-album-p (not jao-emms-random-album-p)) - (message "Random album %s" - (if jao-emms-random-album-p "enabled" "disabled"))) - -;;;###autoload -(defun jao-emms-random-album-next () - (interactive) - (save-excursion - (ignore-errors (emms-browser-clear-playlist)) - (emms-browse-by-album) - (jao-emms-goto-random-album) - (let ((album (substring-no-properties (thing-at-point 'line) 0 -1))) - (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) - (jao-minibuffer-refresh))) - -;;;###autoload -(defun jao-emms-random-album-reset () - (interactive) - (setq jao-emms-random-lines nil) - (jao-emms-random-lines-save)) - -(setq emms-player-next-function 'jao-emms-next-noerror) - - -(provide 'jao-emms-random-album) -;;; jao-emms-random-album.el ends here diff --git a/lib/media/jao-emms.el b/lib/media/jao-emms.el deleted file mode 100644 index 53b3513..0000000 --- a/lib/media/jao-emms.el +++ /dev/null @@ -1,27 +0,0 @@ -;; jao-emms.el -- shared bits - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; Author: Jose Antonio Ortega Ruiz -;; Start date: Sat Jul 04, 2009 13:51 - -;; This file is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3 of the License, or -;; (at your option) any later version. - -;; This file is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Code: - -(defgroup jao-emms nil "Emms extensions" :group 'emms) - - -(provide 'jao-emms) -;;; jao-emms.el ends here diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el new file mode 100644 index 0000000..512d21b --- /dev/null +++ b/lib/media/jao-mpc.el @@ -0,0 +1,224 @@ +;;; jao-mpc-random-album.el --- random mpc albums -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 jao + +;; Author: jao +;; Keywords: convenience + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Simple mpd control using mpc commands. + +;;; Code: + +(require 'elmpd) +(require 'jao-minibuffer) +(require 'jao-lyrics) + +(defvar jao-mpc--connection nil) +(defvar jao-mpc-host "localhost") +(defvar jao-mpc-port 6600) + +(defun jao-mpc-disconnect () + (interactive) + (when jao-mpc--connection + (delete-process (elmpd-connection--fd jao-mpc--connection)) + (setq jao-mpc--connection nil))) + +(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))) + (jao-mpc--watcher jao-mpc--connection 'player)) + jao-mpc--connection) + +(defun jao-mpc--send (cmd cb) + (elmpd-send jao-mpc--connection cmd cb )) + +(defvar jao-mpc--play-status '()) +(defvar jao-mpc--current '()) +(defvar jao-mpc-minibuffer-str "") + +(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)))) + (when next (funcall next)))))) + (jao-mpc--send "status" cb))) + +(defun jao-mpc--current-get (x &optional def) + (alist-get x jao-mpc--current def nil #'string=)) + +(defun jao-mpc--status-get (x &optional def) + (alist-get x jao-mpc--play-status def nil #'string=)) + +(defun jao-mpc--playing-p () + (string= (jao-mpc--status-get "state" "") "play")) + +(defun jao-mpc--current-str () + (let ((title (jao-mpc--current-get "Title")) + (album (jao-mpc--current-get "Album")) + (no (string-to-number (jao-mpc--current-get "Track" "0"))) + (len (string-to-number (jao-mpc--status-get "playlistlength" "1"))) + (artist (jao-mpc--current-get "Artist")) + (composer (jao-mpc--current-get "Composer"))) + (format " %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)))) + +(defun jao-mpc--update-minibuffer () + (setq jao-mpc-minibuffer-str + (if (jao-mpc--playing-p) (jao-mpc--current-str) "")) + (jao-minibuffer-refresh)) + +(defun jao-mpc--update-current () + (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))))) + (jao-mpc--send "currentsong" cb))) + +(defun jao-mpc--watcher (_conn _subsys) + (jao-mpc--update-status #'jao-mpc--update-current)) + + + +(defconst jao-mpc--albums "*MPC Albums*") +(defconst jao-mpc--playlist "*MPC Playlist*") + +(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) + (delete-region (point-min) (point-max)) + (insert (shell-command-to-string "mpc list album")) + (goto-char (point-min)) + (read-only-mode 1)) + +(define-key jao-mpc-albums-mode-map (kbd "n") #'next-line) +(define-key jao-mpc-albums-mode-map (kbd "p") #'previous-line) +(define-key jao-mpc-albums-mode-map (kbd "RET") #'jao-mpc-add-and-play) +(define-key jao-mpc-albums-mode-map (kbd "q") #'bury-buffer) + +(defun jao-mpc--album-buffer () + (if-let (b (get-buffer jao-mpc--albums)) + b + (with-current-buffer (get-buffer-create jao-mpc--albums) + (jao-mpc-albums-mode) + (current-buffer)))) + +(defun jao-mpc--add-and-play (&optional album) + (interactive) + (let* ((album (or album (string-trim (thing-at-point 'line)))) + (cmd (format "mpc findadd album \"%s\" && mpc play" album))) + (shell-command-to-string "mpc clear") + (shell-command-to-string cmd))) + +(define-derived-mode jao-mpc-playlist-mode fundamental-mode "MPC Playlist" + "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")) + (goto-char (point-min)) + (read-only-mode 1)) + +(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) + +(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)))) + +;;;###autoload +(defun jao-mpc-stop () + (interactive) + (shell-command-to-string "mpc stop")) + +;;;###autoload +(defun jao-mpc-toggle () + (interactive) + (jao-mpc--send "pause" nil)) + +;;;###autoload +(defun jao-mpc-play () + (interactive) + (jao-mpc--send "play" nil)) + +;;;###autoload +(defun jao-mpc-next () + (interactive) + (jao-mpc--send "next" nil)) + +;;;###autoload +(defun jao-mpc-previous () + (interactive) + (jao-mpc--send "previous" nil)) + +;;;###autoload +(defun jao-mpc-echo-current () + (interactive) + (jao-notify (jao-mpc--current-str))) + +;;;###autoload +(defun jao-mpc-show-albums () + "Show album list." + (interactive) + (pop-to-buffer (jao-mpc--album-buffer))) + +;;;###autoload +(defun jao-mpc-show-playlist () + "Show current playlist." + (interactive) + (pop-to-buffer (jao-mpc--playlist-buffer))) + +;;;###autoload +(defun jao-mpc-lyrics-track-data () + (when-let* ((title (jao-mpc--current-get "Title")) + (artist (jao-mpc--current-get "Artist"))) + (cons (substring-no-properties title) (substring-no-properties artist)))) + +;;;###autoload +(defun jao-mpc-setup () + (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-connect) + (jao-minibuffer-add-msg-variable 'jao-mpc-minibuffer-str 1)) + +(provide 'jao-mpc) +;;; jao-mpc.el ends here diff --git a/lib/media/jao-random-album.el b/lib/media/jao-random-album.el index 7158417..791b241 100644 --- a/lib/media/jao-random-album.el +++ b/lib/media/jao-random-album.el @@ -1,6 +1,6 @@ ;; jao-random-album.el -- play random albums -;; Copyright (C) 2009, 2010, 2017, 2018, 2019 Jose Antonio Ortega Ruiz +;; Copyright (C) 2009, 2010, 2017, 2018, 2019, 2021 Jose Antonio Ortega Ruiz ;; Author: Jose Antonio Ortega Ruiz ;; Start date: Sat Jul 04, 2009 13:06 @@ -77,13 +77,11 @@ (defun jao-random-album-next () (interactive) (with-current-buffer (get-buffer (funcall jao-random-album-buffer)) - (save-excursion - (jao-goto-random-album) - (let ((album (string-trim - (substring-no-properties (thing-at-point 'line) 0 -1)))) - (funcall jao-random-album-add-tracks-and-play) - (when jao-random-album-notify-p - (jao-notify album "Next album" jao-random-album-notify-icon)))))) + (jao-goto-random-album) + (let ((album (string-trim (thing-at-point 'line)))) + (funcall jao-random-album-add-tracks-and-play album) + (when jao-random-album-notify-p + (jao-notify album "Next album" jao-random-album-notify-icon))))) (defun jao-random-album-reset () (interactive) -- cgit v1.2.3