mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Consistently use "current queue" to avoid confusion
This commit is contained in:
parent
7eeceb2786
commit
b4992bccf7
6 changed files with 61 additions and 59 deletions
|
|
@ -102,15 +102,15 @@
|
|||
|
||||
(rf/reg-sub :audio/summary summary)
|
||||
|
||||
(defn playlist
|
||||
"Lists the complete playlist"
|
||||
(defn current-queue
|
||||
"Lists the complete current-queue"
|
||||
[summary _]
|
||||
(:playlist summary))
|
||||
(:current-queue summary))
|
||||
|
||||
(rf/reg-sub
|
||||
:audio/playlist
|
||||
:audio/current-queue
|
||||
:<- [:audio/summary]
|
||||
playlist)
|
||||
current-queue)
|
||||
|
||||
(defn current-song
|
||||
"Gives us information about the currently played song as presented by
|
||||
|
|
@ -120,7 +120,7 @@
|
|||
|
||||
(rf/reg-sub
|
||||
:audio/current-song
|
||||
:<- [:audio/playlist]
|
||||
:<- [:audio/current-queue]
|
||||
current-song)
|
||||
|
||||
(defn playback-status
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
(:refer-clojure :exclude [peek])
|
||||
(:require [airsonic-ui.helpers :refer [find-where]]))
|
||||
|
||||
(defrecord Playlist [queue playback-mode repeat-mode]
|
||||
(defrecord Playlist [items playback-mode repeat-mode]
|
||||
cljs.core/ICounted
|
||||
(-count [this]
|
||||
(count (:queue this))))
|
||||
(count (:items this))))
|
||||
|
||||
(defmulti ->playlist
|
||||
"Creates a new playlist that behaves according to the given playback- and
|
||||
|
|
@ -38,11 +38,11 @@
|
|||
(defn set-current-song
|
||||
"Marks a song in the queue as currently playing, given its ID"
|
||||
[playlist next-idx]
|
||||
(let [[current-idx _] (find-where :playlist/currently-playing? (:queue playlist))]
|
||||
(let [[current-idx _] (find-where :playlist/currently-playing? (:items playlist))]
|
||||
(-> (if current-idx
|
||||
(update-in playlist [:queue current-idx] dissoc :playlist/currently-playing?)
|
||||
(update-in playlist [:items current-idx] dissoc :playlist/currently-playing?)
|
||||
playlist)
|
||||
(assoc-in [:queue next-idx :playlist/currently-playing?] true))))
|
||||
(assoc-in [:items next-idx :playlist/currently-playing?] true))))
|
||||
|
||||
(defn set-playback-mode
|
||||
"Changes the playback mode of a playlist and re-shuffles it if necessary"
|
||||
|
|
@ -50,14 +50,14 @@
|
|||
(if (= playback-mode :shuffled)
|
||||
;; for shuffled playlists we reorder the songs make sure that the currently
|
||||
;; playing song has order 0
|
||||
(let [playlist (->playlist (:queue playlist) :playback-mode playback-mode :repeat-mode (:repeat-mode playlist))
|
||||
[current-idx current-song] (find-where :playlist/currently-playing? (:queue playlist))
|
||||
[swap-idx _] (find-where #(= 0 (:playlist/order %)) (:queue playlist))]
|
||||
(-> (assoc-in playlist [:queue current-idx :playlist/order] 0)
|
||||
(assoc-in [:queue swap-idx :playlist/order] (:playlist/order current-song))))
|
||||
(let [playlist (->playlist (:items playlist) :playback-mode playback-mode :repeat-mode (:repeat-mode playlist))
|
||||
[current-idx current-song] (find-where :playlist/currently-playing? (:items playlist))
|
||||
[swap-idx _] (find-where #(= 0 (:playlist/order %)) (:items playlist))]
|
||||
(-> (assoc-in playlist [:items current-idx :playlist/order] 0)
|
||||
(assoc-in [:items swap-idx :playlist/order] (:playlist/order current-song))))
|
||||
;; for linear songs we just make sure that the current does not change
|
||||
(let [[current-idx _] (find-where :playlist/currently-playing? (:queue playlist))]
|
||||
(-> (->playlist (:queue playlist) :playback-mode playback-mode :repeat-mode (:repeat-mode playlist))
|
||||
(let [[current-idx _] (find-where :playlist/currently-playing? (:items playlist))]
|
||||
(-> (->playlist (:items playlist) :playback-mode playback-mode :repeat-mode (:repeat-mode playlist))
|
||||
(set-current-song current-idx)))))
|
||||
|
||||
(defn set-repeat-mode
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
(defn peek
|
||||
"Returns the song in a playlist that is currently playing"
|
||||
[playlist]
|
||||
(->> (:queue playlist)
|
||||
(->> (:items playlist)
|
||||
(filter :playlist/currently-playing?)
|
||||
(first)))
|
||||
|
||||
|
|
@ -77,9 +77,9 @@
|
|||
(defmethod next-song :repeat-none
|
||||
[playlist]
|
||||
;; this is pretty easy; get the next song and stop playing at the at
|
||||
(let [[current-idx current-song] (find-where :playlist/currently-playing? (:queue playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %) (inc (:playlist/order current-song))) (:queue playlist))]
|
||||
(update playlist :queue
|
||||
(let [[current-idx current-song] (find-where :playlist/currently-playing? (:items playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %) (inc (:playlist/order current-song))) (:items playlist))]
|
||||
(update playlist :items
|
||||
(fn [queue]
|
||||
(cond-> queue
|
||||
current-idx (update current-idx dissoc :playlist/currently-playing?)
|
||||
|
|
@ -89,10 +89,10 @@
|
|||
|
||||
(defmethod next-song :repeat-all
|
||||
[playlist]
|
||||
(let [[current-idx current-song] (find-where :playlist/currently-playing? (:queue playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %) (inc (:playlist/order current-song))) (:queue playlist))]
|
||||
(-> (update-in playlist [:queue current-idx] dissoc :playlist/currently-playing?)
|
||||
(update :queue
|
||||
(let [[current-idx current-song] (find-where :playlist/currently-playing? (:items playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %) (inc (:playlist/order current-song))) (:items playlist))]
|
||||
(-> (update-in playlist [:items current-idx] dissoc :playlist/currently-playing?)
|
||||
(update :items
|
||||
(fn [queue]
|
||||
;; we need special treatment here if we're playing the last song and
|
||||
;; have a shuffled playlist because we need to re-shuffle
|
||||
|
|
@ -109,31 +109,31 @@
|
|||
(defmethod previous-song :repeat-single [playlist] playlist)
|
||||
|
||||
(defmethod previous-song :repeat-none [playlist]
|
||||
(let [[current-idx current-song] (find-where :playlist/currently-playing? (:queue playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %) (dec (:playlist/order current-song))) (:queue playlist))]
|
||||
(let [[current-idx current-song] (find-where :playlist/currently-playing? (:items playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %) (dec (:playlist/order current-song))) (:items playlist))]
|
||||
(set-current-song playlist (or next-idx current-idx))))
|
||||
|
||||
(defmethod previous-song :repeat-all [playlist]
|
||||
(let [[_ current-song] (find-where :playlist/currently-playing? (:queue playlist))
|
||||
(let [[_ current-song] (find-where :playlist/currently-playing? (:items playlist))
|
||||
[next-idx _] (find-where #(= (:playlist/order %)
|
||||
(rem (dec (:playlist/order current-song)) (count playlist)))
|
||||
(:queue playlist))]
|
||||
(:items playlist))]
|
||||
(if next-idx
|
||||
(set-current-song playlist next-idx)
|
||||
(if (= :shuffled (:playback-mode playlist))
|
||||
(let [highest-order (dec (count playlist))
|
||||
playlist (update playlist :queue -shuffle-songs)
|
||||
[last-idx _] (find-where #(= (:playlist/order %) highest-order) (:queue playlist))]
|
||||
playlist (update playlist :items -shuffle-songs)
|
||||
[last-idx _] (find-where #(= (:playlist/order %) highest-order) (:items playlist))]
|
||||
(set-current-song playlist last-idx))
|
||||
(set-current-song playlist (mod (dec (:playlist/order current-song)) (count playlist)))))))
|
||||
|
||||
(defn enqueue-last [playlist song]
|
||||
(let [highest-order (last (sort (map :playlist/order (:queue playlist))))]
|
||||
(update playlist :queue conj (assoc song :playlist/order (inc highest-order)))))
|
||||
(let [highest-order (last (sort (map :playlist/order (:items playlist))))]
|
||||
(update playlist :items conj (assoc song :playlist/order (inc highest-order)))))
|
||||
|
||||
(defn enqueue-next [playlist song]
|
||||
(let [[_ current-song] (find-where :playlist/currently-playing? (:queue playlist))]
|
||||
(update playlist :queue
|
||||
(let [[_ current-song] (find-where :playlist/currently-playing? (:items playlist))]
|
||||
(update playlist :items
|
||||
(fn [queue]
|
||||
(-> (mapv #(if (> (:playlist/order %) (:playlist/order current-song)) (update % :playlist/order inc) %) queue)
|
||||
(conj (assoc song :playlist/order (inc (:playlist/order current-song)))))))))
|
||||
|
|
|
|||
|
|
@ -10,43 +10,43 @@
|
|||
(let [playlist (-> (playlist/->playlist songs :playback-mode :linear :repeat-mode :repeat-all)
|
||||
(playlist/set-current-song start-idx))]
|
||||
{:audio/play (api/stream-url (:credentials db) (playlist/peek playlist))
|
||||
:db (assoc-in db [:audio :playlist] playlist)})))
|
||||
:db (assoc-in db [:audio :current-queue] playlist)})))
|
||||
|
||||
(rf/reg-event-db
|
||||
:audio-player/set-playback-mode
|
||||
(fn [db [_ playback-mode]]
|
||||
(update-in db [:audio :playlist] #(playlist/set-playback-mode % playback-mode))))
|
||||
(update-in db [:audio :current-queue] #(playlist/set-playback-mode % playback-mode))))
|
||||
|
||||
(rf/reg-event-db
|
||||
:audio-player/set-repeat-mode
|
||||
(fn [db [_ repeat-mode]]
|
||||
(update-in db [:audio :playlist] #(playlist/set-repeat-mode % repeat-mode))))
|
||||
(update-in db [:audio :current-queue] #(playlist/set-repeat-mode % repeat-mode))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:audio-player/next-song
|
||||
(fn [{:keys [db]} _]
|
||||
(let [db (update-in db [:audio :playlist] playlist/next-song)
|
||||
next (playlist/peek (get-in db [:audio :playlist]))]
|
||||
(let [db (update-in db [:audio :current-queue] playlist/next-song)
|
||||
next (playlist/peek (get-in db [:audio :current-queue]))]
|
||||
{:db db
|
||||
:audio/play (api/stream-url (:credentials db) next)})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:audio-player/previous-song
|
||||
(fn [{:keys [db]} _]
|
||||
(let [db (update-in db [:audio :playlist] playlist/previous-song)
|
||||
prev (playlist/peek (get-in db [:audio :playlist]))]
|
||||
(let [db (update-in db [:audio :current-queue] playlist/previous-song)
|
||||
prev (playlist/peek (get-in db [:audio :current-queue]))]
|
||||
{:db db
|
||||
:audio/play (api/stream-url (:credentials db) prev)})))
|
||||
|
||||
(rf/reg-event-db
|
||||
:audio-player/enqueue-next
|
||||
(fn [db [_ song]]
|
||||
(update-in db [:audio :playlist] #(playlist/enqueue-next % song))))
|
||||
(update-in db [:audio :current-queue] #(playlist/enqueue-next % song))))
|
||||
|
||||
(rf/reg-event-db
|
||||
:audio-player/enqueue-last
|
||||
(fn [db [_ song]]
|
||||
(update-in db [:audio :playlist] #(playlist/enqueue-last % song))))
|
||||
(update-in db [:audio :current-queue] #(playlist/enqueue-last % song))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:audio-player/toggle-play-pause
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
(rf/reg-event-fx
|
||||
:audio-player/seek
|
||||
(fn [{:keys [db]} [_ percentage]]
|
||||
(let [duration (:duration (playlist/peek (get-in db [:audio :playlist])))]
|
||||
(let [duration (:duration (playlist/peek (get-in db [:audio :current-queue])))]
|
||||
{:audio/seek [percentage duration]})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@
|
|||
|
||||
(defn audio-player []
|
||||
(let [current-song @(subscribe [:audio/current-song])
|
||||
playlist @(subscribe [:audio/playlist])
|
||||
current-queue @(subscribe [:audio/current-queue])
|
||||
playback-status @(subscribe [:audio/playback-status])
|
||||
is-playing? @(subscribe [:audio/is-playing?])]
|
||||
[:nav.audio-player
|
||||
|
|
@ -153,6 +153,6 @@
|
|||
[progress-indicators current-song playback-status]
|
||||
[playback-controls is-playing?]
|
||||
[volume-controls playback-status]
|
||||
[playback-mode-controls playlist]]
|
||||
[playback-mode-controls current-queue]]
|
||||
;; not playing anything
|
||||
[:p.navbar-item.idle-notification "No audio playing"])]))
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@
|
|||
[:section.section>div.container
|
||||
[:h1.title "Current Queue"]
|
||||
[sortable/sortable-component]
|
||||
(if-let [playlist @(subscribe [:audio/playlist])]
|
||||
[song/listing (:queue playlist)]
|
||||
[:p "You are currently not playing anything. Use the search or go to your "
|
||||
[:a {:href (r/url-for ::r/library)} "Library"] " to start playing some music."])])
|
||||
(let [current-queue @(subscribe [:audio/current-queue])
|
||||
#_#_ current-song @(subscribe [:audio/current-song])]
|
||||
(if (some? current-queue)
|
||||
[song/listing (:items current-queue)]
|
||||
[:p "You are currently not playing anything. Use the search or go to your "
|
||||
[:a {:href (r/url-for ::r/library)} "Library"] " to start playing some music."]))])
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
linear (playlist/->playlist queue :playback-mode :linear :repeat-mode :repeat-none)
|
||||
shuffled (playlist/set-playback-mode linear :shuffled)]
|
||||
(testing "should re-order the tracks"
|
||||
(is (not= (map :playlist/order (:queue shuffled)) (map :playlist/order (:queue linear)))))
|
||||
(is (not= (map :playlist/order (:items shuffled)) (map :playlist/order (:items linear)))))
|
||||
(testing "should not change the currently playing track"
|
||||
(is (same-song? (playlist/peek linear) (playlist/peek shuffled))))
|
||||
(testing "should not change the repeat mode"
|
||||
|
|
@ -66,8 +66,8 @@
|
|||
shuffled (playlist/->playlist queue :playback-mode :shuffled :repeat-mode :repeat-none)
|
||||
linear (playlist/set-playback-mode shuffled :linear)]
|
||||
(testing "should set the correct order for tracks"
|
||||
(is (every? #(apply same-song? %) (interleave queue (:queue linear))))
|
||||
(is (< (:playlist/order (first (:queue linear))) (:playlist/order (last (:queue linear))))))
|
||||
(is (every? #(apply same-song? %) (interleave queue (:items linear))))
|
||||
(is (< (:playlist/order (first (:items linear))) (:playlist/order (last (:items linear))))))
|
||||
(testing "should not change the currently playing track"
|
||||
(is (same-song? (playlist/peek linear) (playlist/peek shuffled))))
|
||||
(testing "should not change the repeat mode"
|
||||
|
|
@ -124,9 +124,9 @@
|
|||
(str repeat-mode)))))
|
||||
(testing "Should re-shuffle the playlist when wrapping around and repeat-mode is all"
|
||||
(let [playlist (playlist/->playlist (song-queue 100) :playback-mode :shuffled :repeat-mode :repeat-all)
|
||||
[last-idx _] (find-where #(= (:playlist/order %) 99) (:queue playlist))]
|
||||
(is (not= (map :playlist/order (:queue playlist))
|
||||
(map :playlist/order (:queue (-> (playlist/set-current-song playlist last-idx)
|
||||
[last-idx _] (find-where #(= (:playlist/order %) 99) (:items playlist))]
|
||||
(is (not= (map :playlist/order (:items playlist))
|
||||
(map :playlist/order (:items (-> (playlist/set-current-song playlist last-idx)
|
||||
(playlist/next-song))))))))
|
||||
(testing "Should always give the same track when repeat-mode is single"
|
||||
(let [queue (song-queue 3)
|
||||
|
|
@ -202,7 +202,7 @@
|
|||
(playlist/->playlist (song-queue 10) :playback-mode :shuffled :repeat-mode :repeat-all))
|
||||
playlist' (with-redefs [shuffle reverse]
|
||||
(playlist/previous-song playlist))]
|
||||
(is (not= (map :playlist/order (:queue playlist)) (map :playlist/order (:queue playlist'))))))))
|
||||
(is (not= (map :playlist/order (:items playlist)) (map :playlist/order (:items playlist'))))))))
|
||||
|
||||
(deftest set-current-song
|
||||
(testing "Should correctly set the new song"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue