[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/mpv 937bdf522a 17/50: implement seeking and changing of pl
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/mpv 937bdf522a 17/50: implement seeking and changing of playback speed |
Date: |
Tue, 28 Dec 2021 00:58:39 -0500 (EST) |
branch: elpa/mpv
commit 937bdf522a48951d9de0654498a05f9d41c2fc3e
Author: Johann Klähn <kljohann@gmail.com>
Commit: Johann Klähn <kljohann@gmail.com>
implement seeking and changing of playback speed
---
mpv.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/mpv.el b/mpv.el
index f69c33368b..9a86d9a2c6 100644
--- a/mpv.el
+++ b/mpv.el
@@ -4,7 +4,7 @@
;; Author: Johann Klähn <kljohann@gmail.com>
;; Keywords: tools, multimedia
-;; Package-Requires: ((json "1.3") (org "8.0"))
+;; Package-Requires: ((json "1.3") (org "8.0") (cl-lib "0.5"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -37,6 +37,7 @@
(eval-when-compile (require 'names))
+(require 'cl-lib)
(require 'json)
(require 'org)
(require 'org-timer)
@@ -50,6 +51,13 @@
"Name or path to the mpv executable."
:type 'file)
+(defcustom speed-step 1.10
+ "Scale factor used when adjusting playback speed."
+ :type 'number)
+
+(defcustom seek-step 5
+ "Step size in seconds used when seeking.")
+
(defvar -process nil)
(defvar -queue nil)
@@ -101,7 +109,7 @@ below."
t))
(defun -tq-filter (tq string)
-"Append to the queue's buffer and process the new data.
+ "Append to the queue's buffer and process the new data.
TQ is a transaction queue created by `tq-create'.
STRING is the data fragment received from the process.
@@ -138,6 +146,7 @@ drops unsolicited event messages."
(tq-queue-pop tq)))
(-tq-process-buffer tq))))
+:autoload
(defun play (path)
"Start an mpv process playing the file at PATH.
@@ -208,6 +217,49 @@ This can be used with the `org-open-at-point-functions'
hook."
(let ((secs (org-timer-hms-to-secs (match-string 0))))
(when (> secs 0)
(-enqueue `("seek" ,secs "absolute") #'ignore))))))
+
+(defun speed-set (factor)
+ "Set playback speed to FACTOR."
+ (interactive "nFactor: ")
+ (-enqueue `("multiply" "speed" ,(abs factor)) #'ignore))
+
+(defun speed-increase (steps)
+ "Increase playback speed by STEPS factors of `mpv-speed-step'."
+ (interactive "p")
+ (let ((factor (* (abs steps)
+ (if (> steps 0)
+ mpv-speed-step
+ (/ 1 mpv-speed-step)))))
+ (-enqueue `("multiply" "speed" ,factor) #'ignore)))
+
+(defun speed-decrease (steps)
+ "Decrease playback speed by STEPS factors of `mpv-speed-step'."
+ (interactive "p")
+ (speed-increase (- steps)))
+
+(defun -raw-prefix-to-seconds (arg)
+ "Convert raw prefix argument ARG to seconds using `mpv-seek-step'.
+Numeric arguments will be treated as seconds, repeated use
+\\[universal-argument] will be multiplied with `mpv-seek-step'."
+ (if (numberp arg)
+ arg
+ (* mpv-seek-step
+ (cl-signum (or (car arg) 1))
+ (log (abs (or (car arg) 4)) 4))))
+
+(defun seek-forward (arg)
+ "Seek forward ARG seconds.
+If ARG is numeric, it is used as the number of seconds. Else each use
+of \\[universal-argument] will add another `mpv-seek-step' seconds."
+ (interactive "P")
+ (-enqueue `("seek" ,(-raw-prefix-to-seconds arg) "relative") #'ignore))
+
+(defun seek-backward (arg)
+ "Seek backward ARG seconds.
+If ARG is numeric, it is used as the number of seconds. Else each use
+of \\[universal-argument] will add another `mpv-seek-step' seconds."
+ (interactive "P")
+ (seek-forward (- (-raw-prefix-to-seconds arg))))
)
(provide 'mpv)
- [nongnu] elpa/mpv 604b32d7e6 11/50: add play command, (continued)
- [nongnu] elpa/mpv 604b32d7e6 11/50: add play command, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 15c51ddc5e 10/50: remove dependency on dash library, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 059135de39 28/50: version 0.1.0, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 9e1781249f 27/50: convert numbers to strings before encoding as JSON, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 79e01bf89b 35/50: Remove stale socket files when mpv process is gone, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 4dddd55c5e 41/50: Add mpv-version., ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 2d40c45505 38/50: Add mpv-seek and mpv-revert-seek commands, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv a5c6eed9ac 44/50: Add volume control commands, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 3a43c9e60a 14/50: reorder function definitions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 338af25d20 23/50: add mpv-on-event-hook, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 937bdf522a 17/50: implement seeking and changing of playback speed,
ELPA Syncer <=
- [nongnu] elpa/mpv 0e4318b45f 13/50: improve docstrings, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 0579b5c707 09/50: support inserting org timer list items, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv ce3bbfac36 22/50: add mpv-default-options, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 9ef359d712 20/50: fix generation of autoloads, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 9ff4d5d80b 25/50: fix mpv-insert-playback-position, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 705e81b8a6 42/50: Make mpv-version more verbose and update its docstring as suggested, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv ed83369372 39/50: Fix mpv-seek-to-position-at-point for start-of-playback position, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 2d24187f7b 43/50: Merge pull request #9 from firmart/patch-mpv-version, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv ed9c7b0028 21/50: move functions to public interface, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv ec4929ad5d 19/50: fix package header for melpa, ELPA Syncer, 2021/12/28