@opendaw/studio-core 0.0.83 → 0.0.85

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 (70) hide show
  1. package/dist/EffectFactories.d.ts +0 -2
  2. package/dist/EffectFactories.d.ts.map +1 -1
  3. package/dist/EffectFactories.js +1 -1
  4. package/dist/Engine.d.ts +2 -1
  5. package/dist/Engine.d.ts.map +1 -1
  6. package/dist/EngineFacade.d.ts +2 -1
  7. package/dist/EngineFacade.d.ts.map +1 -1
  8. package/dist/EngineFacade.js +3 -1
  9. package/dist/EngineWorklet.d.ts +2 -1
  10. package/dist/EngineWorklet.d.ts.map +1 -1
  11. package/dist/EngineWorklet.js +5 -2
  12. package/dist/ExternalLib.d.ts +3 -2
  13. package/dist/ExternalLib.d.ts.map +1 -1
  14. package/dist/ExternalLib.js +2 -2
  15. package/dist/Preferences.d.ts +6 -0
  16. package/dist/Preferences.d.ts.map +1 -1
  17. package/dist/Preferences.js +5 -2
  18. package/dist/Storage.d.ts.map +1 -1
  19. package/dist/Storage.js +14 -5
  20. package/dist/capture/Capture.d.ts +4 -1
  21. package/dist/capture/Capture.d.ts.map +1 -1
  22. package/dist/capture/Capture.js +4 -0
  23. package/dist/capture/CaptureDevices.js +1 -1
  24. package/dist/capture/RecordAudio.d.ts.map +1 -1
  25. package/dist/capture/RecordAudio.js +20 -10
  26. package/dist/capture/RecordMidi.d.ts.map +1 -1
  27. package/dist/capture/RecordMidi.js +1 -0
  28. package/dist/capture/Recording.d.ts.map +1 -1
  29. package/dist/capture/Recording.js +1 -0
  30. package/dist/dawproject/BuiltinDevices.d.ts +1 -1
  31. package/dist/dawproject/DawProject.d.ts.map +1 -1
  32. package/dist/dawproject/DawProject.js +17 -3
  33. package/dist/midi/MIDILearning.d.ts +4 -16
  34. package/dist/midi/MIDILearning.d.ts.map +1 -1
  35. package/dist/midi/MIDILearning.js +94 -62
  36. package/dist/processors.js +17 -17
  37. package/dist/processors.js.map +4 -4
  38. package/dist/project/Project.d.ts +2 -2
  39. package/dist/project/Project.d.ts.map +1 -1
  40. package/dist/project/Project.js +16 -9
  41. package/dist/project/ProjectApi.js +2 -2
  42. package/dist/project/ProjectBundle.d.ts.map +1 -1
  43. package/dist/project/ProjectBundle.js +21 -6
  44. package/dist/project/ProjectMigration.d.ts.map +1 -1
  45. package/dist/project/ProjectMigration.js +20 -4
  46. package/dist/project/ProjectValidation.d.ts.map +1 -1
  47. package/dist/project/ProjectValidation.js +15 -13
  48. package/dist/project/audio/AudioContentFactory.d.ts.map +1 -1
  49. package/dist/project/audio/AudioContentFactory.js +3 -3
  50. package/dist/project/audio/AudioContentModifier.d.ts.map +1 -1
  51. package/dist/project/audio/AudioContentModifier.js +15 -3
  52. package/dist/project/audio/AudioFileBoxFactory.d.ts.map +1 -1
  53. package/dist/project/audio/AudioFileBoxFactory.js +5 -0
  54. package/dist/samples/DefaultSampleLoader.d.ts.map +1 -1
  55. package/dist/samples/DefaultSampleLoader.js +8 -4
  56. package/dist/samples/DefaultSampleLoaderManager.d.ts.map +1 -1
  57. package/dist/samples/DefaultSampleLoaderManager.js +5 -2
  58. package/dist/soundfont/DefaultSoundfontLoader.d.ts.map +1 -1
  59. package/dist/soundfont/DefaultSoundfontLoader.js +16 -11
  60. package/dist/soundfont/SoundfontService.d.ts.map +1 -1
  61. package/dist/soundfont/SoundfontService.js +3 -6
  62. package/dist/ui/RegionClipResolver.d.ts.map +1 -1
  63. package/dist/ui/RegionClipResolver.js +15 -6
  64. package/dist/ui/RegionModifyStrategies.js +3 -3
  65. package/dist/ui/TimeGrid.d.ts +2 -1
  66. package/dist/ui/TimeGrid.d.ts.map +1 -1
  67. package/dist/ui/TimeGrid.js +28 -14
  68. package/dist/workers-main.js +1 -1
  69. package/dist/workers-main.js.map +3 -3
  70. package/package.json +16 -16
@@ -15,9 +15,9 @@ export var RegionModifyStrategy;
15
15
  (function (RegionModifyStrategy) {
16
16
  RegionModifyStrategy.Identity = Object.freeze({
17
17
  readPosition: (region) => region.position,
18
- readComplete: (region) => region.complete,
19
- readLoopOffset: (region) => region.loopOffset,
20
- readLoopDuration: (region) => region.loopDuration,
18
+ readComplete: (region) => region.resolveComplete(region.position),
19
+ readLoopOffset: (region) => region.resolveLoopOffset(region.position),
20
+ readLoopDuration: (region) => region.resolveLoopDuration(region.position),
21
21
  readMirror: (region) => region.isMirrowed,
22
22
  translateTrackIndex: (value) => value,
23
23
  iterateRange: (regions, from, to) => regions.iterateRange(from, to)
@@ -1,5 +1,6 @@
1
1
  import { int } from "@opendaw/lib-std";
2
2
  import { TimelineRange } from "./TimelineRange";
3
+ import { SignatureTrackAdapter } from "@opendaw/studio-adapters";
3
4
  export declare namespace TimeGrid {
4
5
  type Signature = [int, int];
5
6
  type Options = {
@@ -14,6 +15,6 @@ export declare namespace TimeGrid {
14
15
  pulse: number;
15
16
  };
16
17
  type Designer = (fragment: Fragment) => void;
17
- const fragment: ([nominator, denominator]: Signature, range: TimelineRange, designer: Designer, options?: Options) => void;
18
+ const fragment: (signatureTrack: SignatureTrackAdapter, range: TimelineRange, designer: Designer, options?: Options) => void;
18
19
  }
19
20
  //# sourceMappingURL=TimeGrid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TimeGrid.d.ts","sourceRoot":"","sources":["../../src/ui/TimeGrid.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAgB,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAE7C,yBAAiB,QAAQ,CAAC;IACtB,KAAY,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAClC,KAAY,OAAO,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,KAAY,QAAQ,GAAG;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5G,KAAY,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAA;IAE5C,MAAM,QAAQ,GAAI,0BAA0B,SAAS,EACnC,OAAO,aAAa,EAAE,UAAU,QAAQ,EAAE,UAAU,OAAO,KAAG,IA4DtF,CAAA;CACJ"}
1
+ {"version":3,"file":"TimeGrid.d.ts","sourceRoot":"","sources":["../../src/ui/TimeGrid.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAuB,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAC,qBAAqB,EAAC,MAAM,0BAA0B,CAAA;AAE9D,yBAAiB,QAAQ,CAAC;IACtB,KAAY,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAClC,KAAY,OAAO,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,KAAY,QAAQ,GAAG;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5G,KAAY,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAA;IA8C5C,MAAM,QAAQ,GAAI,gBAAgB,qBAAqB,EACrC,OAAO,aAAa,EAAE,UAAU,QAAQ,EAAE,UAAU,OAAO,KAAG,IAmBtF,CAAA;CACJ"}
@@ -1,15 +1,10 @@
1
1
  import { PPQN } from "@opendaw/lib-dsp";
2
- import { quantizeFloor } from "@opendaw/lib-std";
2
+ import { isDefined, Iterables } from "@opendaw/lib-std";
3
3
  export var TimeGrid;
4
4
  (function (TimeGrid) {
5
- TimeGrid.fragment = ([nominator, denominator], range, designer, options) => {
6
- const unitsPerPixel = range.unitsPerPixel;
7
- if (unitsPerPixel <= 0) {
8
- return;
9
- }
5
+ const computeInterval = (nominator, denominator, unitsPerPixel, minLength) => {
10
6
  const barPulses = PPQN.fromSignature(nominator, denominator);
11
7
  const beatPulses = PPQN.fromSignature(1, denominator);
12
- const minLength = options?.minLength ?? 48;
13
8
  let interval = barPulses;
14
9
  let pixel = interval / unitsPerPixel;
15
10
  if (pixel > minLength) {
@@ -62,13 +57,32 @@ export var TimeGrid;
62
57
  pixel = interval / unitsPerPixel;
63
58
  }
64
59
  }
65
- const p0 = quantizeFloor(range.unitMin, interval);
66
- const p1 = range.unitMax;
67
- for (let pulse = p0; pulse < p1; pulse += interval) {
68
- const { bars, beats, semiquavers, ticks } = PPQN.toParts(pulse, nominator, denominator);
69
- const isBeat = ticks === 0 && semiquavers === 0;
70
- const isBar = isBeat && beats === 0;
71
- designer({ bars, beats, ticks, isBar, isBeat, pulse });
60
+ return interval;
61
+ };
62
+ TimeGrid.fragment = (signatureTrack, range, designer, options) => {
63
+ const unitsPerPixel = range.unitsPerPixel;
64
+ if (unitsPerPixel <= 0) {
65
+ return;
66
+ }
67
+ const minLength = options?.minLength ?? 48;
68
+ for (const [prev, next] of Iterables.pairWise(signatureTrack.iterateAll())) {
69
+ const { accumulatedPpqn, accumulatedBars, nominator, denominator } = prev;
70
+ const interval = computeInterval(prev.nominator, prev.denominator, unitsPerPixel, minLength);
71
+ const barDuration = PPQN.fromSignature(nominator, denominator);
72
+ const p0 = accumulatedPpqn;
73
+ const p1 = isDefined(next) ? next.accumulatedPpqn : range.unitMax;
74
+ for (let pulse = p0; pulse < p1; pulse += interval) {
75
+ if (pulse < range.unitMin - barDuration) {
76
+ continue;
77
+ }
78
+ if (pulse >= range.unitMax) {
79
+ break;
80
+ }
81
+ const { bars, beats, semiquavers, ticks } = PPQN.toParts(pulse - accumulatedPpqn, nominator, denominator);
82
+ const isBeat = ticks === 0 && semiquavers === 0;
83
+ const isBar = isBeat && beats === 0;
84
+ designer({ bars: bars + accumulatedBars, beats, ticks, isBar, isBeat, pulse });
85
+ }
72
86
  }
73
87
  };
74
88
  })(TimeGrid || (TimeGrid = {}));
@@ -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 H=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 j=()=>{};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.tryCatch=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 G=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 W=Object.freeze({Empty:{terminate:j},create:o=>({terminate:o}),many:(...o)=>({terminate:()=>{for(;o.length>0;)o.pop().terminate()}})});var C=class{static subscribeMany(t,...e){return W.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:j}),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 H(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 D;(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)})})(D||(D={}));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(W.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 D.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.delay=(i,a)=>Promise.all([i,D.timeSpan(a)]).then(([c])=>c),o.fail=(i,a="fail")=>Promise.reject(a),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 k;(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 H(s)}}})(k||(k={}));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 k.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=G.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(0)}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),Y=Number.POSITIVE_INFINITY,U=Number.NEGATIVE_INFINITY,lt=0;for(let st=0;st<i;++st){let ht=L[st];if(Y=Math.min(ht,Y),U=Math.max(ht,U),(++lt&w)===0){for(let V=0;V<h;++V){let ft=f[V],N=St[V];N.min=Math.min(N.min,Y),N.max=Math.max(N.max,U),((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)}Y=Number.POSITIVE_INFINITY,U=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 k.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 z=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 z,f=new z,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