emms-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emms-patches] [COMMIT] emms-cue.el: New file. emms-setup.el: Enable emm


From: William Xu
Subject: [Emms-patches] [COMMIT] emms-cue.el: New file. emms-setup.el: Enable emms-cue and emms-mode-line-icon modules.
Date: Mon, 23 Nov 2009 21:27:45 +0800

---
 lisp/emms-cue.el   |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lisp/emms-setup.el |    6 ++-
 2 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 lisp/emms-cue.el

diff --git a/lisp/emms-cue.el b/lisp/emms-cue.el
new file mode 100644
index 0000000..03d0b28
--- /dev/null
+++ b/lisp/emms-cue.el
@@ -0,0 +1,93 @@
+;;; emms-cue.el --- Recognize cue sheet file
+
+;; Copyright (C) 2009 Free Software Foundation, Inc.
+
+;; Author: William Xu <address@hidden>
+
+;; This file is part of EMMS.
+
+;; EMMS 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.
+
+;; EMMS 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 EMMS; if not, write to the Free Software Foundation,
+;; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; By parsing cue file, we will be able to play next/previous track from a
+;; single .ape or .flac file.
+
+;;; Code:
+
+(require 'emms-playing-time)
+
+(defun emms-cue-next ()
+  "Play next track from .cue file."
+  (interactive)
+  (let ((cue-track (emms-cue-next-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-previous ()
+  "Play previous track from .cue file."
+  (interactive)
+  (let ((cue-track (emms-cue-previous-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.
+
+When PREVIOUS-P is t, get previous track info instead."
+  (let* ((track (emms-playlist-current-selected-track))
+         (name (emms-track-get track 'name))
+         (cue (concat (file-name-sans-extension name)".cue")))
+    (when (file-exists-p cue)
+      (with-current-buffer (find-file-noselect cue)
+        (save-excursion
+          (if previous-p
+              (goto-char (point-max))
+            (goto-char (point-min)))
+          (let ((offset nil)
+                (title "")
+                ;; We should search one more track far when getting previous
+                ;; track.
+                (one-more-track previous-p))
+            (while (and (not offset)
+                        (funcall 
+                         (if previous-p 'search-backward-regexp 
'search-forward-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))))
+                (when (funcall (if previous-p '> '<) emms-playing-time 
total-sec)
+                  (if (not one-more-track)
+                      (progn
+                        (setq offset total-sec)
+                        (when (search-backward-regexp "TITLE \"\\(.*\\)\"" nil 
t 1)
+                          (setq title (match-string-no-properties 1))))
+                    (setq one-more-track nil)))))
+            (cons title offset)))))))
+
+(defun emms-cue-previous-track ()
+  "See `emms-cue-next-track'."
+  (emms-cue-next-track t))
+
+
+(provide 'emms-cue)
+;;; emms-cue.el ends here
diff --git a/lisp/emms-setup.el b/lisp/emms-setup.el
index cb67a7c..c8cc2ae 100644
--- a/lisp/emms-setup.el
+++ b/lisp/emms-setup.el
@@ -109,7 +109,8 @@ stable features which come with the Emms distribution."
     (require 'emms-player-xine)
     (require 'emms-playlist-sort)
     (require 'emms-browser)
-    (require 'emms-lastfm))
+    (require 'emms-lastfm)
+    (require 'emms-mode-line-icon))
   ;; setup
   (emms-mode-line 1)
   (emms-mode-line-blank)
@@ -137,7 +138,8 @@ on the edge."
     (require 'emms-i18n)
     (require 'emms-tag-editor)
     (require 'emms-volume)
-    (require 'emms-playlist-limit))
+    (require 'emms-playlist-limit)
+    (require 'emms-cue))
   ;; setup
   (add-hook 'emms-player-started-hook 'emms-last-played-update-current)
   (emms-score 1)
-- 
debian.1.5.6.1.19.ge6b2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]