@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
|
@@ -134,9 +134,14 @@ function normalizeSound(input, index, peakScale = 1) {
|
|
|
134
134
|
tags,
|
|
135
135
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
136
136
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
137
|
-
download: input.download ? String(input.download) : null
|
|
137
|
+
download: input.download ? String(input.download) : null,
|
|
138
|
+
loop: isLoop(input.loop)
|
|
138
139
|
};
|
|
139
140
|
}
|
|
141
|
+
var LOOP_FILTERS = ["loop", "one-shot"];
|
|
142
|
+
function isLoop(value) {
|
|
143
|
+
return value === true || value === 1 || value === "true" || value === "1";
|
|
144
|
+
}
|
|
140
145
|
function parseManifest(manifest) {
|
|
141
146
|
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
142
147
|
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
@@ -159,7 +164,7 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
159
164
|
function facets(sounds) {
|
|
160
165
|
const types = /* @__PURE__ */ new Map();
|
|
161
166
|
const keys = /* @__PURE__ */ new Set();
|
|
162
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
167
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
163
168
|
for (const s of sounds) {
|
|
164
169
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
165
170
|
if (s.key) keys.add(s.key);
|
|
@@ -168,17 +173,22 @@ function facets(sounds) {
|
|
|
168
173
|
max = Math.max(max, s.bpm);
|
|
169
174
|
}
|
|
170
175
|
if (s.duration != null) hasDuration = true;
|
|
176
|
+
if (s.loop) loops++;
|
|
171
177
|
}
|
|
172
178
|
return {
|
|
173
179
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
174
180
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
175
181
|
bpm: min === Infinity ? null : { min, max },
|
|
176
|
-
hasDuration
|
|
182
|
+
hasDuration,
|
|
183
|
+
loops,
|
|
184
|
+
oneShots: sounds.length - loops
|
|
177
185
|
};
|
|
178
186
|
}
|
|
179
187
|
function matches(sound, filter = {}) {
|
|
180
188
|
if (filter.type && sound.type !== filter.type) return false;
|
|
181
189
|
if (filter.key && sound.key !== normalizeKey(filter.key)) return false;
|
|
190
|
+
if (filter.loop === "loop" && !sound.loop) return false;
|
|
191
|
+
if (filter.loop === "one-shot" && sound.loop) return false;
|
|
182
192
|
const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
|
|
183
193
|
if (filter.bpmMin != null && filter.bpmMin !== "" && Number.isFinite(lo) || filter.bpmMax != null && filter.bpmMax !== "" && Number.isFinite(hi)) {
|
|
184
194
|
if (sound.bpm == null) return false;
|
|
@@ -328,7 +338,7 @@ function partsOf(menu) {
|
|
|
328
338
|
value: menu.querySelector("[data-ws-menu-value]")
|
|
329
339
|
};
|
|
330
340
|
}
|
|
331
|
-
var focusOwner = (p) => p.search || p.list;
|
|
341
|
+
var focusOwner = (p) => p.search || p.list || p.pop.querySelector("input") || p.pop.querySelector("button");
|
|
332
342
|
var optionsOf = (p, visibleOnly = false) => [...p.list.querySelectorAll('[role="option"]')].filter((o) => !visibleOnly || !o.hidden);
|
|
333
343
|
var Menus = class {
|
|
334
344
|
/**
|
|
@@ -360,6 +370,15 @@ var Menus = class {
|
|
|
360
370
|
this.open(menu);
|
|
361
371
|
}
|
|
362
372
|
}, sig);
|
|
373
|
+
if (!p.list) {
|
|
374
|
+
p.pop.addEventListener("keydown", (e) => {
|
|
375
|
+
if (e.key !== "Escape") return;
|
|
376
|
+
e.preventDefault();
|
|
377
|
+
e.stopPropagation();
|
|
378
|
+
this.close(true);
|
|
379
|
+
}, sig);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
363
382
|
p.list.addEventListener("click", (e) => {
|
|
364
383
|
const opt = e.target.closest('[role="option"]');
|
|
365
384
|
if (opt) this._pick(name, opt.dataset.value);
|
|
@@ -394,8 +413,8 @@ var Menus = class {
|
|
|
394
413
|
}
|
|
395
414
|
menu.classList.remove("ws-menu--end");
|
|
396
415
|
if (p.pop.getBoundingClientRect().right > this.container.getBoundingClientRect().right + 1) menu.classList.add("ws-menu--end");
|
|
397
|
-
this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
398
|
-
focusOwner(p)
|
|
416
|
+
if (p.list) this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
417
|
+
focusOwner(p)?.focus();
|
|
399
418
|
}
|
|
400
419
|
/**
|
|
401
420
|
* Close the open menu, if any.
|
|
@@ -423,6 +442,7 @@ var Menus = class {
|
|
|
423
442
|
const menu = this.menus[name];
|
|
424
443
|
if (!menu) return;
|
|
425
444
|
const p = partsOf(menu);
|
|
445
|
+
if (!p.list) return;
|
|
426
446
|
let label = null;
|
|
427
447
|
for (const opt of optionsOf(p)) {
|
|
428
448
|
const on = opt.dataset.value === String(value ?? "");
|
|
@@ -560,6 +580,31 @@ function limitToReveal(limit, pos) {
|
|
|
560
580
|
return pos >= limit ? pos + 1 : limit;
|
|
561
581
|
}
|
|
562
582
|
|
|
583
|
+
// src/js/data/bpm.js
|
|
584
|
+
function bpmFilterFromRange(lo, hi, extent) {
|
|
585
|
+
const a = Math.min(lo, hi), b = Math.max(lo, hi);
|
|
586
|
+
return {
|
|
587
|
+
bpmMin: a > extent.min ? String(a) : "",
|
|
588
|
+
bpmMax: b < extent.max ? String(b) : ""
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
function bpmRangeFromFilter(filter, extent) {
|
|
592
|
+
const read = (v, fallback) => {
|
|
593
|
+
const n = Number(v);
|
|
594
|
+
return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
|
|
595
|
+
};
|
|
596
|
+
const lo = read(filter.bpmMin, extent.min);
|
|
597
|
+
const hi = read(filter.bpmMax, extent.max);
|
|
598
|
+
return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
|
|
599
|
+
}
|
|
600
|
+
function bpmFraction(value, extent) {
|
|
601
|
+
const span = extent.max - extent.min;
|
|
602
|
+
return span > 0 ? Math.min(Math.max((value - extent.min) / span, 0), 1) : 0;
|
|
603
|
+
}
|
|
604
|
+
function hasBpmFilter(filter) {
|
|
605
|
+
return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
|
|
606
|
+
}
|
|
607
|
+
|
|
563
608
|
// src/js/render/strings.js
|
|
564
609
|
var DEFAULT_STRINGS = {
|
|
565
610
|
search: "Search sounds",
|
|
@@ -575,6 +620,8 @@ var DEFAULT_STRINGS = {
|
|
|
575
620
|
bpm: "BPM",
|
|
576
621
|
bpmMin: "Min BPM",
|
|
577
622
|
bpmMax: "Max BPM",
|
|
623
|
+
anyBpm: "Any BPM",
|
|
624
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
578
625
|
sort: "Sort",
|
|
579
626
|
sortBy: "Sort by",
|
|
580
627
|
sortDefault: "Default",
|
|
@@ -583,6 +630,10 @@ var DEFAULT_STRINGS = {
|
|
|
583
630
|
sortKey: "Key",
|
|
584
631
|
sortDuration: "Length",
|
|
585
632
|
loop: "Loop",
|
|
633
|
+
loopFilter: "Loops or one-shots",
|
|
634
|
+
loops: "Loops",
|
|
635
|
+
oneShots: "One-shots",
|
|
636
|
+
isLoop: "Loop",
|
|
586
637
|
play: "Play {title}",
|
|
587
638
|
pause: "Pause {title}",
|
|
588
639
|
seek: "Seek {title}",
|
|
@@ -605,13 +656,18 @@ var SORT_LABEL_KEYS = {
|
|
|
605
656
|
function fill(template, vars = {}) {
|
|
606
657
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
607
658
|
}
|
|
659
|
+
function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
|
|
660
|
+
if (!hasBpmFilter(filter)) return strings.anyBpm;
|
|
661
|
+
const { lo, hi } = bpmRangeFromFilter(filter, extent);
|
|
662
|
+
return fill(strings.bpmRange, { min: lo, max: hi });
|
|
663
|
+
}
|
|
608
664
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
609
665
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
610
666
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
611
667
|
}
|
|
612
668
|
|
|
613
669
|
// src/js/render/options.js
|
|
614
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
670
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
615
671
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
616
672
|
var RENDER_DEFAULTS = {
|
|
617
673
|
player: "inline",
|
|
@@ -662,7 +718,7 @@ var DEFAULT_OPTIONS = {
|
|
|
662
718
|
progressColor: null,
|
|
663
719
|
barWidth: 2,
|
|
664
720
|
barGap: 1,
|
|
665
|
-
loop:
|
|
721
|
+
loop: null,
|
|
666
722
|
autoAdvance: false,
|
|
667
723
|
arrowAudition: true,
|
|
668
724
|
idPrefix: null,
|
|
@@ -788,12 +844,16 @@ function toolbarPlan(f, o) {
|
|
|
788
844
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
789
845
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
790
846
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
847
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
791
848
|
sorts: sorts.length > 1 ? sorts : [],
|
|
792
849
|
search: !!o.search,
|
|
793
850
|
loop: !!o.loopToggle,
|
|
794
851
|
count: !!o.showCount
|
|
795
852
|
};
|
|
796
853
|
}
|
|
854
|
+
function loopsByDefault(loop, f) {
|
|
855
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
856
|
+
}
|
|
797
857
|
function renderSearch(s) {
|
|
798
858
|
return h(
|
|
799
859
|
"label",
|
|
@@ -847,19 +907,63 @@ function renderMenu(name, m) {
|
|
|
847
907
|
)
|
|
848
908
|
);
|
|
849
909
|
}
|
|
850
|
-
function
|
|
851
|
-
const
|
|
910
|
+
function renderBpmMenu({ id, s, range }) {
|
|
911
|
+
const popId = `${id}-bpm-pop`;
|
|
912
|
+
const handle = (attr, label, value) => h("input", {
|
|
913
|
+
type: "range",
|
|
914
|
+
class: "ws-range-input",
|
|
915
|
+
[attr]: true,
|
|
916
|
+
"aria-label": label,
|
|
917
|
+
min: range.min,
|
|
918
|
+
max: range.max,
|
|
919
|
+
step: "1",
|
|
920
|
+
value
|
|
921
|
+
});
|
|
922
|
+
return h(
|
|
923
|
+
"div",
|
|
924
|
+
{ class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
|
|
925
|
+
h(
|
|
926
|
+
"button",
|
|
927
|
+
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
928
|
+
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
929
|
+
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
930
|
+
ICONS.chevron
|
|
931
|
+
),
|
|
932
|
+
h(
|
|
933
|
+
"div",
|
|
934
|
+
{ class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
|
|
935
|
+
h(
|
|
936
|
+
"div",
|
|
937
|
+
{ class: "ws-bpm-head" },
|
|
938
|
+
h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
|
|
939
|
+
h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
|
|
940
|
+
),
|
|
941
|
+
h(
|
|
942
|
+
"div",
|
|
943
|
+
{ class: "ws-range", "data-ws-bpm-range": true },
|
|
944
|
+
handle("data-ws-bpm-min", s.bpmMin, range.min),
|
|
945
|
+
handle("data-ws-bpm-max", s.bpmMax, range.max)
|
|
946
|
+
),
|
|
947
|
+
h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
|
|
948
|
+
)
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
function renderLoopFilter(s) {
|
|
952
|
+
const button = (value, label) => h(
|
|
953
|
+
"button",
|
|
954
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
955
|
+
h("span", {}, text(label))
|
|
956
|
+
);
|
|
852
957
|
return h(
|
|
853
|
-
"
|
|
854
|
-
{ class: "ws-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
958
|
+
"div",
|
|
959
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
960
|
+
button("", s.all),
|
|
961
|
+
button("loop", s.loops),
|
|
962
|
+
button("one-shot", s.oneShots)
|
|
859
963
|
);
|
|
860
964
|
}
|
|
861
|
-
function renderLoopToggle(s) {
|
|
862
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed":
|
|
965
|
+
function renderLoopToggle(s, pressed) {
|
|
966
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
863
967
|
}
|
|
864
968
|
function renderChip(value, label, count, pressed) {
|
|
865
969
|
return h(
|
|
@@ -885,14 +989,15 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
885
989
|
placeholder: s.findKey,
|
|
886
990
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
887
991
|
}),
|
|
888
|
-
plan.bpm &&
|
|
992
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
993
|
+
plan.loops && renderLoopFilter(s),
|
|
889
994
|
plan.sorts.length > 0 && menu("sort", {
|
|
890
995
|
label: s.sort,
|
|
891
996
|
prefix: s.sortBy,
|
|
892
997
|
value: plan.sorts[0],
|
|
893
998
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
894
999
|
}),
|
|
895
|
-
plan.loop && renderLoopToggle(s)
|
|
1000
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
896
1001
|
].filter(Boolean);
|
|
897
1002
|
const chips = plan.types === "chips" && h(
|
|
898
1003
|
"div",
|
|
@@ -936,10 +1041,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
936
1041
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
937
1042
|
"data-waveform": sound.waveform,
|
|
938
1043
|
"data-download": sound.download,
|
|
1044
|
+
"data-loop": sound.loop ? "true" : null,
|
|
939
1045
|
hidden
|
|
940
1046
|
},
|
|
941
1047
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
942
|
-
h(
|
|
1048
|
+
h(
|
|
1049
|
+
"span",
|
|
1050
|
+
{ class: "ws-cell ws-title" },
|
|
1051
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
1052
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
1053
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
1054
|
+
),
|
|
943
1055
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
944
1056
|
// rows: one line under the title.
|
|
945
1057
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
@@ -1004,7 +1116,8 @@ function readRows(list) {
|
|
|
1004
1116
|
tags: d.tags,
|
|
1005
1117
|
peaks: d.peaks,
|
|
1006
1118
|
waveform: d.waveform,
|
|
1007
|
-
download: d.download
|
|
1119
|
+
download: d.download,
|
|
1120
|
+
loop: d.loop
|
|
1008
1121
|
}, sounds.length);
|
|
1009
1122
|
if (!sound) {
|
|
1010
1123
|
row.remove();
|
|
@@ -1062,7 +1175,7 @@ function resolveCssColor(container, value) {
|
|
|
1062
1175
|
function urlKeys(urlState) {
|
|
1063
1176
|
if (!urlState) return null;
|
|
1064
1177
|
const p = typeof urlState === "string" ? `${urlState}-` : "";
|
|
1065
|
-
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
|
|
1178
|
+
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
|
|
1066
1179
|
}
|
|
1067
1180
|
function parseBpmRange(value) {
|
|
1068
1181
|
const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
|
|
@@ -1084,6 +1197,8 @@ function readUrlState(search, keys, available, sorts) {
|
|
|
1084
1197
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
1085
1198
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
1086
1199
|
if (bpm) Object.assign(out.filter, bpm);
|
|
1200
|
+
const loop = sp.get(keys.loop);
|
|
1201
|
+
if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
|
|
1087
1202
|
const sort = sp.get(keys.sort);
|
|
1088
1203
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
1089
1204
|
return out;
|
|
@@ -1096,12 +1211,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
1096
1211
|
set(keys.type, filter.type);
|
|
1097
1212
|
set(keys.key, filter.key);
|
|
1098
1213
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
1214
|
+
set(keys.loop, filter.loop);
|
|
1099
1215
|
set(keys.sort, sort !== defaultSort ? sort : "");
|
|
1100
1216
|
return url.href;
|
|
1101
1217
|
}
|
|
1102
1218
|
|
|
1103
1219
|
// src/js/core/WaveformSounds.js
|
|
1104
|
-
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
|
|
1220
|
+
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
|
|
1105
1221
|
var SEARCH_DELAY = 120;
|
|
1106
1222
|
var BPM_DELAY = 200;
|
|
1107
1223
|
var URL_DELAY = 250;
|
|
@@ -1168,7 +1284,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1168
1284
|
this._bind();
|
|
1169
1285
|
this._observe();
|
|
1170
1286
|
this._resolveColors();
|
|
1287
|
+
if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, facets(this.sounds));
|
|
1171
1288
|
this._setLoop(this.loop);
|
|
1289
|
+
this._bpmExtent = facets(this.sounds).bpm;
|
|
1172
1290
|
this._sorts = availableSorts(this.render.sorts, facets(this.sounds));
|
|
1173
1291
|
if (!this._sortSet) this.sortBy = this._sorts[0] || "default";
|
|
1174
1292
|
this._readUrl();
|
|
@@ -1200,13 +1318,18 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1200
1318
|
search: q("[data-ws-search]"),
|
|
1201
1319
|
bpmMin: q("[data-ws-bpm-min]"),
|
|
1202
1320
|
bpmMax: q("[data-ws-bpm-max]"),
|
|
1321
|
+
bpmRange: q("[data-ws-bpm-range]"),
|
|
1322
|
+
bpmReadout: q("[data-ws-bpm-readout]"),
|
|
1323
|
+
bpmClear: q("[data-ws-bpm-clear]"),
|
|
1324
|
+
bpmLabel: q('[data-ws-menu="bpm"] [data-ws-menu-value]'),
|
|
1203
1325
|
loop: q("[data-ws-loop]"),
|
|
1204
1326
|
count: q("[data-ws-count]"),
|
|
1205
1327
|
empty: q("[data-ws-empty]"),
|
|
1206
1328
|
more: q("[data-ws-more]"),
|
|
1207
1329
|
engine: q("[data-ws-engine]"),
|
|
1208
1330
|
status: q("[data-ws-status]"),
|
|
1209
|
-
chips: [...this.container.querySelectorAll("[data-ws-type]")]
|
|
1331
|
+
chips: [...this.container.querySelectorAll("[data-ws-type]")],
|
|
1332
|
+
loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
|
|
1210
1333
|
};
|
|
1211
1334
|
this.rows = indexRows(this.$.list);
|
|
1212
1335
|
}
|
|
@@ -1238,12 +1361,20 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1238
1361
|
this.setFilter({ query: "" });
|
|
1239
1362
|
}
|
|
1240
1363
|
}, sig);
|
|
1241
|
-
const onBpm = () => {
|
|
1364
|
+
const onBpm = (moved) => {
|
|
1365
|
+
const lo = Number($.bpmMin.value), hi = Number($.bpmMax.value);
|
|
1366
|
+
if (lo > hi) moved.value = String(moved === $.bpmMin ? hi : lo);
|
|
1367
|
+
const f = bpmFilterFromRange(Number($.bpmMin.value), Number($.bpmMax.value), this._bpmExtent);
|
|
1368
|
+
this._showBpm(f);
|
|
1242
1369
|
clearTimeout(bpmTimer);
|
|
1243
|
-
bpmTimer = setTimeout(() => this.setFilter(
|
|
1370
|
+
bpmTimer = setTimeout(() => this.setFilter(f), BPM_DELAY);
|
|
1244
1371
|
};
|
|
1245
|
-
$.bpmMin?.addEventListener("input", onBpm, sig);
|
|
1246
|
-
$.bpmMax?.addEventListener("input", onBpm, sig);
|
|
1372
|
+
$.bpmMin?.addEventListener("input", () => onBpm($.bpmMin), sig);
|
|
1373
|
+
$.bpmMax?.addEventListener("input", () => onBpm($.bpmMax), sig);
|
|
1374
|
+
$.bpmClear?.addEventListener("click", () => {
|
|
1375
|
+
clearTimeout(bpmTimer);
|
|
1376
|
+
this.setFilter({ bpmMin: "", bpmMax: "" });
|
|
1377
|
+
}, sig);
|
|
1247
1378
|
this.menus = new Menus(root, {
|
|
1248
1379
|
signal: this._ctl.signal,
|
|
1249
1380
|
onPick: (name, value) => name === "sort" ? this.setSort(value) : this.setFilter({ [name]: value })
|
|
@@ -1255,7 +1386,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1255
1386
|
}
|
|
1256
1387
|
/* ── Input ────────────────────────────────────────────────────────── */
|
|
1257
1388
|
/**
|
|
1258
|
-
* Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
|
|
1389
|
+
* Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
|
|
1259
1390
|
* (seek), and anywhere else on a row (play/pause).
|
|
1260
1391
|
* @private
|
|
1261
1392
|
*/
|
|
@@ -1266,6 +1397,11 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1266
1397
|
this.setFilter({ type: chip.dataset.wsType });
|
|
1267
1398
|
return;
|
|
1268
1399
|
}
|
|
1400
|
+
const seg = t.closest("[data-ws-loop-filter]");
|
|
1401
|
+
if (seg) {
|
|
1402
|
+
this.setFilter({ loop: seg.dataset.wsLoopFilter });
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1269
1405
|
if (t.closest("[data-ws-more]")) {
|
|
1270
1406
|
this.showMore();
|
|
1271
1407
|
return;
|
|
@@ -1530,9 +1666,31 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1530
1666
|
this.menus?.setValue("type", f.type || "");
|
|
1531
1667
|
this.menus?.setValue("key", f.key || "");
|
|
1532
1668
|
this.menus?.setValue("sort", this.sortBy);
|
|
1533
|
-
if ($.bpmMin && $.
|
|
1534
|
-
|
|
1669
|
+
if ($.bpmMin && $.bpmMax && this._bpmExtent) {
|
|
1670
|
+
const { lo, hi } = bpmRangeFromFilter(f, this._bpmExtent);
|
|
1671
|
+
$.bpmMin.value = String(lo);
|
|
1672
|
+
$.bpmMax.value = String(hi);
|
|
1673
|
+
this._showBpm(f);
|
|
1674
|
+
}
|
|
1535
1675
|
$.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
|
|
1676
|
+
$.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Show a BPM filter in its menu: the button label, the panel's readout,
|
|
1680
|
+
* the filled part of the track, and which handle sits on top (the one
|
|
1681
|
+
* that can still move, when they meet).
|
|
1682
|
+
* @private
|
|
1683
|
+
*/
|
|
1684
|
+
_showBpm(f) {
|
|
1685
|
+
const $ = this.$, extent = this._bpmExtent;
|
|
1686
|
+
if (!$?.bpmRange || !extent) return;
|
|
1687
|
+
const { lo, hi } = bpmRangeFromFilter(f, extent);
|
|
1688
|
+
if ($.bpmLabel) $.bpmLabel.textContent = bpmLabel(f, extent, this.strings);
|
|
1689
|
+
if ($.bpmReadout) $.bpmReadout.textContent = fill(this.strings.bpmRange, { min: lo, max: hi });
|
|
1690
|
+
$.bpmRange.style.setProperty("--ws-lo", String(bpmFraction(lo, extent)));
|
|
1691
|
+
$.bpmRange.style.setProperty("--ws-hi", String(bpmFraction(hi, extent)));
|
|
1692
|
+
$.bpmRange.classList.toggle("is-min-top", lo >= hi && lo > extent.min);
|
|
1693
|
+
$.bpmRange.classList.toggle("is-active", lo > extent.min || hi < extent.max);
|
|
1536
1694
|
}
|
|
1537
1695
|
/**
|
|
1538
1696
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
@@ -1704,10 +1862,13 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1704
1862
|
return true;
|
|
1705
1863
|
}
|
|
1706
1864
|
/**
|
|
1707
|
-
* Loop the current sound (auditioning a loop is the common case).
|
|
1865
|
+
* Loop the current sound (auditioning a loop is the common case). When
|
|
1866
|
+
* the list marks its loops (`loop: true` on any sound), only those
|
|
1867
|
+
* repeat: a one-shot always plays once.
|
|
1708
1868
|
* @param {boolean} on
|
|
1709
1869
|
*/
|
|
1710
1870
|
setLoop(on) {
|
|
1871
|
+
this._loopSet = true;
|
|
1711
1872
|
this.loop = !!on;
|
|
1712
1873
|
this._setLoop(this.loop);
|
|
1713
1874
|
}
|
|
@@ -1717,7 +1878,17 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1717
1878
|
*/
|
|
1718
1879
|
_setLoop(on) {
|
|
1719
1880
|
this.$?.loop?.setAttribute("aria-pressed", String(on));
|
|
1720
|
-
if (this.engine?.audio) this.engine.audio.loop =
|
|
1881
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Should the current sound repeat? The Loop toggle is on, and either
|
|
1885
|
+
* the list doesn't say which sounds are loops or this one is.
|
|
1886
|
+
* @private
|
|
1887
|
+
*/
|
|
1888
|
+
_repeats() {
|
|
1889
|
+
if (!this.loop) return false;
|
|
1890
|
+
const marksLoops = this.sounds.some((s) => s.loop);
|
|
1891
|
+
return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
|
|
1721
1892
|
}
|
|
1722
1893
|
/**
|
|
1723
1894
|
* Seek a row's sound to `fraction`; a row that isn't current starts
|
|
@@ -1745,7 +1916,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1745
1916
|
* @private
|
|
1746
1917
|
*/
|
|
1747
1918
|
_onEngineLoad() {
|
|
1748
|
-
if (this.engine?.audio) this.engine.audio.loop = this.
|
|
1919
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1749
1920
|
const sound = this.sounds[this.currentIndex];
|
|
1750
1921
|
if (sound && !sound.peaks && this.engine?.waveformData?.length) {
|
|
1751
1922
|
sound.peaks = resample(this.engine.waveformData, 96);
|