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