From 9e075d6e0c315a827c92d0703da3d2ec653a5dfa Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Mon, 10 Jun 2019 14:11:52 +0200 Subject: [PATCH] =?UTF-8?q?[Music]=20Introduce=20=E2=80=98db/play-auto-pla?= =?UTF-8?q?ylist=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the main entry point to play automatically generated playlists (“auto playlists”). It is using the value of ‘db/auto-playlist-file-function’ to generate a list of files to play. This list if currently played using EMMS, via ‘db/-emms-playlist-from-files’. --- init.el | 12 ++++-- site-lisp/db-emms.el | 2 +- site-lisp/db-music.el | 86 ++++++++++++++++++++++++------------------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/init.el b/init.el index dac8b4d..bda9232 100644 --- a/init.el +++ b/init.el @@ -2145,10 +2145,14 @@ search commands like `db/helm-shortcuts’." (require 'helm-adaptive))) (use-package db-music - :init (setq db/playlist-play-function #'db/play-playlist-from-git-annex-find) - :commands (db/play-playlist-from-cache - db/play-playlist-from-git-annex-find - db/update-playlist-from-directory)) + :init (setq db/auto-playlist-file-function + #'(lambda () + (db/playlist-files-from-git-annex-find + "--metadata db-playlist=include"))) + :commands (db/play-auto-playlist + db/playlist-files-from-cache + db/playlist-files-from-git-annex-find + db/update-playlist-cache-from-directory)) ;; * Shells and such diff --git a/site-lisp/db-emms.el b/site-lisp/db-emms.el index 662efbc..841ebcf 100644 --- a/site-lisp/db-emms.el +++ b/site-lisp/db-emms.el @@ -131,7 +131,7 @@ _RET_: ?RET? _M_: ?M? ("-" emms-volume-lower "lower volume") ("+" emms-volume-raise "raise volume") ("M" emms "show playlist") - ("P" (call-interactively db/playlist-play-function) + ("P" (db/play-auto-playlist) "Play automatically generated playlist")) diff --git a/site-lisp/db-music.el b/site-lisp/db-music.el index d18679a..239e64b 100644 --- a/site-lisp/db-music.el +++ b/site-lisp/db-music.el @@ -13,18 +13,22 @@ :group 'convenience :tag "db-music") -(defcustom db/playlist-play-function #'db/play-playlist-from-cache - "Function to use to automatically generate playlists" +(defcustom db/auto-playlist-file-function #'db/play-playlist-from-cache + "Function that has to return a list of all music files that +should be included in the auto playlist." :group 'db-music :type 'function) -(defcustom db/playlist nil - "List of songs to include in a random playlist." - :group 'db-music - :type '(alist :value-type (choice (const :tag "Undecided" :undecided) - (const :tag "Include" :include) - (const :tag "Exclude" :exclude)) - :key-type file)) +(defun db/play-auto-playlist () + "Generate playlist using `db/auto-playlist-file-function’ and +start playing it. + +Current backend is EMMS." + (interactive) + (db/-emms-playlist-from-files (funcall db/auto-playlist-file-function))) + +;; Idea: make this customizable, so that we can later switch to another backend +;; if necessary (defun db/-emms-playlist-from-files (files) "Generate EMMS playlist from FILES. @@ -47,16 +51,23 @@ Shuffle it and start playing it afterwards." (emms-playlist-select-first) (emms-start))))) -(defun db/play-playlist-from-cache () - "Start playing songs from `db/playlist’" - (interactive) - (db/-emms-playlist-from-files - (->> db/playlist - (cl-remove-if-not #'(lambda (track) - (eq (cdr track) :include))) - (mapcar #'car)))) +(defcustom db/playlist nil + "List of songs to include in a random playlist." + :group 'db-music + :type '(alist :value-type (choice (const :tag "Undecided" :undecided) + (const :tag "Include" :include) + (const :tag "Exclude" :exclude)) + :key-type file)) -(defun db/play-playlist-from-git-annex-find (match-expression) +(defun db/playlist-files-from-cache () + "Generate files for auto playlist from `db/playlist’ cache." + (interactive) + (->> db/playlist + (cl-remove-if-not #'(lambda (track) + (eq (cdr track) :include))) + (mapcar #'car))) + +(defun db/playlist-files-from-git-annex-find (match-expression) "Generate playlist from git annex find on MATCH-EXPRESSION. Prompts for MATCH-EXPRESSION when called interactively. @@ -65,27 +76,26 @@ are match it. Assumes `emms-source-file-default-directory’ to be part of a git-annex repository, and will complain otherwise." (interactive "smatch expression: ") (let* ((default-directory emms-source-file-default-directory)) - (db/-emms-playlist-from-files - (->> (split-string (with-output-to-string - (with-current-buffer standard-output - (let ((return-value (apply #'call-process - "git" nil t nil - "annex" "find" - (split-string match-expression)))) - (unless (zerop return-value) - (error "Call to `git-annex-find’ failed: %s" - (buffer-string)))))) - "\n") - (cl-remove-if-not #'(lambda (path) - (and (not (string-empty-p path)) - (file-exists-p path) - (file-readable-p path)))) - (mapcar #'(lambda (path) - (expand-file-name - path - emms-source-file-default-directory))))))) + (->> (split-string (with-output-to-string + (with-current-buffer standard-output + (let ((return-value (apply #'call-process + "git" nil t nil + "annex" "find" + (split-string match-expression)))) + (unless (zerop return-value) + (error "Call to `git-annex-find’ failed: %s" + (buffer-string)))))) + "\n") + (cl-remove-if-not #'(lambda (path) + (and (not (string-empty-p path)) + (file-exists-p path) + (file-readable-p path)))) + (mapcar #'(lambda (path) + (expand-file-name + path + emms-source-file-default-directory)))))) -(defun db/update-playlist-from-directory (directory) +(defun db/update-playlist-cache-from-directory (directory) "Recursively traverse DIRECTORY and update `db/playlist’. Files not present `db/playlist’ but that are found in DIRECTORY