aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--playlist.lisp60
1 files changed, 50 insertions, 10 deletions
diff --git a/playlist.lisp b/playlist.lisp
index cd9533e..b28f82e 100644
--- a/playlist.lisp
+++ b/playlist.lisp
@@ -52,6 +52,13 @@
(delete tr (playlist-tracks pl)))
t)))
+(defun swap-tracks (pl n m)
+ (unless (or (minusp (min m n))
+ (>= (max m n) (length (playlist-tracks pl)) ))
+ (with-transaction ()
+ (setf (playlist-tracks pl)
+ (nswap (playlist-tracks pl) n m)))))
+
(defun new-track (file trackinfo)
"Trackinfo is a plist containing information about the track to create."
(with-transaction ()
@@ -140,11 +147,12 @@
(defun load-now-playing-display (ctl track-ctl)
(let ((tr (track track-ctl)))
(setf (text (np-title ctl)) (track-title tr)
- (text (np-artist ctl)) (or (track-artist tr) "")
+ (text (np-artist ctl)) (if (track-artist tr)
+ (format nil "~a |" (track-artist tr))
+ "")
(url-src (np-thumb ctl)) (or (track-thumb-url tr) "")
(text (np-dur ctl)) (secs-to-hms (or (track-duration tr) 0))
- (text (np-time ctl)) (secs-to-hms 0)
- (text (np-play ctl)) "|>")))
+ (text (np-time ctl)) (secs-to-hms 0))))
(defun toggle-now-playing (e)
(when-let (ctl (get-playlist-ctl e))
@@ -201,6 +209,30 @@
(delete track-ctl (tracks ctl)))
(destroy (container track-ctl)))))
+(defun move-track-down (track-ctl)
+ (when-let* ((ctl (get-playlist-ctl (container track-ctl)))
+ (pos (position track-ctl (tracks ctl))))
+ (when (swap-tracks (playlist ctl) pos (1+ pos))
+ (let* ((next
+ (nth (1+ pos) (tracks ctl))))
+ ;; swap track-ctls
+ (setf (tracks ctl)
+ (nswap (tracks ctl) pos (1+ pos)))
+ ;; swap list items in the dom
+ (place-before (container track-ctl) (container next))))))
+
+(defun move-track-up (track-ctl)
+ (when-let* ((ctl (get-playlist-ctl (container track-ctl)))
+ (pos (position track-ctl (tracks ctl))))
+ (when (swap-tracks (playlist ctl) pos (1- pos))
+ (let* ((next
+ (nth (1- pos) (tracks ctl))))
+ ;; swap track-ctls
+ (setf (tracks ctl)
+ (nswap (tracks ctl) pos (1- pos)))
+ ;; swap list items in the dom
+ (place-after (container track-ctl) (container next))))))
+
;;; CLIENT UI
(defun playlist-title-content (playlist)
@@ -214,7 +246,9 @@
(section (:h3 :content "Now Playing"))
(img (:bind thumb))
(p ()
+ (span (:content " | "))
(span (:bind title))
+ (span (:content " | "))
(span (:bind artist)))
(p ()
(span (:bind time))
@@ -250,11 +284,15 @@
(defun create-track-list-item (list track ctl)
(with-clog-create list
(list-item (:bind container)
- (p ()
- (span (:content "[X] " :hidden t :bind delbtn))
- (span (:content (track-listing-line track)))
- (span (:content " -- "))
- (span (:content (secs-to-hms (or (track-duration track) 0)))))
+ (div ()
+ (button (:content "delete " :hidden t :bind delbtn))
+ (button (:content "↓" :bind downbtn))
+ (button (:content "↑" :bind upbtn)))
+ (div (:bind item)
+ (span (:content (track-listing-line track)))
+ (span (:content " -- "))
+ (span (:content (secs-to-hms (or (track-duration track) 0)))))
+
(audio (:source (media-url-path track) :controls nil :bind audio)))
(let ((track-ctl
(make-instance 'track-ctl
@@ -264,10 +302,12 @@
(setf (tracks ctl)
(insert-nth track-ctl -1 (tracks ctl) t))
(setf (visiblep delbtn) t)
- (set-on-click delbtn (alambda (remove-track track-ctl))))
+ (set-on-click delbtn (alambda (remove-track track-ctl)))
+ (set-on-click downbtn (alambda (move-track-down track-ctl)))
+ (set-on-click upbtn (alambda (move-track-up track-ctl))))
(set-on-time-update audio 'update-now-playing-time)
(set-on-ended audio 'advance-now-playing)
- (set-on-click container (alambda (play-this-audio audio)))))
+ (set-on-click item (alambda (play-this-audio audio)))))
(defun create-track-listing (parent pl)
(when-let (ctl (get-playlist-ctl parent))