branch: externals/listen
commit 9a195763bd2d3890e1786509113b4a47a1eca943
Author: Adam Porter <[email protected]>
Commit: Adam Porter <[email protected]>

    Fix: Playing next track after track is removed
    
    Also, this is exporting the readme file with Org 9.7.11, and now it's
    not preserving blank lines before headings, and I can't find any
    relevant option.  At least those don't matter for GitHub rendering.
---
 README.org      | 40 +---------------------------------------
 docs/README.org |  1 +
 listen-queue.el | 27 +++++++++++++++++++++------
 3 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/README.org b/README.org
index 89f1a062b3..3afd3bfb19 100644
--- a/README.org
+++ b/README.org
@@ -18,7 +18,6 @@ The primary interface to one's music library is through the 
filesystem, by selec
 A simple "library" view is provided that shows a list of files organized into 
a hierarchy by genre, date, artist, album, etc.  (This will be made more 
configurable and useful in the future.)
 
 Note a silly limitation: a track may be present in a queue only once (but who 
would want to have a track more than once in a playlist).
-
 * Contents
 :CONTENTS:
 - [[#screenshots][Screenshots]]
@@ -28,24 +27,20 @@ Note a silly limitation: a track may be present in a queue 
only once (but who wo
 - [[#changelog][Changelog]]
 - [[#development][Development]]
 :END:
-
 * Screenshots
 
 [[file:images/screenshot-modus-vivendi-tinted.png]]
-
 * Installation
 
 *Requirements:*
 - Emacs version 29.1 or later.
 - [[https://mpv.io/][MPV]] or [[https://www.videolan.org/vlc/][VLC]]: used to 
play audio.
 - Optional: ~ffprobe~ (part of [[https://ffmpeg.org/ffprobe.html][FFmpeg]]) is 
used to read tracks' duration when available.
-
 ** GNU ELPA
 
 Listen.el is published in [[http://elpa.gnu.org/][GNU ELPA]] as 
[[https://elpa.gnu.org/packages/listen.html][listen]], so it may be installed 
in Emacs with the command ~M-x package-install RET listen RET~.  This is the 
recommended way to install Listen.el, as it will install the current stable 
release.
 
 The latest development build may be installed from 
[[https://elpa.gnu.org/devel/listen.html][ELPA-devel]] or from Git (see below).
-
 ** Git
 
 The ~master~ branch of the Git repository is intended to be usable at all 
times; only minor bugs are expected to be found in it before a new stable 
release is made.
@@ -63,11 +58,9 @@ To install from Git, it is recommended to use 
[[https://github.com/quelpa/quelpa
 #+end_src
 
 One might also use systems like 
[[https://github.com/progfolio/elpaca][Elpaca]] or 
[[https://github.com/radian-software/straight.el][Straight]] (which is also 
used by [[https://github.com/doomemacs/doomemacs][DOOM]]), but the author 
cannot offer support for them.
-
 * Configuration
 
 Listen is intended to work with little-to-no configuration.  You can set the 
~listen-directory~ to the location of your music library if it's not at 
~~/Music~.  See ~M-x customize-group RET listen RET~.
-
 * Usage
 Use the command ~listen~ to show the Transient menu.  From there, it 
is--hopefully--self-explanatory.  Please feel free to give feedback if it 
doesn't seem so.  For more information, see the following sections.
 
@@ -78,7 +71,6 @@ Use the command ~listen~ to show the Transient menu.  From 
there, it is--hopeful
 - [[#mode][Mode]]
 - [[#tips][Tips]]
 :END:
-
 ** Queues
 
 While ~listen~ can simply play one track and stop, playing multiple tracks 
sequentially is provided by /queues/ (what other players may call /playlists/). 
 A queue is a list of tracks, each of which is backed by a file on disk, and 
which may have associated metadata (provided by reading the file in Emacs with 
the ~listen-info~ library, or from an external source, like an MPD server).
@@ -88,7 +80,6 @@ Queues are automatically persisted to disk in the variable 
~listen-queues~.
 A new, empty queue may be made with the command ~listen-queue-new~, but it's 
usually more convenient to use a command that adds tracks to a queue and enter 
a new queue name.
 
 A queue's tracks may be de-duplicated using the command 
~listen-queue-deduplicate~.  Tracks that appear to have the same metadata 
(artist, album, and title, compared case-insensitively) are de-duplicated.  
Also, any tracks no longer backed by a file are removed.
-
 *** Adding tracks to a queue
 
 Tracks can be added to a queue from various sources using these commands:
@@ -96,11 +87,9 @@ Tracks can be added to a queue from various sources using 
these commands:
 - Files and directories: ~listen-queue-add-files~.  Individual files may be 
chosen, or a directory may be, which will be searched recursively for tracks, 
which are added to the selected queue.
 - From an MPD server: ~listen-queue-add-from-mpd~.  An MPD search query will 
be read with completion, and matching tracks are added to the selected queue.
 - From a playlist file: ~listen-queue-add-from-playlist-file~.  The playlist 
file is read, and its tracks are added to the selected queue.
-
 *** Queue buffer
 
 A queue may be shown in a buffer with the command ~listen-queue~, which shows 
its tracks in a [[info:vtable#Introduction][vtable]] with columns for metadata 
and filename.
-
 **** Commands
 
 In the buffer, you can use these commands:
@@ -125,11 +114,9 @@ In the buffer, you can use these commands:
 | Revert queue's tracks from disk | ~C-u g~                     |
 | Pause the player                | ~listen-pause~ (~SPC~)      |
 | Show the menu                   | ~listen-menu~ (~?~)         |
-
 **** Bookmarks
 
 Queue buffers may be bookmarked with ~bookmark-set~ (~C-x r m~).  The bookmark 
record refers to the queue by name, so if the queue is renamed or discarded, 
the bookmark will remain.
-
 *** Queue list buffer
 
 The queue list buffer may be shown with the command ~listen-queue-list~.  In 
the list buffer, you can use these commands:
@@ -144,7 +131,6 @@ The queue list buffer may be shown with the command 
~listen-queue-list~.  In the
 | Revert the queue list | ~listen-queue-list~ (~g~) |
 | Pause the player      | ~listen-pause~ (~SPC~)    |
 | Show the menu         | ~listen-menu~ (~?~)       |
-
 ** Library
 
 To help with exploring and managing a music library, ~listen~ provides various 
"library" features.  Tracks can be passed between library and queue buffers and 
operated on with similar commands and bindings.
@@ -152,11 +138,9 @@ To help with exploring and managing a music library, 
~listen~ provides various "
 ~listen~ does not maintain its own database of audio files; they are simply 
read from the filesystem as needed.  But if a local MPD server is available, 
tracks can be loaded from its database (which does a fine job of indexing audio 
files and their metadata); this is generally much faster, because it avoids 
having to read tracks' metadata with Emacs Lisp or their durations with 
~ffprobe~.
 
 ~listen~ does not provide features to modify tracks' metadata, but it provides 
commands to run shell commands on tracks' filenames, which works well with 
external tools like [[https://picard.musicbrainz.org/][Picard]].
-
 *** Library buffer
 
 A library buffer provides a hierarchical view of tracks grouped by their 
metadata using [[info:taxy#Top][Taxy]], rendered with 
[[info:magit-section#Top][Magit Section]].  Each section can be folded, and it 
shows the number of tracks in it and its subgroups.
-
 **** Showing a library buffer
 
 Tracks from various sources can be shown in a library using these commands:
@@ -164,7 +148,6 @@ Tracks from various sources can be shown in a library using 
these commands:
 - Files and directories: ~listen-library~.  Individual files may be chosen, or 
a directory may be, which will be searched recursively for tracks.
 - From an MPD server: ~listen-library-from-mpd~.  An MPD search query will be 
read with completion, and matching tracks are read from the MPD server.
 - From a playlist file: ~listen-library-from-playlist-file~.  Tracks are read 
from the given playlist file.
-
 **** Commands
 
 In the library buffer, you can use these commands:
@@ -181,11 +164,9 @@ In the library buffer, you can use these commands:
 | Revert the library buffer | ~listen-library-revert~ (~g~) |
 | Pause the player          | ~listen-pause~ (~SPC~)        |
 | Show the menu             | ~listen-menu~ (~?~)           |
-
 **** Bookmarks
 
 Library buffers may be bookmarked with ~bookmark-set~ (~C-x r m~).  The 
bookmark record refers to the buffer by the way it was created (e.g. the 
filename paths, queue name, MPD query, or playlist file the tracks came from), 
so jumping to the bookmark will show an updated view, as if calling the 
original command with the same arguments.
-
 ** Players
 
 ~listen~ supports audio playback via MPV or VLC backends.  Internally, any 
number of simultaneous player instances could be controlled, but ~listen~'s UI 
provides the means to control one at a time.
@@ -193,15 +174,12 @@ Library buffers may be bookmarked with ~bookmark-set~ 
(~C-x r m~).  The bookmark
 Controlling the player is mainly done through the main 
[[info:transient#Top][Transient]] menu, through the command ~listen~.  However, 
all of the commands provided in it are also available as interactive commands, 
which could be bound by the user in any keymap (see, e.g. 
[[elisp:(apropos-command "^listen-")][M-x apropos-command RET ^listen- RET]]).
 
 The player is run in a child process, which is started when playback begins.  
The ~listen-quit~ command terminates the player process.
-
 *** Volume
 
 The ~listen-volume~ command is used to set the current player's volume.  Its 
argument should be an integer percentage.  Some players, e.g. VLC, may allow 
settings above 100% to boost output beyond normal levels.
-
 *** Seeking
 
 The ~listen-seek~ command is used to seek to a position in the current track.  
Its argument should be a timestamp in MM:SS format, and it may include a ~-~ or 
~+~ prefix to indicate a position relative to the current one.
-
 *** Repeat modes
 
 Three repeat modes are provided, controlled by the option 
~listen-queue-repeat-mode~, which may have these values:
@@ -211,16 +189,13 @@ Three repeat modes are provided, controlled by the option 
~listen-queue-repeat-m
 - ~shuffle~ :: When the last track in the current queue finishes playing, the 
queue is shuffled and played again.
 
 The repeat mode is most easily set using the commands in the ~listen~ menu.
-
 ** Mode
 
 The ~listen-mode~ minor mode runs a timer which plays the next track in the 
current queue when a track finishes playing (when playing a queue).  It is 
automatically activated when playing a queue.  It also shows the current track 
in the ~global-mode-string~, which may be displayed in the mode line or tab bar.
-
 ** Tips
 
 - When using VLC as a backend, 
[[https://www.freedesktop.org/wiki/Specifications/mpris-spec/][MPRIS]]-based 
player info and controls "just work", so you can use things like media hotkeys 
and various widgets to control ~listen~'s playback.  When using MPV as a 
backend, see the [[https://github.com/hoyon/mpv-mpris][mpv-mpris]] package.
 - Similarly, you might even see an icon in your task switcher indicating that 
Emacs is playing sound (e.g. with KDE Plasma).
-
 * Changelog
 
 ** v0.10-pre
@@ -232,8 +207,8 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 - Faces for parts of mode line lighter.
 
 *Fixes*
+- Playing next track in queue after current track has been removed.
 - Updating vtables for Emacs versions before 30.
-
 ** v0.9
 
 /Released without additional changes due to change in ELPA recipe./
@@ -241,12 +216,10 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 *Fixes*
 - Currently playing column in queue list buffer.
 - Autoload of ~listen~ / ~listen-menu~ commands (See 
[[https://github.com/magit/transient/issues/280][Transient issue]].  Thanks to 
Jonas Bernoulli.).
-
 ** v0.8.1
 
 *Fixes*
 - Autoload of ~listen~ / ~listen-menu~ commands.
-
 ** v0.8
 
 *Additions*
@@ -263,7 +236,6 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 - Set metadata slot when reverting track from disk.
 - Don't highlight current track in non-playing queues.
 - Increase minimum ~ffprobe~ timeout for a single track.
-
 ** v0.7
 
 *Additions*
@@ -283,7 +255,6 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 - Queue bookmark handler.
 - Open library buffer with point at beginning.
 - In queue buffer, sort track numbers numerically.
-
 ** v0.6
 
 *Additions*
@@ -299,12 +270,10 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 
 *Fixes*
 - Reading new queue name when no queue is playing.
-
 ** v0.5.1
 
 *Fixes*
 - Viewing queues which aren't currently playing.
-
 ** v0.5
 
 *Additions*
@@ -326,7 +295,6 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 - Increase timeout for reading track durations.
 - Command ~listen-queue-deduplicate~ first removes any tracks not backed by a 
file.
 - In queue buffer, mark current track by comparing filename (rather than 
internal track identity).
-
 ** v0.4
 
 *Additions*
@@ -337,7 +305,6 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 *Fixes*
 - Transposing a track in a queue keeps point on the track.
 - Autoloading of ~listen~ command.
-
 ** v0.3
 
 *Additions*
@@ -359,7 +326,6 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 
 *Credits*
 - Thanks to [[https://amodernist.com/][Philip Kaludercic]] for reviewing.
-
 ** v0.2
 
 *Additions*
@@ -371,19 +337,15 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 - The queue could sometimes skip tracks when playing.
 - Improve handling of tracks that are changed during playback (e.g. metadata).
 - Update copyright statements in all libraries.
-
 ** v0.1
 
 Initial release.
-
 * Development
 
 Feedback and patches are welcome.
-
 ** Copyright assignment
 
 Listen.el is published in GNU ELPA and is considered part of GNU Emacs.  
Therefore, cumulative contributions of more than 15 lines of code require that 
the author assign copyright of such contributions to the FSF.  Authors who are 
interested in doing so may contact [[mailto:[email protected]][[email protected]]] to 
request the appropriate form.
-
 ** Known issues
 
 - Queue buffers that are not visible during playback are not updated 
automatically (i.e. to show the currently playing track).  This is due to a 
limitation of the ~vtable~ library (see 
[[https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69837][bug #69837]]).
diff --git a/docs/README.org b/docs/README.org
index fbb983b7d7..7a62cb9767 100644
--- a/docs/README.org
+++ b/docs/README.org
@@ -244,6 +244,7 @@ The ~listen-mode~ minor mode runs a timer which plays the 
next track in the curr
 + Faces for parts of mode line lighter.
 
 *Fixes*
++ Playing next track in queue after current track has been removed.
 + Updating vtables for Emacs versions before 30.
 
 ** v0.9
diff --git a/listen-queue.el b/listen-queue.el
index 4c1e49b6a9..94d7f431ee 100644
--- a/listen-queue.el
+++ b/listen-queue.el
@@ -351,6 +351,9 @@ select track as well."
      (list queue track)))
   (let ((player (listen-current-player)))
     (listen-play player (listen-track-filename track))
+    ;; Remember queue position of track so if it gets removed, we can still go 
to the next track.
+    (setf (map-elt (listen-queue-etc queue) :track-number)
+          (seq-position (listen-queue-tracks queue) track))
     (let ((previous-track (listen-queue-current queue)))
       (setf (listen-queue-current queue) track
             (map-elt (listen-player-etc player) :queue) queue)
@@ -638,12 +641,24 @@ tracks no longer backed by a file are removed."
       ;; the track metadata and refreshes the queue from disk while
       ;; the track is playing), in which case it won't be able to find
       ;; the track in the queue, so look again by comparing filenames.
-      (seq-elt (listen-queue-tracks queue)
-               (1+ (seq-position (listen-queue-tracks queue)
-                                 (listen-queue-current queue)
-                                 (lambda (a b)
-                                   (equal (listen-track-filename a)
-                                          (listen-track-filename b))))))))
+      (let ((current-track-position
+             (or (seq-position (listen-queue-tracks queue)
+                               (listen-queue-current queue)
+                               (lambda (a b)
+                                 (equal (expand-file-name 
(listen-track-filename a))
+                                        (expand-file-name 
(listen-track-filename b)))))
+                 (progn
+                   (display-warning 'listen-queue
+                                    (format-message "listen: Can't find track 
(%S) in queue (%S)"
+                                                    (listen-queue-current 
queue)
+                                                    (listen-queue-name queue))
+                                    :debug)
+                   (if-let ((track-number (map-elt (listen-queue-etc queue) 
:track-number)))
+                       ;; If the track was removed, the next track in the 
queue should have
+                       ;; taken its place, and we don't want to skip it, so 
subtract one.
+                       (1- track-number)
+                     (error "listen: Couldn't find track in queue, and track 
number is nil"))))))
+        (seq-elt (listen-queue-tracks queue) (1+ current-track-position)))))
 
 (declare-function listen-shell-command "listen")
 (defun listen-queue-shell-command (command filenames)

Reply via email to