branch: externals/listen
commit 5083dc108d116c6549afeb75fbc733e6d14c2bde
Author: Adam Porter <a...@alphapapa.net>
Commit: Adam Porter <a...@alphapapa.net>

    Change: Improve max-volume, especially with VLC
---
 README.org    |  1 +
 listen-lib.el |  5 ++++-
 listen-vlc.el | 33 ++++++++++++++++++++++++---------
 listen.el     |  5 +++--
 4 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/README.org b/README.org
index 465bdf0668..c81b2566d9 100644
--- a/README.org
+++ b/README.org
@@ -84,6 +84,7 @@ Use the command ~listen~ to show the Transient menu.  From 
there, it is--hopeful
 + Command ~listen-queue~ switches to existing queue buffers without reverting 
them.
 + Transient ~qq~ command exits the transient.
 + Optimize updating of individual tracks in queue buffer.
++ Improve handling of maximum volume with VLC (allowing boosting over 100%).
 
 ** v0.6
 
diff --git a/listen-lib.el b/listen-lib.el
index 7ddaae463a..a63c708424 100644
--- a/listen-lib.el
+++ b/listen-lib.el
@@ -44,7 +44,10 @@
 
 (cl-defstruct listen-player
   ;; TODO: Add queue slot.
-  process command args etc)
+  process command args
+  (max-volume
+   100 :documentation "Maximum volume in percent (may be greater than 100 for 
some players).")
+  etc)
 
 (cl-defstruct listen-queue
   name tracks current etc)
diff --git a/listen-vlc.el b/listen-vlc.el
index 4646c537f4..7d61671a8a 100755
--- a/listen-vlc.el
+++ b/listen-vlc.el
@@ -31,10 +31,19 @@
 
 ;;;; Types
 
-(cl-defstruct (listen-player-vlc
-               (:include listen-player
-                         (command "vlc")
-                         (args '("-I" "rc")))))
+(cl-defstruct
+    (listen-player-vlc
+     (:include listen-player
+               (command "vlc")
+               (args '("-I" "rc"))
+               (max-volume
+                ;; VLC allows very large volume percentages to boost volume 
far beyond what would be
+                ;; practical (but it's sometimes useful).  It's not clear what 
the actual maximum
+                ;; percentage is, even from looking at VLC's source code, but 
testing shows that
+                ;; values up to at least 800 seem to work.  The Qt GUI for VLC 
3.0.20 allows up to
+                ;; 200% (in the OSD text, while showing a max of 125% in the 
slider), so let's go
+                ;; with that.
+                200))))
 
 ;;;; Functions
 
@@ -116,11 +125,17 @@ Stops playing, clears playlist, adds FILE, and plays it."
 (cl-defmethod listen--volume ((player listen-player-vlc) &optional volume)
   "Return or set PLAYER's VOLUME.
 VOLUME is an integer percentage."
-  (if volume
-      (progn
-        (cl-assert (<= 0 volume 100) nil "VOLUME must be 0-100")
-        (listen--send player (format "volume %s" (* 255 (/ volume 100.0)))))
-    (* 100 (/ (string-to-number (listen--send player "volume")) 255.0))))
+  ;; While it is unclear from VLC's documentation, and even its source code at 
some revisions,
+  ;; testing shows that the "rc" interface handles volume on a scale of 256 
steps, where 255 = 100%
+  ;; (and values >255 are >100%).  See 
<https://code.videolan.org/videolan/vlc/-/issues/25143> and
+  ;; 
<https://code.videolan.org/videolan/vlc/-/commits/80b8c8254cb2fddd59d31ba3a46a6640d7ef23da>.
+  (pcase-let (((cl-struct listen-player max-volume) player))
+    (if volume
+        (progn
+          (unless (<= 0 volume max-volume)
+            (user-error "VOLUME must be 0-%s" max-volume))
+          (listen--send player (format "volume %s" (* 255 (/ volume 100.0)))))
+      (* 100 (/ (string-to-number (listen--send player "volume")) 255.0)))))
 
 (provide 'listen-vlc)
 
diff --git a/listen.el b/listen.el
index f8a26ee1d4..3286d2b118 100755
--- a/listen.el
+++ b/listen.el
@@ -362,8 +362,9 @@ TIME is a string like \"SS\", \"MM:SS\", or \"HH:MM:SS\"."
      :transient t)
     ("V" "Up" (lambda ()
                 (interactive)
-                (let ((player (listen-current-player)))
-                  (listen-volume player (min 100 (+ (listen--volume player) 
5)))))
+                (let* ((player (listen-current-player))
+                       (max-volume (listen-player-max-volume player)))
+                  (listen-volume player (min max-volume (+ (listen--volume 
player) 5)))))
      :transient t)]
    ["Repeat"
     ("rn" "None" (lambda () (interactive) (setopt listen-queue-repeat-mode 
nil))

Reply via email to