>From 187dafa766012971bb40872d203b443bd0c3f51e Mon Sep 17 00:00:00 2001 From: Akito Mikami Date: Sat, 2 Mar 2024 14:51:49 +0900 Subject: [PATCH] * emms-cue.el: add command to jump to a track using completing-read --- emms-cue.el | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/emms-cue.el b/emms-cue.el index 880d2d8..0bc2bf7 100644 --- a/emms-cue.el +++ b/emms-cue.el @@ -22,8 +22,8 @@ ;;; Commentary: -;; By parsing cue file, we will be able to play next/previous track from a -;; single .ape or .flac file. +;; By parsing cue file, we will be able to jump to arbitary track or +;; play next/previous track from a single .ape or .flac file. ;;; Code: @@ -50,6 +50,16 @@ (message "Will play: %s" (car cue-track))) (message "Nothing to seek or missing .cue file?")))) +(defun emms-cue-jump () + "Select a track from .cue file to play using completion." + (interactive) + (let ((cue-track (emms-cue-select-track))) + (if (cdr cue-track) + (progn + (emms-seek-to (cdr cue-track)) + (message "Will play: %s" (car cue-track))) + (message "Nothing to seek or missing .cue file?")))) + (defun emms-cue-next-track (&optional previous-p) "Get title and offset of next track from .cue file. @@ -90,6 +100,34 @@ When PREVIOUS-P is t, get previous track info instead." "See `emms-cue-next-track'." (emms-cue-next-track t)) +(defun emms-cue-select-track () + "Get a list of title and offset of tracks from .cue file and call +completing-read to select one" + (let* ((track (emms-playlist-current-selected-track)) + (name (emms-track-get track 'name)) + (cue (concat (file-name-sans-extension name)".cue")) + (tracks-found '())) + (when (file-exists-p cue) + (with-temp-buffer + (emms-insert-file-contents cue) + (save-excursion + (goto-char (point-max)) ; search backwards + (while (search-backward-regexp "INDEX 01 \\([0-9][0-9]\\):\\([0-9][0-9]\\):\\([0-9][0-9]\\)" nil t 1) + (let* ((min (string-to-number (match-string-no-properties 1))) + (sec (string-to-number (match-string-no-properties 2))) + (msec (string-to-number (match-string-no-properties 3))) + (total-sec (+ (* min 60) sec (/ msec 100.0))) + (title "")) + (when (search-backward-regexp "TITLE \"\\(.*\\)\"" nil t 1) + (setq title (match-string-no-properties 1))) + (push (cons title total-sec) tracks-found))))) + (let* ((tracks-complete-table (lambda (string pred action) + (if (eq action 'metadata) + `(metadata (display-sort-function . ,#'identity)) ; don't sort + (complete-with-action action (mapcar #'car tracks-found) string pred)))) + (selection (completing-read "Select a track to play: " tracks-complete-table nil t))) + (assoc selection tracks-found))))) + (defun emms-info-cueinfo (track) "Add track information to TRACK. This is a useful element for `emms-info-functions'." -- 2.43.1