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

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

[nongnu] elpa/subed 5577c44bac 2/8: Add support for setting timestamps w


From: ELPA Syncer
Subject: [nongnu] elpa/subed 5577c44bac 2/8: Add support for setting timestamps with the mouse
Date: Sun, 18 Jun 2023 16:02:31 -0400 (EDT)

branch: elpa/subed
commit 5577c44bace1636237c84a18143505259b0fd417
Author: Marcin Borkowski <mbork@mbork.pl>
Commit: Marcin Borkowski <mbork@mbork.pl>

    Add support for setting timestamps with the mouse
---
 subed/subed-waveform.el | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/subed/subed-waveform.el b/subed/subed-waveform.el
index 62993f5dd6..4cfbc32693 100644
--- a/subed/subed-waveform.el
+++ b/subed/subed-waveform.el
@@ -73,6 +73,14 @@ when people speak are indistinguishable from silence."
   :type 'number
   :group 'subed-waveform)
 
+(defcustom subed-waveform-timestamp-resolution
+  20
+  "Resolution of the timestamps.
+When the user clicks on the waveform, the timestamp set will be
+rounded to the nearest multiple of this number."
+  :type 'integer
+  :group 'subed-waveform)
+
 (defun subed-show-waveform-p ()
   "Whether waveform is displayed for the current subtitle."
   (member #'subed-waveform-put-svg subed-subtitle-motion-hook))
@@ -249,6 +257,13 @@ times per second."
     subed--waveform-stop))
   (subed--waveform-update-overlay-svg))
 
+(defconst subed-waveform-map
+  (let ((subed-waveform-map (make-keymap)))
+    (define-key subed-waveform-map [mouse-1] #'subed-waveform-set-start)
+    (define-key subed-waveform-map [mouse-3] #'subed-waveform-set-stop)
+    subed-waveform-map)
+  "A keymap for clicking on the waveform.")
+
 (defun subed--waveform-update-overlay-svg ()
   "Update the SVG in the overlay.
 Assume `subed--waveform-svg' is already set."
@@ -256,8 +271,9 @@ Assume `subed--waveform-svg' is already set."
               'before-string
               (propertize
                " "
-               'display
-               (svg-image subed--waveform-svg))))
+               'display (svg-image subed--waveform-svg)
+               'pointer 'arrow
+               'keymap subed-waveform-map)))
 
 (defun subed-waveform-put-svg ()
   "Put an overlay with the SVG in the current subtitle.
@@ -274,6 +290,27 @@ Set the relevant variables if necessary."
                 "\n"))
   (subed--waveform-set-svg))
 
+(defun waveform-mouse-event-to-ms (event)
+  "Return the millisecond position of EVENT."
+  (let* ((x (car (elt (cadr event) 8)))
+         (width (car (elt (cadr event) 9))))
+    (* subed-waveform-timestamp-resolution
+       (round (+ (* (/ (* 1.0 x) width)
+                   (- subed--waveform-stop subed--waveform-start))
+                subed--waveform-start)
+             subed-waveform-timestamp-resolution))))
+
+(defun subed-waveform-set-start (event)
+  "Set the start timestamp in the place clicked."
+  (interactive "e")
+  (subed-set-subtitle-time-start (waveform-mouse-event-to-ms event))
+  (subed--waveform-update-bars (subed-subtitle-msecs-start)))
+
+(defun subed-waveform-set-stop (event)
+  "Set the start timestamp in the place clicked."
+  (interactive "e")
+  (subed-set-subtitle-time-stop (waveform-mouse-event-to-ms event))
+  (subed--waveform-update-bars (subed-subtitle-msecs-start)))
 
 (provide 'subed-waveform)
 ;;; subed-waveform.el ends here



reply via email to

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