branch: externals/emms
commit a330e64c212a1bf1e538be8e4615dd57a3e5191d
Author: Yoni Rabkin <y...@gnu.org>
Commit: Yoni Rabkin <y...@gnu.org>

    * emms-cue.el: Use completing-read to jump to tracks in cue file
    
    Patch by Akito Mikami
---
 AUTHORS     |  1 +
 emms-cue.el | 42 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index aae71c007f..70834e3f83 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -4,6 +4,7 @@ claims on sources, so please don't be too humble and add 
yourself.
 
 
 Alex Kost               <alez...@gmail.com>
+Akito Mikami            <m...@a64.work>
 Bram van der Kroef       <b...@fortfrances.com>
 Bruno Félix R. Ribeiro  <oitofe...@gnu.org>
 Daimrod                 <daim...@gmail.com>
diff --git a/emms-cue.el b/emms-cue.el
index 880d2d8cc3..0bc2bf72da 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'."

Reply via email to