aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--vampire.lisp57
1 files changed, 35 insertions, 22 deletions
diff --git a/vampire.lisp b/vampire.lisp
index 5971392..60b8a49 100644
--- a/vampire.lisp
+++ b/vampire.lisp
@@ -151,12 +151,20 @@
(defclass/std playlist/ctl ()
((playlist track-display audio->track now-playing :std nil)))
+(defmethod (setf now-playing) :before (newval ctl)
+ (with-slots (now-playing) ctl
+ (when now-playing
+ (remove-class (parent-element now-playing) "now-playing")))
+ (when newval
+ (add-class (parent-element newval) "now-playing")))
+
(defclass/std track-display ()
((title-elem
thumb-elem
artist-elem
time-elem
- duration-elem)))
+ duration-elem
+ play/pause-btn)))
(defun get-audio-track (ctl audio)
(cdr (assoc audio (audio->track ctl))))
@@ -175,15 +183,19 @@
(when now-playing
(pause-media now-playing)
(setf (media-position now-playing) 0
- now-playing nil))))
+ now-playing nil
+ (text (play/pause-btn (track-display ctl))) "⏵"))))
(defun pause-playback (ctl)
(when-let (audio (now-playing ctl))
- (pause-media audio)))
+ (pause-media audio)
+ (setf (text (play/pause-btn (track-display ctl))) "⏵")))
(defun start-playback (ctl)
(when-let (audio (now-playing ctl))
- (play-media audio)))
+ (play-media audio)
+ (setf (text (play/pause-btn (track-display ctl)))
+ "⏸")))
(defun load-track-display (ctl)
(when-let (track (get-audio-track ctl (now-playing ctl)))
@@ -209,7 +221,7 @@
(setf (connection-data-item obj "playlist/ctl")
(make-instance 'playlist/ctl :playlist playlist)))
-(defun install-track-display (thumb title artist time dur)
+(defun install-track-display (thumb title artist time dur play/pause)
(let ((ctl (playlist/ctl thumb)))
(setf (track-display ctl)
(make-instance 'track-display
@@ -217,7 +229,8 @@
:time-elem time
:artist-elem artist
:thumb-elem thumb
- :title-elem title))))
+ :title-elem title
+ :play/pause-btn play/pause))))
(defun install-audio-track (audio track &optional (position -1))
(when-let (ctl (playlist/ctl audio))
@@ -238,15 +251,19 @@
(defun ctl/play-audio (audio)
(when-let (ctl (playlist/ctl audio))
- (stop-playback ctl)
- (setf (now-playing ctl) audio)
- (start-playback ctl)
- (load-track-display ctl)))
+ (unless (eq audio (now-playing ctl))
+ (stop-playback ctl)
+ (setf (now-playing ctl) audio)
+ (start-playback ctl)
+ (load-track-display ctl))))
(defun ctl/toggle-play (elem)
- (if-let (now (ctl/now-playing elem))
- (if (pausedp now) (play-media now) (pause-media now))
- (ctl/next-track elem)))
+ (when-let (ctl (playlist/ctl elem))
+ (if (now-playing ctl)
+ (if (pausedp (now-playing ctl))
+ (start-playback ctl)
+ (pause-playback ctl))
+ (ctl/next-track elem))))
(defun ctl/next-track (elem)
(when-let (ctl (playlist/ctl elem))
@@ -344,15 +361,11 @@
(setf (height thumb-elem) 120)
(set-on-click stop-button 'ctl/stop)
(set-on-click next-button 'ctl/next-track)
- (let ((playingp nil))
- (set-on-click
- pause/play-button
- (alambda
- (setf (text pause/play-button)
- (if playingp "⏵" "⏸")
- playingp (not playingp))
- (ctl/toggle-play obj))))
- (install-track-display thumb-elem title-elem artist-elem time-elem duration-elem)))
+ (set-on-click
+ pause/play-button
+ #'ctl/toggle-play)
+ (install-track-display thumb-elem title-elem artist-elem time-elem duration-elem
+ pause/play-button)))
(defun playlist-page (body)
(when-let* ((listid