@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
package/README.md
CHANGED
|
@@ -56,6 +56,21 @@ 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 repeats only loops: a
|
|
70
|
+
one-shot always plays once. A list that marks nothing works as before.
|
|
71
|
+
`waveform-gen --manifest` sets `loop: true` for files whose folder or name
|
|
72
|
+
contains the word "loop".
|
|
73
|
+
|
|
59
74
|
## Download links
|
|
60
75
|
|
|
61
76
|
Optional, per sound — a free sample, the `.mid` of a MIDI preview. Rows
|
|
@@ -70,7 +85,7 @@ It's a plain `<a download>`: gating (an email, a login) is the site's job.
|
|
|
70
85
|
## Filters in the address
|
|
71
86
|
|
|
72
87
|
`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
|
|
88
|
+
`?q=bass&type=Bass+loops&key=Fm&bpm=120-130&loop=one-shot&sort=bpm` — so a filtered list
|
|
74
89
|
can be shared and survives a refresh. `urlState: 'pack'` prefixes the names
|
|
75
90
|
(`pack-q`, `pack-type`, …) when a page has more than one list. It uses
|
|
76
91
|
`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;
|
|
@@ -622,6 +632,10 @@ var DEFAULT_STRINGS = {
|
|
|
622
632
|
sortKey: "Key",
|
|
623
633
|
sortDuration: "Length",
|
|
624
634
|
loop: "Loop",
|
|
635
|
+
loopFilter: "Loops or one-shots",
|
|
636
|
+
loops: "Loops",
|
|
637
|
+
oneShots: "One-shots",
|
|
638
|
+
isLoop: "Loop",
|
|
625
639
|
play: "Play {title}",
|
|
626
640
|
pause: "Pause {title}",
|
|
627
641
|
seek: "Seek {title}",
|
|
@@ -650,7 +664,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
650
664
|
}
|
|
651
665
|
|
|
652
666
|
// src/js/render/options.js
|
|
653
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
667
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
654
668
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
655
669
|
var RENDER_DEFAULTS = {
|
|
656
670
|
player: "inline",
|
|
@@ -827,6 +841,7 @@ function toolbarPlan(f, o) {
|
|
|
827
841
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
828
842
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
829
843
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
844
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
830
845
|
sorts: sorts.length > 1 ? sorts : [],
|
|
831
846
|
search: !!o.search,
|
|
832
847
|
loop: !!o.loopToggle,
|
|
@@ -897,6 +912,20 @@ function renderBpmRange(s, range) {
|
|
|
897
912
|
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
898
913
|
);
|
|
899
914
|
}
|
|
915
|
+
function renderLoopFilter(s) {
|
|
916
|
+
const button = (value, label) => h(
|
|
917
|
+
"button",
|
|
918
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
919
|
+
h("span", {}, text(label))
|
|
920
|
+
);
|
|
921
|
+
return h(
|
|
922
|
+
"div",
|
|
923
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
924
|
+
button("", s.all),
|
|
925
|
+
button("loop", s.loops),
|
|
926
|
+
button("one-shot", s.oneShots)
|
|
927
|
+
);
|
|
928
|
+
}
|
|
900
929
|
function renderLoopToggle(s) {
|
|
901
930
|
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
902
931
|
}
|
|
@@ -925,6 +954,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
925
954
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
926
955
|
}),
|
|
927
956
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
957
|
+
plan.loops && renderLoopFilter(s),
|
|
928
958
|
plan.sorts.length > 0 && menu("sort", {
|
|
929
959
|
label: s.sort,
|
|
930
960
|
prefix: s.sortBy,
|
|
@@ -975,10 +1005,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
975
1005
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
976
1006
|
"data-waveform": sound.waveform,
|
|
977
1007
|
"data-download": sound.download,
|
|
1008
|
+
"data-loop": sound.loop ? "true" : null,
|
|
978
1009
|
hidden
|
|
979
1010
|
},
|
|
980
1011
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
981
|
-
h(
|
|
1012
|
+
h(
|
|
1013
|
+
"span",
|
|
1014
|
+
{ class: "ws-cell ws-title" },
|
|
1015
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
1016
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
1017
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
1018
|
+
),
|
|
982
1019
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
983
1020
|
// rows: one line under the title.
|
|
984
1021
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
@@ -1043,7 +1080,8 @@ function readRows(list) {
|
|
|
1043
1080
|
tags: d.tags,
|
|
1044
1081
|
peaks: d.peaks,
|
|
1045
1082
|
waveform: d.waveform,
|
|
1046
|
-
download: d.download
|
|
1083
|
+
download: d.download,
|
|
1084
|
+
loop: d.loop
|
|
1047
1085
|
}, sounds.length);
|
|
1048
1086
|
if (!sound) {
|
|
1049
1087
|
row.remove();
|
|
@@ -1101,7 +1139,7 @@ function resolveCssColor(container, value) {
|
|
|
1101
1139
|
function urlKeys(urlState) {
|
|
1102
1140
|
if (!urlState) return null;
|
|
1103
1141
|
const p = typeof urlState === "string" ? `${urlState}-` : "";
|
|
1104
|
-
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
|
|
1142
|
+
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
|
|
1105
1143
|
}
|
|
1106
1144
|
function parseBpmRange(value) {
|
|
1107
1145
|
const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
|
|
@@ -1123,6 +1161,8 @@ function readUrlState(search, keys, available, sorts) {
|
|
|
1123
1161
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
1124
1162
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
1125
1163
|
if (bpm) Object.assign(out.filter, bpm);
|
|
1164
|
+
const loop = sp.get(keys.loop);
|
|
1165
|
+
if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
|
|
1126
1166
|
const sort = sp.get(keys.sort);
|
|
1127
1167
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
1128
1168
|
return out;
|
|
@@ -1135,12 +1175,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
1135
1175
|
set(keys.type, filter.type);
|
|
1136
1176
|
set(keys.key, filter.key);
|
|
1137
1177
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
1178
|
+
set(keys.loop, filter.loop);
|
|
1138
1179
|
set(keys.sort, sort !== defaultSort ? sort : "");
|
|
1139
1180
|
return url.href;
|
|
1140
1181
|
}
|
|
1141
1182
|
|
|
1142
1183
|
// src/js/core/WaveformSounds.js
|
|
1143
|
-
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
|
|
1184
|
+
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
|
|
1144
1185
|
var SEARCH_DELAY = 120;
|
|
1145
1186
|
var BPM_DELAY = 200;
|
|
1146
1187
|
var URL_DELAY = 250;
|
|
@@ -1245,7 +1286,8 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1245
1286
|
more: q("[data-ws-more]"),
|
|
1246
1287
|
engine: q("[data-ws-engine]"),
|
|
1247
1288
|
status: q("[data-ws-status]"),
|
|
1248
|
-
chips: [...this.container.querySelectorAll("[data-ws-type]")]
|
|
1289
|
+
chips: [...this.container.querySelectorAll("[data-ws-type]")],
|
|
1290
|
+
loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
|
|
1249
1291
|
};
|
|
1250
1292
|
this.rows = indexRows(this.$.list);
|
|
1251
1293
|
}
|
|
@@ -1294,7 +1336,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1294
1336
|
}
|
|
1295
1337
|
/* ── Input ────────────────────────────────────────────────────────── */
|
|
1296
1338
|
/**
|
|
1297
|
-
* Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
|
|
1339
|
+
* Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
|
|
1298
1340
|
* (seek), and anywhere else on a row (play/pause).
|
|
1299
1341
|
* @private
|
|
1300
1342
|
*/
|
|
@@ -1305,6 +1347,11 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1305
1347
|
this.setFilter({ type: chip.dataset.wsType });
|
|
1306
1348
|
return;
|
|
1307
1349
|
}
|
|
1350
|
+
const seg = t.closest("[data-ws-loop-filter]");
|
|
1351
|
+
if (seg) {
|
|
1352
|
+
this.setFilter({ loop: seg.dataset.wsLoopFilter });
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1308
1355
|
if (t.closest("[data-ws-more]")) {
|
|
1309
1356
|
this.showMore();
|
|
1310
1357
|
return;
|
|
@@ -1572,6 +1619,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1572
1619
|
if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
|
|
1573
1620
|
if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
|
|
1574
1621
|
$.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
|
|
1622
|
+
$.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
|
|
1575
1623
|
}
|
|
1576
1624
|
/**
|
|
1577
1625
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
@@ -1743,7 +1791,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1743
1791
|
return true;
|
|
1744
1792
|
}
|
|
1745
1793
|
/**
|
|
1746
|
-
* Loop the current sound (auditioning a loop is the common case).
|
|
1794
|
+
* Loop the current sound (auditioning a loop is the common case). When
|
|
1795
|
+
* the list marks its loops (`loop: true` on any sound), only those
|
|
1796
|
+
* repeat: a one-shot always plays once.
|
|
1747
1797
|
* @param {boolean} on
|
|
1748
1798
|
*/
|
|
1749
1799
|
setLoop(on) {
|
|
@@ -1756,7 +1806,17 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1756
1806
|
*/
|
|
1757
1807
|
_setLoop(on) {
|
|
1758
1808
|
this.$?.loop?.setAttribute("aria-pressed", String(on));
|
|
1759
|
-
if (this.engine?.audio) this.engine.audio.loop =
|
|
1809
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Should the current sound repeat? The Loop toggle is on, and either
|
|
1813
|
+
* the list doesn't say which sounds are loops or this one is.
|
|
1814
|
+
* @private
|
|
1815
|
+
*/
|
|
1816
|
+
_repeats() {
|
|
1817
|
+
if (!this.loop) return false;
|
|
1818
|
+
const marksLoops = this.sounds.some((s) => s.loop);
|
|
1819
|
+
return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
|
|
1760
1820
|
}
|
|
1761
1821
|
/**
|
|
1762
1822
|
* Seek a row's sound to `fraction`; a row that isn't current starts
|
|
@@ -1784,7 +1844,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1784
1844
|
* @private
|
|
1785
1845
|
*/
|
|
1786
1846
|
_onEngineLoad() {
|
|
1787
|
-
if (this.engine?.audio) this.engine.audio.loop = this.
|
|
1847
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1788
1848
|
const sound = this.sounds[this.currentIndex];
|
|
1789
1849
|
if (sound && !sound.peaks && this.engine?.waveformData?.length) {
|
|
1790
1850
|
sound.peaks = resample(this.engine.waveformData, 96);
|
|
@@ -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;
|
|
@@ -583,6 +593,10 @@ var DEFAULT_STRINGS = {
|
|
|
583
593
|
sortKey: "Key",
|
|
584
594
|
sortDuration: "Length",
|
|
585
595
|
loop: "Loop",
|
|
596
|
+
loopFilter: "Loops or one-shots",
|
|
597
|
+
loops: "Loops",
|
|
598
|
+
oneShots: "One-shots",
|
|
599
|
+
isLoop: "Loop",
|
|
586
600
|
play: "Play {title}",
|
|
587
601
|
pause: "Pause {title}",
|
|
588
602
|
seek: "Seek {title}",
|
|
@@ -611,7 +625,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
611
625
|
}
|
|
612
626
|
|
|
613
627
|
// src/js/render/options.js
|
|
614
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
628
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
615
629
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
616
630
|
var RENDER_DEFAULTS = {
|
|
617
631
|
player: "inline",
|
|
@@ -788,6 +802,7 @@ function toolbarPlan(f, o) {
|
|
|
788
802
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
789
803
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
790
804
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
805
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
791
806
|
sorts: sorts.length > 1 ? sorts : [],
|
|
792
807
|
search: !!o.search,
|
|
793
808
|
loop: !!o.loopToggle,
|
|
@@ -858,6 +873,20 @@ function renderBpmRange(s, range) {
|
|
|
858
873
|
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
859
874
|
);
|
|
860
875
|
}
|
|
876
|
+
function renderLoopFilter(s) {
|
|
877
|
+
const button = (value, label) => h(
|
|
878
|
+
"button",
|
|
879
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
880
|
+
h("span", {}, text(label))
|
|
881
|
+
);
|
|
882
|
+
return h(
|
|
883
|
+
"div",
|
|
884
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
885
|
+
button("", s.all),
|
|
886
|
+
button("loop", s.loops),
|
|
887
|
+
button("one-shot", s.oneShots)
|
|
888
|
+
);
|
|
889
|
+
}
|
|
861
890
|
function renderLoopToggle(s) {
|
|
862
891
|
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
863
892
|
}
|
|
@@ -886,6 +915,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
886
915
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
887
916
|
}),
|
|
888
917
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
918
|
+
plan.loops && renderLoopFilter(s),
|
|
889
919
|
plan.sorts.length > 0 && menu("sort", {
|
|
890
920
|
label: s.sort,
|
|
891
921
|
prefix: s.sortBy,
|
|
@@ -936,10 +966,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
936
966
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
937
967
|
"data-waveform": sound.waveform,
|
|
938
968
|
"data-download": sound.download,
|
|
969
|
+
"data-loop": sound.loop ? "true" : null,
|
|
939
970
|
hidden
|
|
940
971
|
},
|
|
941
972
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
942
|
-
h(
|
|
973
|
+
h(
|
|
974
|
+
"span",
|
|
975
|
+
{ class: "ws-cell ws-title" },
|
|
976
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
977
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
978
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
979
|
+
),
|
|
943
980
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
944
981
|
// rows: one line under the title.
|
|
945
982
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
@@ -1004,7 +1041,8 @@ function readRows(list) {
|
|
|
1004
1041
|
tags: d.tags,
|
|
1005
1042
|
peaks: d.peaks,
|
|
1006
1043
|
waveform: d.waveform,
|
|
1007
|
-
download: d.download
|
|
1044
|
+
download: d.download,
|
|
1045
|
+
loop: d.loop
|
|
1008
1046
|
}, sounds.length);
|
|
1009
1047
|
if (!sound) {
|
|
1010
1048
|
row.remove();
|
|
@@ -1062,7 +1100,7 @@ function resolveCssColor(container, value) {
|
|
|
1062
1100
|
function urlKeys(urlState) {
|
|
1063
1101
|
if (!urlState) return null;
|
|
1064
1102
|
const p = typeof urlState === "string" ? `${urlState}-` : "";
|
|
1065
|
-
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
|
|
1103
|
+
return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
|
|
1066
1104
|
}
|
|
1067
1105
|
function parseBpmRange(value) {
|
|
1068
1106
|
const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
|
|
@@ -1084,6 +1122,8 @@ function readUrlState(search, keys, available, sorts) {
|
|
|
1084
1122
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
1085
1123
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
1086
1124
|
if (bpm) Object.assign(out.filter, bpm);
|
|
1125
|
+
const loop = sp.get(keys.loop);
|
|
1126
|
+
if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
|
|
1087
1127
|
const sort = sp.get(keys.sort);
|
|
1088
1128
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
1089
1129
|
return out;
|
|
@@ -1096,12 +1136,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
1096
1136
|
set(keys.type, filter.type);
|
|
1097
1137
|
set(keys.key, filter.key);
|
|
1098
1138
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
1139
|
+
set(keys.loop, filter.loop);
|
|
1099
1140
|
set(keys.sort, sort !== defaultSort ? sort : "");
|
|
1100
1141
|
return url.href;
|
|
1101
1142
|
}
|
|
1102
1143
|
|
|
1103
1144
|
// src/js/core/WaveformSounds.js
|
|
1104
|
-
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
|
|
1145
|
+
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
|
|
1105
1146
|
var SEARCH_DELAY = 120;
|
|
1106
1147
|
var BPM_DELAY = 200;
|
|
1107
1148
|
var URL_DELAY = 250;
|
|
@@ -1206,7 +1247,8 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1206
1247
|
more: q("[data-ws-more]"),
|
|
1207
1248
|
engine: q("[data-ws-engine]"),
|
|
1208
1249
|
status: q("[data-ws-status]"),
|
|
1209
|
-
chips: [...this.container.querySelectorAll("[data-ws-type]")]
|
|
1250
|
+
chips: [...this.container.querySelectorAll("[data-ws-type]")],
|
|
1251
|
+
loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
|
|
1210
1252
|
};
|
|
1211
1253
|
this.rows = indexRows(this.$.list);
|
|
1212
1254
|
}
|
|
@@ -1255,7 +1297,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1255
1297
|
}
|
|
1256
1298
|
/* ── Input ────────────────────────────────────────────────────────── */
|
|
1257
1299
|
/**
|
|
1258
|
-
* Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
|
|
1300
|
+
* Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
|
|
1259
1301
|
* (seek), and anywhere else on a row (play/pause).
|
|
1260
1302
|
* @private
|
|
1261
1303
|
*/
|
|
@@ -1266,6 +1308,11 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1266
1308
|
this.setFilter({ type: chip.dataset.wsType });
|
|
1267
1309
|
return;
|
|
1268
1310
|
}
|
|
1311
|
+
const seg = t.closest("[data-ws-loop-filter]");
|
|
1312
|
+
if (seg) {
|
|
1313
|
+
this.setFilter({ loop: seg.dataset.wsLoopFilter });
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1269
1316
|
if (t.closest("[data-ws-more]")) {
|
|
1270
1317
|
this.showMore();
|
|
1271
1318
|
return;
|
|
@@ -1533,6 +1580,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1533
1580
|
if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
|
|
1534
1581
|
if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
|
|
1535
1582
|
$.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
|
|
1583
|
+
$.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
|
|
1536
1584
|
}
|
|
1537
1585
|
/**
|
|
1538
1586
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
@@ -1704,7 +1752,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1704
1752
|
return true;
|
|
1705
1753
|
}
|
|
1706
1754
|
/**
|
|
1707
|
-
* Loop the current sound (auditioning a loop is the common case).
|
|
1755
|
+
* Loop the current sound (auditioning a loop is the common case). When
|
|
1756
|
+
* the list marks its loops (`loop: true` on any sound), only those
|
|
1757
|
+
* repeat: a one-shot always plays once.
|
|
1708
1758
|
* @param {boolean} on
|
|
1709
1759
|
*/
|
|
1710
1760
|
setLoop(on) {
|
|
@@ -1717,7 +1767,17 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1717
1767
|
*/
|
|
1718
1768
|
_setLoop(on) {
|
|
1719
1769
|
this.$?.loop?.setAttribute("aria-pressed", String(on));
|
|
1720
|
-
if (this.engine?.audio) this.engine.audio.loop =
|
|
1770
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Should the current sound repeat? The Loop toggle is on, and either
|
|
1774
|
+
* the list doesn't say which sounds are loops or this one is.
|
|
1775
|
+
* @private
|
|
1776
|
+
*/
|
|
1777
|
+
_repeats() {
|
|
1778
|
+
if (!this.loop) return false;
|
|
1779
|
+
const marksLoops = this.sounds.some((s) => s.loop);
|
|
1780
|
+
return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
|
|
1721
1781
|
}
|
|
1722
1782
|
/**
|
|
1723
1783
|
* Seek a row's sound to `fraction`; a row that isn't current starts
|
|
@@ -1745,7 +1805,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1745
1805
|
* @private
|
|
1746
1806
|
*/
|
|
1747
1807
|
_onEngineLoad() {
|
|
1748
|
-
if (this.engine?.audio) this.engine.audio.loop = this.
|
|
1808
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1749
1809
|
const sound = this.sounds[this.currentIndex];
|
|
1750
1810
|
if (sound && !sound.peaks && this.engine?.waveformData?.length) {
|
|
1751
1811
|
sound.peaks = resample(this.engine.waveformData, 96);
|
|
@@ -128,9 +128,13 @@ function normalizeSound(input, index, peakScale = 1) {
|
|
|
128
128
|
tags,
|
|
129
129
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
130
130
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
131
|
-
download: input.download ? String(input.download) : null
|
|
131
|
+
download: input.download ? String(input.download) : null,
|
|
132
|
+
loop: isLoop(input.loop)
|
|
132
133
|
};
|
|
133
134
|
}
|
|
135
|
+
function isLoop(value) {
|
|
136
|
+
return value === true || value === 1 || value === "true" || value === "1";
|
|
137
|
+
}
|
|
134
138
|
function parseManifest(manifest) {
|
|
135
139
|
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
136
140
|
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
@@ -153,7 +157,7 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
153
157
|
function facets(sounds) {
|
|
154
158
|
const types = /* @__PURE__ */ new Map();
|
|
155
159
|
const keys = /* @__PURE__ */ new Set();
|
|
156
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
160
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
157
161
|
for (const s of sounds) {
|
|
158
162
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
159
163
|
if (s.key) keys.add(s.key);
|
|
@@ -162,12 +166,15 @@ function facets(sounds) {
|
|
|
162
166
|
max = Math.max(max, s.bpm);
|
|
163
167
|
}
|
|
164
168
|
if (s.duration != null) hasDuration = true;
|
|
169
|
+
if (s.loop) loops++;
|
|
165
170
|
}
|
|
166
171
|
return {
|
|
167
172
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
168
173
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
169
174
|
bpm: min === Infinity ? null : { min, max },
|
|
170
|
-
hasDuration
|
|
175
|
+
hasDuration,
|
|
176
|
+
loops,
|
|
177
|
+
oneShots: sounds.length - loops
|
|
171
178
|
};
|
|
172
179
|
}
|
|
173
180
|
var SORTS = ["default", "title", "bpm", "key", "duration"];
|
|
@@ -239,6 +246,10 @@ var DEFAULT_STRINGS = {
|
|
|
239
246
|
sortKey: "Key",
|
|
240
247
|
sortDuration: "Length",
|
|
241
248
|
loop: "Loop",
|
|
249
|
+
loopFilter: "Loops or one-shots",
|
|
250
|
+
loops: "Loops",
|
|
251
|
+
oneShots: "One-shots",
|
|
252
|
+
isLoop: "Loop",
|
|
242
253
|
play: "Play {title}",
|
|
243
254
|
pause: "Pause {title}",
|
|
244
255
|
seek: "Seek {title}",
|
|
@@ -267,7 +278,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
267
278
|
}
|
|
268
279
|
|
|
269
280
|
// src/js/render/options.js
|
|
270
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
281
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
271
282
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
272
283
|
var RENDER_DEFAULTS = {
|
|
273
284
|
player: "inline",
|
|
@@ -327,6 +338,7 @@ function toolbarPlan(f, o) {
|
|
|
327
338
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
328
339
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
329
340
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
341
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
330
342
|
sorts: sorts.length > 1 ? sorts : [],
|
|
331
343
|
search: !!o.search,
|
|
332
344
|
loop: !!o.loopToggle,
|
|
@@ -397,6 +409,20 @@ function renderBpmRange(s, range) {
|
|
|
397
409
|
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
398
410
|
);
|
|
399
411
|
}
|
|
412
|
+
function renderLoopFilter(s) {
|
|
413
|
+
const button = (value, label) => h(
|
|
414
|
+
"button",
|
|
415
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
416
|
+
h("span", {}, text(label))
|
|
417
|
+
);
|
|
418
|
+
return h(
|
|
419
|
+
"div",
|
|
420
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
421
|
+
button("", s.all),
|
|
422
|
+
button("loop", s.loops),
|
|
423
|
+
button("one-shot", s.oneShots)
|
|
424
|
+
);
|
|
425
|
+
}
|
|
400
426
|
function renderLoopToggle(s) {
|
|
401
427
|
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
402
428
|
}
|
|
@@ -425,6 +451,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
425
451
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
426
452
|
}),
|
|
427
453
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
454
|
+
plan.loops && renderLoopFilter(s),
|
|
428
455
|
plan.sorts.length > 0 && menu("sort", {
|
|
429
456
|
label: s.sort,
|
|
430
457
|
prefix: s.sortBy,
|
|
@@ -475,10 +502,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
475
502
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
476
503
|
"data-waveform": sound.waveform,
|
|
477
504
|
"data-download": sound.download,
|
|
505
|
+
"data-loop": sound.loop ? "true" : null,
|
|
478
506
|
hidden
|
|
479
507
|
},
|
|
480
508
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
481
|
-
h(
|
|
509
|
+
h(
|
|
510
|
+
"span",
|
|
511
|
+
{ class: "ws-cell ws-title" },
|
|
512
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
513
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
514
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
515
|
+
),
|
|
482
516
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
483
517
|
// rows: one line under the title.
|
|
484
518
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|