@arraypress/waveform-sounds 0.1.2 → 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 +74 -13
- package/dist/waveform-sounds-no-autoinit.esm.js +74 -13
- package/dist/waveform-sounds-render.cjs +40 -5
- package/dist/waveform-sounds-render.esm.js +40 -5
- package/dist/waveform-sounds.cjs +74 -13
- package/dist/waveform-sounds.css +40 -3
- package/dist/waveform-sounds.esm.js +74 -13
- package/dist/waveform-sounds.js +74 -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 +40 -3
- package/src/js/core/WaveformSounds.js +22 -5
- package/src/js/data/sounds.js +39 -8
- 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
|
@@ -56,6 +56,7 @@ function formatDuration(seconds) {
|
|
|
56
56
|
if (seconds == null || seconds === "") return "";
|
|
57
57
|
const s = Number(seconds);
|
|
58
58
|
if (!Number.isFinite(s) || s < 0) return "";
|
|
59
|
+
if (s > 0 && s < 0.95) return `${Math.max(0.1, Math.round(s * 10) / 10).toFixed(1)}s`;
|
|
59
60
|
const total = Math.round(s);
|
|
60
61
|
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
|
|
61
62
|
}
|
|
@@ -92,9 +93,13 @@ function normalizeSound(input, index, peakScale = 1) {
|
|
|
92
93
|
tags,
|
|
93
94
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
94
95
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
95
|
-
download: input.download ? String(input.download) : null
|
|
96
|
+
download: input.download ? String(input.download) : null,
|
|
97
|
+
loop: isLoop(input.loop)
|
|
96
98
|
};
|
|
97
99
|
}
|
|
100
|
+
function isLoop(value) {
|
|
101
|
+
return value === true || value === 1 || value === "true" || value === "1";
|
|
102
|
+
}
|
|
98
103
|
function parseManifest(manifest) {
|
|
99
104
|
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
100
105
|
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
@@ -117,7 +122,7 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
117
122
|
function facets(sounds) {
|
|
118
123
|
const types = /* @__PURE__ */ new Map();
|
|
119
124
|
const keys = /* @__PURE__ */ new Set();
|
|
120
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
125
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
121
126
|
for (const s of sounds) {
|
|
122
127
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
123
128
|
if (s.key) keys.add(s.key);
|
|
@@ -126,12 +131,15 @@ function facets(sounds) {
|
|
|
126
131
|
max = Math.max(max, s.bpm);
|
|
127
132
|
}
|
|
128
133
|
if (s.duration != null) hasDuration = true;
|
|
134
|
+
if (s.loop) loops++;
|
|
129
135
|
}
|
|
130
136
|
return {
|
|
131
137
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
132
138
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
133
139
|
bpm: min === Infinity ? null : { min, max },
|
|
134
|
-
hasDuration
|
|
140
|
+
hasDuration,
|
|
141
|
+
loops,
|
|
142
|
+
oneShots: sounds.length - loops
|
|
135
143
|
};
|
|
136
144
|
}
|
|
137
145
|
var SORTS = ["default", "title", "bpm", "key", "duration"];
|
|
@@ -203,6 +211,10 @@ var DEFAULT_STRINGS = {
|
|
|
203
211
|
sortKey: "Key",
|
|
204
212
|
sortDuration: "Length",
|
|
205
213
|
loop: "Loop",
|
|
214
|
+
loopFilter: "Loops or one-shots",
|
|
215
|
+
loops: "Loops",
|
|
216
|
+
oneShots: "One-shots",
|
|
217
|
+
isLoop: "Loop",
|
|
206
218
|
play: "Play {title}",
|
|
207
219
|
pause: "Pause {title}",
|
|
208
220
|
seek: "Seek {title}",
|
|
@@ -231,7 +243,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
231
243
|
}
|
|
232
244
|
|
|
233
245
|
// src/js/render/options.js
|
|
234
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
246
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
235
247
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
236
248
|
var RENDER_DEFAULTS = {
|
|
237
249
|
player: "inline",
|
|
@@ -291,6 +303,7 @@ function toolbarPlan(f, o) {
|
|
|
291
303
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
292
304
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
293
305
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
306
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
294
307
|
sorts: sorts.length > 1 ? sorts : [],
|
|
295
308
|
search: !!o.search,
|
|
296
309
|
loop: !!o.loopToggle,
|
|
@@ -361,6 +374,20 @@ function renderBpmRange(s, range) {
|
|
|
361
374
|
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
362
375
|
);
|
|
363
376
|
}
|
|
377
|
+
function renderLoopFilter(s) {
|
|
378
|
+
const button = (value, label) => h(
|
|
379
|
+
"button",
|
|
380
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
381
|
+
h("span", {}, text(label))
|
|
382
|
+
);
|
|
383
|
+
return h(
|
|
384
|
+
"div",
|
|
385
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
386
|
+
button("", s.all),
|
|
387
|
+
button("loop", s.loops),
|
|
388
|
+
button("one-shot", s.oneShots)
|
|
389
|
+
);
|
|
390
|
+
}
|
|
364
391
|
function renderLoopToggle(s) {
|
|
365
392
|
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
366
393
|
}
|
|
@@ -389,6 +416,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
389
416
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
390
417
|
}),
|
|
391
418
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
419
|
+
plan.loops && renderLoopFilter(s),
|
|
392
420
|
plan.sorts.length > 0 && menu("sort", {
|
|
393
421
|
label: s.sort,
|
|
394
422
|
prefix: s.sortBy,
|
|
@@ -439,10 +467,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
439
467
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
440
468
|
"data-waveform": sound.waveform,
|
|
441
469
|
"data-download": sound.download,
|
|
470
|
+
"data-loop": sound.loop ? "true" : null,
|
|
442
471
|
hidden
|
|
443
472
|
},
|
|
444
473
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
445
|
-
h(
|
|
474
|
+
h(
|
|
475
|
+
"span",
|
|
476
|
+
{ class: "ws-cell ws-title" },
|
|
477
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
478
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
479
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
480
|
+
),
|
|
446
481
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
447
482
|
// rows: one line under the title.
|
|
448
483
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
package/dist/waveform-sounds.cjs
CHANGED
|
@@ -136,6 +136,7 @@ function formatDuration(seconds) {
|
|
|
136
136
|
if (seconds == null || seconds === "") return "";
|
|
137
137
|
const s = Number(seconds);
|
|
138
138
|
if (!Number.isFinite(s) || s < 0) return "";
|
|
139
|
+
if (s > 0 && s < 0.95) return `${Math.max(0.1, Math.round(s * 10) / 10).toFixed(1)}s`;
|
|
139
140
|
const total = Math.round(s);
|
|
140
141
|
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
|
|
141
142
|
}
|
|
@@ -172,9 +173,14 @@ function normalizeSound(input, index, peakScale = 1) {
|
|
|
172
173
|
tags,
|
|
173
174
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
174
175
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
175
|
-
download: input.download ? String(input.download) : null
|
|
176
|
+
download: input.download ? String(input.download) : null,
|
|
177
|
+
loop: isLoop(input.loop)
|
|
176
178
|
};
|
|
177
179
|
}
|
|
180
|
+
var LOOP_FILTERS = ["loop", "one-shot"];
|
|
181
|
+
function isLoop(value) {
|
|
182
|
+
return value === true || value === 1 || value === "true" || value === "1";
|
|
183
|
+
}
|
|
178
184
|
function parseManifest(manifest) {
|
|
179
185
|
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
180
186
|
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
@@ -197,7 +203,7 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
197
203
|
function facets(sounds) {
|
|
198
204
|
const types = /* @__PURE__ */ new Map();
|
|
199
205
|
const keys = /* @__PURE__ */ new Set();
|
|
200
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
206
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
201
207
|
for (const s of sounds) {
|
|
202
208
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
203
209
|
if (s.key) keys.add(s.key);
|
|
@@ -206,17 +212,22 @@ function facets(sounds) {
|
|
|
206
212
|
max = Math.max(max, s.bpm);
|
|
207
213
|
}
|
|
208
214
|
if (s.duration != null) hasDuration = true;
|
|
215
|
+
if (s.loop) loops++;
|
|
209
216
|
}
|
|
210
217
|
return {
|
|
211
218
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
212
219
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
213
220
|
bpm: min === Infinity ? null : { min, max },
|
|
214
|
-
hasDuration
|
|
221
|
+
hasDuration,
|
|
222
|
+
loops,
|
|
223
|
+
oneShots: sounds.length - loops
|
|
215
224
|
};
|
|
216
225
|
}
|
|
217
226
|
function matches(sound, filter = {}) {
|
|
218
227
|
if (filter.type && sound.type !== filter.type) return false;
|
|
219
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;
|
|
220
231
|
const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
|
|
221
232
|
if (filter.bpmMin != null && filter.bpmMin !== "" && Number.isFinite(lo) || filter.bpmMax != null && filter.bpmMax !== "" && Number.isFinite(hi)) {
|
|
222
233
|
if (sound.bpm == null) return false;
|
|
@@ -621,6 +632,10 @@ var DEFAULT_STRINGS = {
|
|
|
621
632
|
sortKey: "Key",
|
|
622
633
|
sortDuration: "Length",
|
|
623
634
|
loop: "Loop",
|
|
635
|
+
loopFilter: "Loops or one-shots",
|
|
636
|
+
loops: "Loops",
|
|
637
|
+
oneShots: "One-shots",
|
|
638
|
+
isLoop: "Loop",
|
|
624
639
|
play: "Play {title}",
|
|
625
640
|
pause: "Pause {title}",
|
|
626
641
|
seek: "Seek {title}",
|
|
@@ -649,7 +664,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
649
664
|
}
|
|
650
665
|
|
|
651
666
|
// src/js/render/options.js
|
|
652
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
667
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
653
668
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
654
669
|
var RENDER_DEFAULTS = {
|
|
655
670
|
player: "inline",
|
|
@@ -826,6 +841,7 @@ function toolbarPlan(f, o) {
|
|
|
826
841
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
827
842
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
828
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,
|
|
829
845
|
sorts: sorts.length > 1 ? sorts : [],
|
|
830
846
|
search: !!o.search,
|
|
831
847
|
loop: !!o.loopToggle,
|
|
@@ -896,6 +912,20 @@ function renderBpmRange(s, range) {
|
|
|
896
912
|
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
897
913
|
);
|
|
898
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
|
+
}
|
|
899
929
|
function renderLoopToggle(s) {
|
|
900
930
|
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
901
931
|
}
|
|
@@ -924,6 +954,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
924
954
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
925
955
|
}),
|
|
926
956
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
957
|
+
plan.loops && renderLoopFilter(s),
|
|
927
958
|
plan.sorts.length > 0 && menu("sort", {
|
|
928
959
|
label: s.sort,
|
|
929
960
|
prefix: s.sortBy,
|
|
@@ -974,10 +1005,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
974
1005
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
975
1006
|
"data-waveform": sound.waveform,
|
|
976
1007
|
"data-download": sound.download,
|
|
1008
|
+
"data-loop": sound.loop ? "true" : null,
|
|
977
1009
|
hidden
|
|
978
1010
|
},
|
|
979
1011
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
980
|
-
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
|
+
),
|
|
981
1019
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
982
1020
|
// rows: one line under the title.
|
|
983
1021
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
@@ -1042,7 +1080,8 @@ function readRows(list) {
|
|
|
1042
1080
|
tags: d.tags,
|
|
1043
1081
|
peaks: d.peaks,
|
|
1044
1082
|
waveform: d.waveform,
|
|
1045
|
-
download: d.download
|
|
1083
|
+
download: d.download,
|
|
1084
|
+
loop: d.loop
|
|
1046
1085
|
}, sounds.length);
|
|
1047
1086
|
if (!sound) {
|
|
1048
1087
|
row.remove();
|
|
@@ -1100,7 +1139,7 @@ function resolveCssColor(container, value) {
|
|
|
1100
1139
|
function urlKeys(urlState) {
|
|
1101
1140
|
if (!urlState) return null;
|
|
1102
1141
|
const p = typeof urlState === "string" ? `${urlState}-` : "";
|
|
1103
|
-
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` };
|
|
1104
1143
|
}
|
|
1105
1144
|
function parseBpmRange(value) {
|
|
1106
1145
|
const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
|
|
@@ -1122,6 +1161,8 @@ function readUrlState(search, keys, available, sorts) {
|
|
|
1122
1161
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
1123
1162
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
1124
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;
|
|
1125
1166
|
const sort = sp.get(keys.sort);
|
|
1126
1167
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
1127
1168
|
return out;
|
|
@@ -1134,12 +1175,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
1134
1175
|
set(keys.type, filter.type);
|
|
1135
1176
|
set(keys.key, filter.key);
|
|
1136
1177
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
1178
|
+
set(keys.loop, filter.loop);
|
|
1137
1179
|
set(keys.sort, sort !== defaultSort ? sort : "");
|
|
1138
1180
|
return url.href;
|
|
1139
1181
|
}
|
|
1140
1182
|
|
|
1141
1183
|
// src/js/core/WaveformSounds.js
|
|
1142
|
-
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
|
|
1184
|
+
var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
|
|
1143
1185
|
var SEARCH_DELAY = 120;
|
|
1144
1186
|
var BPM_DELAY = 200;
|
|
1145
1187
|
var URL_DELAY = 250;
|
|
@@ -1244,7 +1286,8 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1244
1286
|
more: q("[data-ws-more]"),
|
|
1245
1287
|
engine: q("[data-ws-engine]"),
|
|
1246
1288
|
status: q("[data-ws-status]"),
|
|
1247
|
-
chips: [...this.container.querySelectorAll("[data-ws-type]")]
|
|
1289
|
+
chips: [...this.container.querySelectorAll("[data-ws-type]")],
|
|
1290
|
+
loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
|
|
1248
1291
|
};
|
|
1249
1292
|
this.rows = indexRows(this.$.list);
|
|
1250
1293
|
}
|
|
@@ -1293,7 +1336,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1293
1336
|
}
|
|
1294
1337
|
/* ── Input ────────────────────────────────────────────────────────── */
|
|
1295
1338
|
/**
|
|
1296
|
-
* 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
|
|
1297
1340
|
* (seek), and anywhere else on a row (play/pause).
|
|
1298
1341
|
* @private
|
|
1299
1342
|
*/
|
|
@@ -1304,6 +1347,11 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1304
1347
|
this.setFilter({ type: chip.dataset.wsType });
|
|
1305
1348
|
return;
|
|
1306
1349
|
}
|
|
1350
|
+
const seg = t.closest("[data-ws-loop-filter]");
|
|
1351
|
+
if (seg) {
|
|
1352
|
+
this.setFilter({ loop: seg.dataset.wsLoopFilter });
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1307
1355
|
if (t.closest("[data-ws-more]")) {
|
|
1308
1356
|
this.showMore();
|
|
1309
1357
|
return;
|
|
@@ -1571,6 +1619,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1571
1619
|
if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
|
|
1572
1620
|
if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
|
|
1573
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 || ""))));
|
|
1574
1623
|
}
|
|
1575
1624
|
/**
|
|
1576
1625
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
@@ -1742,7 +1791,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1742
1791
|
return true;
|
|
1743
1792
|
}
|
|
1744
1793
|
/**
|
|
1745
|
-
* 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.
|
|
1746
1797
|
* @param {boolean} on
|
|
1747
1798
|
*/
|
|
1748
1799
|
setLoop(on) {
|
|
@@ -1755,7 +1806,17 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1755
1806
|
*/
|
|
1756
1807
|
_setLoop(on) {
|
|
1757
1808
|
this.$?.loop?.setAttribute("aria-pressed", String(on));
|
|
1758
|
-
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;
|
|
1759
1820
|
}
|
|
1760
1821
|
/**
|
|
1761
1822
|
* Seek a row's sound to `fraction`; a row that isn't current starts
|
|
@@ -1783,7 +1844,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1783
1844
|
* @private
|
|
1784
1845
|
*/
|
|
1785
1846
|
_onEngineLoad() {
|
|
1786
|
-
if (this.engine?.audio) this.engine.audio.loop = this.
|
|
1847
|
+
if (this.engine?.audio) this.engine.audio.loop = this._repeats();
|
|
1787
1848
|
const sound = this.sounds[this.currentIndex];
|
|
1788
1849
|
if (sound && !sound.peaks && this.engine?.waveformData?.length) {
|
|
1789
1850
|
sound.peaks = resample(this.engine.waveformData, 96);
|
package/dist/waveform-sounds.css
CHANGED
|
@@ -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,10 +363,13 @@
|
|
|
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; }
|
|
337
|
-
|
|
370
|
+
/* A dot only after an earlier cell with something in it: a sound with no
|
|
371
|
+
key must not read "· 0:08". */
|
|
372
|
+
.ws-cells > .ws-cell:not(:empty) ~ .ws-cell:not(:empty)::before { content: '·'; margin-right: 0.5rem; opacity: 0.6; }
|
|
338
373
|
.ws-wave { grid-area: wave; margin-top: 0.35rem; min-width: 0; }
|
|
339
374
|
.ws-download { grid-area: dl; align-self: start; }
|
|
340
375
|
}
|
|
@@ -361,7 +396,9 @@
|
|
|
361
396
|
padding: 0.75rem;
|
|
362
397
|
border: 1px solid var(--ws-border);
|
|
363
398
|
border-radius: var(--ws-radius);
|
|
364
|
-
|
|
399
|
+
/* The page surface (measured, or given), not the system Canvas colour,
|
|
400
|
+
which is white on a dark page that doesn't declare color-scheme. */
|
|
401
|
+
background: var(--ws-strip-bg, var(--ws-surface, Canvas));
|
|
365
402
|
z-index: 1;
|
|
366
403
|
}
|
|
367
404
|
|