emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/emms cbfa25ac34 1/3: * emms.el: accept timestamps in em


From: ELPA Syncer
Subject: [elpa] externals/emms cbfa25ac34 1/3: * emms.el: accept timestamps in emms-seek*
Date: Tue, 6 Sep 2022 14:57:47 -0400 (EDT)

branch: externals/emms
commit cbfa25ac34c7d7c5456dcbc58d48b101570ef753
Author: Yoni Rabkin <yoni@rabkins.net>
Commit: Yoni Rabkin <yoni@rabkins.net>

    * emms.el: accept timestamps in emms-seek*
    
    Modifies emms-seek and emms-seek-to functions to accept timestamps in
    addition to seconds (as they do now).  Timespec format follows ffmpeg.
    
    Patch by Petteri Hintsanen.
---
 emms.el | 53 +++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 12 deletions(-)

diff --git a/emms.el b/emms.el
index fccecb9b47..e6b7783ae7 100644
--- a/emms.el
+++ b/emms.el
@@ -455,21 +455,50 @@ If player hasn't started, then start it now."
       (emms-player-pause)
     (emms-start)))
 
-(defun emms-seek (seconds)
-  "Seek the current player SECONDS seconds.
-This can be a floating point number for sub-second fractions.
-It can also be negative to seek backwards."
-  (interactive "nSeconds to seek: ")
+(defun emms-seek (duration)
+  "Seek the current player by DURATION from its current position.
+DURATION can be:
+
+- A single number, in which case it is interpreted as seconds.
+
+- A string of form [-][HH:]MM:SS.m, where HH is hours, MM is
+  minutes, and SS is seconds.
+
+In both forms seconds can be a floating point number.  A negative
+value seeks backwards."
+  (interactive "sDuration to seek: ")
   (emms-ensure-player-playing-p)
-  (emms-player-seek seconds))
+  (emms-player-seek (emms-timespec-to-secs duration)))
 
-(defun emms-seek-to (seconds)
-  "Seek the current player to SECONDS seconds.
-This can be a floating point number for sub-second fractions.
-It can also be negative to seek backwards."
-  (interactive "nSeconds to seek to: ")
+(defun emms-seek-to (timestamp)
+  "Seek the current player to TIMESTAMP.
+TIMESTAMP can be:
+
+- A single number, in which case it is interpreted as seconds.
+
+- A string of form [HH:]MM:SS.m, where HH is hours, MM is
+  minutes, and SS is seconds.
+
+In both forms seconds can be a floating point number."
+  (interactive "sTimestamp to seek to: ")
   (emms-ensure-player-playing-p)
-  (emms-player-seek-to seconds))
+  (emms-player-seek-to (emms-timespec-to-secs timestamp t)))
+
+(defun emms-timespec-to-secs (timespec &optional absolute)
+  "TODO: docstring"
+  (let ((tokens (split-string timespec ":")))
+    (if (= (length tokens) 1)
+        ;; seconds only
+        (let ((secs (string-to-number (car tokens))))
+          (if absolute (abs secs) secs))
+      ;; HH:MM:SS
+      (let* ((sign (if (< (string-to-number (car tokens)) 0) -1 1))
+             (revtokens (reverse tokens))
+             (seconds (abs (string-to-number (or (pop revtokens) "0"))))
+             (minutes (abs (string-to-number (or (pop revtokens) "0"))))
+             (hours (abs (string-to-number (or (pop revtokens) "0"))))
+             (seekpos (* sign (+ (* 60 60 hours) (* 60 minutes) seconds))))
+        (if absolute (abs seekpos) seekpos)))))
 
 (defun emms-seek-forward ()
   "Seek ten seconds forward."



reply via email to

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