@arraypress/waveform-sounds 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/waveform-sounds-no-autoinit.cjs +73 -13
- package/dist/waveform-sounds-no-autoinit.esm.js +73 -13
- package/dist/waveform-sounds-render.cjs +39 -5
- package/dist/waveform-sounds-render.esm.js +39 -5
- package/dist/waveform-sounds.cjs +73 -13
- package/dist/waveform-sounds.css +34 -1
- package/dist/waveform-sounds.esm.js +73 -13
- package/dist/waveform-sounds.js +73 -13
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +1 -1
- package/index.d.ts +20 -4
- package/package.json +1 -1
- package/src/css/waveform-sounds.css +34 -1
- package/src/js/core/WaveformSounds.js +22 -5
- package/src/js/data/sounds.js +31 -6
- package/src/js/data/url-state.js +11 -7
- package/src/js/dom/rows.js +1 -1
- package/src/js/render/markup.js +23 -5
- package/src/js/render/options.js +1 -1
- package/src/js/render/strings.js +4 -0
|
@@ -205,6 +205,33 @@
|
|
|
205
205
|
.ws-loop[aria-pressed='true'] { border-color: var(--ws-accent); background: var(--ws-accent); }
|
|
206
206
|
.ws-loop[aria-pressed='true'] > * { color: var(--ws-on-accent); }
|
|
207
207
|
|
|
208
|
+
/* Loops or one-shots: a segmented control, one button pressed. */
|
|
209
|
+
.ws-seg {
|
|
210
|
+
display: inline-flex;
|
|
211
|
+
height: 2.75rem;
|
|
212
|
+
padding: 0.25rem;
|
|
213
|
+
gap: 0.15rem;
|
|
214
|
+
border: 1px solid var(--ws-border);
|
|
215
|
+
border-radius: var(--ws-control-radius);
|
|
216
|
+
}
|
|
217
|
+
.ws-seg-btn {
|
|
218
|
+
padding: 0 0.85rem;
|
|
219
|
+
border: 0;
|
|
220
|
+
border-radius: var(--ws-control-radius);
|
|
221
|
+
background: none;
|
|
222
|
+
color: inherit;
|
|
223
|
+
font: inherit;
|
|
224
|
+
font-size: 0.88em;
|
|
225
|
+
white-space: nowrap;
|
|
226
|
+
cursor: pointer;
|
|
227
|
+
transition: background 0.15s;
|
|
228
|
+
}
|
|
229
|
+
.ws-seg-btn:hover { background: var(--ws-hover); }
|
|
230
|
+
/* On the accent the CHILD takes the inverted ink: the button itself never
|
|
231
|
+
* sets a colour (see the pause icon note at the top). */
|
|
232
|
+
.ws-seg-btn[aria-pressed='true'] { background: var(--ws-accent); }
|
|
233
|
+
.ws-seg-btn[aria-pressed='true'] > * { color: var(--ws-on-accent); }
|
|
234
|
+
|
|
208
235
|
.ws-meta { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
|
|
209
236
|
.ws-types { display: flex; flex-wrap: wrap; gap: 0.4rem; flex: 1 1 auto; min-width: 0; }
|
|
210
237
|
.ws-chip {
|
|
@@ -276,13 +303,18 @@
|
|
|
276
303
|
.ws-chip:focus-visible,
|
|
277
304
|
.ws-menu-btn:focus-visible,
|
|
278
305
|
.ws-loop:focus-visible,
|
|
306
|
+
.ws-seg-btn:focus-visible,
|
|
279
307
|
.ws-more:focus-visible,
|
|
280
308
|
.ws-clear:focus-visible,
|
|
281
309
|
.ws-wave:focus-visible,
|
|
282
310
|
.ws-download:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 2px; }
|
|
283
311
|
|
|
284
312
|
.ws-cell { min-width: 0; font-size: 0.9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
285
|
-
.ws-title { flex: 1.4 1 9rem; font-weight: 500; }
|
|
313
|
+
.ws-title { flex: 1.4 1 9rem; display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }
|
|
314
|
+
.ws-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
315
|
+
/* A loop's mark: quiet, beside the name. */
|
|
316
|
+
.ws-loop-mark { flex: none; display: inline-flex; color: var(--ws-muted); }
|
|
317
|
+
.ws-loop-mark .ws-icon { width: 0.95em; height: 0.95em; }
|
|
286
318
|
.ws-type { flex: 1 1 6rem; color: var(--ws-muted); }
|
|
287
319
|
.ws-bpm, .ws-key, .ws-duration { flex: none; font-family: var(--ws-mono); font-size: 0.82em; color: var(--ws-muted); font-variant-numeric: tabular-nums; }
|
|
288
320
|
.ws-bpm { width: 3.25ch; text-align: right; }
|
|
@@ -331,6 +363,7 @@
|
|
|
331
363
|
}
|
|
332
364
|
.ws-play { grid-area: play; align-self: center; }
|
|
333
365
|
.ws-title { grid-area: title; white-space: normal; overflow-wrap: anywhere; }
|
|
366
|
+
.ws-title-text { overflow: visible; }
|
|
334
367
|
.ws-cells { grid-area: cells; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.5rem; min-width: 0; }
|
|
335
368
|
.ws-cells > .ws-cell { flex: none; width: auto; text-align: left; font-size: 0.78em; }
|
|
336
369
|
.ws-cells > .ws-cell:empty { display: none; }
|
|
@@ -43,7 +43,7 @@ import {emit, isTyping, LOG, pointerFraction} from '../shared/utils.js';
|
|
|
43
43
|
export {DEFAULT_OPTIONS};
|
|
44
44
|
|
|
45
45
|
/** An empty filter: everything matches. */
|
|
46
|
-
const NO_FILTER = Object.freeze({query: '', type: '', key: '', bpmMin: '', bpmMax: ''});
|
|
46
|
+
const NO_FILTER = Object.freeze({query: '', type: '', key: '', bpmMin: '', bpmMax: '', loop: ''});
|
|
47
47
|
|
|
48
48
|
/** Debounce for typing in the search box and the BPM fields (ms). */
|
|
49
49
|
const SEARCH_DELAY = 120;
|
|
@@ -183,6 +183,7 @@ export class WaveformSounds {
|
|
|
183
183
|
engine: q('[data-ws-engine]'),
|
|
184
184
|
status: q('[data-ws-status]'),
|
|
185
185
|
chips: [...this.container.querySelectorAll('[data-ws-type]')],
|
|
186
|
+
loopFilter: [...this.container.querySelectorAll('[data-ws-loop-filter]')],
|
|
186
187
|
};
|
|
187
188
|
this.rows = indexRows(this.$.list);
|
|
188
189
|
}
|
|
@@ -235,7 +236,7 @@ export class WaveformSounds {
|
|
|
235
236
|
/* ── Input ────────────────────────────────────────────────────────── */
|
|
236
237
|
|
|
237
238
|
/**
|
|
238
|
-
* Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
|
|
239
|
+
* Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
|
|
239
240
|
* (seek), and anywhere else on a row (play/pause).
|
|
240
241
|
* @private
|
|
241
242
|
*/
|
|
@@ -243,6 +244,8 @@ export class WaveformSounds {
|
|
|
243
244
|
const t = e.target;
|
|
244
245
|
const chip = t.closest('[data-ws-type]');
|
|
245
246
|
if (chip) { this.setFilter({type: chip.dataset.wsType}); return; }
|
|
247
|
+
const seg = t.closest('[data-ws-loop-filter]');
|
|
248
|
+
if (seg) { this.setFilter({loop: seg.dataset.wsLoopFilter}); return; }
|
|
246
249
|
if (t.closest('[data-ws-more]')) { this.showMore(); return; }
|
|
247
250
|
if (t.closest('[data-ws-clear]')) { this.clearFilters(); return; }
|
|
248
251
|
if (t.closest('[data-ws-loop]')) { this.setLoop(!this.loop); return; }
|
|
@@ -516,6 +519,7 @@ export class WaveformSounds {
|
|
|
516
519
|
if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
|
|
517
520
|
if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
|
|
518
521
|
$.chips.forEach((c) => c.setAttribute('aria-pressed', String(c.dataset.wsType === (f.type || ''))));
|
|
522
|
+
$.loopFilter.forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.wsLoopFilter === (f.loop || ''))));
|
|
519
523
|
}
|
|
520
524
|
|
|
521
525
|
/**
|
|
@@ -686,7 +690,9 @@ export class WaveformSounds {
|
|
|
686
690
|
}
|
|
687
691
|
|
|
688
692
|
/**
|
|
689
|
-
* Loop the current sound (auditioning a loop is the common case).
|
|
693
|
+
* Loop the current sound (auditioning a loop is the common case). When
|
|
694
|
+
* the list marks its loops (`loop: true` on any sound), only those
|
|
695
|
+
* repeat: a one-shot always plays once.
|
|
690
696
|
* @param {boolean} on
|
|
691
697
|
*/
|
|
692
698
|
setLoop(on) {
|
|
@@ -700,7 +706,18 @@ export class WaveformSounds {
|
|
|
700
706
|
*/
|
|
701
707
|
_setLoop(on) {
|
|
702
708
|
this.$?.loop?.setAttribute('aria-pressed', String(on));
|
|
703
|
-
if (this.engine?.audio) this.engine.audio.loop =
|
|
709
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Should the current sound repeat? The Loop toggle is on, and either
|
|
714
|
+
* the list doesn't say which sounds are loops or this one is.
|
|
715
|
+
* @private
|
|
716
|
+
*/
|
|
717
|
+
_repeats() {
|
|
718
|
+
if (!this.loop) return false;
|
|
719
|
+
const marksLoops = this.sounds.some((s) => s.loop);
|
|
720
|
+
return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
|
|
704
721
|
}
|
|
705
722
|
|
|
706
723
|
/**
|
|
@@ -724,7 +741,7 @@ export class WaveformSounds {
|
|
|
724
741
|
* @private
|
|
725
742
|
*/
|
|
726
743
|
_onEngineLoad() {
|
|
727
|
-
if (this.engine?.audio) this.engine.audio.loop = this.
|
|
744
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
728
745
|
const sound = this.sounds[this.currentIndex];
|
|
729
746
|
if (sound && !sound.peaks && this.engine?.waveformData?.length) {
|
|
730
747
|
sound.peaks = resample(this.engine.waveformData, 96);
|
package/src/js/data/sounds.js
CHANGED
|
@@ -138,7 +138,7 @@ export function titleFromUrl(url) {
|
|
|
138
138
|
* Normalise one sound into the shape the runtime and renderer use.
|
|
139
139
|
*
|
|
140
140
|
* @param {Object} input - A sound: `{url, title?, type?, bpm?, key?,
|
|
141
|
-
* duration?, tags?, peaks?, waveform?, id?}`.
|
|
141
|
+
* duration?, tags?, peaks?, waveform?, download?, loop?, id?}`.
|
|
142
142
|
* @param {number} index - Its position (used for a fallback id).
|
|
143
143
|
* @param {number} [peakScale=1] - Scale of an integer `peaks` array.
|
|
144
144
|
* @returns {import('../../../index').Sound|null} The sound, or null if it has
|
|
@@ -164,9 +164,27 @@ export function normalizeSound(input, index, peakScale = 1) {
|
|
|
164
164
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
165
165
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
166
166
|
download: input.download ? String(input.download) : null,
|
|
167
|
+
loop: isLoop(input.loop),
|
|
167
168
|
};
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
/**
|
|
172
|
+
* The values of the loops-or-one-shots filter. A sound is a loop only when
|
|
173
|
+
* it says so (`loop: true`); everything else is a one-shot.
|
|
174
|
+
*/
|
|
175
|
+
export const LOOP_FILTERS = ['loop', 'one-shot'];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Is this a loop? Only an explicit yes counts: `true`, or `"true"` / `"1"`
|
|
179
|
+
* as an attribute or a CSV-ish manifest writes it. Unset is a one-shot.
|
|
180
|
+
*
|
|
181
|
+
* @param {unknown} value
|
|
182
|
+
* @returns {boolean}
|
|
183
|
+
*/
|
|
184
|
+
export function isLoop(value) {
|
|
185
|
+
return value === true || value === 1 || value === 'true' || value === '1';
|
|
186
|
+
}
|
|
187
|
+
|
|
170
188
|
/**
|
|
171
189
|
* Read a sounds manifest. Accepts `{version, peakScale?, sounds: [...]}`
|
|
172
190
|
* (what `waveform-gen --manifest` writes) or a bare array of sounds.
|
|
@@ -205,32 +223,37 @@ export function normalizeSounds(list, peakScale = 1) {
|
|
|
205
223
|
|
|
206
224
|
/**
|
|
207
225
|
* What the filter controls offer, derived from the sounds: each type with
|
|
208
|
-
* its count (in first-seen order), each key (in musical order),
|
|
209
|
-
*
|
|
226
|
+
* its count (in first-seen order), each key (in musical order), the BPM
|
|
227
|
+
* range, and how many are loops and one-shots. A control with nothing to
|
|
228
|
+
* offer is not rendered.
|
|
210
229
|
*
|
|
211
230
|
* @param {import('../../../index').Sound[]} sounds
|
|
212
|
-
* @returns {{types: {name: string, count: number}[], keys: string[], bpm: {min: number, max: number}|null, hasDuration: boolean}}
|
|
231
|
+
* @returns {{types: {name: string, count: number}[], keys: string[], bpm: {min: number, max: number}|null, hasDuration: boolean, loops: number, oneShots: number}}
|
|
213
232
|
*/
|
|
214
233
|
export function facets(sounds) {
|
|
215
234
|
const types = new Map();
|
|
216
235
|
const keys = new Set();
|
|
217
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
236
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
218
237
|
for (const s of sounds) {
|
|
219
238
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
220
239
|
if (s.key) keys.add(s.key);
|
|
221
240
|
if (s.bpm != null) { min = Math.min(min, s.bpm); max = Math.max(max, s.bpm); }
|
|
222
241
|
if (s.duration != null) hasDuration = true;
|
|
242
|
+
if (s.loop) loops++;
|
|
223
243
|
}
|
|
224
244
|
return {
|
|
225
245
|
types: [...types].map(([name, count]) => ({name, count})),
|
|
226
246
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
227
247
|
bpm: min === Infinity ? null : {min, max},
|
|
228
248
|
hasDuration,
|
|
249
|
+
loops,
|
|
250
|
+
oneShots: sounds.length - loops,
|
|
229
251
|
};
|
|
230
252
|
}
|
|
231
253
|
|
|
232
254
|
/**
|
|
233
|
-
* Does a sound match the filter? Every set criterion must hold.
|
|
255
|
+
* Does a sound match the filter? Every set criterion must hold. `loop` is
|
|
256
|
+
* `'loop'` (loops only), `'one-shot'` (everything else) or empty (both).
|
|
234
257
|
*
|
|
235
258
|
* `query` matches the title, type, key and tags with
|
|
236
259
|
* `@arraypress/text`'s `matchesAll`: every word, in any order, forgiving
|
|
@@ -245,6 +268,8 @@ export function facets(sounds) {
|
|
|
245
268
|
export function matches(sound, filter = {}) {
|
|
246
269
|
if (filter.type && sound.type !== filter.type) return false;
|
|
247
270
|
if (filter.key && sound.key !== normalizeKey(filter.key)) return false;
|
|
271
|
+
if (filter.loop === 'loop' && !sound.loop) return false;
|
|
272
|
+
if (filter.loop === 'one-shot' && sound.loop) return false;
|
|
248
273
|
const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
|
|
249
274
|
if ((filter.bpmMin != null && filter.bpmMin !== '' && Number.isFinite(lo)) ||
|
|
250
275
|
(filter.bpmMax != null && filter.bpmMax !== '' && Number.isFinite(hi))) {
|
package/src/js/data/url-state.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* the runtime passes `location.search` / `location.href` in and calls
|
|
5
5
|
* `history.replaceState` with what comes out.
|
|
6
6
|
*
|
|
7
|
-
* ?q=bass&type=Bass+loops&key=Fm&bpm=120-130&sort=bpm
|
|
7
|
+
* ?q=bass&type=Bass+loops&key=Fm&bpm=120-130&loop=one-shot&sort=bpm
|
|
8
8
|
*
|
|
9
9
|
* @module url-state
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {normalizeKey} from './sounds.js';
|
|
12
|
+
import {LOOP_FILTERS, normalizeKey} from './sounds.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The parameter names, or null when urlState is off. A string urlState
|
|
@@ -17,12 +17,12 @@ import {normalizeKey} from './sounds.js';
|
|
|
17
17
|
* page don't share a filter.
|
|
18
18
|
*
|
|
19
19
|
* @param {boolean|string|null|undefined} urlState
|
|
20
|
-
* @returns {{q: string, type: string, key: string, bpm: string, sort: string}|null}
|
|
20
|
+
* @returns {{q: string, type: string, key: string, bpm: string, loop: string, sort: string}|null}
|
|
21
21
|
*/
|
|
22
22
|
export function urlKeys(urlState) {
|
|
23
23
|
if (!urlState) return null;
|
|
24
24
|
const p = typeof urlState === 'string' ? `${urlState}-` : '';
|
|
25
|
-
return {q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort`};
|
|
25
|
+
return {q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort`};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -50,13 +50,14 @@ export function formatBpmRange(min, max) {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Read the filter and sort from a query string. Values the list can't use
|
|
53
|
-
* (a type it doesn't have, a key no sound is in, a
|
|
53
|
+
* (a type it doesn't have, a key no sound is in, a loops filter on a list
|
|
54
|
+
* that isn't a mix of loops and one-shots, a sort it doesn't offer)
|
|
54
55
|
* are ignored, never applied: a stale link shows the whole list, not an
|
|
55
56
|
* empty one.
|
|
56
57
|
*
|
|
57
58
|
* @param {string} search - `location.search`.
|
|
58
59
|
* @param {ReturnType<typeof urlKeys>} keys
|
|
59
|
-
* @param {{types: {name: string}[], keys: string[]}} available - From `facets()`.
|
|
60
|
+
* @param {{types: {name: string}[], keys: string[], loops?: number, oneShots?: number}} available - From `facets()`.
|
|
60
61
|
* @param {string[]} sorts - The sort orders offered.
|
|
61
62
|
* @returns {{filter: Object, sort: string|null}} A filter patch, and the sort (or null).
|
|
62
63
|
*/
|
|
@@ -72,6 +73,8 @@ export function readUrlState(search, keys, available, sorts) {
|
|
|
72
73
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
73
74
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
74
75
|
if (bpm) Object.assign(out.filter, bpm);
|
|
76
|
+
const loop = sp.get(keys.loop);
|
|
77
|
+
if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
|
|
75
78
|
const sort = sp.get(keys.sort);
|
|
76
79
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
77
80
|
return out;
|
|
@@ -84,7 +87,7 @@ export function readUrlState(search, keys, available, sorts) {
|
|
|
84
87
|
*
|
|
85
88
|
* @param {string} href - `location.href`.
|
|
86
89
|
* @param {ReturnType<typeof urlKeys>} keys
|
|
87
|
-
* @param {{query: string, type: string, key: string, bpmMin: string, bpmMax: string}} filter
|
|
90
|
+
* @param {{query: string, type: string, key: string, bpmMin: string, bpmMax: string, loop?: string}} filter
|
|
88
91
|
* @param {string} sort
|
|
89
92
|
* @param {string} defaultSort - The starting order (not written).
|
|
90
93
|
* @returns {string} The new href (equal to `href` when nothing changed).
|
|
@@ -97,6 +100,7 @@ export function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
97
100
|
set(keys.type, filter.type);
|
|
98
101
|
set(keys.key, filter.key);
|
|
99
102
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
103
|
+
set(keys.loop, filter.loop);
|
|
100
104
|
set(keys.sort, sort !== defaultSort ? sort : '');
|
|
101
105
|
return url.href;
|
|
102
106
|
}
|
package/src/js/dom/rows.js
CHANGED
|
@@ -27,7 +27,7 @@ export function readRows(list) {
|
|
|
27
27
|
const d = row.dataset;
|
|
28
28
|
const sound = normalizeSound({
|
|
29
29
|
id: d.wsId, url: d.url, title: d.title, type: d.type, bpm: d.bpm, key: d.key,
|
|
30
|
-
duration: d.duration, tags: d.tags, peaks: d.peaks, waveform: d.waveform, download: d.download,
|
|
30
|
+
duration: d.duration, tags: d.tags, peaks: d.peaks, waveform: d.waveform, download: d.download, loop: d.loop,
|
|
31
31
|
}, sounds.length);
|
|
32
32
|
if (!sound) { row.remove(); continue; }
|
|
33
33
|
row.dataset.wsIndex = String(sounds.length);
|
package/src/js/render/markup.js
CHANGED
|
@@ -41,13 +41,14 @@ export function idBase(sounds) {
|
|
|
41
41
|
/**
|
|
42
42
|
* Which controls the toolbar shows. Each appears only when it's enabled
|
|
43
43
|
* AND the data gives it something to do: no type filter for one type, no
|
|
44
|
-
* key menu for one key, no BPM range without a spread of BPMs, no
|
|
45
|
-
*
|
|
44
|
+
* key menu for one key, no BPM range without a spread of BPMs, no loops
|
|
45
|
+
* filter unless the list has both loops and one-shots, no sort menu with
|
|
46
|
+
* one usable order. Types past `maxTypeChips` become a menu (a
|
|
46
47
|
* pack has a handful; a whole library can have fifty).
|
|
47
48
|
*
|
|
48
49
|
* @param {ReturnType<typeof facets>} f - The sounds' facets.
|
|
49
50
|
* @param {ReturnType<typeof resolveRenderOptions>} o - Resolved options.
|
|
50
|
-
* @returns {{types: 'chips'|'menu'|null, key: boolean, bpm: boolean, sorts: string[], search: boolean, loop: boolean, count: boolean}}
|
|
51
|
+
* @returns {{types: 'chips'|'menu'|null, key: boolean, bpm: boolean, loops: boolean, sorts: string[], search: boolean, loop: boolean, count: boolean}}
|
|
51
52
|
*/
|
|
52
53
|
export function toolbarPlan(f, o) {
|
|
53
54
|
const typed = o.filters.includes('type') && f.types.length > 1;
|
|
@@ -56,6 +57,7 @@ export function toolbarPlan(f, o) {
|
|
|
56
57
|
types: !typed ? null : f.types.length > o.maxTypeChips ? 'menu' : 'chips',
|
|
57
58
|
key: o.filters.includes('key') && f.keys.length > 1,
|
|
58
59
|
bpm: o.filters.includes('bpm') && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
60
|
+
loops: o.filters.includes('loop') && f.loops > 0 && f.oneShots > 0,
|
|
59
61
|
sorts: sorts.length > 1 ? sorts : [],
|
|
60
62
|
search: !!o.search,
|
|
61
63
|
loop: !!o.loopToggle,
|
|
@@ -135,6 +137,16 @@ function renderBpmRange(s, range) {
|
|
|
135
137
|
);
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Loops or one-shots: three buttons, one pressed ('' = both).
|
|
142
|
+
*/
|
|
143
|
+
function renderLoopFilter(s) {
|
|
144
|
+
const button = (value, label) => h('button', {type: 'button', class: 'ws-seg-btn', 'data-ws-loop-filter': value, 'aria-pressed': String(value === '')},
|
|
145
|
+
h('span', {}, text(label)));
|
|
146
|
+
return h('div', {class: 'ws-seg', role: 'group', 'aria-label': s.loopFilter},
|
|
147
|
+
button('', s.all), button('loop', s.loops), button('one-shot', s.oneShots));
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
/** The Loop toggle. */
|
|
139
151
|
function renderLoopToggle(s) {
|
|
140
152
|
return h('button', {type: 'button', class: 'ws-loop', 'data-ws-loop': true, 'aria-pressed': 'false'}, ICONS.loop, h('span', {}, text(s.loop)));
|
|
@@ -148,7 +160,7 @@ function renderChip(value, label, count, pressed) {
|
|
|
148
160
|
|
|
149
161
|
/**
|
|
150
162
|
* The toolbar: search, the controls row (type menu, key menu, BPM range,
|
|
151
|
-
* sort menu, Loop) and the meta row (type chips + the count).
|
|
163
|
+
* loops or one-shots, sort menu, Loop) and the meta row (type chips + the count).
|
|
152
164
|
*
|
|
153
165
|
* @param {ReturnType<typeof toolbarPlan>} plan
|
|
154
166
|
* @param {Object} ctx - `{o, s, f, total, id}` from {@link renderSounds}.
|
|
@@ -166,6 +178,7 @@ function renderToolbar(plan, {o, s, f, total, id}) {
|
|
|
166
178
|
options: [{value: '', label: s.anyKey}, ...f.keys.map((k) => ({value: k, label: k}))],
|
|
167
179
|
}),
|
|
168
180
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
181
|
+
plan.loops && renderLoopFilter(s),
|
|
169
182
|
plan.sorts.length > 0 && menu('sort', {
|
|
170
183
|
label: s.sort, prefix: s.sortBy, value: plan.sorts[0],
|
|
171
184
|
options: plan.sorts.map((k) => ({value: k, label: s[SORT_LABEL_KEYS[k]]})),
|
|
@@ -228,10 +241,15 @@ export function renderRow(sound, index, o, hidden = false) {
|
|
|
228
241
|
'data-peaks': sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
229
242
|
'data-waveform': sound.waveform,
|
|
230
243
|
'data-download': sound.download,
|
|
244
|
+
'data-loop': sound.loop ? 'true' : null,
|
|
231
245
|
hidden,
|
|
232
246
|
},
|
|
233
247
|
h('button', {type: 'button', class: 'ws-play', 'aria-pressed': 'false', 'aria-label': fill(s.play, vars)}, ICONS.play, ICONS.pause),
|
|
234
|
-
h('span', {class: 'ws-cell ws-title'},
|
|
248
|
+
h('span', {class: 'ws-cell ws-title'},
|
|
249
|
+
h('span', {class: 'ws-title-text'}, text(sound.title)),
|
|
250
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
251
|
+
sound.loop && h('span', {class: 'ws-loop-mark', title: s.isLoop}, ICONS.loop, h('span', {class: 'ws-sr'}, text(s.isLoop))),
|
|
252
|
+
),
|
|
235
253
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
236
254
|
// rows: one line under the title.
|
|
237
255
|
cells.length > 0 && h('span', {class: 'ws-cells'}, cells),
|
package/src/js/render/options.js
CHANGED
|
@@ -10,7 +10,7 @@ import {SORTS} from '../data/sounds.js';
|
|
|
10
10
|
import {DEFAULT_STRINGS} from './strings.js';
|
|
11
11
|
|
|
12
12
|
/** The filter controls a list can offer. */
|
|
13
|
-
export const FILTERS = ['type', 'key', 'bpm'];
|
|
13
|
+
export const FILTERS = ['type', 'key', 'bpm', 'loop'];
|
|
14
14
|
|
|
15
15
|
/** The columns a row can show after its title. */
|
|
16
16
|
export const COLUMNS = ['type', 'bpm', 'key', 'duration'];
|
package/src/js/render/strings.js
CHANGED
|
@@ -29,6 +29,10 @@ export const DEFAULT_STRINGS = {
|
|
|
29
29
|
sortKey: 'Key',
|
|
30
30
|
sortDuration: 'Length',
|
|
31
31
|
loop: 'Loop',
|
|
32
|
+
loopFilter: 'Loops or one-shots',
|
|
33
|
+
loops: 'Loops',
|
|
34
|
+
oneShots: 'One-shots',
|
|
35
|
+
isLoop: 'Loop',
|
|
32
36
|
play: 'Play {title}',
|
|
33
37
|
pause: 'Pause {title}',
|
|
34
38
|
seek: 'Seek {title}',
|