A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: various queue improvements

+39 -23
+1 -1
src/components/engine/queue/element.js
··· 22 22 23 23 // Query 24 24 const query = QS.stringify({ 25 - "fill-size": this.getAttribute("fill-size"), 25 + "fill": this.getAttribute("fill"), 26 26 }); 27 27 28 28 // Setup worker
+1 -1
src/components/engine/queue/types.d.ts
··· 2 2 import type { SignalReader } from "@common/signal.d.ts"; 3 3 4 4 export type Actions = { 5 - add: (args: { inFront?: boolean; items: Item[] }) => void; 5 + add: (args: { inFront?: boolean; tracks: Track[] }) => void; 6 6 pool: (tracks: Track[]) => void; 7 7 shift: () => void; 8 8 unshift: () => void;
+35 -17
src/components/engine/queue/worker.js
··· 10 10 */ 11 11 12 12 const QUERY = QS.parse(location.search); 13 - const qFillSize = QUERY?.["fill-size"]; 13 + const qFill = QUERY?.["fill"]; 14 14 15 - /** @type {number} */ 16 - const FILL_SIZE = qFillSize && qFillSize !== null 17 - ? Array.isArray(qFillSize) && qFillSize[0] !== null 18 - ? parseInt(qFillSize[0], 10) 19 - : parseInt(/** @type {string} */ (qFillSize), 10) 20 - : 25; 15 + /** @type {number | null} */ 16 + const FILL = qFill && qFill !== null 17 + ? Array.isArray(qFill) && qFill[0] !== null 18 + ? parseInt(qFill[0], 10) 19 + : parseInt(/** @type {string} */ (qFill), 10) 20 + : null; 21 21 22 22 //////////////////////////////////////////// 23 23 // STATE ··· 35 35 /** 36 36 * @type {Actions['add']} 37 37 */ 38 - export function add({ inFront, items }) { 39 - // TODO: An entry is always manual and should be added in the correct place 38 + export function add({ inFront, tracks }) { 39 + const items = tracks.map((track) => { 40 + return { ...track, manualEntry: true }; 41 + }); 42 + 40 43 $future.value = inFront 41 44 ? [...items, ...$future.value] 42 45 : [...$future.value, ...items]; ··· 107 110 //////////////////////////////////////////// 108 111 109 112 /** 113 + * Automatically add non-manual items to the queue. 114 + * 110 115 * @param {Item[]} future 111 116 * @returns {Item[]} 112 117 */ 113 118 function fill(future) { 114 - let fillFutureCount = 0; 119 + if (!FILL) return future; 120 + 121 + // Count 122 + let autoFutureCount = 0; 115 123 let manualFutureCount = 0; 116 124 117 125 future.forEach((item) => { 118 126 if (item.manualEntry) manualFutureCount++; 119 - else fillFutureCount++; 127 + else autoFutureCount++; 120 128 }); 121 129 122 - if (fillFutureCount >= FILL_SIZE) return future; 130 + // Exit early if queue already filled appropriatly 131 + if (autoFutureCount >= FILL) return future; 132 + 133 + // Fill 134 + return fillShuffle(future, autoFutureCount); 135 + } 123 136 137 + /** 138 + * @param {Item[]} future 139 + * @param {number} autoFutureCount 140 + * @returns {Item[]} 141 + */ 142 + export function fillShuffle(future, autoFutureCount) { 143 + // Determine pool of available tracks 124 144 /** @type {Item[]} */ 125 145 const pool = []; 126 146 127 - let p = new Set($past.value.map((t) => t.id)); 147 + const pastSet = new Set($past.value.map((i) => i.id)); 128 148 let reducedPool = pool; 129 149 130 150 $lake.value.forEach((track) => { 131 - if (p.has(track.id)) { 132 - p = p.difference(new Set(track.id)); 133 - } else { 151 + if (pastSet.delete(track.id) === false) { 134 152 pool.push({ 135 153 ...track, 136 154 manualEntry: false, ··· 144 162 145 163 const poolSelection = arrayShuffle(reducedPool).slice( 146 164 0, 147 - FILL_SIZE - fillFutureCount, 165 + Math.max(0, (FILL ?? 0) - autoFutureCount), 148 166 ); 149 167 150 168 return [...future, ...poolSelection];
+1 -3
src/themes/webamp/browser/element.js
··· 67 67 playTrack(track) { 68 68 this.queue.add({ 69 69 inFront: true, 70 - items: [ 71 - { ...track, manualEntry: true }, 72 - ], 70 + tracks: [track], 73 71 }); 74 72 } 75 73
+1 -1
src/themes/webamp/index.vto
··· 75 75 COMPONENTS 76 76 77 77 --> 78 - <de-queue fill-size="10"></de-queue> 78 + <de-queue fill="10"></de-queue> 79 79 80 80 <!-- Inputs, Output & Processors --> 81 81 <di-opensubsonic></di-opensubsonic>