[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get a list of tracks current playlist, then play one? (or, wh
From: |
Yoni Rabkin |
Subject: |
Re: How to get a list of tracks current playlist, then play one? (or, why doesn't my attempt work)? |
Date: |
Sun, 19 Dec 2021 13:40:20 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.90 (gnu/linux) |
hugo@heagren.com writes:
> I'm writing a consult-based interface for EMMS. consult--read is a
> function much like completing-read. I want to write a function which
> presents the current playlist in a completing-read like interface, and
> the jumps to the track the user selects. I intend this with embark
> actions for more operations (moving/killing tracks etc.)
>
> So, I need to get a list of tracks in the current playlist, in such a
> way that I can then write a function which plays the selected one. The
> basic data structure of EMMS is a buffer with a list of tracks, so I
> decided to get an alist of track names and the value of point where
> that track is (this makes it pretty simple to write a function which
> visits the right bffer, goes to that char, then plays the track at
> point). I have this:
>
> ```elisp
> (cl-remove-if
> (lambda (cell) (null (car cell)))
> (with-current-buffer emms-playlist-buffer
> (save-excursion
> (cl-loop initially do (goto-char (point-min))
> until (eobp)
> collect (cons
> (emms-track-get (emms-playlist-track-at) 'info-title)
> (point))
> do (next-line)))))
> ```
Emms tracks have `emms-track' text property attached to them. So you can
use that to find where actual tracks begin and end.
(with-current-emms-playlist
(save-excursion
(let (track-list (next t) track)
(goto-char (point-min))
(while next
(setq next (next-single-property-change (point) 'emms-track))
(when (setq next (next-single-property-change (point) 'emms-track))
(goto-char next))
(when (setq track (emms-playlist-track-at (point)))
(push track track-list)))
track-list)))
I don't know the details of your problem, but note that making a list
out of a playlist buffer may be taking a superfluous step. The emms
playlist buffer is already a data structure. Perhaps it would make more
sense for you to write accessor functions that work directly on the
playlist instead of making a list out of the playlist and working on
that instead. Something to keep in mind.
--
"Cut your own wood and it will warm you twice"