@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 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
@@ -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("span", { class: "ws-cell ws-title" }, text(sound.title)),
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 = on;
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.loop;
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);
@@ -97,6 +97,7 @@ function formatDuration(seconds) {
97
97
  if (seconds == null || seconds === "") return "";
98
98
  const s = Number(seconds);
99
99
  if (!Number.isFinite(s) || s < 0) return "";
100
+ if (s > 0 && s < 0.95) return `${Math.max(0.1, Math.round(s * 10) / 10).toFixed(1)}s`;
100
101
  const total = Math.round(s);
101
102
  return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
102
103
  }
@@ -133,9 +134,14 @@ function normalizeSound(input, index, peakScale = 1) {
133
134
  tags,
134
135
  peaks: decodePeaks(input.peaks, peakScale),
135
136
  waveform: input.waveform ? String(input.waveform) : null,
136
- download: input.download ? String(input.download) : null
137
+ download: input.download ? String(input.download) : null,
138
+ loop: isLoop(input.loop)
137
139
  };
138
140
  }
141
+ var LOOP_FILTERS = ["loop", "one-shot"];
142
+ function isLoop(value) {
143
+ return value === true || value === 1 || value === "true" || value === "1";
144
+ }
139
145
  function parseManifest(manifest) {
140
146
  const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
141
147
  const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
@@ -158,7 +164,7 @@ function normalizeSounds(list, peakScale = 1) {
158
164
  function facets(sounds) {
159
165
  const types = /* @__PURE__ */ new Map();
160
166
  const keys = /* @__PURE__ */ new Set();
161
- let min = Infinity, max = -Infinity, hasDuration = false;
167
+ let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
162
168
  for (const s of sounds) {
163
169
  if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
164
170
  if (s.key) keys.add(s.key);
@@ -167,17 +173,22 @@ function facets(sounds) {
167
173
  max = Math.max(max, s.bpm);
168
174
  }
169
175
  if (s.duration != null) hasDuration = true;
176
+ if (s.loop) loops++;
170
177
  }
171
178
  return {
172
179
  types: [...types].map(([name, count]) => ({ name, count })),
173
180
  keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
174
181
  bpm: min === Infinity ? null : { min, max },
175
- hasDuration
182
+ hasDuration,
183
+ loops,
184
+ oneShots: sounds.length - loops
176
185
  };
177
186
  }
178
187
  function matches(sound, filter = {}) {
179
188
  if (filter.type && sound.type !== filter.type) return false;
180
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;
181
192
  const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
182
193
  if (filter.bpmMin != null && filter.bpmMin !== "" && Number.isFinite(lo) || filter.bpmMax != null && filter.bpmMax !== "" && Number.isFinite(hi)) {
183
194
  if (sound.bpm == null) return false;
@@ -582,6 +593,10 @@ var DEFAULT_STRINGS = {
582
593
  sortKey: "Key",
583
594
  sortDuration: "Length",
584
595
  loop: "Loop",
596
+ loopFilter: "Loops or one-shots",
597
+ loops: "Loops",
598
+ oneShots: "One-shots",
599
+ isLoop: "Loop",
585
600
  play: "Play {title}",
586
601
  pause: "Pause {title}",
587
602
  seek: "Seek {title}",
@@ -610,7 +625,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
610
625
  }
611
626
 
612
627
  // src/js/render/options.js
613
- var FILTERS = ["type", "key", "bpm"];
628
+ var FILTERS = ["type", "key", "bpm", "loop"];
614
629
  var COLUMNS = ["type", "bpm", "key", "duration"];
615
630
  var RENDER_DEFAULTS = {
616
631
  player: "inline",
@@ -787,6 +802,7 @@ function toolbarPlan(f, o) {
787
802
  types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
788
803
  key: o.filters.includes("key") && f.keys.length > 1,
789
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,
790
806
  sorts: sorts.length > 1 ? sorts : [],
791
807
  search: !!o.search,
792
808
  loop: !!o.loopToggle,
@@ -857,6 +873,20 @@ function renderBpmRange(s, range) {
857
873
  h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
858
874
  );
859
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
+ }
860
890
  function renderLoopToggle(s) {
861
891
  return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
862
892
  }
@@ -885,6 +915,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
885
915
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
886
916
  }),
887
917
  plan.bpm && renderBpmRange(s, f.bpm),
918
+ plan.loops && renderLoopFilter(s),
888
919
  plan.sorts.length > 0 && menu("sort", {
889
920
  label: s.sort,
890
921
  prefix: s.sortBy,
@@ -935,10 +966,17 @@ function renderRow(sound, index, o, hidden = false) {
935
966
  "data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
936
967
  "data-waveform": sound.waveform,
937
968
  "data-download": sound.download,
969
+ "data-loop": sound.loop ? "true" : null,
938
970
  hidden
939
971
  },
940
972
  h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
941
- h("span", { class: "ws-cell ws-title" }, text(sound.title)),
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
+ ),
942
980
  // Wide rows: `display: contents` makes each cell a column. Narrow
943
981
  // rows: one line under the title.
944
982
  cells.length > 0 && h("span", { class: "ws-cells" }, cells),
@@ -1003,7 +1041,8 @@ function readRows(list) {
1003
1041
  tags: d.tags,
1004
1042
  peaks: d.peaks,
1005
1043
  waveform: d.waveform,
1006
- download: d.download
1044
+ download: d.download,
1045
+ loop: d.loop
1007
1046
  }, sounds.length);
1008
1047
  if (!sound) {
1009
1048
  row.remove();
@@ -1061,7 +1100,7 @@ function resolveCssColor(container, value) {
1061
1100
  function urlKeys(urlState) {
1062
1101
  if (!urlState) return null;
1063
1102
  const p = typeof urlState === "string" ? `${urlState}-` : "";
1064
- 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` };
1065
1104
  }
1066
1105
  function parseBpmRange(value) {
1067
1106
  const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
@@ -1083,6 +1122,8 @@ function readUrlState(search, keys, available, sorts) {
1083
1122
  if (key && available.keys.includes(key)) out.filter.key = key;
1084
1123
  const bpm = parseBpmRange(sp.get(keys.bpm));
1085
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;
1086
1127
  const sort = sp.get(keys.sort);
1087
1128
  if (sort && sorts.includes(sort)) out.sort = sort;
1088
1129
  return out;
@@ -1095,12 +1136,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
1095
1136
  set(keys.type, filter.type);
1096
1137
  set(keys.key, filter.key);
1097
1138
  set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
1139
+ set(keys.loop, filter.loop);
1098
1140
  set(keys.sort, sort !== defaultSort ? sort : "");
1099
1141
  return url.href;
1100
1142
  }
1101
1143
 
1102
1144
  // src/js/core/WaveformSounds.js
1103
- var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
1145
+ var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
1104
1146
  var SEARCH_DELAY = 120;
1105
1147
  var BPM_DELAY = 200;
1106
1148
  var URL_DELAY = 250;
@@ -1205,7 +1247,8 @@ var WaveformSounds = class _WaveformSounds {
1205
1247
  more: q("[data-ws-more]"),
1206
1248
  engine: q("[data-ws-engine]"),
1207
1249
  status: q("[data-ws-status]"),
1208
- chips: [...this.container.querySelectorAll("[data-ws-type]")]
1250
+ chips: [...this.container.querySelectorAll("[data-ws-type]")],
1251
+ loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
1209
1252
  };
1210
1253
  this.rows = indexRows(this.$.list);
1211
1254
  }
@@ -1254,7 +1297,7 @@ var WaveformSounds = class _WaveformSounds {
1254
1297
  }
1255
1298
  /* ── Input ────────────────────────────────────────────────────────── */
1256
1299
  /**
1257
- * 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
1258
1301
  * (seek), and anywhere else on a row (play/pause).
1259
1302
  * @private
1260
1303
  */
@@ -1265,6 +1308,11 @@ var WaveformSounds = class _WaveformSounds {
1265
1308
  this.setFilter({ type: chip.dataset.wsType });
1266
1309
  return;
1267
1310
  }
1311
+ const seg = t.closest("[data-ws-loop-filter]");
1312
+ if (seg) {
1313
+ this.setFilter({ loop: seg.dataset.wsLoopFilter });
1314
+ return;
1315
+ }
1268
1316
  if (t.closest("[data-ws-more]")) {
1269
1317
  this.showMore();
1270
1318
  return;
@@ -1532,6 +1580,7 @@ var WaveformSounds = class _WaveformSounds {
1532
1580
  if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
1533
1581
  if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
1534
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 || ""))));
1535
1584
  }
1536
1585
  /**
1537
1586
  * Lay the rows out for the current filter, sort and page: order, hide,
@@ -1703,7 +1752,9 @@ var WaveformSounds = class _WaveformSounds {
1703
1752
  return true;
1704
1753
  }
1705
1754
  /**
1706
- * 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.
1707
1758
  * @param {boolean} on
1708
1759
  */
1709
1760
  setLoop(on) {
@@ -1716,7 +1767,17 @@ var WaveformSounds = class _WaveformSounds {
1716
1767
  */
1717
1768
  _setLoop(on) {
1718
1769
  this.$?.loop?.setAttribute("aria-pressed", String(on));
1719
- if (this.engine?.audio) this.engine.audio.loop = on;
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;
1720
1781
  }
1721
1782
  /**
1722
1783
  * Seek a row's sound to `fraction`; a row that isn't current starts
@@ -1744,7 +1805,7 @@ var WaveformSounds = class _WaveformSounds {
1744
1805
  * @private
1745
1806
  */
1746
1807
  _onEngineLoad() {
1747
- if (this.engine?.audio) this.engine.audio.loop = this.loop;
1808
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1748
1809
  const sound = this.sounds[this.currentIndex];
1749
1810
  if (sound && !sound.peaks && this.engine?.waveformData?.length) {
1750
1811
  sound.peaks = resample(this.engine.waveformData, 96);
@@ -91,6 +91,7 @@ function formatDuration(seconds) {
91
91
  if (seconds == null || seconds === "") return "";
92
92
  const s = Number(seconds);
93
93
  if (!Number.isFinite(s) || s < 0) return "";
94
+ if (s > 0 && s < 0.95) return `${Math.max(0.1, Math.round(s * 10) / 10).toFixed(1)}s`;
94
95
  const total = Math.round(s);
95
96
  return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
96
97
  }
@@ -127,9 +128,13 @@ function normalizeSound(input, index, peakScale = 1) {
127
128
  tags,
128
129
  peaks: decodePeaks(input.peaks, peakScale),
129
130
  waveform: input.waveform ? String(input.waveform) : null,
130
- download: input.download ? String(input.download) : null
131
+ download: input.download ? String(input.download) : null,
132
+ loop: isLoop(input.loop)
131
133
  };
132
134
  }
135
+ function isLoop(value) {
136
+ return value === true || value === 1 || value === "true" || value === "1";
137
+ }
133
138
  function parseManifest(manifest) {
134
139
  const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
135
140
  const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
@@ -152,7 +157,7 @@ function normalizeSounds(list, peakScale = 1) {
152
157
  function facets(sounds) {
153
158
  const types = /* @__PURE__ */ new Map();
154
159
  const keys = /* @__PURE__ */ new Set();
155
- let min = Infinity, max = -Infinity, hasDuration = false;
160
+ let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
156
161
  for (const s of sounds) {
157
162
  if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
158
163
  if (s.key) keys.add(s.key);
@@ -161,12 +166,15 @@ function facets(sounds) {
161
166
  max = Math.max(max, s.bpm);
162
167
  }
163
168
  if (s.duration != null) hasDuration = true;
169
+ if (s.loop) loops++;
164
170
  }
165
171
  return {
166
172
  types: [...types].map(([name, count]) => ({ name, count })),
167
173
  keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
168
174
  bpm: min === Infinity ? null : { min, max },
169
- hasDuration
175
+ hasDuration,
176
+ loops,
177
+ oneShots: sounds.length - loops
170
178
  };
171
179
  }
172
180
  var SORTS = ["default", "title", "bpm", "key", "duration"];
@@ -238,6 +246,10 @@ var DEFAULT_STRINGS = {
238
246
  sortKey: "Key",
239
247
  sortDuration: "Length",
240
248
  loop: "Loop",
249
+ loopFilter: "Loops or one-shots",
250
+ loops: "Loops",
251
+ oneShots: "One-shots",
252
+ isLoop: "Loop",
241
253
  play: "Play {title}",
242
254
  pause: "Pause {title}",
243
255
  seek: "Seek {title}",
@@ -266,7 +278,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
266
278
  }
267
279
 
268
280
  // src/js/render/options.js
269
- var FILTERS = ["type", "key", "bpm"];
281
+ var FILTERS = ["type", "key", "bpm", "loop"];
270
282
  var COLUMNS = ["type", "bpm", "key", "duration"];
271
283
  var RENDER_DEFAULTS = {
272
284
  player: "inline",
@@ -326,6 +338,7 @@ function toolbarPlan(f, o) {
326
338
  types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
327
339
  key: o.filters.includes("key") && f.keys.length > 1,
328
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,
329
342
  sorts: sorts.length > 1 ? sorts : [],
330
343
  search: !!o.search,
331
344
  loop: !!o.loopToggle,
@@ -396,6 +409,20 @@ function renderBpmRange(s, range) {
396
409
  h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
397
410
  );
398
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
+ }
399
426
  function renderLoopToggle(s) {
400
427
  return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
401
428
  }
@@ -424,6 +451,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
424
451
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
425
452
  }),
426
453
  plan.bpm && renderBpmRange(s, f.bpm),
454
+ plan.loops && renderLoopFilter(s),
427
455
  plan.sorts.length > 0 && menu("sort", {
428
456
  label: s.sort,
429
457
  prefix: s.sortBy,
@@ -474,10 +502,17 @@ function renderRow(sound, index, o, hidden = false) {
474
502
  "data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
475
503
  "data-waveform": sound.waveform,
476
504
  "data-download": sound.download,
505
+ "data-loop": sound.loop ? "true" : null,
477
506
  hidden
478
507
  },
479
508
  h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
480
- h("span", { class: "ws-cell ws-title" }, text(sound.title)),
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
+ ),
481
516
  // Wide rows: `display: contents` makes each cell a column. Narrow
482
517
  // rows: one line under the title.
483
518
  cells.length > 0 && h("span", { class: "ws-cells" }, cells),