[Top][All Lists]

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

[emms-help] Re: Playlist shuffle fix

From: Lucas Bonnet
Subject: [emms-help] Re: Playlist shuffle fix
Date: Sun, 29 May 2005 15:42:43 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Jorgen Schaefer <address@hidden> writes:

> Since tracks are not regenerated, `eq' is a good way to search for
> them:


> (defun emms-playlist-search-track (track)
>   "Returns the index of the track TRACK."
>   (catch 'loop
>     (let ((i 0))
>       (while (< i (length emms-playlist))
>         (if (eq track
>                 (elt emms-playlist i))
>             (throw 'loop i)
>           (setq i (1+ i)))))))
> This has the advantage of also working for non-file tracks.


>>       (emms-playlist-set-current new-index)
>>       (emms-pbi-rebuild-playlist-buffer))))
>          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> I know it's a horrible thought for you :-), but there are people
> who don't even load emms-pbi - emms.el does not use any functions
> of pbi directly. `emms-playlist-set-current' runs the hook
> `emms-playlist-current-changed-hook', which in turn will have the
> `emms-pbi-rebuild-playlist-buffer' on it.

Ooops, sorry. That's the drawback on coding during breakfast :)

> I remember someone suggesting to keep the current track as the
> first track of the playlist when shuffling. Is there any specific
> reason against that?

Sounds like a good idea to me too. It was paroneayea, on IRC yesterday
evening, just when I was too tired to code it :)

> (defun emms-playlist-search-vector (track vector)
>   "Returns the index of the track TRACK in VECTOR."
>   (catch 'loop
>     (let ((i 0))
>       (while (< i (length vector))
>         (if (eq track
>                 (elt vector i))
>             (throw 'loop i)
>           (setq i (1+ i)))))))

Yeah, generalization is always better.

> (defun emms-playlist-shuffle ()
>   "Shuffle the current playlist.
> This retains the current track at the front if anything is
> playling."
>   (if (not emms-player-playing-p)
>       (emms-playlist-set-playlist
>        (emms-playlist-shuffle-vector
>         (emms-playlist-get-playlist)))
>     (let* ((current-track (emms-playlist-current-track))
>            (playlist (emms-playlist-shuffle-vector
>                       (emms-playlist-get-playlist)))
>            (new-index (emms-playlist-search-vector current-track playlist))
>            (first (elt playlist 0)))
>       (aset playlist 0 (elt playlist new-index))
>       (aset playlist new-index first)
>       (emms-playlist-set-playlist playlist)
>       (emms-playlist-set-current 0))))

Yeah, that's the behavior I'd like, too.

> Your approach is useful for sorting, though:

Glad to see that my code is useful :-)


> Is it a problem that these now call `emms-playlist-changed-hook'
> and `emms-playlist-current-changed-hook' directly after each
> other?

Why should it be a problem ? If someone adds same functions to both ?

Did you commit your changes ? (way too lazy to check :p)

Lucas, morning coder, afternoon commentator

reply via email to

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