@arraypress/waveform-sounds 0.1.3 → 0.3.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 +17 -1
- package/dist/waveform-sounds-no-autoinit.cjs +206 -35
- package/dist/waveform-sounds-no-autoinit.esm.js +206 -35
- package/dist/waveform-sounds-render.cjs +105 -17
- package/dist/waveform-sounds-render.esm.js +105 -17
- package/dist/waveform-sounds.cjs +206 -35
- package/dist/waveform-sounds.css +136 -15
- package/dist/waveform-sounds.esm.js +206 -35
- package/dist/waveform-sounds.js +206 -35
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +1 -1
- package/index.d.ts +27 -6
- package/package.json +1 -1
- package/src/css/waveform-sounds.css +136 -15
- package/src/js/core/WaveformSounds.js +73 -13
- package/src/js/core/options.js +1 -1
- package/src/js/data/bpm.js +68 -0
- package/src/js/data/sounds.js +31 -6
- package/src/js/data/url-state.js +11 -7
- package/src/js/dom/menus.js +19 -4
- package/src/js/dom/rows.js +1 -1
- package/src/js/render/markup.js +77 -19
- package/src/js/render/options.js +1 -1
- package/src/js/render/strings.js +23 -0
package/README.md
CHANGED
|
@@ -56,6 +56,22 @@ Every control can go. No BPM anywhere:
|
|
|
56
56
|
{filters: ['type', 'key'], columns: ['type', 'key', 'duration'], sorts: ['default', 'title', 'key']}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
## Loops and one-shots
|
|
60
|
+
|
|
61
|
+
A sound is a one-shot unless it says otherwise. Mark loops with `loop: true`:
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
{url: '/previews/drums-01.mp3', title: 'Drums 01', bpm: 128, loop: true}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A loop gets a small loop icon beside its name. Once a list has both kinds,
|
|
68
|
+
a **All / Loops / One-shots** filter appears (`filters` entry `'loop'`;
|
|
69
|
+
drop it to hide the control). And the Loop toggle starts on and repeats
|
|
70
|
+
only loops: a one-shot always plays once (turn it off to hear loops once).
|
|
71
|
+
A list that marks nothing works as before.
|
|
72
|
+
`waveform-gen --manifest` sets `loop: true` for files whose folder or name
|
|
73
|
+
contains the word "loop".
|
|
74
|
+
|
|
59
75
|
## Download links
|
|
60
76
|
|
|
61
77
|
Optional, per sound — a free sample, the `.mid` of a MIDI preview. Rows
|
|
@@ -70,7 +86,7 @@ It's a plain `<a download>`: gating (an email, a login) is the site's job.
|
|
|
70
86
|
## Filters in the address
|
|
71
87
|
|
|
72
88
|
`urlState: true` keeps the filters in the URL —
|
|
73
|
-
`?q=bass&type=Bass+loops&key=Fm&bpm=120-130&sort=bpm` — so a filtered list
|
|
89
|
+
`?q=bass&type=Bass+loops&key=Fm&bpm=120-130&loop=one-shot&sort=bpm` — so a filtered list
|
|
74
90
|
can be shared and survives a refresh. `urlState: 'pack'` prefixes the names
|
|
75
91
|
(`pack-q`, `pack-type`, …) when a page has more than one list. It uses
|
|
76
92
|
`replaceState`, so filtering adds no back-button entries; values the data
|
|
@@ -173,9 +173,14 @@ function normalizeSound(input, index, peakScale = 1) {
|
|
|
173
173
|
tags,
|
|
174
174
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
175
175
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
176
|
-
download: input.download ? String(input.download) : null
|
|
176
|
+
download: input.download ? String(input.download) : null,
|
|
177
|
+
loop: isLoop(input.loop)
|
|
177
178
|
};
|
|
178
179
|
}
|
|
180
|
+
var LOOP_FILTERS = ["loop", "one-shot"];
|
|
181
|
+
function isLoop(value) {
|
|
182
|
+
return value === true || value === 1 || value === "true" || value === "1";
|
|
183
|
+
}
|
|
179
184
|
function parseManifest(manifest) {
|
|
180
185
|
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
181
186
|
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
@@ -198,7 +203,7 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
198
203
|
function facets(sounds) {
|
|
199
204
|
const types = /* @__PURE__ */ new Map();
|
|
200
205
|
const keys = /* @__PURE__ */ new Set();
|
|
201
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
206
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
202
207
|
for (const s of sounds) {
|
|
203
208
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
204
209
|
if (s.key) keys.add(s.key);
|
|
@@ -207,17 +212,22 @@ function facets(sounds) {
|
|
|
207
212
|
max = Math.max(max, s.bpm);
|
|
208
213
|
}
|
|
209
214
|
if (s.duration != null) hasDuration = true;
|
|
215
|
+
if (s.loop) loops++;
|
|
210
216
|
}
|
|
211
217
|
return {
|
|
212
218
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
213
219
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
214
220
|
bpm: min === Infinity ? null : { min, max },
|
|
215
|
-
hasDuration
|
|
221
|
+
hasDuration,
|
|
222
|
+
loops,
|
|
223
|
+
oneShots: sounds.length - loops
|
|
216
224
|
};
|
|
217
225
|
}
|
|
218
226
|
function matches(sound, filter = {}) {
|
|
219
227
|
if (filter.type && sound.type !== filter.type) return false;
|
|
220
228
|
if (filter.key && sound.key !== normalizeKey(filter.key)) return false;
|
|
229
|
+
if (filter.loop === "loop" && !sound.loop) return false;
|
|
230
|
+
if (filter.loop === "one-shot" && sound.loop) return false;
|
|
221
231
|
const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
|
|
222
232
|
if (filter.bpmMin != null && filter.bpmMin !== "" && Number.isFinite(lo) || filter.bpmMax != null && filter.bpmMax !== "" && Number.isFinite(hi)) {
|
|
223
233
|
if (sound.bpm == null) return false;
|
|
@@ -367,7 +377,7 @@ function partsOf(menu) {
|
|
|
367
377
|
value: menu.querySelector("[data-ws-menu-value]")
|
|
368
378
|
};
|
|
369
379
|
}
|
|
370
|
-
var focusOwner = (p) => p.search || p.list;
|
|
380
|
+
var focusOwner = (p) => p.search || p.list || p.pop.querySelector("input") || p.pop.querySelector("button");
|
|
371
381
|
var optionsOf = (p, visibleOnly = false) => [...p.list.querySelectorAll('[role="option"]')].filter((o) => !visibleOnly || !o.hidden);
|
|
372
382
|
var Menus = class {
|
|
373
383
|
/**
|
|
@@ -399,6 +409,15 @@ var Menus = class {
|
|
|
399
409
|
this.open(menu);
|
|
400
410
|
}
|
|
401
411
|
}, sig);
|
|
412
|
+
if (!p.list) {
|
|
413
|
+
p.pop.addEventListener("keydown", (e) => {
|
|
414
|
+
if (e.key !== "Escape") return;
|
|
415
|
+
e.preventDefault();
|
|
416
|
+
e.stopPropagation();
|
|
417
|
+
this.close(true);
|
|
418
|
+
}, sig);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
402
421
|
p.list.addEventListener("click", (e) => {
|
|
403
422
|
const opt = e.target.closest('[role="option"]');
|
|
404
423
|
if (opt) this._pick(name, opt.dataset.value);
|
|
@@ -433,8 +452,8 @@ var Menus = class {
|
|
|
433
452
|
}
|
|
434
453
|
menu.classList.remove("ws-menu--end");
|
|
435
454
|
if (p.pop.getBoundingClientRect().right > this.container.getBoundingClientRect().right + 1) menu.classList.add("ws-menu--end");
|
|
436
|
-
this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
437
|
-
focusOwner(p)
|
|
455
|
+
if (p.list) this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
456
|
+
focusOwner(p)?.focus();
|
|
438
457
|
}
|
|
439
458
|
/**
|
|
440
459
|
* Close the open menu, if any.
|
|
@@ -462,6 +481,7 @@ var Menus = class {
|
|
|
462
481
|
const menu = this.menus[name];
|
|
463
482
|
if (!menu) return;
|
|
464
483
|
const p = partsOf(menu);
|
|
484
|
+
if (!p.list) return;
|
|
465
485
|
let label = null;
|
|
466
486
|
for (const opt of optionsOf(p)) {
|
|
467
487
|
const on = opt.dataset.value === String(value ?? "");
|
|
@@ -599,6 +619,31 @@ function limitToReveal(limit, pos) {
|
|
|
599
619
|
return pos >= limit ? pos + 1 : limit;
|
|
600
620
|
}
|
|
601
621
|
|
|
622
|
+
// src/js/data/bpm.js
|
|
623
|
+
function bpmFilterFromRange(lo, hi, extent) {
|
|
624
|
+
const a = Math.min(lo, hi), b = Math.max(lo, hi);
|
|
625
|
+
return {
|
|
626
|
+
bpmMin: a > extent.min ? String(a) : "",
|
|
627
|
+
bpmMax: b < extent.max ? String(b) : ""
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
function bpmRangeFromFilter(filter, extent) {
|
|
631
|
+
const read = (v, fallback) => {
|
|
632
|
+
const n = Number(v);
|
|
633
|
+
return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
|
|
634
|
+
};
|
|
635
|
+
const lo = read(filter.bpmMin, extent.min);
|
|
636
|
+
const hi = read(filter.bpmMax, extent.max);
|
|
637
|
+
return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
|
|
638
|
+
}
|
|
639
|
+
function bpmFraction(value, extent) {
|
|
640
|
+
const span = extent.max - extent.min;
|
|
641
|
+
return span > 0 ? Math.min(Math.max((value - extent.min) / span, 0), 1) : 0;
|
|
642
|
+
}
|
|
643
|
+
function hasBpmFilter(filter) {
|
|
644
|
+
return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
|
|
645
|
+
}
|
|
646
|
+
|
|
602
647
|
// src/js/render/strings.js
|
|
603
648
|
var DEFAULT_STRINGS = {
|
|
604
649
|
search: "Search sounds",
|
|
@@ -614,6 +659,8 @@ var DEFAULT_STRINGS = {
|
|
|
614
659
|
bpm: "BPM",
|
|
615
660
|
bpmMin: "Min BPM",
|
|
616
661
|
bpmMax: "Max BPM",
|
|
662
|
+
anyBpm: "Any BPM",
|
|
663
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
617
664
|
sort: "Sort",
|
|
618
665
|
sortBy: "Sort by",
|
|
619
666
|
sortDefault: "Default",
|
|
@@ -622,6 +669,10 @@ var DEFAULT_STRINGS = {
|
|
|
622
669
|
sortKey: "Key",
|
|
623
670
|
sortDuration: "Length",
|
|
624
671
|
loop: "Loop",
|
|
672
|
+
loopFilter: "Loops or one-shots",
|
|
673
|
+
loops: "Loops",
|
|
674
|
+
oneShots: "One-shots",
|
|
675
|
+
isLoop: "Loop",
|
|
625
676
|
play: "Play {title}",
|
|
626
677
|
pause: "Pause {title}",
|
|
627
678
|
seek: "Seek {title}",
|
|
@@ -644,13 +695,18 @@ var SORT_LABEL_KEYS = {
|
|
|
644
695
|
function fill(template, vars = {}) {
|
|
645
696
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
646
697
|
}
|
|
698
|
+
function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
|
|
699
|
+
if (!hasBpmFilter(filter)) return strings.anyBpm;
|
|
700
|
+
const { lo, hi } = bpmRangeFromFilter(filter, extent);
|
|
701
|
+
return fill(strings.bpmRange, { min: lo, max: hi });
|
|
702
|
+
}
|
|
647
703
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
648
704
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
649
705
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
650
706
|
}
|
|
651
707
|
|
|
652
708
|
// src/js/render/options.js
|
|
653
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
709
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
654
710
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
655
711
|
var RENDER_DEFAULTS = {
|
|
656
712
|
player: "inline",
|
|
@@ -701,7 +757,7 @@ var DEFAULT_OPTIONS = {
|
|
|
701
757
|
progressColor: null,
|
|
702
758
|
barWidth: 2,
|
|
703
759
|
barGap: 1,
|
|
704
|
-
loop:
|
|
760
|
+
loop: null,
|
|
705
761
|
autoAdvance: false,
|
|
706
762
|
arrowAudition: true,
|
|
707
763
|
idPrefix: null,
|
|
@@ -827,12 +883,16 @@ function toolbarPlan(f, o) {
|
|
|
827
883
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
828
884
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
829
885
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
886
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
830
887
|
sorts: sorts.length > 1 ? sorts : [],
|
|
831
888
|
search: !!o.search,
|
|
832
889
|
loop: !!o.loopToggle,
|
|
833
890
|
count: !!o.showCount
|
|
834
891
|
};
|
|
835
892
|
}
|
|
893
|
+
function loopsByDefault(loop, f) {
|
|
894
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
895
|
+
}
|
|
836
896
|
function renderSearch(s) {
|
|
837
897
|
return h(
|
|
838
898
|
"label",
|
|
@@ -886,19 +946,63 @@ function renderMenu(name, m) {
|
|
|
886
946
|
)
|
|
887
947
|
);
|
|
888
948
|
}
|
|
889
|
-
function
|
|
890
|
-
const
|
|
949
|
+
function renderBpmMenu({ id, s, range }) {
|
|
950
|
+
const popId = `${id}-bpm-pop`;
|
|
951
|
+
const handle = (attr, label, value) => h("input", {
|
|
952
|
+
type: "range",
|
|
953
|
+
class: "ws-range-input",
|
|
954
|
+
[attr]: true,
|
|
955
|
+
"aria-label": label,
|
|
956
|
+
min: range.min,
|
|
957
|
+
max: range.max,
|
|
958
|
+
step: "1",
|
|
959
|
+
value
|
|
960
|
+
});
|
|
961
|
+
return h(
|
|
962
|
+
"div",
|
|
963
|
+
{ class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
|
|
964
|
+
h(
|
|
965
|
+
"button",
|
|
966
|
+
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
967
|
+
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
968
|
+
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
969
|
+
ICONS.chevron
|
|
970
|
+
),
|
|
971
|
+
h(
|
|
972
|
+
"div",
|
|
973
|
+
{ class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
|
|
974
|
+
h(
|
|
975
|
+
"div",
|
|
976
|
+
{ class: "ws-bpm-head" },
|
|
977
|
+
h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
|
|
978
|
+
h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
|
|
979
|
+
),
|
|
980
|
+
h(
|
|
981
|
+
"div",
|
|
982
|
+
{ class: "ws-range", "data-ws-bpm-range": true },
|
|
983
|
+
handle("data-ws-bpm-min", s.bpmMin, range.min),
|
|
984
|
+
handle("data-ws-bpm-max", s.bpmMax, range.max)
|
|
985
|
+
),
|
|
986
|
+
h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
|
|
987
|
+
)
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
function renderLoopFilter(s) {
|
|
991
|
+
const button = (value, label) => h(
|
|
992
|
+
"button",
|
|
993
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
994
|
+
h("span", {}, text(label))
|
|
995
|
+
);
|
|
891
996
|
return h(
|
|
892
|
-
"
|
|
893
|
-
{ class: "ws-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
997
|
+
"div",
|
|
998
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
999
|
+
button("", s.all),
|
|
1000
|
+
button("loop", s.loops),
|
|
1001
|
+
button("one-shot", s.oneShots)
|
|
898
1002
|
);
|
|
899
1003
|
}
|
|
900
|
-
function renderLoopToggle(s) {
|
|
901
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed":
|
|
1004
|
+
function renderLoopToggle(s, pressed) {
|
|
1005
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
902
1006
|
}
|
|
903
1007
|
function renderChip(value, label, count, pressed) {
|
|
904
1008
|
return h(
|
|
@@ -924,14 +1028,15 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
924
1028
|
placeholder: s.findKey,
|
|
925
1029
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
926
1030
|
}),
|
|
927
|
-
plan.bpm &&
|
|
1031
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
1032
|
+
plan.loops && renderLoopFilter(s),
|
|
928
1033
|
plan.sorts.length > 0 && menu("sort", {
|
|
929
1034
|
label: s.sort,
|
|
930
1035
|
prefix: s.sortBy,
|
|
931
1036
|
value: plan.sorts[0],
|
|
932
1037
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
933
1038
|
}),
|
|
934
|
-
plan.loop && renderLoopToggle(s)
|
|
1039
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
935
1040
|
].filter(Boolean);
|
|
936
1041
|
const chips = plan.types === "chips" && h(
|
|
937
1042
|
"div",
|
|
@@ -975,10 +1080,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
975
1080
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
976
1081
|
"data-waveform": sound.waveform,
|
|
977
1082
|
"data-download": sound.download,
|
|
1083
|
+
"data-loop": sound.loop ? "true" : null,
|
|
978
1084
|
hidden
|
|
979
1085
|
},
|
|
980
1086
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
981
|
-
h(
|
|
1087
|
+
h(
|
|
1088
|
+
"span",
|
|
1089
|
+
{ class: "ws-cell ws-title" },
|
|
1090
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
1091
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
1092
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
1093
|
+
),
|
|
982
1094
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
983
1095
|
// rows: one line under the title.
|
|
984
1096
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
@@ -1043,7 +1155,8 @@ function readRows(list) {
|
|
|
1043
1155
|
tags: d.tags,
|
|
1044
1156
|
peaks: d.peaks,
|
|
1045
1157
|
waveform: d.waveform,
|
|
1046
|
-
download: d.download
|
|
1158
|
+
download: d.download,
|
|
1159
|
+
loop: d.loop
|
|
1047
1160
|
}, sounds.length);
|
|
1048
1161
|
if (!sound) {
|
|
1049
1162
|
row.remove();
|
|
@@ -1101,7 +1214,7 @@ function resolveCssColor(container, value) {
|
|
|
1101
1214
|
function urlKeys(urlState) {
|
|
1102
1215
|
if (!urlState) return null;
|
|
1103
1216
|
const p = typeof urlState === "string" ? `${urlState}-` : "";
|
|
1104
|
-
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
|
|
1217
|
+
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
|
|
1105
1218
|
}
|
|
1106
1219
|
function parseBpmRange(value) {
|
|
1107
1220
|
const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
|
|
@@ -1123,6 +1236,8 @@ function readUrlState(search, keys, available, sorts) {
|
|
|
1123
1236
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
1124
1237
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
1125
1238
|
if (bpm) Object.assign(out.filter, bpm);
|
|
1239
|
+
const loop = sp.get(keys.loop);
|
|
1240
|
+
if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
|
|
1126
1241
|
const sort = sp.get(keys.sort);
|
|
1127
1242
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
1128
1243
|
return out;
|
|
@@ -1135,12 +1250,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
1135
1250
|
set(keys.type, filter.type);
|
|
1136
1251
|
set(keys.key, filter.key);
|
|
1137
1252
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
1253
|
+
set(keys.loop, filter.loop);
|
|
1138
1254
|
set(keys.sort, sort !== defaultSort ? sort : "");
|
|
1139
1255
|
return url.href;
|
|
1140
1256
|
}
|
|
1141
1257
|
|
|
1142
1258
|
// src/js/core/WaveformSounds.js
|
|
1143
|
-
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
|
|
1259
|
+
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
|
|
1144
1260
|
var SEARCH_DELAY = 120;
|
|
1145
1261
|
var BPM_DELAY = 200;
|
|
1146
1262
|
var URL_DELAY = 250;
|
|
@@ -1207,7 +1323,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1207
1323
|
this._bind();
|
|
1208
1324
|
this._observe();
|
|
1209
1325
|
this._resolveColors();
|
|
1326
|
+
if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, facets(this.sounds));
|
|
1210
1327
|
this._setLoop(this.loop);
|
|
1328
|
+
this._bpmExtent = facets(this.sounds).bpm;
|
|
1211
1329
|
this._sorts = availableSorts(this.render.sorts, facets(this.sounds));
|
|
1212
1330
|
if (!this._sortSet) this.sortBy = this._sorts[0] || "default";
|
|
1213
1331
|
this._readUrl();
|
|
@@ -1239,13 +1357,18 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1239
1357
|
search: q("[data-ws-search]"),
|
|
1240
1358
|
bpmMin: q("[data-ws-bpm-min]"),
|
|
1241
1359
|
bpmMax: q("[data-ws-bpm-max]"),
|
|
1360
|
+
bpmRange: q("[data-ws-bpm-range]"),
|
|
1361
|
+
bpmReadout: q("[data-ws-bpm-readout]"),
|
|
1362
|
+
bpmClear: q("[data-ws-bpm-clear]"),
|
|
1363
|
+
bpmLabel: q('[data-ws-menu="bpm"] [data-ws-menu-value]'),
|
|
1242
1364
|
loop: q("[data-ws-loop]"),
|
|
1243
1365
|
count: q("[data-ws-count]"),
|
|
1244
1366
|
empty: q("[data-ws-empty]"),
|
|
1245
1367
|
more: q("[data-ws-more]"),
|
|
1246
1368
|
engine: q("[data-ws-engine]"),
|
|
1247
1369
|
status: q("[data-ws-status]"),
|
|
1248
|
-
chips: [...this.container.querySelectorAll("[data-ws-type]")]
|
|
1370
|
+
chips: [...this.container.querySelectorAll("[data-ws-type]")],
|
|
1371
|
+
loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
|
|
1249
1372
|
};
|
|
1250
1373
|
this.rows = indexRows(this.$.list);
|
|
1251
1374
|
}
|
|
@@ -1277,12 +1400,20 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1277
1400
|
this.setFilter({ query: "" });
|
|
1278
1401
|
}
|
|
1279
1402
|
}, sig);
|
|
1280
|
-
const onBpm = () => {
|
|
1403
|
+
const onBpm = (moved) => {
|
|
1404
|
+
const lo = Number($.bpmMin.value), hi = Number($.bpmMax.value);
|
|
1405
|
+
if (lo > hi) moved.value = String(moved === $.bpmMin ? hi : lo);
|
|
1406
|
+
const f = bpmFilterFromRange(Number($.bpmMin.value), Number($.bpmMax.value), this._bpmExtent);
|
|
1407
|
+
this._showBpm(f);
|
|
1281
1408
|
clearTimeout(bpmTimer);
|
|
1282
|
-
bpmTimer = setTimeout(() => this.setFilter(
|
|
1409
|
+
bpmTimer = setTimeout(() => this.setFilter(f), BPM_DELAY);
|
|
1283
1410
|
};
|
|
1284
|
-
$.bpmMin?.addEventListener("input", onBpm, sig);
|
|
1285
|
-
$.bpmMax?.addEventListener("input", onBpm, sig);
|
|
1411
|
+
$.bpmMin?.addEventListener("input", () => onBpm($.bpmMin), sig);
|
|
1412
|
+
$.bpmMax?.addEventListener("input", () => onBpm($.bpmMax), sig);
|
|
1413
|
+
$.bpmClear?.addEventListener("click", () => {
|
|
1414
|
+
clearTimeout(bpmTimer);
|
|
1415
|
+
this.setFilter({ bpmMin: "", bpmMax: "" });
|
|
1416
|
+
}, sig);
|
|
1286
1417
|
this.menus = new Menus(root, {
|
|
1287
1418
|
signal: this._ctl.signal,
|
|
1288
1419
|
onPick: (name, value) => name === "sort" ? this.setSort(value) : this.setFilter({ [name]: value })
|
|
@@ -1294,7 +1425,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1294
1425
|
}
|
|
1295
1426
|
/* ── Input ────────────────────────────────────────────────────────── */
|
|
1296
1427
|
/**
|
|
1297
|
-
* Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
|
|
1428
|
+
* Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
|
|
1298
1429
|
* (seek), and anywhere else on a row (play/pause).
|
|
1299
1430
|
* @private
|
|
1300
1431
|
*/
|
|
@@ -1305,6 +1436,11 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1305
1436
|
this.setFilter({ type: chip.dataset.wsType });
|
|
1306
1437
|
return;
|
|
1307
1438
|
}
|
|
1439
|
+
const seg = t.closest("[data-ws-loop-filter]");
|
|
1440
|
+
if (seg) {
|
|
1441
|
+
this.setFilter({ loop: seg.dataset.wsLoopFilter });
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1308
1444
|
if (t.closest("[data-ws-more]")) {
|
|
1309
1445
|
this.showMore();
|
|
1310
1446
|
return;
|
|
@@ -1569,9 +1705,31 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1569
1705
|
this.menus?.setValue("type", f.type || "");
|
|
1570
1706
|
this.menus?.setValue("key", f.key || "");
|
|
1571
1707
|
this.menus?.setValue("sort", this.sortBy);
|
|
1572
|
-
if ($.bpmMin && $.
|
|
1573
|
-
|
|
1708
|
+
if ($.bpmMin && $.bpmMax && this._bpmExtent) {
|
|
1709
|
+
const { lo, hi } = bpmRangeFromFilter(f, this._bpmExtent);
|
|
1710
|
+
$.bpmMin.value = String(lo);
|
|
1711
|
+
$.bpmMax.value = String(hi);
|
|
1712
|
+
this._showBpm(f);
|
|
1713
|
+
}
|
|
1574
1714
|
$.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
|
|
1715
|
+
$.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Show a BPM filter in its menu: the button label, the panel's readout,
|
|
1719
|
+
* the filled part of the track, and which handle sits on top (the one
|
|
1720
|
+
* that can still move, when they meet).
|
|
1721
|
+
* @private
|
|
1722
|
+
*/
|
|
1723
|
+
_showBpm(f) {
|
|
1724
|
+
const $ = this.$, extent = this._bpmExtent;
|
|
1725
|
+
if (!$?.bpmRange || !extent) return;
|
|
1726
|
+
const { lo, hi } = bpmRangeFromFilter(f, extent);
|
|
1727
|
+
if ($.bpmLabel) $.bpmLabel.textContent = bpmLabel(f, extent, this.strings);
|
|
1728
|
+
if ($.bpmReadout) $.bpmReadout.textContent = fill(this.strings.bpmRange, { min: lo, max: hi });
|
|
1729
|
+
$.bpmRange.style.setProperty("--ws-lo", String(bpmFraction(lo, extent)));
|
|
1730
|
+
$.bpmRange.style.setProperty("--ws-hi", String(bpmFraction(hi, extent)));
|
|
1731
|
+
$.bpmRange.classList.toggle("is-min-top", lo >= hi && lo > extent.min);
|
|
1732
|
+
$.bpmRange.classList.toggle("is-active", lo > extent.min || hi < extent.max);
|
|
1575
1733
|
}
|
|
1576
1734
|
/**
|
|
1577
1735
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
@@ -1743,10 +1901,13 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1743
1901
|
return true;
|
|
1744
1902
|
}
|
|
1745
1903
|
/**
|
|
1746
|
-
* Loop the current sound (auditioning a loop is the common case).
|
|
1904
|
+
* Loop the current sound (auditioning a loop is the common case). When
|
|
1905
|
+
* the list marks its loops (`loop: true` on any sound), only those
|
|
1906
|
+
* repeat: a one-shot always plays once.
|
|
1747
1907
|
* @param {boolean} on
|
|
1748
1908
|
*/
|
|
1749
1909
|
setLoop(on) {
|
|
1910
|
+
this._loopSet = true;
|
|
1750
1911
|
this.loop = !!on;
|
|
1751
1912
|
this._setLoop(this.loop);
|
|
1752
1913
|
}
|
|
@@ -1756,7 +1917,17 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1756
1917
|
*/
|
|
1757
1918
|
_setLoop(on) {
|
|
1758
1919
|
this.$?.loop?.setAttribute("aria-pressed", String(on));
|
|
1759
|
-
if (this.engine?.audio) this.engine.audio.loop =
|
|
1920
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Should the current sound repeat? The Loop toggle is on, and either
|
|
1924
|
+
* the list doesn't say which sounds are loops or this one is.
|
|
1925
|
+
* @private
|
|
1926
|
+
*/
|
|
1927
|
+
_repeats() {
|
|
1928
|
+
if (!this.loop) return false;
|
|
1929
|
+
const marksLoops = this.sounds.some((s) => s.loop);
|
|
1930
|
+
return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
|
|
1760
1931
|
}
|
|
1761
1932
|
/**
|
|
1762
1933
|
* Seek a row's sound to `fraction`; a row that isn't current starts
|
|
@@ -1784,7 +1955,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1784
1955
|
* @private
|
|
1785
1956
|
*/
|
|
1786
1957
|
_onEngineLoad() {
|
|
1787
|
-
if (this.engine?.audio) this.engine.audio.loop = this.
|
|
1958
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1788
1959
|
const sound = this.sounds[this.currentIndex];
|
|
1789
1960
|
if (sound && !sound.peaks && this.engine?.waveformData?.length) {
|
|
1790
1961
|
sound.peaks = resample(this.engine.waveformData, 96);
|