@opendaw/studio-core 0.0.83 → 0.0.84

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.
Files changed (40) hide show
  1. package/dist/ExternalLib.d.ts +3 -2
  2. package/dist/ExternalLib.d.ts.map +1 -1
  3. package/dist/ExternalLib.js +2 -2
  4. package/dist/Preferences.d.ts +4 -0
  5. package/dist/Preferences.d.ts.map +1 -1
  6. package/dist/Preferences.js +4 -2
  7. package/dist/capture/CaptureDevices.js +1 -1
  8. package/dist/capture/RecordAudio.d.ts.map +1 -1
  9. package/dist/capture/RecordAudio.js +17 -9
  10. package/dist/dawproject/BuiltinDevices.d.ts +1 -1
  11. package/dist/dawproject/DawProject.d.ts.map +1 -1
  12. package/dist/dawproject/DawProject.js +17 -3
  13. package/dist/midi/MIDILearning.d.ts +4 -16
  14. package/dist/midi/MIDILearning.d.ts.map +1 -1
  15. package/dist/midi/MIDILearning.js +95 -62
  16. package/dist/processors.js +17 -17
  17. package/dist/processors.js.map +4 -4
  18. package/dist/project/Project.d.ts.map +1 -1
  19. package/dist/project/Project.js +1 -0
  20. package/dist/project/ProjectBundle.d.ts.map +1 -1
  21. package/dist/project/ProjectBundle.js +17 -3
  22. package/dist/project/ProjectMigration.d.ts.map +1 -1
  23. package/dist/project/ProjectMigration.js +4 -3
  24. package/dist/project/ProjectValidation.d.ts.map +1 -1
  25. package/dist/project/ProjectValidation.js +15 -13
  26. package/dist/project/audio/AudioContentFactory.d.ts.map +1 -1
  27. package/dist/project/audio/AudioContentFactory.js +3 -3
  28. package/dist/project/audio/AudioContentModifier.d.ts.map +1 -1
  29. package/dist/project/audio/AudioContentModifier.js +0 -1
  30. package/dist/project/audio/AudioFileBoxFactory.d.ts.map +1 -1
  31. package/dist/project/audio/AudioFileBoxFactory.js +5 -0
  32. package/dist/samples/DefaultSampleLoaderManager.d.ts.map +1 -1
  33. package/dist/samples/DefaultSampleLoaderManager.js +4 -1
  34. package/dist/soundfont/DefaultSoundfontLoader.d.ts.map +1 -1
  35. package/dist/soundfont/DefaultSoundfontLoader.js +8 -7
  36. package/dist/soundfont/SoundfontService.d.ts.map +1 -1
  37. package/dist/soundfont/SoundfontService.js +3 -6
  38. package/dist/workers-main.js +1 -1
  39. package/dist/workers-main.js.map +2 -2
  40. package/package.json +15 -15
@@ -1 +1 @@
1
- {"version":3,"file":"Project.d.ts","sourceRoot":"","sources":["../../src/project/Project.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,IAAI,EAEJ,SAAS,EAET,UAAU,EACV,eAAe,EACf,UAAU,EACV,IAAI,EACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AACrD,OAAO,EACH,WAAW,EAGX,YAAY,EACZ,KAAK,EAEL,OAAO,EACP,WAAW,EAEX,gBAAgB,EACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACH,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAEhB,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAElB,kBAAkB,EAClB,eAAe,EAClB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAC,MAAM,qBAAqB,CAAA;AAC7E,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AACvC,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAC,cAAc,EAAY,MAAM,YAAY,CAAA;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAc,YAAY,EAAC,MAAM,SAAS,CAAA;AAGjD,OAAO,EAAyB,IAAI,EAAE,QAAQ,EAAW,MAA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BAAgB,EAAE,MAAM,GAAG,IAAI;IAe9F,kBAAkB,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;IAM/C,aAAa,IAAI,eAAe;IAIhC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO;IAIxC,OAAO,IAAI,OAAO;IAmBlB,SAAS,IAAI,IAAI;CAIpB"}
@@ -118,6 +118,7 @@ export class Project {
118
118
  }
119
119
  follow(box) {
120
120
  this.userEditingManager.follow(box);
121
+ this.midiLearning.followUser(box.midiControllers);
121
122
  this.selection.switch(box.selection);
122
123
  }
123
124
  own(terminable) { return this.#terminator.own(terminable); }
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectBundle.d.ts","sourceRoot":"","sources":["../../src/project/ProjectBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,QAAQ,EAAE,IAAI,EAAC,MAAM,kBAAkB,CAAA;AAI1F,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAO/C,yBAAiB,aAAa,CAAC;IACpB,MAAM,MAAM,GAAU,gCAA8B,cAAc,EAC5C,UAAU,QAAQ,CAAC,OAAO,KAAG,OAAO,CAAC,WAAW,CAoC5E,CAAA;IAEM,MAAM,MAAM,GAAU,KAAK,UAAU,EACf,aAAa,WAAW,EACxB,kBAAkB,IAAI,CAAC,KAAK,KAAG,OAAO,CAAC,cAAc,CAqCjF,CAAA;CAgDJ"}
1
+ {"version":3,"file":"ProjectBundle.d.ts","sourceRoot":"","sources":["../../src/project/ProjectBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,QAAQ,EAAmB,IAAI,EAAC,MAAM,kBAAkB,CAAA;AAI3G,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAO/C,yBAAiB,aAAa,CAAC;IACpB,MAAM,MAAM,GAAU,gCAA8B,cAAc,EAC5C,UAAU,QAAQ,CAAC,OAAO,KAAG,OAAO,CAAC,WAAW,CA2C5E,CAAA;IAEM,MAAM,MAAM,GAAU,KAAK,UAAU,EACf,aAAa,WAAW,EACxB,kBAAkB,IAAI,CAAC,KAAK,KAAG,OAAO,CAAC,cAAc,CA4CjF,CAAA;CAgDJ"}
@@ -1,4 +1,4 @@
1
- import { asDefined, isDefined, Option, panic, UUID } from "@opendaw/lib-std";
1
+ import { asDefined, isDefined, Option, panic, RuntimeNotifier, UUID } from "@opendaw/lib-std";
2
2
  import { AudioFileBox, SoundfontFileBox } from "@opendaw/studio-boxes";
3
3
  import { Project } from "./Project";
4
4
  import { ProjectPaths } from "./ProjectPaths";
@@ -10,7 +10,14 @@ import { ExternalLib } from "../ExternalLib";
10
10
  export var ProjectBundle;
11
11
  (function (ProjectBundle) {
12
12
  ProjectBundle.encode = async ({ uuid, project, meta, cover }, progress) => {
13
- const JSZip = await ExternalLib.JSZip();
13
+ const { status, value: JSZip, error } = await ExternalLib.JSZip();
14
+ if (status === "rejected") {
15
+ await RuntimeNotifier.info({
16
+ headline: "Error",
17
+ message: `Could not load JSZip: ${String(error)}`
18
+ });
19
+ return Promise.reject(error);
20
+ }
14
21
  const zip = new JSZip();
15
22
  zip.file("version", "1");
16
23
  zip.file("uuid", uuid, { binary: true });
@@ -45,7 +52,14 @@ export var ProjectBundle;
45
52
  return blob.arrayBuffer();
46
53
  };
47
54
  ProjectBundle.decode = async (env, arrayBuffer, openProfileUUID) => {
48
- const JSZip = await ExternalLib.JSZip();
55
+ const { status, value: JSZip, error } = await ExternalLib.JSZip();
56
+ if (status === "rejected") {
57
+ await RuntimeNotifier.info({
58
+ headline: "Error",
59
+ message: `Could not load JSZip: ${String(error)}`
60
+ });
61
+ return Promise.reject(error);
62
+ }
49
63
  const zip = await JSZip.loadAsync(arrayBuffer);
50
64
  if (await asDefined(zip.file("version")).async("text") !== "1") {
51
65
  return panic("Unknown bundle version");
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectMigration.d.ts","sourceRoot":"","sources":["../../src/project/ProjectMigration.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAA;AAIxD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AASvC,qBAAa,gBAAgB;WACZ,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,EAAC,QAAQ,EAAE,cAAc,EAAC,EAAE,eAAe;CAyOpF"}
1
+ {"version":3,"file":"ProjectMigration.d.ts","sourceRoot":"","sources":["../../src/project/ProjectMigration.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAA;AAIxD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AASvC,qBAAa,gBAAgB;WACZ,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,EAAC,QAAQ,EAAE,cAAc,EAAC,EAAE,eAAe;CA0OpF"}
@@ -26,13 +26,14 @@ export class ProjectMigration {
26
26
  const loadAudioData = (uuid) => {
27
27
  const { promise, resolve, reject } = Promise.withResolvers();
28
28
  const loader = env.sampleManager.getOrCreate(uuid);
29
- const subscription = loader.subscribe(state => {
29
+ let subscription;
30
+ subscription = loader.subscribe(state => {
30
31
  if (state.type === "loaded") {
31
- subscription.terminate();
32
+ queueMicrotask(() => subscription.terminate());
32
33
  resolve(loader.data.unwrap("State mismatch"));
33
34
  }
34
35
  else if (state.type === "error") {
35
- subscription.terminate();
36
+ queueMicrotask(() => subscription.terminate());
36
37
  reject(state.reason);
37
38
  }
38
39
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectValidation.d.ts","sourceRoot":"","sources":["../../src/project/ProjectValidation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAA;AAGxD,yBAAiB,iBAAiB,CAAC;IACxB,MAAM,QAAQ,GAAI,UAAU,eAAe,KAAG,IA2CpD,CAAA;CACJ"}
1
+ {"version":3,"file":"ProjectValidation.d.ts","sourceRoot":"","sources":["../../src/project/ProjectValidation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAA;AAGxD,yBAAiB,iBAAiB,CAAC;IACxB,MAAM,QAAQ,GAAI,UAAU,eAAe,KAAG,IA6CpD,CAAA;CACJ"}
@@ -18,20 +18,22 @@ export var ProjectValidation;
18
18
  visitNoteRegionBox: (box) => validateRegion(box),
19
19
  visitValueRegionBox: (box) => validateRegion(box),
20
20
  visitAudioRegionBox: (box) => validateRegion(box),
21
- visitTrackBox: (box) => Arrays.iterateAdjacent(box.regions.pointerHub.incoming()
22
- .map(({ box }) => asDefined(box.accept({
23
- visitNoteRegionBox: (box) => box,
24
- visitValueRegionBox: (box) => box,
25
- visitAudioRegionBox: (box) => box
26
- }), "Box must be a NoteRegionBox, ValueRegionBox or AudioRegionBox"))
27
- .sort((a, b) => a.position.getValue() - b.position.getValue()))
28
- .forEach(([left, right]) => {
29
- if (right.position.getValue() < left.position.getValue() + left.duration.getValue()) {
30
- console.warn(left, right, "Overlapping regions");
31
- invalidBoxes.add(left);
32
- invalidBoxes.add(right);
21
+ visitTrackBox: (box) => {
22
+ const regions = box.regions.pointerHub.incoming()
23
+ .map(({ box }) => asDefined(box.accept({
24
+ visitNoteRegionBox: (box) => box,
25
+ visitValueRegionBox: (box) => box,
26
+ visitAudioRegionBox: (box) => box
27
+ }), "Box must be a NoteRegionBox, ValueRegionBox or AudioRegionBox"))
28
+ .sort((a, b) => a.position.getValue() - b.position.getValue());
29
+ for (const [left, right] of Arrays.iterateAdjacent(regions)) {
30
+ if (right.position.getValue() < left.position.getValue() + left.duration.getValue()) {
31
+ console.warn(left, right, "Overlapping regions");
32
+ invalidBoxes.add(left);
33
+ invalidBoxes.add(right);
34
+ }
33
35
  }
34
- })
36
+ }
35
37
  }));
36
38
  if (invalidBoxes.size === 0) {
37
39
  return;
@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AAA;QACxB,WAAW,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAA;QAC/C,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;IAED,KAAY,IAAI,GAAG,KAAK,GAAG;QAAE,KAAK,EAAE,GAAG,CAAA;KAAE,CAAA;IACzC,KAAY,MAAM,GAAG,KAAK,GAAG;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAE9D,KAAY,kBAAkB,GAAG;QAC7B,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;QACrC,YAAY,CAAC,EAAE,MAAM,CAAA;KACxB,GAAG,KAAK,CAAA;IAET,KAAY,mBAAmB,GAAG,EAA0C,GAAG,KAAK,CAAA;IAEpF,KAAY,iBAAiB,GAAG,EAA0C,GAAG,KAAK,CAAA;IAI3E,MAAM,yBAAyB,GAAI,OAAO,kBAAkB,GAAG,MAAM,KAAG,cAM9E,CAAA;IAEM,MAAM,0BAA0B,GAAI,OAAO,mBAAmB,GAAG,MAAM,KAAG,cAEhF,CAAA;IAEM,MAAM,wBAAwB,GAAI,OAAO,iBAAiB,GAAG,MAAM,KAAG,cAgB5E,CAAA;IAIM,MAAM,uBAAuB,GAAI,OAAO,kBAAkB,GAAG,IAAI,KAAG,YAM1E,CAAA;IAEM,MAAM,wBAAwB,GAAI,OAAO,mBAAmB,GAAG,IAAI,KAAG,YAG5E,CAAA;IAEM,MAAM,sBAAsB,GAAI,OAAO,iBAAiB,GAAG,IAAI,KAAG,YAcxE,CAAA;CA6DJ"}
@@ -1,6 +1,6 @@
1
1
  import { PPQN, TimeBase } from "@opendaw/lib-dsp";
2
2
  import { ColorCodes, TrackType } from "@opendaw/studio-adapters";
3
- import { isDefined, panic, quantizeRound, UUID } from "@opendaw/lib-std";
3
+ import { isDefined, panic, quantizeCeil, UUID } from "@opendaw/lib-std";
4
4
  import { AudioClipBox, AudioPitchStretchBox, AudioRegionBox, AudioTimeStretchBox, ValueEventCollectionBox } from "@opendaw/studio-boxes";
5
5
  import { TransientPlayMode } from "@opendaw/studio-enums";
6
6
  import { AudioContentHelpers } from "./AudioContentHelpers";
@@ -68,7 +68,7 @@ export var AudioContentFactory;
68
68
  return panic("Cannot create audio-region on non-audio track");
69
69
  }
70
70
  const { name, duration: durationInSeconds, bpm } = sample;
71
- const durationInPPQN = props.duration ?? quantizeRound(PPQN.secondsToPulses(durationInSeconds, bpm), PPQN.SemiQuaver);
71
+ const durationInPPQN = props.duration ?? quantizeCeil(PPQN.secondsToPulses(durationInSeconds, bpm), PPQN.SemiQuaver);
72
72
  if (isDefined(props.warpMarkers)) {
73
73
  AudioContentHelpers.addWarpMarkers(boxGraph, playMode, props.warpMarkers);
74
74
  }
@@ -97,7 +97,7 @@ export var AudioContentFactory;
97
97
  return panic("Cannot create audio-region on non-audio track");
98
98
  }
99
99
  const { name, duration: durationInSeconds, bpm } = sample;
100
- const durationInPPQN = props.duration ?? quantizeRound(PPQN.secondsToPulses(durationInSeconds, bpm), PPQN.SemiQuaver);
100
+ const durationInPPQN = props.duration ?? quantizeCeil(PPQN.secondsToPulses(durationInSeconds, bpm), PPQN.SemiQuaver);
101
101
  if (isDefined(props.warpMarkers)) {
102
102
  AudioContentHelpers.addWarpMarkers(boxGraph, playMode, props.warpMarkers);
103
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AudioContentModifier.d.ts","sourceRoot":"","sources":["../../../src/project/audio/AudioContentModifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAgC,MAAM,kBAAkB,CAAA;AAS/E,OAAO,EAAC,sBAAsB,EAAwB,MAAM,0BAA0B,CAAA;AAItF,yBAAiB,oBAAoB,CAAC;IAC3B,MAAM,cAAc,GAAU,UAAU,aAAa,CAAC,sBAAsB,CAAC,KAAG,OAAO,CAAC,IAAI,CAOlG,CAAA;IAEM,MAAM,cAAc,GAAU,UAAU,aAAa,CAAC,sBAAsB,CAAC,KAAG,OAAO,CAAC,IAAI,CA2BlG,CAAA;IAEM,MAAM,aAAa,GAAU,UAAU,aAAa,CAAC,sBAAsB,CAAC,KAAG,OAAO,CAAC,IAAI,CA2CjG,CAAA;CA4BJ"}
1
+ {"version":3,"file":"AudioContentModifier.d.ts","sourceRoot":"","sources":["../../../src/project/audio/AudioContentModifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAgC,MAAM,kBAAkB,CAAA;AAS/E,OAAO,EAAC,sBAAsB,EAAwB,MAAM,0BAA0B,CAAA;AAItF,yBAAiB,oBAAoB,CAAC;IAC3B,MAAM,cAAc,GAAU,UAAU,aAAa,CAAC,sBAAsB,CAAC,KAAG,OAAO,CAAC,IAAI,CAOlG,CAAA;IAEM,MAAM,cAAc,GAAU,UAAU,aAAa,CAAC,sBAAsB,CAAC,KAAG,OAAO,CAAC,IAAI,CA2BlG,CAAA;IAEM,MAAM,aAAa,GAAU,UAAU,aAAa,CAAC,sBAAsB,CAAC,KAAG,OAAO,CAAC,IAAI,CA2CjG,CAAA;CA2BJ"}
@@ -105,7 +105,6 @@ export var AudioContentModifier;
105
105
  box.duration.setValue(file.endInSeconds);
106
106
  box.accept({
107
107
  visitAudioRegionBox: (box) => {
108
- console.debug("RESET");
109
108
  box.loopOffset.setValue(0);
110
109
  box.loopDuration.setValue(file.endInSeconds);
111
110
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AudioFileBoxFactory.d.ts","sourceRoot":"","sources":["../../../src/project/audio/AudioFileBoxFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAqB,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAS,QAAQ,EAAE,IAAI,EAAC,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAC,SAAS,EAAE,iBAAiB,EAAC,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAEzC,yBAAiB,mBAAmB,CAAC;IAO1B,MAAM,cAAc,GAAU,mBAAmB,iBAAiB,EACpC,UAAU,QAAQ,EAClB,WAAW,SAAS,EACpB,MAAM,IAAI,CAAC,KAAK,EAChB,MAAM,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAyBjF,CAAA;CACJ"}
1
+ {"version":3,"file":"AudioFileBoxFactory.d.ts","sourceRoot":"","sources":["../../../src/project/audio/AudioFileBoxFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAqB,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAS,QAAQ,EAAE,IAAI,EAAC,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAC,SAAS,EAAE,iBAAiB,EAAC,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAEzC,yBAAiB,mBAAmB,CAAC;IAO1B,MAAM,cAAc,GAAU,mBAAmB,iBAAiB,EACpC,UAAU,QAAQ,EAClB,WAAW,SAAS,EACpB,MAAM,IAAI,CAAC,KAAK,EAChB,MAAM,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CA8BjF,CAAA;CACJ"}
@@ -23,6 +23,11 @@ export var AudioFileBoxFactory;
23
23
  const transients = await transientProtocol.detect(audioData);
24
24
  const durationInSeconds = audioData.numberOfFrames / audioData.sampleRate;
25
25
  return () => {
26
+ // Re-check in case another drop created it between createModifier and now
27
+ const existingBox = boxGraph.findBox(uuid);
28
+ if (existingBox.nonEmpty()) {
29
+ return existingBox.unwrap();
30
+ }
26
31
  const audioFileBox = AudioFileBox.create(boxGraph, uuid, box => {
27
32
  box.fileName.setValue(name);
28
33
  box.startInSeconds.setValue(0);
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultSampleLoaderManager.d.ts","sourceRoot":"","sources":["../../src/samples/DefaultSampleLoaderManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAa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,OAAO,GAAG,OAAO,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAIzF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK;IACvB,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK;IAE3B,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAElC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,GAAG,YAAY;IAIrC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC;CAe3D"}
@@ -19,11 +19,14 @@ export class DefaultSampleLoaderManager {
19
19
  async getAudioData(uuid) {
20
20
  const { promise, resolve, reject } = Promise.withResolvers();
21
21
  const loader = this.getOrCreate(uuid);
22
- loader.subscribe(state => {
22
+ let subscription;
23
+ subscription = loader.subscribe(state => {
23
24
  if (state.type === "error") {
25
+ queueMicrotask(() => subscription.terminate());
24
26
  reject(state.reason);
25
27
  }
26
28
  else if (loader.data.nonEmpty()) {
29
+ queueMicrotask(() => subscription.terminate());
27
30
  resolve(loader.data.unwrap());
28
31
  }
29
32
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultSoundfontLoader.d.ts","sourceRoot":"","sources":["../../src/soundfont/DefaultSoundfontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAE,MAAM,EAAY,YAAY,EAAc,IAAI,EAAC,MAAM,kBAAkB,CAAA;AAErG,OAAO,EAAC,eAAe,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAA;AACjG,OAAO,EAAC,6BAA6B,EAAC,MAAM,iCAAiC,CAAA;AAE7E,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AAG1C,qBAAa,sBAAuB,YAAW,eAAe;;gBAY9C,OAAO,EAAE,6BAA6B,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK;IAQpE,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,YAAY;IAQjE,UAAU,IAAI,IAAI;IAOlB,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,CAAoB;IAC1C,IAAI,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC,CAAyB;IAC5D,IAAI,IAAI,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAoB;IACzD,IAAI,KAAK,IAAI,oBAAoB,CAAqB;IAEtD,QAAQ,IAAI,MAAM;CA+CrB"}
1
+ {"version":3,"file":"DefaultSoundfontLoader.d.ts","sourceRoot":"","sources":["../../src/soundfont/DefaultSoundfontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAE,MAAM,EAAY,YAAY,EAAc,IAAI,EAAC,MAAM,kBAAkB,CAAA;AAErG,OAAO,EAAC,eAAe,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAA;AACjG,OAAO,EAAC,6BAA6B,EAAC,MAAM,iCAAiC,CAAA;AAE7E,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AAG1C,qBAAa,sBAAuB,YAAW,eAAe;;gBAU9C,OAAO,EAAE,6BAA6B,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK;IAQpE,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,YAAY;IAQjE,UAAU,IAAI,IAAI;IAOlB,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,CAAoB;IAC1C,IAAI,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC,CAAyB;IAC5D,IAAI,IAAI,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAoB;IACzD,IAAI,KAAK,IAAI,oBAAoB,CAAqB;IAEtD,QAAQ,IAAI,MAAM;CA8CrB"}
@@ -6,7 +6,6 @@ export class DefaultSoundfontLoader {
6
6
  #manager;
7
7
  #uuid;
8
8
  #notifier;
9
- #soundFont2 = Promises.memoizeAsync(() => ExternalLib.SoundFont2());
10
9
  #meta = Option.None;
11
10
  #soundfont = Option.None;
12
11
  #state = { type: "progress", progress: 0.0 };
@@ -40,7 +39,10 @@ export class DefaultSoundfontLoader {
40
39
  }
41
40
  #get() {
42
41
  SoundfontStorage.get().load(this.#uuid).then(async ([file, meta]) => {
43
- this.#soundfont = Option.wrap(await this.#createSoundFont2(file));
42
+ const { status, value: SoundFont2, error } = await ExternalLib.SoundFont2();
43
+ if (status === "rejected")
44
+ return console.warn(error);
45
+ this.#soundfont = Option.wrap(new SoundFont2(new Uint8Array(file)));
44
46
  this.#meta = Option.wrap(meta);
45
47
  this.#setState({ type: "loaded" });
46
48
  }, (error) => {
@@ -64,7 +66,10 @@ export class DefaultSoundfontLoader {
64
66
  const [file, meta] = fetchResult.value;
65
67
  const storeResult = await Promises.tryCatch(SoundfontStorage.get().save({ uuid: this.#uuid, file, meta }));
66
68
  if (storeResult.status === "resolved") {
67
- this.#soundfont = Option.wrap(await this.#createSoundFont2(file));
69
+ const { status, value: SoundFont2, error } = await ExternalLib.SoundFont2();
70
+ if (status === "rejected")
71
+ return console.warn(error);
72
+ this.#soundfont = Option.wrap(new SoundFont2(new Uint8Array(file)));
68
73
  this.#meta = Option.wrap(meta);
69
74
  this.#setState({ type: "loaded" });
70
75
  }
@@ -73,8 +78,4 @@ export class DefaultSoundfontLoader {
73
78
  this.#setState({ type: "error", reason: "N/A" });
74
79
  }
75
80
  }
76
- async #createSoundFont2(buffer) {
77
- const SoundFont2 = await this.#soundFont2();
78
- return new SoundFont2(new Uint8Array(buffer));
79
- }
80
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SoundfontService.d.ts","sourceRoot":"","sources":["../../src/soundfont/SoundfontService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,EAAE,MAAM,EAAS,SAAS,EAAwB,MAAM,kBAAkB,CAAA;AAC/F,OAAO,EAAC,GAAG,EAAC,MAAM,kBAAkB,CAAA;AAGpC,OAAO,EAAC,SAAS,EAAoB,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SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAmB;IACzD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAuC;gBAKlF,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC;IAY1C,IAAI,KAAK,IAAI,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAqB;IAClE,IAAI,MAAM,IAAI,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAsB;IAE9D,UAAU,CAAC,EAAC,IAAI,EAAE,WAAW,EAAC,EAAE,YAAY,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;cA4ClE,eAAe,IAAI,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;CAKvE"}
@@ -1,5 +1,5 @@
1
1
  import { Arrays, Option, panic, RuntimeNotifier, UUID } from "@opendaw/lib-std";
2
- import { Promises, Wait } from "@opendaw/lib-runtime";
2
+ import { Wait } from "@opendaw/lib-runtime";
3
3
  import { SoundfontFileBox } from "@opendaw/studio-boxes";
4
4
  import { SoundfontStorage } from "./SoundfontStorage";
5
5
  import { FilePickerAcceptTypes } from "../FilePickerAcceptTypes";
@@ -44,12 +44,13 @@ export class SoundfontService extends AssetService {
44
44
  uuid ??= await UUID.sha256(arrayBuffer);
45
45
  console.timeEnd("UUID.sha256");
46
46
  console.time("SoundFont2");
47
- const { status, value: soundFont2, error } = await Promises.tryCatch(this.#createSoundFont2(arrayBuffer));
47
+ const { status, value: SoundFont2, error } = await ExternalLib.SoundFont2();
48
48
  console.timeEnd("SoundFont2");
49
49
  if (status === "rejected") {
50
50
  updater.terminate();
51
51
  return panic(error);
52
52
  }
53
+ const soundFont2 = new SoundFont2(new Uint8Array(arrayBuffer));
53
54
  const meta = {
54
55
  name: soundFont2.metaData.name,
55
56
  size: arrayBuffer.byteLength,
@@ -72,8 +73,4 @@ export class SoundfontService extends AssetService {
72
73
  const local = await SoundfontStorage.get().list();
73
74
  return Arrays.merge(stock, local, (a, b) => a.uuid === b.uuid);
74
75
  }
75
- async #createSoundFont2(buffer) {
76
- const SoundFont2 = await ExternalLib.SoundFont2();
77
- return new SoundFont2(new Uint8Array(buffer));
78
- }
79
76
  }
@@ -1,2 +1,2 @@
1
- var y=o=>o!=null,ut=o=>o===null;var mt=o=>o!==void 0;var x=(o,t="asDefined failed")=>o??p(R(t));var R=o=>o instanceof Function?o():o;var dt=(o,...t)=>o?.apply(null,t);var V=o=>{throw new Error(`Unhandled ${o}`)},p=o=>{throw typeof o=="string"?new Error(o):o},M=(o,t)=>o?void 0:p(R(t));var v=o=>new Proxy({},{get(){return p(o)}});var nt=class{value;status="success";constructor(t){this.value=t}error=v("Cannot access error when succeeded")},rt=class{error;status="failure";constructor(t){this.error=t}value=v("Cannot access value when failed")},pt=o=>{try{return new nt(o())}catch(t){return new rt(t)}};var H=()=>{};var it;(function(o){o[o.Ascending=1]="Ascending",o[o.Descending=-1]="Descending"})(it||(it={}));var b=class{static#t=Object.freeze(new Array(0));static empty=()=>this.#t;static clear=t=>{t.length=0};static replace=(t,e)=>{t.length=0,t.push(...e)};static consume=(t,e)=>{for(let s=0;s<t.length;)e(t[s])?t.splice(s,1):s++};static peekFirst=t=>t.at(0)??null;static peekLast=t=>t.at(-1)??null;static getFirst=(t,e)=>x(t.at(0),e);static getLast=(t,e)=>x(t.at(-1),e);static getPrev=(t,e)=>{let s=t.indexOf(e);return s===-1?p(`${e} not found in ${t}`):x(t.at((s-1)%t.length),"Internal Error")};static getNext=(t,e)=>{let s=t.indexOf(e);return s===-1?p(`${e} not found in ${t}`):x(t.at((s+1)%t.length),"Internal Error")};static removeLast=(t,e)=>x(t.pop(),e);static create=(t,e)=>{let s=new Array(e);for(let n=0;n<e;n++)s[n]=t(n);return s};static equals=(t,e)=>{if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0};static satisfy=(t,e)=>{if(t.length<2)return!0;let s=t[0];for(let n=1;n<t.length;n++)if(!e(s,t[n]))return!1;return!0};static remove=(t,e)=>{let s=t.indexOf(e);if(s===-1)return p(`${e} not found in ${t}`);t.splice(s,1)};static removeIf=(t,e)=>{for(let s=t.length-1;s>=0;s--)e(t[s])&&t.splice(s,1)};static removeOpt=(t,e)=>{let s=t.indexOf(e);return s===-1?!1:(t.splice(s,1),!0)};static hasDuplicates=t=>new Set(t).size<t.length;static removeDuplicates=t=>{let e=0,s=new Set;for(let n of t)s.has(n)||(s.add(n),t[e++]=n);return t.length=e,t};static removeDuplicateKeys=(t,e)=>{let s=0,n=new Set;for(let r of t){let i=r[e];n.has(i)||(n.add(i),t[s++]=r)}return t.length=s,t};static subtract(t,e,s){return t.filter(n=>!e.some(r=>s(n,r)))}static intersect(t,e,s){return t.filter(n=>e.some(r=>s(n,r)))}static merge(t,e,s){return[...t.filter(n=>!e.some(r=>s(n,r))),...e]}static*iterate(t){for(let e=0;e<t.length;e++)yield t[e]}static*iterateReverse(t){for(let e=t.length-1;e>=0;e--)yield t[e]}static*iterateStateFull(t){let e=t.length-1;for(let s=0;s<=e;s++)yield{value:t[s],isFirst:s===0,isLast:s===e}}static*iterateAdjacent(t){if(!(t.length<=1))for(let e=1,s=t[0];e<t.length;e++){let n=t[e];yield[s,n],s=n}}static isSorted(t,e=it.Ascending){if(t.length<2)return!0;let s=t[0];for(let n=1;n<t.length;n++){let r=t[n];if(Math.sign(s-r)===e)return!1;s=r}return!0}static toRecord(t,e){return t.reduce((s,n)=>(s[e(n)]=n,s),{})}static concatArrayBuffers(t,e){let s=new ArrayBuffer(t.byteLength+e.byteLength),n=new Uint8Array(s);return n.set(new Uint8Array(t),0),n.set(new Uint8Array(e),t.byteLength),s}};var T;(function(o){o.wrap=e=>y(e)?new t(e):o.None,o.from=e=>o.wrap(e()),o.tryFrom=e=>{try{return o.wrap(e())}catch{return o.None}},o.execute=(e,...s)=>o.wrap(e?.apply(null,s)),o.async=e=>e.then(s=>o.wrap(s),()=>o.None);class t{#t;constructor(s){this.#t=x(s)}unwrap(){return this.#t}unwrapOrElse(s){return this.#t}unwrapOrNull(){return this.#t}unwrapOrUndefined(){return this.#t}contains(s){return s===this.#t}match(s){return s.some(this.#t)}ifSome(s){return s(this.#t)}ifAbsent(s){}isEmpty(){return!1}nonEmpty(){return!0}map(s){return o.wrap(s(this.#t))}mapOr(s,n){return s(this.#t)}flatMap(s){return s(this.#t)}equals(s){return this.unwrapOrNull()===s.unwrapOrNull()}assert(s){return this}toString(){return`{Option.Some(${this.#t})}`}get[Symbol.toStringTag](){return this.toString()}}o.Some=t,o.None=new class{unwrap=e=>p(y(e)?R(e):"unwrap failed");unwrapOrElse=e=>R(e);unwrapOrNull=()=>null;unwrapOrUndefined=()=>{};contains=e=>!1;match=e=>e.none();ifSome=e=>{};ifAbsent=e=>e(void 0);isEmpty=()=>!0;nonEmpty=()=>!1;map=e=>o.None;mapOr=(e,s)=>R(s);flatMap=e=>o.None;equals=e=>e.isEmpty();assert=e=>p(R(e)??"assert failed");toString=()=>"{Option.None}";get[Symbol.toStringTag](){return this.toString()}}})(T||(T={}));var A=Math.PI*2,Ut=Math.PI/2,Vt=Math.PI/4,Ht=1/Math.sqrt(2),_=(o,t,e)=>Math.max(t,Math.min(o,e));var wt=o=>Math.pow(2,Math.ceil(Math.log(o)/Math.log(2)));var S=new DataView(new ArrayBuffer(8)),gt;(function(o){o.MIN_VALUE=-2147483648,o.MAX_VALUE=2147483647,o.toByte=t=>(S.setInt8(0,t),S.getInt8(0)),o.toShort=t=>(S.setInt16(0,t),S.getInt16(0)),o.toInt=t=>(S.setInt32(0,t),S.getInt32(0))})(gt||(gt={}));var O;(function(o){let s=new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT),n=new Float32Array(s),r=new Int32Array(s);o.floatToIntBits=i=>{let a=o.floatToRawIntBits(i);return(a&2139095040)===2139095040&&(a&8388607)!==0?2143289344:a},o.intBitsToFloat=i=>(r[0]=i,n[0]),o.floatToRawIntBits=i=>(n[0]=i,r[0]),o.toFloat32=i=>(S.setFloat32(0,i),S.getFloat32(0))})(O||(O={}));var B;(function(o){o.floatToIntBits=t=>{let e=O.floatToIntBits(t),s=e>>>16&32768,n=(e&2147483647)+4096;return n>=1199570944?(e&2147483647)>=1199570944?n<2139095040?s|31744:s|31744|(e&8388607)>>>13:s|31743:n>=947912704?s|n-939524096>>>13:n<855638016?s:(n=(e&2147483647)>>>23,s|(e&8388607|8388608)+(8388608>>>n-102)>>>126-n)},o.intBitsToFloat=t=>{let e=t&1023,s=t&31744;if(s===31744)s=261120;else if(s!==0){if(s+=114688,e===0&&s>115712)return O.intBitsToFloat((t&32768)<<16|s<<13|1023)}else if(e!==0){s=115712;do e<<=1,s-=1024;while((e&1024)===0);e&=1023}return O.intBitsToFloat((t&32768)<<16|(s|e)<<13)}})(B||(B={}));var xt;(function(o){let t=9218868437227405312n,e=4503599627370495n,s=new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT),n=new Float64Array(s),r=new BigInt64Array(s);o.float64ToLongBits=i=>{let a=o.float64ToRawLongBits(i);return(a&t)===t&&(a&e)!==0n?0x7ff8000000000000n:a},o.longBitsToFloat64=i=>(r[0]=i,n[0]),o.float64ToRawLongBits=i=>(n[0]=i,r[0]),o.clamp=i=>(S.setFloat64(0,i),S.getFloat64(0))})(xt||(xt={}));var F=class{static*empty(){}static one(t){return[t]}static count(t){let e=0;for(let s of t)e++;return e}static some(t,e){for(let s of t)if(e(s))return!0;return!1}static every(t,e){for(let s of t)if(!e(s))return!1;return!0}static reduce(t,e,s){let n=s,r=0;for(let i of t)n=e(n,i,r++);return n}static includes(t,e){for(let s of t)if(s===e)return!0;return!1}static forEach(t,e){for(let s of t)e(s)}static*map(t,e){let s=0;for(let n of t)yield e(n,s++)}static*take(t,e){let s=0;for(let n of t){if(s++>=e)return;yield n}}static filter(t,e){let s=[];for(let n of t)e(n)&&s.push(n);return s}static filterMap(t,e){let s=[];for(let n of t){let r=e(n);y(r)&&s.push(r)}return s}static reverse(t){let e=[];for(let s of t)e.push(s);return e.reverse()}static*pairWise(t){let e=t[Symbol.iterator](),{done:s,value:n}=e.next(),r=n;if(s!==!0)for(;;){let{done:i,value:a}=e.next();if(i===!0){yield[r,null];return}yield[r,a],r=a}}};var j=class o{static create(t=1024){return this.use(new ArrayBuffer(t))}static use(t,e=0){return new o(new DataView(t,e))}littleEndian=!1;#t;#e=0;constructor(t){this.#t=t}get remaining(){return this.#t.byteLength-this.#e}get position(){return this.#e}set position(t){t<0?p(`position(${t}) cannot be negative.`):t>this.#t.byteLength?p(`position(${t}) is outside range (${this.#t.byteLength}).`):this.#e=t}writeBoolean(t){this.writeByte(t?1:0)}writeByte(t){this.#s(1),this.#t.setInt8(this.#e++,t)}writeShort(t){this.#s(Int16Array.BYTES_PER_ELEMENT),this.#t.setInt16(this.#e,t,this.littleEndian),this.#e+=Int16Array.BYTES_PER_ELEMENT}writeInt(t){this.#s(Int32Array.BYTES_PER_ELEMENT),this.#t.setInt32(this.#e,t,this.littleEndian),this.#e+=Int32Array.BYTES_PER_ELEMENT}writeLong(t){this.#s(BigInt64Array.BYTES_PER_ELEMENT),this.#t.setBigInt64(this.#e,t,this.littleEndian),this.#e+=BigInt64Array.BYTES_PER_ELEMENT}writeFloat(t){this.#s(Float32Array.BYTES_PER_ELEMENT),this.#t.setFloat32(this.#e,t,this.littleEndian),this.#e+=Float32Array.BYTES_PER_ELEMENT}writeDouble(t){this.#s(Float64Array.BYTES_PER_ELEMENT),this.#t.setFloat64(this.#e,t,this.littleEndian),this.#e+=Float64Array.BYTES_PER_ELEMENT}writeBytes(t){this.#s(t.length);for(let e=0;e<t.length;++e)this.#t.setInt8(this.#e++,t[e])}writeString(t){let e=t.length;this.#s(Int32Array.BYTES_PER_ELEMENT+e*Int16Array.BYTES_PER_ELEMENT),this.writeInt(e);for(let s=0;s<e;s++)this.writeShort(t.charCodeAt(s))}toArrayBuffer(){return this.#t.buffer.slice(0,this.#e)}#s(t){let e=this.#t.byteLength;if(this.#e+t>e){let s=this.#t;this.#t=new DataView(new ArrayBuffer(wt(e+t)));for(let n=0;n<this.#e;n++)this.#t.setInt8(n,s.getInt8(n))}}};var G=Object.freeze({Empty:{terminate:H},create:o=>({terminate:o}),many:(...o)=>({terminate:()=>{for(;o.length>0;)o.pop().terminate()}})});var C=class{static subscribeMany(t,...e){return G.many(...e.map(s=>s.subscribe(()=>t(s))))}#t=new Set;subscribe(t){return this.#t.add(t),{terminate:()=>this.#t.delete(t)}}isEmpty(){return this.#t.size===0}notify(t){this.#t.forEach(e=>e(t))}observers(){return this.#t}terminate(){this.#t.clear()}};var Et=(()=>{let o=T.None;return{info:t=>o.match({none:()=>Promise.resolve(),some:e=>e.info(t)}),approve:t=>o.match({none:()=>Promise.resolve(!0),some:e=>e.approve(t)}),progress:t=>o.match({none:()=>({message:"",terminate:H}),some:e=>e.progress(t)}),install:t=>{M(o.isEmpty(),"RuntimeNotification already installed"),o=T.wrap(t)}}})();var D=class o{static POSITIVE_INFINITY=new o(Number.POSITIVE_INFINITY);static millis=t=>new o(t);static seconds=t=>new o(t*o.#t);static minutes=t=>new o(t*o.#e);static hours=t=>new o(t*o.#s);static days=t=>new o(t*o.#n);static#t=1e3;static#e=6e4;static#s=36e5;static#n=864e5;#r;constructor(t){this.#r=t}millis(){return this.#r}absSeconds(){return Math.abs(this.#r)/o.#t}absMinutes(){return Math.abs(this.#r)/o.#e}absHours(){return Math.abs(this.#r)/o.#s}absDays(){return Math.abs(this.#r)/o.#n}split(){return{d:Math.floor(this.absDays()),h:Math.floor(this.absHours())%24,m:Math.floor(this.absMinutes())%60,s:Math.floor(this.absSeconds())%60}}isNow(){return this.#r===0}isPast(){return this.#r<0}isFuture(){return this.#r>0}toUnitString(){let t,e,s=Math.floor(Math.abs(this.#r)/1e3),n=Math.floor(s/60),r=Math.floor(n/60),i=Math.floor(r/24);return s<60?(t=s,e="second"):n<60?(t=n,e="minute"):r<24?(t=r,e="hour"):(t=i,e="day"),new Intl.RelativeTimeFormat("en",{numeric:"auto",style:"long"}).format(t*Math.sign(this.#r),e)}toString(){if(isNaN(this.#r))return"NaN";if(!isFinite(this.#r))return"\u221E";let{d:t,h:e,m:s,s:n}=this.split();return t>0?[o.#i("d",t),o.#i("h",e),o.#i("m",s),o.#i("s",n)].join(", "):e>0?[o.#i("h",e),o.#i("m",s),o.#i("s",n)].join(", "):s>0?[o.#i("m",s),o.#i("s",n)].join(", "):n>0?o.#i("s",n):"now"}static#i=(t,e)=>{switch(t){case"d":return`${e} ${e<2?"day":"days"}`;case"h":return`${e} ${e<2?"hour":"hours"}`;case"m":return`${e} ${e<2?"minute":"minutes"}`;case"s":return`${e} ${e<2?"second":"seconds"}`;default:return V(t)}}};var P;(function(o){o.sender=(n,r)=>r(new e(n)),o.executor=(n,r)=>new s(n,r);let t=n=>{let r=[];for(let i of n)i instanceof MessagePort&&r.push(i),typeof ImageBitmap<"u"&&i instanceof ImageBitmap&&r.push(i),typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas&&r.push(i);return r};class e{#t;#e=new Map;#s;#n=0;constructor(r){this.#t=r,this.#s=r.subscribe(this.#r)}terminate(){this.#s.terminate()}dispatchAndForget=(r,...i)=>{let a=t(i);this.#t.send({type:"send",returnId:!1,func:r.name,args:Array.from(F.map(i,c=>({value:c})))},a)};dispatchAndReturn=(r,...i)=>new Promise((a,c)=>{let l=F.reduce(i,(f,u,m)=>(typeof u=="function"&&f.push([m,u]),f),[]);this.#e.set(this.#n,{executorTuple:{resolve:a,reject:c},callbacks:new Map(l)});let h=t(i);this.#t.send({type:"send",returnId:this.#n,func:r.name,args:Array.from(F.map(i,(f,u)=>typeof f=="function"?{callback:u}:{value:f}))},h),this.#n++});#r=r=>{let i=this.#e.get(r.returnId);y(i)?r.type==="resolve"?(i.executorTuple.resolve(r.resolve),this.#e.delete(r.returnId)):r.type==="reject"?(i.executorTuple.reject(r.reject),this.#e.delete(r.returnId)):r.type==="callback"&&i.callbacks?.get(r.funcAt).apply(this,r.args):p(`Promise has already been resolved. ${JSON.stringify(r)}`)}}class s{#t;#e;#s;constructor(r,i){this.#t=r,this.#e=i,this.#s=r.subscribe(this.#n)}terminate(){this.#s.terminate()}#n=r=>{M(r.type==="send",()=>"Message type must be 'send'");let i=Object.getPrototypeOf(this.#e)===Object.getPrototypeOf({})?this.#e:Object.getPrototypeOf(this.#e),a=x(i[r.func],`${r.func.toString()} does not exists on ${this.#e}`),c=r.returnId;if(c===!1)a.apply(this.#e,r.args.map(l=>"value"in l?l.value:p(`${r.func.toString()} has no promise.`)));else try{a.apply(this.#e,r.args.map(h=>"callback"in h?(...f)=>this.#a(c,h.callback,f):h.value)).then(h=>{try{this.#r(c,h)}catch(f){this.#i(c,f)}},h=>this.#i(c,h))}catch(l){this.#i(c,l)}};#r=(r,i)=>this.#t.send({type:"resolve",returnId:r,resolve:i});#i=(r,i)=>this.#t.send({type:"reject",returnId:r,reject:i});#a=(r,i,a)=>this.#t.send({type:"callback",returnId:r,funcAt:i,args:a})}o.Executor=s})(P||(P={}));var yt={for:o=>new ot(o)},Nt=[],ot=class{#t;#e=new C;constructor(t){if(this.#t=t,y(t.onmessage)||y(t.onmessageerror))throw console.error(t),new Error(`${t} is already wrapped.`);t.onmessage=e=>this.#e.notify(e.data),t.onmessageerror=e=>{throw new Error(e.type)}}send(t,e){this.#t.postMessage(t,e??Nt)}channel(t){return new at(this,t)}subscribe(t){return this.#e.subscribe(t)}terminate(){this.#e.terminate(),this.#t.onmessage=null,this.#t.onmessageerror=null}},at=class o{#t;#e;#s=new C;#n;constructor(t,e){this.#t=t,this.#e=e,this.#n=t.subscribe(s=>{"__id__"in s&&s.__id__==="42"&&"message"in s&&"channel"in s&&s.channel===e&&this.#s.notify(s.message)})}send(t,e){this.#t.send({__id__:"42",channel:this.#e,message:t},e)}channel(t){return new o(this,t)}subscribe(t){return this.#s.subscribe(t)}terminate(){this.#n.terminate(),this.#s.terminate()}};var W;(function(o){o.frame=()=>new Promise(t=>requestAnimationFrame(()=>t())),o.frames=t=>new Promise(e=>{let s=t,n=()=>{--s<=0?e():requestAnimationFrame(n)};requestAnimationFrame(n)}),o.timeSpan=(t,...e)=>new Promise(s=>setTimeout(s,t.millis(),...e)),o.event=(t,e)=>new Promise(s=>t.addEventListener(e,s,{once:!0})),o.observable=t=>new Promise(e=>{let s=t.subscribe(()=>{s.terminate(),e()})}),o.complete=t=>new Promise((e,s)=>{let n=setInterval(()=>{let{status:r,value:i,error:a}=pt(()=>t.next());if(r==="success"){let{done:c,value:l}=i;c&&(clearInterval(n),e(l))}else clearInterval(n),s(a)},0)})})(W||(W={}));var ct=class{maxRetry;timeSpan;#t=0;constructor(t,e){this.maxRetry=t,this.timeSpan=e}retry(t,e){return++this.#t===this.maxRetry?!1:(console.debug(`${t} > will retry in ${this.timeSpan.toString()}`),setTimeout(e,this.timeSpan.millis()),!0)}},K;(function(o){class t{value;status="resolved";constructor(a){this.value=a}error=v("Cannot access error when promise is resolved")}o.ResolveResult=t;class e{error;status="rejected";constructor(a){this.error=a}value=v("Cannot access value when promise is rejected")}o.RejectedResult=e,o.makeAbortable=async(i,a)=>{let c=!0;return i.own(G.create(()=>c=!1)),new Promise((l,h)=>a.then(f=>{c&&l(f)},f=>{c&&h(f)}))},o.tryCatch=i=>i.then(a=>new t(a),a=>new e(a));let s=new ct(3,D.seconds(3));o.retry=(i,a=s)=>i().catch(c=>new Promise((l,h)=>{let f=u=>{a.retry(u,()=>i().then(m=>l(m),f))||h(u)};f(c)})),o.guardedRetry=(i,a)=>{let c=async(l=0)=>{try{return await i()}catch(h){if(a(h,++l))return console.debug("retrying after failure:",h),await W.timeSpan(D.seconds(1)),c(l);throw new Error(`Failed after ${l} retries: ${h}`)}};return c()},o.approvedRetry=(i,a)=>{let c=async()=>{try{return await i()}catch(l){if(await Et.approve(a(l)))return c();throw l}};return c()},o.fail=(i,a)=>{let c=()=>new Promise((l,h)=>setTimeout(()=>h("fails first"),i.millis()));return()=>{let l=c();return c=a,l}},o.timeout=(i,a,c)=>new Promise((l,h)=>{let f=!0,u=setTimeout(()=>{f=!1,h(new Error(c??"timeout"))},a.millis());i.then(m=>{f&&l(m)},m=>{f&&h(m)}).finally(()=>clearTimeout(u))}),o.sequentialAll=i=>i.reduce((a,c)=>a.then(async l=>[...l,await c()]),Promise.resolve([])),o.sequentialize=i=>{let a=Promise.resolve();return c=>{let l=()=>i(c),h=a.then(l,l);return a=h.catch(()=>{}),h}},o.memoizeAsync=(i,a)=>{let c=null,l=Date.now();return()=>{let h=Date.now();return(ut(c)||y(a)&&h-l>a.millis())&&(l=h,c=i(),c.catch(f=>(c=null,f))),c}},o.allWithLimit=async(i,a=1)=>{let c=new Array(i.length),l=0,h=!1,f=async()=>{for(;l<i.length&&!h;){let u=l++;try{let m=await i[u]();h||(c[u]=m)}catch(m){throw h=!0,m}}};return await Promise.all(Array.from({length:Math.min(a,i.length)},f)),c},o.allSettledWithLimit=async(i,a=1)=>{let c=new Array(i.length),l=0,h=async()=>{for(;l<i.length;){let f=l++;try{let u=await i[f]();c[f]={status:"fulfilled",value:u}}catch(u){c[f]={status:"rejected",reason:u}}}};return await Promise.all(Array.from({length:Math.min(a,i.length)},h)),c};class n{max;#t;#e=0;constructor(a=1){this.max=a,this.#t=[]}async add(a){if(this.#e<this.max)return this.#e++,a().finally(()=>this.#s());{let c=Promise.withResolvers();return this.#t.push([a,c]),c.promise.finally(()=>this.#s())}}#s(){if(M(this.#e>0,"Internal Error in Promises.Limit"),--this.#e<this.max&&this.#t.length>0){let[a,{resolve:c,reject:l}]=this.#t.shift();this.#e++,a().then(c,l)}}}o.Limit=n;class r{#t;#e;#s;#n=T.None;constructor(a,c,l){this.#t=a,this.#e=c,this.#s=l}update(a){this.#n=T.wrap(a),a.then(c=>{this.#n.contains(a)&&this.#t(c)}).catch(c=>{this.#n.contains(a)&&this.#e(c)}).finally(()=>{this.#n.contains(a)&&(this.terminate(),dt(this.#s))})}terminate(){this.#n=T.None}}o.Latest=r})(K||(K={}));var It=(o="debug")=>{let t=performance.now();return{lab:e=>console[o].call(console,`${e} in ${(performance.now()-t).toFixed(1)}ms`)}};var $;(function(o){class t{shift;numPeaks;dataOffset;constructor(s,n,r){this.shift=s,this.numPeaks=n,this.dataOffset=r}unitsEachPeak(){return 1<<this.shift}}o.Stage=t,o.unpack=(e,s)=>{switch(s){case 0:return B.intBitsToFloat(e);case 1:return B.intBitsToFloat(e>>16);default:return V(s)}}})($||($={}));var X=class o{stages;data;numFrames;numChannels;static from(t){M(t.readString()==="PEAKS","Wrong header");let e=t.readInt(),s=[];for(let c=0;c<e;c++){let l=t.readInt(),h=t.readInt(),f=t.readInt();t.readInt(),s[c]=new $.Stage(f,h,l)}let n=t.readInt(),r=[];for(let c=0;c<n;c++){let l=new Int8Array(t.readInt());t.readBytes(l),r[c]=new Int32Array(l.buffer)}let i=t.readInt(),a=t.readInt();return new o(s,r,i,a)}static None=new o([],[],0,0);static findBestFit=(t,e=1200)=>{let s=t/e;if(s<=1)return new Uint8Array(0);let n=3,r=Math.floor(Math.log(s)/Math.LN2),i=Math.max(1,Math.floor(r/n));return new Uint8Array(b.create(a=>n*(a+1),i))};constructor(t,e,s,n){this.stages=t,this.data=e,this.numFrames=s,this.numChannels=n}nearest(t){if(this.stages.length===0)return null;let e=Math.floor(Math.log(Math.abs(t))/Math.LN2),s=this.stages.length;for(;--s>-1;)if(e>=this.stages[s].shift)return this.stages[s];return this.stages[0]}toArrayBuffer(){let t=j.create();t.writeString("PEAKS"),t.writeInt(this.stages.length);for(let e=0;e<this.stages.length;e++){let{dataOffset:s,numPeaks:n,shift:r}=this.stages[e];t.writeInt(s),t.writeInt(n),t.writeInt(r),t.writeInt((1<<r)-1)}t.writeInt(this.data.length);for(let e=0;e<this.data.length;e++){let s=new Int8Array(this.data[e].buffer);t.writeInt(s.length),t.writeBytes(s)}return t.writeInt(this.numFrames),t.writeInt(this.numChannels),t.toArrayBuffer()}toString(){return`{SamplePeaks num-stages: ${this.stages.length}}`}};var Q;(function(o){o.install=s=>P.executor(s.channel("peaks"),new class{async generateAsync(n,r,i,a,c){return t(n,r,i,a,c).toArrayBuffer()}});let t=(s,n,r,i,a)=>{if(r.length!==a)return p(`Invalid numberOfChannels. Expected: ${a}. Got ${r.length}`);class c{min=Number.POSITIVE_INFINITY;max=Number.NEGATIVE_INFINITY;index=0}let l=It(),h=n.length,[f,u]=e(n,i),m=b.create(()=>new Int32Array(u),a),w=(1<<f[0].shift)-1,d=a*i,g=0;for(let E=0;E<a;++E){let I=m[E],L=r[E],St=b.create(()=>new c,h),z=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY,lt=0;for(let st=0;st<i;++st){let ht=L[st];if(z=Math.min(ht,z),Y=Math.max(ht,Y),(++lt&w)===0){for(let U=0;U<h;++U){let ft=f[U],N=St[U];N.min=Math.min(N.min,z),N.max=Math.max(N.max,Y),((1<<ft.shift)-1&lt)===0&&(I[ft.dataOffset+N.index++]=o.pack(N.min,N.max),N.min=Number.POSITIVE_INFINITY,N.max=Number.NEGATIVE_INFINITY)}z=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY}(++g&65535)===0&&s(g/d)}}return s(1),l.lab(`SamplePeaks '${self.constructor.name}'`),new X(f,m,i,a)},e=(s,n)=>{let r=0;return[b.create(a=>{let c=s[a],l=Math.ceil(n/(1<<c)),h=new $.Stage(c,l,r);return r+=l,h},s.length),r]};o.pack=(s,n)=>{let r=B.floatToIntBits(s),i=B.floatToIntBits(n);return r|i<<16}})(Q||(Q={}));var Z;(function(o){o.init=s=>P.executor(s.channel("opfs"),new class{#t=new Map;async write(n,r){await this.#e(n,async()=>{let i=await this.#s(n,{create:!0});try{i.truncate(r.length),i.write(r.buffer,{at:0}),i.flush()}finally{i.close()}})}async read(n){return await this.#e(n,async()=>{let r=await this.#s(n);try{let i=r.getSize(),a=new Uint8Array(i);return r.read(a),a}finally{r.close()}})}async delete(n){await this.#e(n,async()=>{let r=e(n);return r.length===0?this.clear():this.#n(r.slice(0,-1)).then(i=>i.removeEntry(x(r.at(-1)),{recursive:!0}))})}async list(n){let r=e(n),{status:i,value:a}=await K.tryCatch(this.#n(r));if(i==="rejected")return b.empty();let c=[];for await(let{name:l,kind:h}of a.values())c.push({name:l,kind:h});return c}async clear(){let n=await navigator.storage.getDirectory();for await(let[r,i]of n.entries())i.kind==="file"?await n.removeEntry(r):i.kind==="directory"&&await n.removeEntry(r,{recursive:!0})}async#e(n,r){for(;;){let i=this.#t.get(n);if(mt(i)){await i;continue}let a=()=>p("Lock not acquired"),c=new Promise(l=>a=l);this.#t.set(n,c);try{return await r()}finally{this.#t.get(n)===c&&this.#t.delete(n),a()}}}async#s(n,r){let i=e(n);return await(await(await this.#n(i.slice(0,-1),r)).getFileHandle(x(i.at(-1)),r)).createSyncAccessHandle()}async#n(n,r){let i=await navigator.storage.getDirectory();for(let a of n)i=await i.getDirectoryHandle(a,r);return i}});let e=s=>{let n=s.replace(/^\/+|\/+$/g,"");return n===""?[]:n.split("/")}})(Z||(Z={}));var J=class{a1=0;a2=0;b0=0;b1=0;b2=0;constructor(){this.identity()}identity(){this.setNormalizedCoefficients(1,0,0,1,0,0)}setLowpassParams(t,e=Math.SQRT1_2){if(t=_(t,0,1),t>=.5)this.setNormalizedCoefficients(1,0,0,1,0,0);else if(t>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=(1-r)/2,a=i,c=2*i,l=i,h=1+n,f=-2*r,u=1-n;this.setNormalizedCoefficients(a,c,l,h,f,u)}else this.setNormalizedCoefficients(0,0,0,1,0,0);return this}setHighpassParams(t,e=Math.SQRT1_2){if(t=_(t,0,1),t===1)this.setNormalizedCoefficients(0,0,0,1,0,0);else if(t>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=(1+r)/2,a=i,c=-2*i,l=i,h=1+n,f=-2*r,u=1-n;this.setNormalizedCoefficients(a,c,l,h,f,u)}else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setNormalizedCoefficients(t,e,s,n,r,i){let a=1/n;return this.b0=t*a,this.b1=e*a,this.b2=s*a,this.a1=r*a,this.a2=i*a,this}setLowShelfParams(t,e){t=_(t,0,1);let s=Math.pow(10,e/40);if(t===1)this.setNormalizedCoefficients(s*s,0,0,1,0,0);else if(t>0){let n=A*t,i=.5*Math.sin(n)*Math.sqrt((s+1/s)*(1/1-1)+2),a=Math.cos(n),c=2*Math.sqrt(s)*i,l=s+1,h=s-1,f=s*(l-h*a+c),u=2*s*(h-l*a),m=s*(l-h*a-c),w=l+h*a+c,d=-2*(h+l*a),g=l+h*a-c;this.setNormalizedCoefficients(f,u,m,w,d,g)}else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setHighShelfParams(t,e){t=_(t,0,1);let s=Math.pow(10,e/40);if(t===1)this.setNormalizedCoefficients(1,0,0,1,0,0);else if(t>0){let n=A*t,i=.5*Math.sin(n)*Math.sqrt((s+1/s)*(1/1-1)+2),a=Math.cos(n),c=2*Math.sqrt(s)*i,l=s+1,h=s-1,f=s*(l+h*a+c),u=-2*s*(h+l*a),m=s*(l+h*a-c),w=l-h*a+c,d=2*(h-l*a),g=l-h*a-c;this.setNormalizedCoefficients(f,u,m,w,d,g)}else this.setNormalizedCoefficients(s*s,0,0,1,0,0);return this}setPeakingParams(t,e,s){t=_(t,0,1),e=Math.max(0,e);let n=Math.pow(10,s/40);if(t>0&&t<1)if(e>0){let r=A*t,i=Math.sin(r)/(2*e),a=Math.cos(r),c=1+i*n,l=-2*a,h=1-i*n,f=1+i/n,u=-2*a,m=1-i/n;this.setNormalizedCoefficients(c,l,h,f,u,m)}else this.setNormalizedCoefficients(n*n,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setAllpassParams(t,e){if(t=_(t,0,1),e=Math.max(0,e),t>0&&t<1)if(e>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=1-n,a=-2*r,c=1+n,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(-1,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setNotchParams(t,e){if(t=_(t,0,1),e=Math.max(0,e),t>0&&t<1)if(e>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=1,a=-2*r,c=1,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(0,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setBandpassParams(t,e){if(t=Math.max(0,t),e=Math.max(0,e),t>0&&t<1){let s=A*t;if(e>0){let n=Math.sin(s)/(2*e),r=Math.cos(s),i=n,a=0,c=-n,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(1,0,0,1,0,0)}else this.setNormalizedCoefficients(0,0,0,1,0,0);return this}getFrequencyResponse(t,e,s){M(t.length===e.length&&t.length===s.length,"Array lengths do not match");let n=this.b0,r=this.b1,i=this.b2,a=this.a1,c=this.a2;for(let l=0;l<t.length;++l){let h=-Math.PI*2*t[l],f=Math.cos(h),u=Math.sin(h),m=n+((r+i*f)*f-i*u*u),w=(r+i*f)*u+i*u*f,d=1+((a+c*f)*f-c*u*u),g=(a+c*f)*u+c*u*f,E=d*d+g*g,I=(m*d+w*g)/E,L=(w*d-m*g)/E;e[l]=Math.sqrt(I*I+L*L),s[l]=Math.atan2(L,I)}}};var k=class{#t=0;#e=0;#s=0;#n=0;reset(){this.#t=0,this.#e=0,this.#s=0,this.#n=0}process({a1:t,a2:e,b0:s,b1:n,b2:r},i,a,c,l){let h=this.#t,f=this.#e,u=this.#s,m=this.#n;for(let w=c;w<l;w++){let d=i[w],g=a[w]=s*d+n*h+r*f-t*u-e*m+1e-18-1e-18;f=h,h=d,m=u,u=g}this.#t=h,this.#e=f,this.#s=u,this.#n=m}processFrame({a1:t,a2:e,b0:s,b1:n,b2:r},i){let a=s*i+n*this.#t+r*this.#e-t*this.#s-e*this.#n+1e-18-1e-18;return this.#e=this.#t,this.#t=i,this.#n=this.#s,this.#s=a,a}};var q=48,Mt=200,bt=2e3,Tt=20,At=2,_t=3e-4,Bt=40,Pt=120,Rt=.2,Ft=20,Lt=.66,vt=.006,Ot={low:1,mid:4,high:8},tt=class o{static detect(t){let e=performance.now(),s=t.numberOfFrames/t.sampleRate,n=new o(t).#h(),r=((performance.now()-e)/1e3/s*100).toFixed(2);return console.debug(`realtime factor: ${r}%`),n}#t;#e;#s;#n;#r;#i;#a;#o;constructor(t){this.#t=t.sampleRate,this.#e=t.numberOfFrames,this.#s=Math.floor(Ft/1e3*this.#t),this.#n=Math.floor(Pt/1e3*this.#t),this.#r=Math.floor(Tt/1e3*this.#t),this.#i=Math.floor(this.#r/2);let e=this.#e/this.#t;this.#a=Math.floor(e*Bt),this.#o=this.#m(t)}#h(){let t=this.#f();return this.#u(t).map(s=>s/this.#t)}#f(){let t=this.#d(),e=[];for(let r of["low","mid","high"]){let i=t[r],a=this.#p(i),c=this.#w(a),l=Ot[r];for(let h of c)e.push({position:h.position,energy:h.energy*l})}let s=[0,this.#e],n=[...e].sort((r,i)=>i.energy-r.energy);for(let r of n){if(s.length>=this.#a+2&&s.length>=At+2)break;this.#g(s,r.position)||this.#x(s,r.position)}return s}#u(t){if(t.length<2)return t;let e=[t[0]],s=Math.floor(this.#t*vt);for(let n=1;n<t.length-1;n++){let r=t[n-1],i=t[n];if(r===0){e.push(i);continue}let a=i-r,c=r+Math.floor(a*Rt),l=i-this.#s,h=Math.max(c,l),f=0;for(let d=0;d<s&&i+d<this.#e;d++)f+=this.#o[i+d]*this.#o[i+d];f=Math.sqrt(f/s);let u=f*Lt,m=1/0,w=i;for(let d=i-1;d>=h;d--){let g=0;for(let I=0;I<s&&d+I<this.#e;I++)g+=this.#o[d+I]*this.#o[d+I];let E=Math.sqrt(g/s);if(E<m&&(m=E,w=d),E<u)break}e.push(w)}return e.push(t[t.length-1]),e}#m(t){let{numberOfFrames:e,numberOfChannels:s,frames:n}=t;if(s===0)return p("Invalid sample. No channels found.");if(s===1)return new Float32Array(n[0]);let r=new Float32Array(e);for(let a=0;a<s;a++){let c=n[a];for(let l=0;l<e;l++)r[l]+=c[l]}let i=1/s;for(let a=0;a<e;a++)r[a]*=i;return r}#c(t,e,s,n){let r=n/12,i=new J,a=e/this.#t;s==="lowpass"?i.setLowpassParams(a,Math.SQRT1_2):i.setHighpassParams(a,Math.SQRT1_2);let c=t;for(let l=0;l<r;l++){let h=new k,f=new k,u=new Float32Array(c.length),m=new Float32Array(c.length);h.process(i,c,u,0,c.length),f.process(i,u,m,0,c.length),c=m}return c}#d(){let t=this.#c(this.#o,Mt,"lowpass",q),e=this.#c(this.#o,Mt,"highpass",q),s=this.#c(e,bt,"lowpass",q),n=this.#c(e,bt,"highpass",q);return{low:t,mid:s,high:n}}#p(t){let e=new Float32Array(t.length),s=0;for(let n=0;n<this.#r&&n<t.length;n++)s+=t[n]*t[n];for(let n=0;n<t.length;n++){let r=n-this.#i,i=n+this.#i;if(r>0&&r-1<t.length){let c=t[r-1];s-=c*c}if(i<t.length){let c=t[i];s+=c*c}let a=Math.min(i,t.length-1)-Math.max(r,0)+1;e[n]=Math.sqrt(Math.max(0,s)/a)}return e}#w(t){let e=0;for(let r=0;r<t.length;r++)t[r]>e&&(e=t[r]);let s=e*_t,n=[];for(let r=1;r<t.length-1;r++){let i=t[r]-t[r-1],a=t[r+1]-t[r];i>s&&i>a&&n.push({position:r,energy:t[r]})}return n}#g(t,e){let s=this.#l(t,e);return s>0&&e-t[s-1]<this.#n?!0:s<t.length&&t[s]-e<this.#n}#x(t,e){let s=this.#l(t,e);t.splice(s,0,e)}#l(t,e){let s=0,n=t.length;for(;s<n;){let r=s+n>>>1;t[r]<e?s=r+1:n=r}return s}};var et=yt.for(self);Z.init(et);Q.install(et);P.executor(et.channel("transients"),new class{async detect(o){return tt.detect(o)}});et.channel("initialize").send("ready");
1
+ var y=o=>o!=null,ut=o=>o===null;var mt=o=>o!==void 0;var x=(o,t="asDefined failed")=>o??p(R(t));var R=o=>o instanceof Function?o():o;var dt=(o,...t)=>o?.apply(null,t);var V=o=>{throw new Error(`Unhandled ${o}`)},p=o=>{throw typeof o=="string"?new Error(o):o},M=(o,t)=>o?void 0:p(R(t));var v=o=>new Proxy({},{get(){return p(o)}});var nt=class{value;status="success";constructor(t){this.value=t}error=v("Cannot access error when succeeded")},rt=class{error;status="failure";constructor(t){this.error=t}value=v("Cannot access value when failed")},pt=o=>{try{return new nt(o())}catch(t){return new rt(t)}};var H=()=>{};var it;(function(o){o[o.Ascending=1]="Ascending",o[o.Descending=-1]="Descending"})(it||(it={}));var b=class{static#t=Object.freeze(new Array(0));static empty=()=>this.#t;static clear=t=>{t.length=0};static replace=(t,e)=>{t.length=0,t.push(...e)};static consume=(t,e)=>{for(let s=0;s<t.length;)e(t[s])?t.splice(s,1):s++};static peekFirst=t=>t.at(0)??null;static peekLast=t=>t.at(-1)??null;static getFirst=(t,e)=>x(t.at(0),e);static getLast=(t,e)=>x(t.at(-1),e);static getPrev=(t,e)=>{let s=t.indexOf(e);return s===-1?p(`${e} not found in ${t}`):x(t.at((s-1)%t.length),"Internal Error")};static getNext=(t,e)=>{let s=t.indexOf(e);return s===-1?p(`${e} not found in ${t}`):x(t.at((s+1)%t.length),"Internal Error")};static removeLast=(t,e)=>x(t.pop(),e);static create=(t,e)=>{let s=new Array(e);for(let n=0;n<e;n++)s[n]=t(n);return s};static equals=(t,e)=>{if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0};static satisfy=(t,e)=>{if(t.length<2)return!0;let s=t[0];for(let n=1;n<t.length;n++)if(!e(s,t[n]))return!1;return!0};static remove=(t,e)=>{let s=t.indexOf(e);if(s===-1)return p(`${e} not found in ${t}`);t.splice(s,1)};static removeIf=(t,e)=>{for(let s=t.length-1;s>=0;s--)e(t[s])&&t.splice(s,1)};static removeOpt=(t,e)=>{let s=t.indexOf(e);return s===-1?!1:(t.splice(s,1),!0)};static hasDuplicates=t=>new Set(t).size<t.length;static removeDuplicates=t=>{let e=0,s=new Set;for(let n of t)s.has(n)||(s.add(n),t[e++]=n);return t.length=e,t};static removeDuplicateKeys=(t,e)=>{let s=0,n=new Set;for(let r of t){let i=r[e];n.has(i)||(n.add(i),t[s++]=r)}return t.length=s,t};static subtract(t,e,s){return t.filter(n=>!e.some(r=>s(n,r)))}static intersect(t,e,s){return t.filter(n=>e.some(r=>s(n,r)))}static merge(t,e,s){return[...t.filter(n=>!e.some(r=>s(n,r))),...e]}static*iterate(t){for(let e=0;e<t.length;e++)yield t[e]}static*iterateReverse(t){for(let e=t.length-1;e>=0;e--)yield t[e]}static*iterateStateFull(t){let e=t.length-1;for(let s=0;s<=e;s++)yield{value:t[s],isFirst:s===0,isLast:s===e}}static*iterateAdjacent(t){if(!(t.length<=1))for(let e=1,s=t[0];e<t.length;e++){let n=t[e];yield[s,n],s=n}}static isSorted(t,e=it.Ascending){if(t.length<2)return!0;let s=t[0];for(let n=1;n<t.length;n++){let r=t[n];if(Math.sign(s-r)===e)return!1;s=r}return!0}static toRecord(t,e){return t.reduce((s,n)=>(s[e(n)]=n,s),{})}static concatArrayBuffers(t,e){let s=new ArrayBuffer(t.byteLength+e.byteLength),n=new Uint8Array(s);return n.set(new Uint8Array(t),0),n.set(new Uint8Array(e),t.byteLength),s}};var T;(function(o){o.wrap=e=>y(e)?new t(e):o.None,o.from=e=>o.wrap(e()),o.tryFrom=e=>{try{return o.wrap(e())}catch{return o.None}},o.execute=(e,...s)=>o.wrap(e?.apply(null,s)),o.async=e=>e.then(s=>o.wrap(s),()=>o.None);class t{#t;constructor(s){this.#t=x(s)}unwrap(){return this.#t}unwrapOrElse(s){return this.#t}unwrapOrNull(){return this.#t}unwrapOrUndefined(){return this.#t}contains(s){return s===this.#t}match(s){return s.some(this.#t)}ifSome(s){return s(this.#t)}ifAbsent(s){}isEmpty(){return!1}nonEmpty(){return!0}map(s){return o.wrap(s(this.#t))}mapOr(s,n){return s(this.#t)}flatMap(s){return s(this.#t)}equals(s){return this.unwrapOrNull()===s.unwrapOrNull()}assert(s){return this}toString(){return`{Option.Some(${this.#t})}`}get[Symbol.toStringTag](){return this.toString()}}o.Some=t,o.None=new class{unwrap=e=>p(y(e)?R(e):"unwrap failed");unwrapOrElse=e=>R(e);unwrapOrNull=()=>null;unwrapOrUndefined=()=>{};contains=e=>!1;match=e=>e.none();ifSome=e=>{};ifAbsent=e=>e(void 0);isEmpty=()=>!0;nonEmpty=()=>!1;map=e=>o.None;mapOr=(e,s)=>R(s);flatMap=e=>o.None;equals=e=>e.isEmpty();assert=e=>p(R(e)??"assert failed");toString=()=>"{Option.None}";get[Symbol.toStringTag](){return this.toString()}}})(T||(T={}));var A=Math.PI*2,Ut=Math.PI/2,Vt=Math.PI/4,Ht=1/Math.sqrt(2),_=(o,t,e)=>Math.max(t,Math.min(o,e));var wt=o=>Math.pow(2,Math.ceil(Math.log(o)/Math.log(2)));var S=new DataView(new ArrayBuffer(8)),gt;(function(o){o.MIN_VALUE=-2147483648,o.MAX_VALUE=2147483647,o.toByte=t=>(S.setInt8(0,t),S.getInt8(0)),o.toShort=t=>(S.setInt16(0,t),S.getInt16(0)),o.toInt=t=>(S.setInt32(0,t),S.getInt32(0))})(gt||(gt={}));var O;(function(o){let s=new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT),n=new Float32Array(s),r=new Int32Array(s);o.floatToIntBits=i=>{let a=o.floatToRawIntBits(i);return(a&2139095040)===2139095040&&(a&8388607)!==0?2143289344:a},o.intBitsToFloat=i=>(r[0]=i,n[0]),o.floatToRawIntBits=i=>(n[0]=i,r[0]),o.toFloat32=i=>(S.setFloat32(0,i),S.getFloat32(0))})(O||(O={}));var B;(function(o){o.floatToIntBits=t=>{let e=O.floatToIntBits(t),s=e>>>16&32768,n=(e&2147483647)+4096;return n>=1199570944?(e&2147483647)>=1199570944?n<2139095040?s|31744:s|31744|(e&8388607)>>>13:s|31743:n>=947912704?s|n-939524096>>>13:n<855638016?s:(n=(e&2147483647)>>>23,s|(e&8388607|8388608)+(8388608>>>n-102)>>>126-n)},o.intBitsToFloat=t=>{let e=t&1023,s=t&31744;if(s===31744)s=261120;else if(s!==0){if(s+=114688,e===0&&s>115712)return O.intBitsToFloat((t&32768)<<16|s<<13|1023)}else if(e!==0){s=115712;do e<<=1,s-=1024;while((e&1024)===0);e&=1023}return O.intBitsToFloat((t&32768)<<16|(s|e)<<13)}})(B||(B={}));var xt;(function(o){let t=9218868437227405312n,e=4503599627370495n,s=new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT),n=new Float64Array(s),r=new BigInt64Array(s);o.float64ToLongBits=i=>{let a=o.float64ToRawLongBits(i);return(a&t)===t&&(a&e)!==0n?0x7ff8000000000000n:a},o.longBitsToFloat64=i=>(r[0]=i,n[0]),o.float64ToRawLongBits=i=>(n[0]=i,r[0]),o.clamp=i=>(S.setFloat64(0,i),S.getFloat64(0))})(xt||(xt={}));var F=class{static*empty(){}static one(t){return[t]}static count(t){let e=0;for(let s of t)e++;return e}static some(t,e){for(let s of t)if(e(s))return!0;return!1}static every(t,e){for(let s of t)if(!e(s))return!1;return!0}static reduce(t,e,s){let n=s,r=0;for(let i of t)n=e(n,i,r++);return n}static includes(t,e){for(let s of t)if(s===e)return!0;return!1}static forEach(t,e){for(let s of t)e(s)}static*map(t,e){let s=0;for(let n of t)yield e(n,s++)}static*take(t,e){let s=0;for(let n of t){if(s++>=e)return;yield n}}static filter(t,e){let s=[];for(let n of t)e(n)&&s.push(n);return s}static filterMap(t,e){let s=[];for(let n of t){let r=e(n);y(r)&&s.push(r)}return s}static reverse(t){let e=[];for(let s of t)e.push(s);return e.reverse()}static*pairWise(t){let e=t[Symbol.iterator](),{done:s,value:n}=e.next(),r=n;if(s!==!0)for(;;){let{done:i,value:a}=e.next();if(i===!0){yield[r,null];return}yield[r,a],r=a}}};var j=class o{static create(t=1024){return this.use(new ArrayBuffer(t))}static use(t,e=0){return new o(new DataView(t,e))}littleEndian=!1;#t;#e=0;constructor(t){this.#t=t}get remaining(){return this.#t.byteLength-this.#e}get position(){return this.#e}set position(t){t<0?p(`position(${t}) cannot be negative.`):t>this.#t.byteLength?p(`position(${t}) is outside range (${this.#t.byteLength}).`):this.#e=t}writeBoolean(t){this.writeByte(t?1:0)}writeByte(t){this.#s(1),this.#t.setInt8(this.#e++,t)}writeShort(t){this.#s(Int16Array.BYTES_PER_ELEMENT),this.#t.setInt16(this.#e,t,this.littleEndian),this.#e+=Int16Array.BYTES_PER_ELEMENT}writeInt(t){this.#s(Int32Array.BYTES_PER_ELEMENT),this.#t.setInt32(this.#e,t,this.littleEndian),this.#e+=Int32Array.BYTES_PER_ELEMENT}writeLong(t){this.#s(BigInt64Array.BYTES_PER_ELEMENT),this.#t.setBigInt64(this.#e,t,this.littleEndian),this.#e+=BigInt64Array.BYTES_PER_ELEMENT}writeFloat(t){this.#s(Float32Array.BYTES_PER_ELEMENT),this.#t.setFloat32(this.#e,t,this.littleEndian),this.#e+=Float32Array.BYTES_PER_ELEMENT}writeDouble(t){this.#s(Float64Array.BYTES_PER_ELEMENT),this.#t.setFloat64(this.#e,t,this.littleEndian),this.#e+=Float64Array.BYTES_PER_ELEMENT}writeBytes(t){this.#s(t.length);for(let e=0;e<t.length;++e)this.#t.setInt8(this.#e++,t[e])}writeString(t){let e=t.length;this.#s(Int32Array.BYTES_PER_ELEMENT+e*Int16Array.BYTES_PER_ELEMENT),this.writeInt(e);for(let s=0;s<e;s++)this.writeShort(t.charCodeAt(s))}toArrayBuffer(){return this.#t.buffer.slice(0,this.#e)}#s(t){let e=this.#t.byteLength;if(this.#e+t>e){let s=this.#t;this.#t=new DataView(new ArrayBuffer(wt(e+t)));for(let n=0;n<this.#e;n++)this.#t.setInt8(n,s.getInt8(n))}}};var G=Object.freeze({Empty:{terminate:H},create:o=>({terminate:o}),many:(...o)=>({terminate:()=>{for(;o.length>0;)o.pop().terminate()}})});var C=class{static subscribeMany(t,...e){return G.many(...e.map(s=>s.subscribe(()=>t(s))))}#t=new Set;subscribe(t){return this.#t.add(t),{terminate:()=>this.#t.delete(t)}}isEmpty(){return this.#t.size===0}notify(t){this.#t.forEach(e=>e(t))}observers(){return this.#t}terminate(){this.#t.clear()}};var Et=(()=>{let o=T.None;return{info:t=>o.match({none:()=>Promise.resolve(),some:e=>e.info(t)}),approve:t=>o.match({none:()=>Promise.resolve(!0),some:e=>e.approve(t)}),progress:t=>o.match({none:()=>({message:"",terminate:H}),some:e=>e.progress(t)}),install:t=>{M(o.isEmpty(),"RuntimeNotification already installed"),o=T.wrap(t)}}})();var $=class o{static POSITIVE_INFINITY=new o(Number.POSITIVE_INFINITY);static millis=t=>new o(t);static seconds=t=>new o(t*o.#t);static minutes=t=>new o(t*o.#e);static hours=t=>new o(t*o.#s);static days=t=>new o(t*o.#n);static#t=1e3;static#e=6e4;static#s=36e5;static#n=864e5;#r;constructor(t){this.#r=t}millis(){return this.#r}absSeconds(){return Math.abs(this.#r)/o.#t}absMinutes(){return Math.abs(this.#r)/o.#e}absHours(){return Math.abs(this.#r)/o.#s}absDays(){return Math.abs(this.#r)/o.#n}split(){return{d:Math.floor(this.absDays()),h:Math.floor(this.absHours())%24,m:Math.floor(this.absMinutes())%60,s:Math.floor(this.absSeconds())%60}}isNow(){return this.#r===0}isPast(){return this.#r<0}isFuture(){return this.#r>0}toUnitString(){let t,e,s=Math.floor(Math.abs(this.#r)/1e3),n=Math.floor(s/60),r=Math.floor(n/60),i=Math.floor(r/24);return s<60?(t=s,e="second"):n<60?(t=n,e="minute"):r<24?(t=r,e="hour"):(t=i,e="day"),new Intl.RelativeTimeFormat("en",{numeric:"auto",style:"long"}).format(t*Math.sign(this.#r),e)}toString(){if(isNaN(this.#r))return"NaN";if(!isFinite(this.#r))return"\u221E";let{d:t,h:e,m:s,s:n}=this.split();return t>0?[o.#i("d",t),o.#i("h",e),o.#i("m",s),o.#i("s",n)].join(", "):e>0?[o.#i("h",e),o.#i("m",s),o.#i("s",n)].join(", "):s>0?[o.#i("m",s),o.#i("s",n)].join(", "):n>0?o.#i("s",n):"now"}static#i=(t,e)=>{switch(t){case"d":return`${e} ${e<2?"day":"days"}`;case"h":return`${e} ${e<2?"hour":"hours"}`;case"m":return`${e} ${e<2?"minute":"minutes"}`;case"s":return`${e} ${e<2?"second":"seconds"}`;default:return V(t)}}};var P;(function(o){o.sender=(n,r)=>r(new e(n)),o.executor=(n,r)=>new s(n,r);let t=n=>{let r=[];for(let i of n)i instanceof MessagePort&&r.push(i),typeof ImageBitmap<"u"&&i instanceof ImageBitmap&&r.push(i),typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas&&r.push(i);return r};class e{#t;#e=new Map;#s;#n=0;constructor(r){this.#t=r,this.#s=r.subscribe(this.#r)}terminate(){this.#s.terminate()}dispatchAndForget=(r,...i)=>{let a=t(i);this.#t.send({type:"send",returnId:!1,func:r.name,args:Array.from(F.map(i,c=>({value:c})))},a)};dispatchAndReturn=(r,...i)=>new Promise((a,c)=>{let l=F.reduce(i,(f,u,m)=>(typeof u=="function"&&f.push([m,u]),f),[]);this.#e.set(this.#n,{executorTuple:{resolve:a,reject:c},callbacks:new Map(l)});let h=t(i);this.#t.send({type:"send",returnId:this.#n,func:r.name,args:Array.from(F.map(i,(f,u)=>typeof f=="function"?{callback:u}:{value:f}))},h),this.#n++});#r=r=>{let i=this.#e.get(r.returnId);y(i)?r.type==="resolve"?(i.executorTuple.resolve(r.resolve),this.#e.delete(r.returnId)):r.type==="reject"?(i.executorTuple.reject(r.reject),this.#e.delete(r.returnId)):r.type==="callback"&&i.callbacks?.get(r.funcAt).apply(this,r.args):p(`Promise has already been resolved. ${JSON.stringify(r)}`)}}class s{#t;#e;#s;constructor(r,i){this.#t=r,this.#e=i,this.#s=r.subscribe(this.#n)}terminate(){this.#s.terminate()}#n=r=>{M(r.type==="send",()=>"Message type must be 'send'");let i=Object.getPrototypeOf(this.#e)===Object.getPrototypeOf({})?this.#e:Object.getPrototypeOf(this.#e),a=x(i[r.func],`${r.func.toString()} does not exists on ${this.#e}`),c=r.returnId;if(c===!1)a.apply(this.#e,r.args.map(l=>"value"in l?l.value:p(`${r.func.toString()} has no promise.`)));else try{a.apply(this.#e,r.args.map(h=>"callback"in h?(...f)=>this.#a(c,h.callback,f):h.value)).then(h=>{try{this.#r(c,h)}catch(f){this.#i(c,f)}},h=>this.#i(c,h))}catch(l){this.#i(c,l)}};#r=(r,i)=>this.#t.send({type:"resolve",returnId:r,resolve:i});#i=(r,i)=>this.#t.send({type:"reject",returnId:r,reject:i});#a=(r,i,a)=>this.#t.send({type:"callback",returnId:r,funcAt:i,args:a})}o.Executor=s})(P||(P={}));var yt={for:o=>new ot(o)},Nt=[],ot=class{#t;#e=new C;constructor(t){if(this.#t=t,y(t.onmessage)||y(t.onmessageerror))throw console.error(t),new Error(`${t} is already wrapped.`);t.onmessage=e=>this.#e.notify(e.data),t.onmessageerror=e=>{throw new Error(e.type)}}send(t,e){this.#t.postMessage(t,e??Nt)}channel(t){return new at(this,t)}subscribe(t){return this.#e.subscribe(t)}terminate(){this.#e.terminate(),this.#t.onmessage=null,this.#t.onmessageerror=null}},at=class o{#t;#e;#s=new C;#n;constructor(t,e){this.#t=t,this.#e=e,this.#n=t.subscribe(s=>{"__id__"in s&&s.__id__==="42"&&"message"in s&&"channel"in s&&s.channel===e&&this.#s.notify(s.message)})}send(t,e){this.#t.send({__id__:"42",channel:this.#e,message:t},e)}channel(t){return new o(this,t)}subscribe(t){return this.#s.subscribe(t)}terminate(){this.#n.terminate(),this.#s.terminate()}};var W;(function(o){o.frame=()=>new Promise(t=>requestAnimationFrame(()=>t())),o.frames=t=>new Promise(e=>{let s=t,n=()=>{--s<=0?e():requestAnimationFrame(n)};requestAnimationFrame(n)}),o.timeSpan=(t,...e)=>new Promise(s=>setTimeout(s,t.millis(),...e)),o.event=(t,e)=>new Promise(s=>t.addEventListener(e,s,{once:!0})),o.observable=t=>new Promise(e=>{let s=t.subscribe(()=>{s.terminate(),e()})}),o.complete=t=>new Promise((e,s)=>{let n=setInterval(()=>{let{status:r,value:i,error:a}=pt(()=>t.next());if(r==="success"){let{done:c,value:l}=i;c&&(clearInterval(n),e(l))}else clearInterval(n),s(a)},0)})})(W||(W={}));var ct=class{maxRetry;timeSpan;#t=0;constructor(t,e){this.maxRetry=t,this.timeSpan=e}retry(t,e){return++this.#t===this.maxRetry?!1:(console.debug(`${t} > will retry in ${this.timeSpan.toString()}`),setTimeout(e,this.timeSpan.millis()),!0)}},K;(function(o){class t{value;status="resolved";constructor(a){this.value=a}error=v("Cannot access error when promise is resolved")}o.ResolveResult=t;class e{error;status="rejected";constructor(a){this.error=a}value=v("Cannot access value when promise is rejected")}o.RejectedResult=e,o.makeAbortable=async(i,a)=>{let c=!0;return i.own(G.create(()=>c=!1)),new Promise((l,h)=>a.then(f=>{c&&l(f)},f=>{c&&h(f)}))},o.tryCatch=i=>i.then(a=>new t(a),a=>new e(a));let s=new ct(3,$.seconds(3));o.retry=(i,a=s)=>i().catch(c=>new Promise((l,h)=>{let f=u=>{a.retry(u,()=>i().then(m=>l(m),f))||h(u)};f(c)})),o.guardedRetry=(i,a)=>{let c=async(l=0)=>{try{return await i()}catch(h){if(a(h,++l))return console.debug(`retry after failure (online: ${navigator.onLine}):`,h),await W.timeSpan($.seconds(1)),c(l);throw new Error(`Failed after ${l} retries: ${h}`)}};return c()},o.approvedRetry=(i,a)=>{let c=async()=>{try{return await i()}catch(l){if(await Et.approve(a(l)))return c();throw l}};return c()},o.fail=(i,a)=>{let c=()=>new Promise((l,h)=>setTimeout(()=>h("fails first"),i.millis()));return()=>{let l=c();return c=a,l}},o.timeout=(i,a,c)=>new Promise((l,h)=>{let f=!0,u=setTimeout(()=>{f=!1,h(new Error(c??"timeout"))},a.millis());i.then(m=>{f&&l(m)},m=>{f&&h(m)}).finally(()=>clearTimeout(u))}),o.sequentialAll=i=>i.reduce((a,c)=>a.then(async l=>[...l,await c()]),Promise.resolve([])),o.sequentialize=i=>{let a=Promise.resolve();return c=>{let l=()=>i(c),h=a.then(l,l);return a=h.catch(()=>{}),h}},o.memoizeAsync=(i,a)=>{let c=null,l=Date.now();return()=>{let h=Date.now();return(ut(c)||y(a)&&h-l>a.millis())&&(l=h,c=i(),c.catch(f=>(c=null,f))),c}},o.allWithLimit=async(i,a=1)=>{let c=new Array(i.length),l=0,h=!1,f=async()=>{for(;l<i.length&&!h;){let u=l++;try{let m=await i[u]();h||(c[u]=m)}catch(m){throw h=!0,m}}};return await Promise.all(Array.from({length:Math.min(a,i.length)},f)),c},o.allSettledWithLimit=async(i,a=1)=>{let c=new Array(i.length),l=0,h=async()=>{for(;l<i.length;){let f=l++;try{let u=await i[f]();c[f]={status:"fulfilled",value:u}}catch(u){c[f]={status:"rejected",reason:u}}}};return await Promise.all(Array.from({length:Math.min(a,i.length)},h)),c};class n{max;#t;#e=0;constructor(a=1){this.max=a,this.#t=[]}async add(a){if(this.#e<this.max)return this.#e++,a().finally(()=>this.#s());{let c=Promise.withResolvers();return this.#t.push([a,c]),c.promise.finally(()=>this.#s())}}#s(){if(M(this.#e>0,"Internal Error in Promises.Limit"),--this.#e<this.max&&this.#t.length>0){let[a,{resolve:c,reject:l}]=this.#t.shift();this.#e++,a().then(c,l)}}}o.Limit=n;class r{#t;#e;#s;#n=T.None;constructor(a,c,l){this.#t=a,this.#e=c,this.#s=l}update(a){this.#n=T.wrap(a),a.then(c=>{this.#n.contains(a)&&this.#t(c)}).catch(c=>{this.#n.contains(a)&&this.#e(c)}).finally(()=>{this.#n.contains(a)&&(this.terminate(),dt(this.#s))})}terminate(){this.#n=T.None}}o.Latest=r})(K||(K={}));var It=(o="debug")=>{let t=performance.now();return{lab:e=>console[o].call(console,`${e} in ${(performance.now()-t).toFixed(1)}ms`)}};var D;(function(o){class t{shift;numPeaks;dataOffset;constructor(s,n,r){this.shift=s,this.numPeaks=n,this.dataOffset=r}unitsEachPeak(){return 1<<this.shift}}o.Stage=t,o.unpack=(e,s)=>{switch(s){case 0:return B.intBitsToFloat(e);case 1:return B.intBitsToFloat(e>>16);default:return V(s)}}})(D||(D={}));var X=class o{stages;data;numFrames;numChannels;static from(t){M(t.readString()==="PEAKS","Wrong header");let e=t.readInt(),s=[];for(let c=0;c<e;c++){let l=t.readInt(),h=t.readInt(),f=t.readInt();t.readInt(),s[c]=new D.Stage(f,h,l)}let n=t.readInt(),r=[];for(let c=0;c<n;c++){let l=new Int8Array(t.readInt());t.readBytes(l),r[c]=new Int32Array(l.buffer)}let i=t.readInt(),a=t.readInt();return new o(s,r,i,a)}static None=new o([],[],0,0);static findBestFit=(t,e=1200)=>{let s=t/e;if(s<=1)return new Uint8Array(0);let n=3,r=Math.floor(Math.log(s)/Math.LN2),i=Math.max(1,Math.floor(r/n));return new Uint8Array(b.create(a=>n*(a+1),i))};constructor(t,e,s,n){this.stages=t,this.data=e,this.numFrames=s,this.numChannels=n}nearest(t){if(this.stages.length===0)return null;let e=Math.floor(Math.log(Math.abs(t))/Math.LN2),s=this.stages.length;for(;--s>-1;)if(e>=this.stages[s].shift)return this.stages[s];return this.stages[0]}toArrayBuffer(){let t=j.create();t.writeString("PEAKS"),t.writeInt(this.stages.length);for(let e=0;e<this.stages.length;e++){let{dataOffset:s,numPeaks:n,shift:r}=this.stages[e];t.writeInt(s),t.writeInt(n),t.writeInt(r),t.writeInt((1<<r)-1)}t.writeInt(this.data.length);for(let e=0;e<this.data.length;e++){let s=new Int8Array(this.data[e].buffer);t.writeInt(s.length),t.writeBytes(s)}return t.writeInt(this.numFrames),t.writeInt(this.numChannels),t.toArrayBuffer()}toString(){return`{SamplePeaks num-stages: ${this.stages.length}}`}};var Q;(function(o){o.install=s=>P.executor(s.channel("peaks"),new class{async generateAsync(n,r,i,a,c){return t(n,r,i,a,c).toArrayBuffer()}});let t=(s,n,r,i,a)=>{if(r.length!==a)return p(`Invalid numberOfChannels. Expected: ${a}. Got ${r.length}`);class c{min=Number.POSITIVE_INFINITY;max=Number.NEGATIVE_INFINITY;index=0}let l=It(),h=n.length,[f,u]=e(n,i),m=b.create(()=>new Int32Array(u),a),w=(1<<f[0].shift)-1,d=a*i,g=0;for(let E=0;E<a;++E){let I=m[E],L=r[E],St=b.create(()=>new c,h),z=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY,lt=0;for(let st=0;st<i;++st){let ht=L[st];if(z=Math.min(ht,z),Y=Math.max(ht,Y),(++lt&w)===0){for(let U=0;U<h;++U){let ft=f[U],N=St[U];N.min=Math.min(N.min,z),N.max=Math.max(N.max,Y),((1<<ft.shift)-1&lt)===0&&(I[ft.dataOffset+N.index++]=o.pack(N.min,N.max),N.min=Number.POSITIVE_INFINITY,N.max=Number.NEGATIVE_INFINITY)}z=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY}(++g&65535)===0&&s(g/d)}}return s(1),l.lab(`SamplePeaks '${self.constructor.name}'`),new X(f,m,i,a)},e=(s,n)=>{let r=0;return[b.create(a=>{let c=s[a],l=Math.ceil(n/(1<<c)),h=new D.Stage(c,l,r);return r+=l,h},s.length),r]};o.pack=(s,n)=>{let r=B.floatToIntBits(s),i=B.floatToIntBits(n);return r|i<<16}})(Q||(Q={}));var Z;(function(o){o.init=s=>P.executor(s.channel("opfs"),new class{#t=new Map;async write(n,r){await this.#e(n,async()=>{let i=await this.#s(n,{create:!0});try{i.truncate(r.length),i.write(r.buffer,{at:0}),i.flush()}finally{i.close()}})}async read(n){return await this.#e(n,async()=>{let r=await this.#s(n);try{let i=r.getSize(),a=new Uint8Array(i);return r.read(a),a}finally{r.close()}})}async delete(n){await this.#e(n,async()=>{let r=e(n);return r.length===0?this.clear():this.#n(r.slice(0,-1)).then(i=>i.removeEntry(x(r.at(-1)),{recursive:!0}))})}async list(n){let r=e(n),{status:i,value:a}=await K.tryCatch(this.#n(r));if(i==="rejected")return b.empty();let c=[];for await(let{name:l,kind:h}of a.values())c.push({name:l,kind:h});return c}async clear(){let n=await navigator.storage.getDirectory();for await(let[r,i]of n.entries())i.kind==="file"?await n.removeEntry(r):i.kind==="directory"&&await n.removeEntry(r,{recursive:!0})}async#e(n,r){for(;;){let i=this.#t.get(n);if(mt(i)){await i;continue}let a=()=>p("Lock not acquired"),c=new Promise(l=>a=l);this.#t.set(n,c);try{return await r()}finally{this.#t.get(n)===c&&this.#t.delete(n),a()}}}async#s(n,r){let i=e(n);return await(await(await this.#n(i.slice(0,-1),r)).getFileHandle(x(i.at(-1)),r)).createSyncAccessHandle()}async#n(n,r){let i=await navigator.storage.getDirectory();for(let a of n)i=await i.getDirectoryHandle(a,r);return i}});let e=s=>{let n=s.replace(/^\/+|\/+$/g,"");return n===""?[]:n.split("/")}})(Z||(Z={}));var J=class{a1=0;a2=0;b0=0;b1=0;b2=0;constructor(){this.identity()}identity(){this.setNormalizedCoefficients(1,0,0,1,0,0)}setLowpassParams(t,e=Math.SQRT1_2){if(t=_(t,0,1),t>=.5)this.setNormalizedCoefficients(1,0,0,1,0,0);else if(t>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=(1-r)/2,a=i,c=2*i,l=i,h=1+n,f=-2*r,u=1-n;this.setNormalizedCoefficients(a,c,l,h,f,u)}else this.setNormalizedCoefficients(0,0,0,1,0,0);return this}setHighpassParams(t,e=Math.SQRT1_2){if(t=_(t,0,1),t===1)this.setNormalizedCoefficients(0,0,0,1,0,0);else if(t>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=(1+r)/2,a=i,c=-2*i,l=i,h=1+n,f=-2*r,u=1-n;this.setNormalizedCoefficients(a,c,l,h,f,u)}else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setNormalizedCoefficients(t,e,s,n,r,i){let a=1/n;return this.b0=t*a,this.b1=e*a,this.b2=s*a,this.a1=r*a,this.a2=i*a,this}setLowShelfParams(t,e){t=_(t,0,1);let s=Math.pow(10,e/40);if(t===1)this.setNormalizedCoefficients(s*s,0,0,1,0,0);else if(t>0){let n=A*t,i=.5*Math.sin(n)*Math.sqrt((s+1/s)*(1/1-1)+2),a=Math.cos(n),c=2*Math.sqrt(s)*i,l=s+1,h=s-1,f=s*(l-h*a+c),u=2*s*(h-l*a),m=s*(l-h*a-c),w=l+h*a+c,d=-2*(h+l*a),g=l+h*a-c;this.setNormalizedCoefficients(f,u,m,w,d,g)}else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setHighShelfParams(t,e){t=_(t,0,1);let s=Math.pow(10,e/40);if(t===1)this.setNormalizedCoefficients(1,0,0,1,0,0);else if(t>0){let n=A*t,i=.5*Math.sin(n)*Math.sqrt((s+1/s)*(1/1-1)+2),a=Math.cos(n),c=2*Math.sqrt(s)*i,l=s+1,h=s-1,f=s*(l+h*a+c),u=-2*s*(h+l*a),m=s*(l+h*a-c),w=l-h*a+c,d=2*(h-l*a),g=l-h*a-c;this.setNormalizedCoefficients(f,u,m,w,d,g)}else this.setNormalizedCoefficients(s*s,0,0,1,0,0);return this}setPeakingParams(t,e,s){t=_(t,0,1),e=Math.max(0,e);let n=Math.pow(10,s/40);if(t>0&&t<1)if(e>0){let r=A*t,i=Math.sin(r)/(2*e),a=Math.cos(r),c=1+i*n,l=-2*a,h=1-i*n,f=1+i/n,u=-2*a,m=1-i/n;this.setNormalizedCoefficients(c,l,h,f,u,m)}else this.setNormalizedCoefficients(n*n,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setAllpassParams(t,e){if(t=_(t,0,1),e=Math.max(0,e),t>0&&t<1)if(e>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=1-n,a=-2*r,c=1+n,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(-1,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setNotchParams(t,e){if(t=_(t,0,1),e=Math.max(0,e),t>0&&t<1)if(e>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=1,a=-2*r,c=1,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(0,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setBandpassParams(t,e){if(t=Math.max(0,t),e=Math.max(0,e),t>0&&t<1){let s=A*t;if(e>0){let n=Math.sin(s)/(2*e),r=Math.cos(s),i=n,a=0,c=-n,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(1,0,0,1,0,0)}else this.setNormalizedCoefficients(0,0,0,1,0,0);return this}getFrequencyResponse(t,e,s){M(t.length===e.length&&t.length===s.length,"Array lengths do not match");let n=this.b0,r=this.b1,i=this.b2,a=this.a1,c=this.a2;for(let l=0;l<t.length;++l){let h=-Math.PI*2*t[l],f=Math.cos(h),u=Math.sin(h),m=n+((r+i*f)*f-i*u*u),w=(r+i*f)*u+i*u*f,d=1+((a+c*f)*f-c*u*u),g=(a+c*f)*u+c*u*f,E=d*d+g*g,I=(m*d+w*g)/E,L=(w*d-m*g)/E;e[l]=Math.sqrt(I*I+L*L),s[l]=Math.atan2(L,I)}}};var k=class{#t=0;#e=0;#s=0;#n=0;reset(){this.#t=0,this.#e=0,this.#s=0,this.#n=0}process({a1:t,a2:e,b0:s,b1:n,b2:r},i,a,c,l){let h=this.#t,f=this.#e,u=this.#s,m=this.#n;for(let w=c;w<l;w++){let d=i[w],g=a[w]=s*d+n*h+r*f-t*u-e*m+1e-18-1e-18;f=h,h=d,m=u,u=g}this.#t=h,this.#e=f,this.#s=u,this.#n=m}processFrame({a1:t,a2:e,b0:s,b1:n,b2:r},i){let a=s*i+n*this.#t+r*this.#e-t*this.#s-e*this.#n+1e-18-1e-18;return this.#e=this.#t,this.#t=i,this.#n=this.#s,this.#s=a,a}};var q=48,Mt=200,bt=2e3,Tt=20,At=2,_t=3e-4,Bt=40,Pt=120,Rt=.2,Ft=20,Lt=.66,vt=.006,Ot={low:1,mid:4,high:8},tt=class o{static detect(t){let e=performance.now(),s=t.numberOfFrames/t.sampleRate,n=new o(t).#h(),r=((performance.now()-e)/1e3/s*100).toFixed(2);return console.debug(`realtime factor: ${r}%`),n}#t;#e;#s;#n;#r;#i;#a;#o;constructor(t){this.#t=t.sampleRate,this.#e=t.numberOfFrames,this.#s=Math.floor(Ft/1e3*this.#t),this.#n=Math.floor(Pt/1e3*this.#t),this.#r=Math.floor(Tt/1e3*this.#t),this.#i=Math.floor(this.#r/2);let e=this.#e/this.#t;this.#a=Math.floor(e*Bt),this.#o=this.#m(t)}#h(){let t=this.#f();return this.#u(t).map(s=>s/this.#t)}#f(){let t=this.#d(),e=[];for(let r of["low","mid","high"]){let i=t[r],a=this.#p(i),c=this.#w(a),l=Ot[r];for(let h of c)e.push({position:h.position,energy:h.energy*l})}let s=[0,this.#e],n=[...e].sort((r,i)=>i.energy-r.energy);for(let r of n){if(s.length>=this.#a+2&&s.length>=At+2)break;this.#g(s,r.position)||this.#x(s,r.position)}return s}#u(t){if(t.length<2)return t;let e=[t[0]],s=Math.floor(this.#t*vt);for(let n=1;n<t.length-1;n++){let r=t[n-1],i=t[n];if(r===0){e.push(i);continue}let a=i-r,c=r+Math.floor(a*Rt),l=i-this.#s,h=Math.max(c,l),f=0;for(let d=0;d<s&&i+d<this.#e;d++)f+=this.#o[i+d]*this.#o[i+d];f=Math.sqrt(f/s);let u=f*Lt,m=1/0,w=i;for(let d=i-1;d>=h;d--){let g=0;for(let I=0;I<s&&d+I<this.#e;I++)g+=this.#o[d+I]*this.#o[d+I];let E=Math.sqrt(g/s);if(E<m&&(m=E,w=d),E<u)break}e.push(w)}return e.push(t[t.length-1]),e}#m(t){let{numberOfFrames:e,numberOfChannels:s,frames:n}=t;if(s===0)return p("Invalid sample. No channels found.");if(s===1)return new Float32Array(n[0]);let r=new Float32Array(e);for(let a=0;a<s;a++){let c=n[a];for(let l=0;l<e;l++)r[l]+=c[l]}let i=1/s;for(let a=0;a<e;a++)r[a]*=i;return r}#c(t,e,s,n){let r=n/12,i=new J,a=e/this.#t;s==="lowpass"?i.setLowpassParams(a,Math.SQRT1_2):i.setHighpassParams(a,Math.SQRT1_2);let c=t;for(let l=0;l<r;l++){let h=new k,f=new k,u=new Float32Array(c.length),m=new Float32Array(c.length);h.process(i,c,u,0,c.length),f.process(i,u,m,0,c.length),c=m}return c}#d(){let t=this.#c(this.#o,Mt,"lowpass",q),e=this.#c(this.#o,Mt,"highpass",q),s=this.#c(e,bt,"lowpass",q),n=this.#c(e,bt,"highpass",q);return{low:t,mid:s,high:n}}#p(t){let e=new Float32Array(t.length),s=0;for(let n=0;n<this.#r&&n<t.length;n++)s+=t[n]*t[n];for(let n=0;n<t.length;n++){let r=n-this.#i,i=n+this.#i;if(r>0&&r-1<t.length){let c=t[r-1];s-=c*c}if(i<t.length){let c=t[i];s+=c*c}let a=Math.min(i,t.length-1)-Math.max(r,0)+1;e[n]=Math.sqrt(Math.max(0,s)/a)}return e}#w(t){let e=0;for(let r=0;r<t.length;r++)t[r]>e&&(e=t[r]);let s=e*_t,n=[];for(let r=1;r<t.length-1;r++){let i=t[r]-t[r-1],a=t[r+1]-t[r];i>s&&i>a&&n.push({position:r,energy:t[r]})}return n}#g(t,e){let s=this.#l(t,e);return s>0&&e-t[s-1]<this.#n?!0:s<t.length&&t[s]-e<this.#n}#x(t,e){let s=this.#l(t,e);t.splice(s,0,e)}#l(t,e){let s=0,n=t.length;for(;s<n;){let r=s+n>>>1;t[r]<e?s=r+1:n=r}return s}};var et=yt.for(self);Z.init(et);Q.install(et);P.executor(et.channel("transients"),new class{async detect(o){return tt.detect(o)}});et.channel("initialize").send("ready");
2
2
  //# sourceMappingURL=workers-main.js.map