spessasynth_core 4.4.12 → 4.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -157,6 +157,17 @@ var IndexedByteArray = class extends Uint8Array {
157
157
  a.currentIndex = 0;
158
158
  return a;
159
159
  }
160
+ /**
161
+ * Gets a new IndexedByteArray view of the ArrayBuffer store for this array, referencing the elements
162
+ * at begin, inclusive, up to end, exclusive.
163
+ * @param begin The index of the beginning of the array.
164
+ * @param end The index of the end of the array.
165
+ * @privateRemarks
166
+ * JSDoc copied from es5 type declarations
167
+ */
168
+ subarray(begin, end) {
169
+ return super.subarray(begin, end);
170
+ }
160
171
  };
161
172
  // src/utils/byte_functions/string.ts
162
173
  /**
@@ -321,6 +332,7 @@ var RIFFChunk = class RIFFChunk {
321
332
  size;
322
333
  /**
323
334
  * Chunk's binary data. Note that this will have a length of 0 if "readData" was set to false.
335
+ * When read from a file, it is a view into the file's buffer.
324
336
  */
325
337
  data;
326
338
  /**
@@ -347,7 +359,7 @@ var RIFFChunk = class RIFFChunk {
347
359
  const header = readBinaryStringIndexed(dataArray, 4);
348
360
  let size = rf64 ? readLE64Indexed(dataArray, 8) : readLittleEndianIndexed(dataArray, 4);
349
361
  if (header === "") size = 0;
350
- const chunkData = readData ? dataArray.slice(dataArray.currentIndex, dataArray.currentIndex + size) : new IndexedByteArray(0);
362
+ const chunkData = readData ? dataArray.subarray(dataArray.currentIndex, dataArray.currentIndex + size) : new IndexedByteArray(0);
351
363
  if (readData) {
352
364
  dataArray.currentIndex += size;
353
365
  if (size % 2 !== 0) dataArray.currentIndex++;
@@ -2861,7 +2873,13 @@ var MIDIPatchTools = class MIDIPatchTools {
2861
2873
  returnReplacement(patches[0]);
2862
2874
  return patches[0];
2863
2875
  }
2864
- if (!isXG) {
2876
+ if (isXG) {
2877
+ p = (bankMSB === 0 && bankLSB !== 48 && bankLSB !== 64 && bankLSB !== 126 && !matchingPrograms.some((p) => p.bankMSB === 0 && p.bankLSB !== 0) ? matchingPrograms.find((p) => p.bankMSB === bankLSB && p.bankLSB === 0) : void 0) ?? (bankMSB === 64 || bankMSB === 126 ? matchingPrograms.find((p) => p.bankMSB === bankMSB && p.bankLSB === 0) : void 0) ?? matchingPrograms.find((p) => p.bankMSB === BankSelectHacks.getDefaultBank(system) && p.bankLSB === 0) ?? matchingPrograms.find((p) => p.bankMSB === 0 && p.bankLSB === 0);
2878
+ if (p) {
2879
+ returnReplacement(p);
2880
+ return p;
2881
+ }
2882
+ } else {
2865
2883
  p = matchingPrograms.find((p) => p.bankMSB === 0 && p.bankLSB === bankLSB);
2866
2884
  if (p) {
2867
2885
  returnReplacement(p);
@@ -6469,7 +6487,7 @@ function parseRMIDIInternal(outputMIDI, binaryData, fileName) {
6469
6487
  while (currentChunk.data.currentIndex < currentChunk.size) {
6470
6488
  const infoChunk = RIFFChunk.read(currentChunk.data);
6471
6489
  const headerTyped = infoChunk.header;
6472
- const infoData = infoChunk.data;
6490
+ const infoData = infoChunk.data.slice();
6473
6491
  if (infoChunk.size === 0) {
6474
6492
  SpessaLog.warn(`Discarding empty RMIDI Info: ${headerTyped}`);
6475
6493
  continue;
@@ -8302,9 +8320,9 @@ const BUILT_IN_CURVES = [
8302
8320
  ];
8303
8321
  const UNRESOLVED_CURVES = /* @__PURE__ */ new Map();
8304
8322
  // src/soundbank/basic_soundbank/custom_curve.ts
8305
- const GRID_POSITIONS = [.../* @__PURE__ */ new Set([...SOURCE_VALUE_7_BIT, ...Array.from(SOURCE_VALUE_7_BIT, (x) => 16384 - x)])];
8306
- const GRID_SLOT = (/* @__PURE__ */ new Int16Array(16385)).fill(-1);
8307
- for (const [slot, x] of GRID_POSITIONS.entries()) GRID_SLOT[x] = slot;
8323
+ const START_SIZE = 33;
8324
+ let packedForConstructor;
8325
+ const POINTS_CACHE = /* @__PURE__ */ new WeakMap();
8308
8326
  /**
8309
8327
  * A modulator source curve stored in an SFe bank (curve type 4).
8310
8328
  * The value between two points is linearly interpolated.
@@ -8332,22 +8350,19 @@ var CustomCurve = class CustomCurve extends ModulatorCurve {
8332
8350
  * > Duplicate entries are allowed since one element can use the same curve multiple times.
8333
8351
  */
8334
8352
  linkedTo = new Array();
8335
- storedPoints;
8336
- px = /* @__PURE__ */ new Int32Array(0);
8337
- py = /* @__PURE__ */ new Float64Array(0);
8338
- start = /* @__PURE__ */ new Int32Array(129);
8339
- gridUnipolar = new Float32Array(GRID_POSITIONS.length);
8340
- gridBipolar = new Float32Array(GRID_POSITIONS.length);
8353
+ data;
8341
8354
  /**
8342
8355
  * Creates a new custom curve.
8343
- * @param points The points, ordered by `x`. At least two are needed.
8356
+ * @param points The points, ordered by `x`. At least two and at most 65,535 are needed.
8344
8357
  * @param name The name of the curve.
8345
8358
  */
8346
8359
  constructor(points, name = "") {
8347
8360
  super(ModulatorCurveTypes.custom);
8348
8361
  this.name = name;
8349
- this.storedPoints = CustomCurve.checkPoints(points);
8350
- this.precompute();
8362
+ if (packedForConstructor) {
8363
+ this.data = packedForConstructor;
8364
+ packedForConstructor = void 0;
8365
+ } else this.data = CustomCurve.pack(points);
8351
8366
  }
8352
8367
  /**
8353
8368
  * The number of modulator sources using this curve.
@@ -8359,18 +8374,87 @@ var CustomCurve = class CustomCurve extends ModulatorCurve {
8359
8374
  * The curve points, ordered by `x`. They are frozen, use {@link setPoints} to change them.
8360
8375
  */
8361
8376
  get points() {
8362
- return this.storedPoints;
8377
+ let points = POINTS_CACHE.get(this);
8378
+ if (!points) {
8379
+ const count = this.pointCount;
8380
+ const list = new Array(count);
8381
+ for (let i = 0; i < count; i++) list[i] = Object.freeze({
8382
+ x: this.data[START_SIZE + i],
8383
+ y: this.data[START_SIZE + count + i]
8384
+ });
8385
+ points = Object.freeze(list);
8386
+ POINTS_CACHE.set(this, points);
8387
+ }
8388
+ return points;
8389
+ }
8390
+ /**
8391
+ * The number of points in the curve.
8392
+ * @privateRemarks
8393
+ * Unlike `points.length`, it does not build the points list.
8394
+ */
8395
+ get pointCount() {
8396
+ return this.data.length - START_SIZE >> 1;
8397
+ }
8398
+ /**
8399
+ * Reads a curve's points from its record in the CURV chunk, without making point objects.
8400
+ * @param data The chunk data, at the first point.
8401
+ * @param pointCount The number of points in the record.
8402
+ * @param name The name of the curve.
8403
+ * @returns The curve.
8404
+ * @throws Error if the points are invalid. The data's index is then left inside the record.
8405
+ * @internal
8406
+ */
8407
+ static read(data, pointCount, name) {
8408
+ const packed = new Uint16Array(START_SIZE + 2 * pointCount);
8409
+ for (let i = 0; i < pointCount; i++) {
8410
+ const x = readLittleEndianIndexed(data, 2);
8411
+ const y = readLittleEndianIndexed(data, 2);
8412
+ if (x > 16384 || y > 16384) throw new Error(`Custom curve point ${i} (${x}, ${y}) is out of range!`);
8413
+ packed[START_SIZE + i] = x;
8414
+ packed[START_SIZE + pointCount + i] = y;
8415
+ }
8416
+ CustomCurve.finishPacked(packed);
8417
+ return CustomCurve.fromPacked(packed, name);
8363
8418
  }
8364
- static checkPoints(points) {
8365
- if (points.length < 2) throw new Error(`A custom curve needs at least 2 points, got ${points.length}.`);
8366
- for (const [i, { x, y }] of points.entries()) {
8419
+ /**
8420
+ * Copies a curve. The copy shares the packed points, since they are never changed in place.
8421
+ * @param curve The curve to copy.
8422
+ * @returns The copy, with the same name and points and no users.
8423
+ * @internal
8424
+ */
8425
+ static copyFrom(curve) {
8426
+ return CustomCurve.fromPacked(curve.data, curve.name);
8427
+ }
8428
+ static fromPacked(data, name) {
8429
+ packedForConstructor = data;
8430
+ return new CustomCurve([], name);
8431
+ }
8432
+ static pack(points) {
8433
+ if (points.length > 65535) throw new Error(`A custom curve can have at most 65535 points, got ${points.length}.`);
8434
+ const count = points.length;
8435
+ const data = new Uint16Array(START_SIZE + 2 * count);
8436
+ for (let i = 0; i < count; i++) {
8437
+ const { x, y } = points[i];
8367
8438
  if (!Number.isInteger(x) || !Number.isInteger(y) || x < 0 || x > 16384 || y < 0 || y > 16384) throw new Error(`Custom curve point ${i} (${x}, ${y}) is out of range.`);
8368
- if (i > 0 && x < points[i - 1].x) throw new Error(`Custom curve point ${i} goes back in x (${points[i - 1].x} to ${x}).`);
8439
+ data[START_SIZE + i] = x;
8440
+ data[START_SIZE + count + i] = y;
8441
+ }
8442
+ CustomCurve.finishPacked(data);
8443
+ return data;
8444
+ }
8445
+ static finishPacked(data) {
8446
+ const count = data.length - START_SIZE >> 1;
8447
+ if (count < 2) throw new Error(`A custom curve needs at least 2 points, got ${count}.`);
8448
+ for (let i = 1; i < count; i++) {
8449
+ const x = data[START_SIZE + i];
8450
+ if (x < data[START_SIZE + i - 1]) throw new Error(`Custom curve point ${i} goes back in x (${data[START_SIZE + i - 1]} to ${x}).`);
8451
+ }
8452
+ let i = -1;
8453
+ for (let c = 0; c < START_SIZE; c++) {
8454
+ const x = c * 512;
8455
+ while (i < count - 1 && data[START_SIZE + i + 1] <= x) i++;
8456
+ data[c] = i + 1;
8369
8457
  }
8370
- return Object.freeze(points.map((p) => Object.freeze({
8371
- x: p.x,
8372
- y: p.y
8373
- })));
8374
8458
  }
8375
8459
  /**
8376
8460
  * Links the curve to an element that uses it.
@@ -8395,12 +8479,12 @@ var CustomCurve = class CustomCurve extends ModulatorCurve {
8395
8479
  }
8396
8480
  /**
8397
8481
  * Replaces the points of the curve. Every modulator using this curve follows the change.
8398
- * @param points The new points, ordered by `x`. At least two are needed.
8482
+ * @param points The new points, ordered by `x`. At least two and at most 65,535 are needed.
8399
8483
  * @throws Error if the points are invalid. The curve is left unchanged then.
8400
8484
  */
8401
8485
  setPoints(points) {
8402
- this.storedPoints = CustomCurve.checkPoints(points);
8403
- this.precompute();
8486
+ this.data = CustomCurve.pack(points);
8487
+ POINTS_CACHE.delete(this);
8404
8488
  }
8405
8489
  /**
8406
8490
  * Checks if two curves have the same points.
@@ -8409,8 +8493,12 @@ var CustomCurve = class CustomCurve extends ModulatorCurve {
8409
8493
  isIdentical(other) {
8410
8494
  if (other === this) return true;
8411
8495
  if (!(other instanceof CustomCurve)) return false;
8412
- if (other.points.length !== this.points.length) return false;
8413
- return this.points.every((p, i) => p.x === other.points[i].x && p.y === other.points[i].y);
8496
+ const a = this.data;
8497
+ const b = other.data;
8498
+ if (a === b) return true;
8499
+ if (a.length !== b.length) return false;
8500
+ for (let i = START_SIZE; i < a.length; i++) if (a[i] !== b[i]) return false;
8501
+ return true;
8414
8502
  }
8415
8503
  /**
8416
8504
  * Gets the curve's `y` for a source value.
@@ -8420,14 +8508,23 @@ var CustomCurve = class CustomCurve extends ModulatorCurve {
8420
8508
  * @internal
8421
8509
  */
8422
8510
  getY(x) {
8423
- const px = this.px;
8424
- const last = px.length - 1;
8425
- let i = this.start[x >> 7];
8426
- while (i < last && px[i + 1] <= x) i++;
8427
- if (i < 0) return this.py[0];
8428
- if (i === last) return this.py[last];
8429
- const ay = this.py[i];
8430
- return ay + (this.py[i + 1] - ay) * (x - px[i]) / (px[i + 1] - px[i]);
8511
+ const data = this.data;
8512
+ const count = data.length - START_SIZE >> 1;
8513
+ const last = count - 1;
8514
+ const ys = START_SIZE + count;
8515
+ const bucket = x >> 9;
8516
+ let i = data[bucket] - 1;
8517
+ let high = bucket < 32 ? data[bucket + 1] - 1 : last;
8518
+ while (i < high) {
8519
+ const middle = i + high + 1 >> 1;
8520
+ if (data[START_SIZE + middle] <= x) i = middle;
8521
+ else high = middle - 1;
8522
+ }
8523
+ if (i < 0) return data[ys];
8524
+ if (i === last) return data[ys + last];
8525
+ const ax = data[START_SIZE + i];
8526
+ const ay = data[ys + i];
8527
+ return ay + (data[ys + i + 1] - ay) * (x - ax) / (data[START_SIZE + i + 1] - ax);
8431
8528
  }
8432
8529
  /**
8433
8530
  * Gets the output of a source using this curve.
@@ -8439,33 +8536,29 @@ var CustomCurve = class CustomCurve extends ModulatorCurve {
8439
8536
  */
8440
8537
  getValue(raw, isBipolar, isNegative) {
8441
8538
  const x = isNegative ? 16384 - raw : raw;
8442
- const slot = GRID_SLOT[x];
8443
- if (slot >= 0) return isBipolar ? this.gridBipolar[slot] : this.gridUnipolar[slot];
8444
8539
  const y = this.getY(x);
8445
8540
  return Math.fround(isBipolar ? (y - 8192) / 8192 : y / 16384);
8446
8541
  }
8447
8542
  toString() {
8448
- return this.name || `Custom curve (${this.points.length} points)`;
8543
+ return this.name || `Custom curve (${this.pointCount} points)`;
8544
+ }
8545
+ /**
8546
+ * Writes the curve's record of the CURV chunk: the name, the point count and the points.
8547
+ * @param data The array to write to.
8548
+ * @internal
8549
+ */
8550
+ write(data) {
8551
+ const count = this.pointCount;
8552
+ writeBinaryStringIndexed(data, this.name, 40);
8553
+ writeWord(data, count);
8554
+ for (let i = 0; i < count; i++) {
8555
+ writeWord(data, this.data[START_SIZE + i]);
8556
+ writeWord(data, this.data[START_SIZE + count + i]);
8557
+ }
8449
8558
  }
8450
8559
  evaluate(value, isBipolar) {
8451
8560
  return this.getValue(Math.round(value * 16384), isBipolar, false);
8452
8561
  }
8453
- precompute() {
8454
- const points = this.storedPoints;
8455
- this.px = Int32Array.from(points, (p) => p.x);
8456
- this.py = Float64Array.from(points, (p) => p.y);
8457
- let i = -1;
8458
- for (let c = 0; c <= 128; c++) {
8459
- const x = c * 128;
8460
- while (i < points.length - 1 && points[i + 1].x <= x) i++;
8461
- this.start[c] = i;
8462
- }
8463
- for (const [slot, x] of GRID_POSITIONS.entries()) {
8464
- const y = this.getY(x);
8465
- this.gridUnipolar[slot] = y / 16384;
8466
- this.gridBipolar[slot] = (y - 8192) / 8192;
8467
- }
8468
- }
8469
8562
  };
8470
8563
  // src/soundbank/basic_soundbank/modulator_source.ts
8471
8564
  /**
@@ -8581,7 +8674,7 @@ var ModulatorSource = class ModulatorSource {
8581
8674
  */
8582
8675
  static copyFrom(source) {
8583
8676
  const curve = source.curve;
8584
- return new ModulatorSource(source.index, curve instanceof CustomCurve && Object.isFrozen(curve) ? new CustomCurve(curve.points, curve.name) : curve, source.isCC, source.isBipolar, source.isNegative);
8677
+ return new ModulatorSource(source.index, curve instanceof CustomCurve && Object.isFrozen(curve) ? CustomCurve.copyFrom(curve) : curve, source.isCC, source.isBipolar, source.isNegative);
8585
8678
  }
8586
8679
  toString() {
8587
8680
  return `${this.sourceName} ${this.curve.toString()} ${this.isBipolar ? "bipolar" : "unipolar"} ${this.isNegative ? "negative" : "positive"}`;
@@ -8966,7 +9059,7 @@ function copyWithOwnCurves(modulators) {
8966
9059
  if (!(curve instanceof CustomCurve)) return ModulatorSource.copyFrom(source);
8967
9060
  let own = curves.get(curve);
8968
9061
  if (!own) {
8969
- own = new CustomCurve(curve.points, curve.name);
9062
+ own = CustomCurve.copyFrom(curve);
8970
9063
  curves.set(curve, own);
8971
9064
  }
8972
9065
  return new ModulatorSource(source.index, own, source.isCC, source.isBipolar, source.isNegative);
@@ -10458,10 +10551,7 @@ function writeSF(bank, format, software, writeDefaultModulators, writeExtendedLi
10458
10551
  let curveIndex;
10459
10552
  if (isSFe) {
10460
10553
  const indexes = /* @__PURE__ */ new Map();
10461
- for (const [i, curve] of curves.entries()) {
10462
- if (curve.points.length > 65535) throw new Error(`The custom curve "${curve.toString()}" has too many points: ${curve.points.length}, the maximum is 65535.`);
10463
- indexes.set(curve, i);
10464
- }
10554
+ for (const [i, curve] of curves.entries()) indexes.set(curve, i);
10465
10555
  curveIndex = (curve) => {
10466
10556
  const index = indexes.get(curve);
10467
10557
  if (index === void 0) throw new Error(`The custom curve "${curve.toString()}" is used by a modulator but is not in the bank's customCurves.`);
@@ -10484,16 +10574,9 @@ function writeSF(bank, format, software, writeDefaultModulators, writeExtendedLi
10484
10574
  }
10485
10575
  if (curves.length > 0) {
10486
10576
  SpessaLog.info(`%cWriting %c${curves.length}%c custom curves...`, ConsoleColors.info, ConsoleColors.recognized, ConsoleColors.info);
10487
- const curvData = new IndexedByteArray(4 + curves.reduce((sum, c) => sum + 42 + c.points.length * 4, 0));
10577
+ const curvData = new IndexedByteArray(4 + curves.reduce((sum, c) => sum + 42 + c.pointCount * 4, 0));
10488
10578
  writeDword(curvData, curves.length);
10489
- for (const c of curves) {
10490
- writeBinaryStringIndexed(curvData, c.name, 40);
10491
- writeWord(curvData, c.points.length);
10492
- for (const p of c.points) {
10493
- writeWord(curvData, p.x);
10494
- writeWord(curvData, p.y);
10495
- }
10496
- }
10579
+ for (const c of curves) c.write(curvData);
10497
10580
  infoArrays.push(...RIFFChunk.getParts("CURV", [curvData], rf64));
10498
10581
  }
10499
10582
  SpessaLog.groupEnd();
@@ -10938,7 +11021,7 @@ var DownloadableSoundsSample = class DownloadableSoundsSample extends DLSVerifie
10938
11021
  const bytesPerSample = readLittleEndianIndexed(fmtChunk.data, 2) / 8;
10939
11022
  const dataChunk = chunks.find((c) => c.header === "data");
10940
11023
  if (!dataChunk) throw new Error("No data chunk in the WAVE chunk!");
10941
- const sample = new DownloadableSoundsSample(wFormatTag, bytesPerSample, sampleRate, dataChunk);
11024
+ const sample = new DownloadableSoundsSample(wFormatTag, bytesPerSample, sampleRate, new RIFFChunk("data", dataChunk.size, dataChunk.data.slice()));
10942
11025
  const waveInfo = RIFFChunk.findListType(chunks, "INFO");
10943
11026
  if (waveInfo) {
10944
11027
  let infoChunk = RIFFChunk.read(waveInfo.data);
@@ -12373,6 +12456,12 @@ var SoundBankCloner = class {
12373
12456
  curveClones = /* @__PURE__ */ new Map();
12374
12457
  instrumentClones = /* @__PURE__ */ new Map();
12375
12458
  /**
12459
+ * The names in the bank and the ones this session gave out, by element kind, built on first use.
12460
+ * A name changed or added in the bank from outside between two clone calls of one session is not seen,
12461
+ * The worst case is a repeated name, which banks allow
12462
+ */
12463
+ takenNames = /* @__PURE__ */ new Map();
12464
+ /**
12376
12465
  * Creates a new clone session.
12377
12466
  * @param bank The bank to clone elements into.
12378
12467
  * @param options The options for this session.
@@ -12433,11 +12522,11 @@ var SoundBankCloner = class {
12433
12522
  * @returns The clone, or the existing preset with the same name if it is reused.
12434
12523
  */
12435
12524
  clonePreset(preset) {
12436
- const all = [...this.bank.presets, ...this.created.presets];
12437
- const existing = this.findReused(preset, all, this.ownReuse);
12525
+ const lists = [this.bank.presets, this.created.presets];
12526
+ const existing = this.findReused(preset, lists, this.ownReuse);
12438
12527
  if (existing) return existing;
12439
12528
  const newPreset = new BasicPreset(this.bank);
12440
- newPreset.name = this.getFreeName(preset.name, all);
12529
+ newPreset.name = this.getFreeName(preset.name, "presets", lists);
12441
12530
  newPreset.bankMSB = preset.bankMSB;
12442
12531
  newPreset.bankLSB = preset.bankLSB;
12443
12532
  newPreset.isGMGSDrum = preset.isGMGSDrum;
@@ -12459,11 +12548,11 @@ var SoundBankCloner = class {
12459
12548
  copyInstrument(instrument, reuse) {
12460
12549
  const cloned = this.instrumentClones.get(instrument);
12461
12550
  if (cloned) return cloned;
12462
- const all = [...this.bank.instruments, ...this.created.instruments];
12463
- const existing = this.findReused(instrument, all, reuse);
12551
+ const lists = [this.bank.instruments, this.created.instruments];
12552
+ const existing = this.findReused(instrument, lists, reuse);
12464
12553
  if (existing) return existing;
12465
12554
  const newInstrument = new BasicInstrument();
12466
- newInstrument.name = this.getFreeName(instrument.name, all);
12555
+ newInstrument.name = this.getFreeName(instrument.name, "instruments", lists);
12467
12556
  newInstrument.globalZone.copyFrom(instrument.globalZone);
12468
12557
  this.cloneCurvesOf(newInstrument.globalZone.modulators);
12469
12558
  for (const zone of instrument.zones) {
@@ -12479,10 +12568,10 @@ var SoundBankCloner = class {
12479
12568
  copySample(sample, reuse) {
12480
12569
  const cloned = this.sampleClones.get(sample);
12481
12570
  if (cloned) return cloned;
12482
- const all = [...this.bank.samples, ...this.created.samples];
12483
- const existing = this.findReused(sample, all, reuse);
12571
+ const lists = [this.bank.samples, this.created.samples];
12572
+ const existing = this.findReused(sample, lists, reuse);
12484
12573
  if (existing) return existing;
12485
- const newSample = new BasicSample(this.getFreeName(sample.name, all), sample.sampleRate, sample.originalKey, sample.pitchCorrection, sample.sampleType, sample.loopStart, sample.loopEnd);
12574
+ const newSample = new BasicSample(this.getFreeName(sample.name, "samples", lists), sample.sampleRate, sample.originalKey, sample.pitchCorrection, sample.sampleType, sample.loopStart, sample.loopEnd);
12486
12575
  if (sample.hasData) newSample.setStoredData(sample.getStoredData());
12487
12576
  else {
12488
12577
  const form = sample.storedForm;
@@ -12502,32 +12591,52 @@ var SoundBankCloner = class {
12502
12591
  copyCurve(curve, reuse) {
12503
12592
  const cloned = this.curveClones.get(curve);
12504
12593
  if (cloned) return cloned;
12505
- const all = [...this.bank.customCurves, ...this.created.customCurves];
12506
- const existing = reuse === "name" ? all.find((c) => c.name === curve.name && c.isIdentical(curve)) : this.findReused(curve, all, reuse);
12594
+ const lists = [this.bank.customCurves, this.created.customCurves];
12595
+ let existing;
12596
+ if (reuse === "name") for (const list of lists) {
12597
+ existing = list.find((c) => c.name === curve.name && c.isIdentical(curve));
12598
+ if (existing) break;
12599
+ }
12600
+ else existing = this.findReused(curve, lists, reuse);
12507
12601
  if (existing) return existing;
12508
- const newCurve = new CustomCurve(curve.points, curve.name);
12602
+ const newCurve = CustomCurve.copyFrom(curve);
12509
12603
  this.curveClones.set(curve, newCurve);
12510
12604
  this.created.customCurves.push(newCurve);
12511
- if (this.options.addToBank) this.bank.addCustomCurves(newCurve);
12605
+ if (this.options.addToBank) this.bank.customCurves.push(newCurve);
12512
12606
  return newCurve;
12513
12607
  }
12514
12608
  /**
12515
12609
  * Finds the element to use instead of a copy, if the options allow one.
12610
+ * The lists are searched in order, without joining them, as this runs for every cloned element.
12516
12611
  */
12517
- findReused(element, elements, reuse) {
12612
+ findReused(element, lists, reuse) {
12518
12613
  switch (reuse) {
12519
12614
  case "none": return;
12520
- case "identity": return elements.includes(element) ? element : void 0;
12521
- case "name": return elements.find((e) => e.name === element.name);
12615
+ case "identity": return lists.some((list) => list.includes(element)) ? element : void 0;
12616
+ case "name":
12617
+ for (const list of lists) {
12618
+ const found = list.find((e) => e.name === element.name);
12619
+ if (found) return found;
12620
+ }
12621
+ return;
12522
12622
  }
12523
12623
  }
12524
- getFreeName(name, elements) {
12525
- const taken = new Set(elements.map((e) => e.name));
12526
- if (!taken.has(name)) return name;
12527
- const base = name.slice(0, MAX_BASE_NAME_LENGTH);
12528
- let count = 1;
12529
- while (taken.has(`${base}-${count}`)) count++;
12530
- return `${base}-${count}`;
12624
+ getFreeName(name, kind, lists) {
12625
+ let taken = this.takenNames.get(kind);
12626
+ if (!taken) {
12627
+ taken = /* @__PURE__ */ new Set();
12628
+ for (const list of lists) for (const e of list) taken.add(e.name);
12629
+ this.takenNames.set(kind, taken);
12630
+ }
12631
+ let free = name;
12632
+ if (taken.has(name)) {
12633
+ const base = name.slice(0, MAX_BASE_NAME_LENGTH);
12634
+ let count = 1;
12635
+ while (taken.has(`${base}-${count}`)) count++;
12636
+ free = `${base}-${count}`;
12637
+ }
12638
+ taken.add(free);
12639
+ return free;
12531
12640
  }
12532
12641
  };
12533
12642
  // src/soundbank/basic_soundbank/basic_soundbank.ts
@@ -12761,10 +12870,10 @@ var BasicSoundBank = class BasicSoundBank {
12761
12870
  * and adds the custom curves they use. The curves that only the old list used are removed.
12762
12871
  */
12763
12872
  resetDefaultModulators() {
12764
- const oldCurves = new Array();
12873
+ const oldCurves = /* @__PURE__ */ new Set();
12765
12874
  collectCurves(this.defaultModulators, oldCurves);
12766
12875
  this.defaultModulators = [];
12767
- this.customCurves = this.customCurves.filter((c) => !oldCurves.includes(c) || c.useCount > 0);
12876
+ this.customCurves = this.customCurves.filter((c) => !oldCurves.has(c) || c.useCount > 0);
12768
12877
  const defaults = copyDefaultModulators();
12769
12878
  this.addCustomCurves(...defaults.curves);
12770
12879
  this.defaultModulators = defaults.modulators;
@@ -12781,7 +12890,7 @@ var BasicSoundBank = class BasicSoundBank {
12781
12890
  const sampleList = [];
12782
12891
  for (const instrument of instrumentList) for (const zone of instrument.zones) if (zone.sample && !sampleList.includes(zone.sample)) sampleList.push(zone.sample);
12783
12892
  this.addElements(this.samples, sampleList);
12784
- const curveList = new Array();
12893
+ const curveList = /* @__PURE__ */ new Set();
12785
12894
  for (const element of [...presets, ...instrumentList]) {
12786
12895
  collectCurves(element.globalZone.modulators, curveList);
12787
12896
  for (const zone of element.zones) collectCurves(zone.modulators, curveList);
@@ -12793,7 +12902,11 @@ var BasicSoundBank = class BasicSoundBank {
12793
12902
  * @param curves The curves to add.
12794
12903
  */
12795
12904
  addCustomCurves(...curves) {
12796
- for (const curve of curves) if (!this.customCurves.includes(curve)) this.customCurves.push(curve);
12905
+ const present = new Set(this.customCurves);
12906
+ for (const curve of curves) if (!present.has(curve)) {
12907
+ present.add(curve);
12908
+ this.customCurves.push(curve);
12909
+ }
12797
12910
  }
12798
12911
  /**
12799
12912
  * Deletes a given custom curve from the sound bank.
@@ -13079,11 +13192,10 @@ var BasicSoundBank = class BasicSoundBank {
13079
13192
  if (deletable) s.unlinkSample();
13080
13193
  return !deletable;
13081
13194
  });
13082
- const used = new Array();
13195
+ const used = /* @__PURE__ */ new Set();
13083
13196
  collectCurves(this.defaultModulators, used);
13084
13197
  for (const element of [...this.presets, ...this.instruments]) for (const zone of [element.globalZone, ...element.zones]) collectCurves(zone.modulators, used);
13085
- const usedSet = new Set(used);
13086
- this.customCurves = this.customCurves.filter((c) => usedSet.has(c));
13198
+ this.customCurves = this.customCurves.filter((c) => used.has(c));
13087
13199
  }
13088
13200
  /**
13089
13201
  * Deletes a given instrument from the sound bank.
@@ -13198,8 +13310,8 @@ var BasicSoundBank = class BasicSoundBank {
13198
13310
  } else SpessaLog.info(`%c${info}: %c${value.toLocaleString()}`, ConsoleColors.info, ConsoleColors.recognized);
13199
13311
  }
13200
13312
  };
13201
- function collectCurves(modulators, list) {
13202
- for (const m of modulators) for (const curve of [m.primarySource.curve, m.secondarySource.curve]) if (curve instanceof CustomCurve && !list.includes(curve)) list.push(curve);
13313
+ function collectCurves(modulators, set) {
13314
+ for (const m of modulators) for (const curve of [m.primarySource.curve, m.secondarySource.curve]) if (curve instanceof CustomCurve) set.add(curve);
13203
13315
  }
13204
13316
  // src/midi/read/tracker/types.ts
13205
13317
  /**
@@ -36404,6 +36516,285 @@ const GSInsertionControlSources = {
36404
36516
  */
36405
36517
  pitchBend: 113
36406
36518
  };
36519
+ // src/synthesizer/audio_engine/effects/gs/implementation/dsp/dattorro.ts
36520
+ /**
36521
+ * Dattorro Reverb Node
36522
+ * by khoin on GitHub, public domain.
36523
+ * https://github.com/khoin/DattorroReverbNode/
36524
+ * Adapted for spessasynth by spessasus.
36525
+ * Further optimized with micro optimizations, check tsx performance_test before changing
36526
+ *
36527
+ * This is the pre v4.4.11 GS reverb, tuned for Hall 2 by default. All its flaws and inconsistencies are preserved.
36528
+ * Mostly a copy of the original dattorro.ts
36529
+ * @internal
36530
+ */
36531
+ var DattorroReverb = class {
36532
+ preDelay = 0;
36533
+ preLPF = .5;
36534
+ decay = .5;
36535
+ gain = 1;
36536
+ inputDiffusion1 = .75;
36537
+ inputDiffusion2 = .625;
36538
+ decayDiffusion1 = .67;
36539
+ decayDiffusion2 = .69;
36540
+ damping = .1;
36541
+ excursionRate = .5;
36542
+ excursionDepth = .7;
36543
+ sampleRate;
36544
+ lp1 = 0;
36545
+ lp2 = 0;
36546
+ lp3 = 0;
36547
+ excPhase1 = 0;
36548
+ excPhase2 = 0;
36549
+ pDWrite = 0;
36550
+ taps;
36551
+ pDelay;
36552
+ pDMask;
36553
+ delayBuffers = new Array(12);
36554
+ delayWrite = /* @__PURE__ */ new Int32Array(12);
36555
+ delayRead = /* @__PURE__ */ new Int32Array(12);
36556
+ delayMask = /* @__PURE__ */ new Int32Array(12);
36557
+ constructor(sampleRate) {
36558
+ this.sampleRate = sampleRate;
36559
+ this.pDMask = 2 ** Math.ceil(Math.log2(sampleRate)) - 1;
36560
+ this.pDelay = new Float32Array(this.pDMask + 1);
36561
+ const delays = [
36562
+ .004771345,
36563
+ .003595309,
36564
+ .012734787,
36565
+ .009307483,
36566
+ .022579886,
36567
+ .149625349,
36568
+ .060481839,
36569
+ .1249958,
36570
+ .030509727,
36571
+ .141695508,
36572
+ .089244313,
36573
+ .106280031
36574
+ ];
36575
+ for (let i = 0; i < delays.length; i++) this.makeDelayLine(delays[i], i);
36576
+ this.taps = Int32Array.from([
36577
+ .008937872,
36578
+ .099929438,
36579
+ .064278754,
36580
+ .067067639,
36581
+ .066866033,
36582
+ .006283391,
36583
+ .035818689,
36584
+ .011861161,
36585
+ .121870905,
36586
+ .041262054,
36587
+ .08981553,
36588
+ .070931756,
36589
+ .011256342,
36590
+ .004065724
36591
+ ], (x) => Math.round(x * this.sampleRate));
36592
+ }
36593
+ clear() {
36594
+ this.pDelay.fill(0);
36595
+ for (const buffer of this.delayBuffers) buffer.fill(0);
36596
+ this.lp1 = 0;
36597
+ this.lp2 = 0;
36598
+ this.lp3 = 0;
36599
+ this.excPhase1 = 0;
36600
+ this.excPhase2 = 0;
36601
+ }
36602
+ process(input, outputLeft, outputRight, startIndex, sampleCount) {
36603
+ const pd = this.preDelay | 0;
36604
+ const fi = this.inputDiffusion1;
36605
+ const si = this.inputDiffusion2;
36606
+ const dc = this.decay;
36607
+ const ft = this.decayDiffusion1;
36608
+ const st = this.decayDiffusion2;
36609
+ const dp = 1 - this.damping;
36610
+ const ex = this.excursionRate / this.sampleRate;
36611
+ const ed = this.excursionDepth * this.sampleRate / 1e3;
36612
+ let lp1 = this.lp1, lp2 = this.lp2, lp3 = this.lp3;
36613
+ let p1 = this.excPhase1, p2 = this.excPhase2;
36614
+ const blockStart = this.pDWrite;
36615
+ const pDelay = this.pDelay;
36616
+ const pDMask = this.pDMask;
36617
+ const taps = this.taps;
36618
+ const gain = this.gain;
36619
+ const d0 = this.delayBuffers[0];
36620
+ let w0 = this.delayWrite[0], r0 = this.delayRead[0];
36621
+ const m0 = this.delayMask[0];
36622
+ const d1 = this.delayBuffers[1];
36623
+ let w1 = this.delayWrite[1], r1 = this.delayRead[1];
36624
+ const m1 = this.delayMask[1];
36625
+ const d2 = this.delayBuffers[2];
36626
+ let w2 = this.delayWrite[2], r2 = this.delayRead[2];
36627
+ const m2 = this.delayMask[2];
36628
+ const d3 = this.delayBuffers[3];
36629
+ let w3 = this.delayWrite[3], r3 = this.delayRead[3];
36630
+ const m3 = this.delayMask[3];
36631
+ const d4 = this.delayBuffers[4];
36632
+ let w4 = this.delayWrite[4], r4 = this.delayRead[4];
36633
+ const m4 = this.delayMask[4];
36634
+ const d5 = this.delayBuffers[5];
36635
+ let w5 = this.delayWrite[5], r5 = this.delayRead[5];
36636
+ const m5 = this.delayMask[5];
36637
+ const d6 = this.delayBuffers[6];
36638
+ let w6 = this.delayWrite[6], r6 = this.delayRead[6];
36639
+ const m6 = this.delayMask[6];
36640
+ const d7 = this.delayBuffers[7];
36641
+ let w7 = this.delayWrite[7], r7 = this.delayRead[7];
36642
+ const m7 = this.delayMask[7];
36643
+ const d8 = this.delayBuffers[8];
36644
+ let w8 = this.delayWrite[8], r8 = this.delayRead[8];
36645
+ const m8 = this.delayMask[8];
36646
+ const d9 = this.delayBuffers[9];
36647
+ let w9 = this.delayWrite[9], r9 = this.delayRead[9];
36648
+ const m9 = this.delayMask[9];
36649
+ const d10 = this.delayBuffers[10];
36650
+ let w10 = this.delayWrite[10], r10 = this.delayRead[10];
36651
+ const m10 = this.delayMask[10];
36652
+ const d11 = this.delayBuffers[11];
36653
+ let w11 = this.delayWrite[11], r11 = this.delayRead[11];
36654
+ const m11 = this.delayMask[11];
36655
+ const TWO_PI = 6.283185307179586;
36656
+ const preLPF = this.preLPF;
36657
+ const step1 = ex * TWO_PI;
36658
+ const step2 = ex * 6.2847;
36659
+ const stepCos1 = Math.cos(step1);
36660
+ const stepSin1 = Math.sin(step1);
36661
+ const stepCos2 = Math.cos(step2);
36662
+ const stepSin2 = Math.sin(step2);
36663
+ let cos1 = Math.cos(p1);
36664
+ let sin1 = Math.sin(p1);
36665
+ let cos2 = Math.cos(p2);
36666
+ let sin2 = Math.sin(p2);
36667
+ for (let i = 0; i < sampleCount; i++) {
36668
+ pDelay[blockStart + i & pDMask] = input[i];
36669
+ const inSample = pDelay[blockStart + i - pd & pDMask];
36670
+ lp1 += preLPF * (inSample - lp1);
36671
+ const read0 = d0[r0];
36672
+ let pre = lp1 - fi * read0;
36673
+ d0[w0] = pre;
36674
+ const read1 = d1[r1];
36675
+ pre = fi * (pre - read1) + read0;
36676
+ d1[w1] = pre;
36677
+ const read2 = d2[r2];
36678
+ pre = fi * pre + read1 - si * read2;
36679
+ d2[w2] = pre;
36680
+ const read3 = d3[r3];
36681
+ pre = si * (pre - read3) + read2;
36682
+ d3[w3] = pre;
36683
+ const split = si * pre + read3;
36684
+ const exc = ed * (1 + cos1);
36685
+ const exc2 = ed * (1 + sin2);
36686
+ const read11 = d11[r11];
36687
+ const f4 = exc - ~~exc;
36688
+ let i4 = ~~exc + r4 - 1;
36689
+ const x4_0 = d4[i4++ & m4], x4_1 = d4[i4++ & m4], x4_2 = d4[i4++ & m4], x4_3 = d4[i4 & m4];
36690
+ const a4 = (3 * (x4_1 - x4_2) - x4_0 + x4_3) * .5;
36691
+ const b4 = 2 * x4_2 + x4_0 - (5 * x4_1 + x4_3) * .5;
36692
+ const c4 = (x4_2 - x4_0) * .5;
36693
+ const readC4 = ((a4 * f4 + b4) * f4 + c4) * f4 + x4_1;
36694
+ let temp = split + dc * read11 + ft * readC4;
36695
+ d4[w4] = temp;
36696
+ d5[w5] = readC4 - ft * temp;
36697
+ const read5 = d5[r5];
36698
+ lp2 += dp * (read5 - lp2);
36699
+ const read6 = d6[r6];
36700
+ temp = dc * lp2 - st * read6;
36701
+ d6[w6] = temp;
36702
+ d7[w7] = read6 + st * temp;
36703
+ const read7 = d7[r7];
36704
+ const f8 = exc2 - ~~exc2;
36705
+ let i8 = ~~exc2 + r8 - 1;
36706
+ const x8_0 = d8[i8++ & m8], x8_1 = d8[i8++ & m8], x8_2 = d8[i8++ & m8], x8_3 = d8[i8 & m8];
36707
+ const a8 = (3 * (x8_1 - x8_2) - x8_0 + x8_3) * .5;
36708
+ const b8 = 2 * x8_2 + x8_0 - (5 * x8_1 + x8_3) * .5;
36709
+ const c8 = (x8_2 - x8_0) * .5;
36710
+ const readC8 = ((a8 * f8 + b8) * f8 + c8) * f8 + x8_1;
36711
+ temp = split + dc * read7 + ft * readC8;
36712
+ d8[w8] = temp;
36713
+ d9[w9] = readC8 - ft * temp;
36714
+ const read9 = d9[r9];
36715
+ lp3 += dp * (read9 - lp3);
36716
+ const read10 = d10[r10];
36717
+ temp = dc * lp3 - st * read10;
36718
+ d10[w10] = temp;
36719
+ d11[w11] = read10 + st * temp;
36720
+ const leftSample = d9[r9 + taps[0] & m9] + d9[r9 + taps[1] & m9] - d10[r10 + taps[2] & m10] + d11[r11 + taps[3] & m11] - d5[r5 + taps[4] & m5] - d6[r6 + taps[5] & m6] - d7[r7 + taps[6] & m7];
36721
+ const rightSample = d5[r5 + taps[7] & m5] + d5[r5 + taps[8] & m5] - d6[r6 + taps[9] & m6] + d7[r7 + taps[10] & m7] - d9[r9 + taps[11] & m9] - d10[r10 + taps[12] & m10] - d11[r11 + taps[13] & m11];
36722
+ const idx = i + startIndex;
36723
+ outputLeft[idx] += leftSample * gain;
36724
+ outputRight[idx] += rightSample * gain;
36725
+ const nextCos1 = cos1 * stepCos1 - sin1 * stepSin1;
36726
+ sin1 = sin1 * stepCos1 + cos1 * stepSin1;
36727
+ cos1 = nextCos1;
36728
+ const nextCos2 = cos2 * stepCos2 - sin2 * stepSin2;
36729
+ sin2 = sin2 * stepCos2 + cos2 * stepSin2;
36730
+ cos2 = nextCos2;
36731
+ w0 = w0 + 1 & m0;
36732
+ r0 = r0 + 1 & m0;
36733
+ w1 = w1 + 1 & m1;
36734
+ r1 = r1 + 1 & m1;
36735
+ w2 = w2 + 1 & m2;
36736
+ r2 = r2 + 1 & m2;
36737
+ w3 = w3 + 1 & m3;
36738
+ r3 = r3 + 1 & m3;
36739
+ w4 = w4 + 1 & m4;
36740
+ r4 = r4 + 1 & m4;
36741
+ w5 = w5 + 1 & m5;
36742
+ r5 = r5 + 1 & m5;
36743
+ w6 = w6 + 1 & m6;
36744
+ r6 = r6 + 1 & m6;
36745
+ w7 = w7 + 1 & m7;
36746
+ r7 = r7 + 1 & m7;
36747
+ w8 = w8 + 1 & m8;
36748
+ r8 = r8 + 1 & m8;
36749
+ w9 = w9 + 1 & m9;
36750
+ r9 = r9 + 1 & m9;
36751
+ w10 = w10 + 1 & m10;
36752
+ r10 = r10 + 1 & m10;
36753
+ w11 = w11 + 1 & m11;
36754
+ r11 = r11 + 1 & m11;
36755
+ }
36756
+ p1 = (p1 + step1 * sampleCount) % TWO_PI;
36757
+ p2 = (p2 + step2 * sampleCount) % TWO_PI;
36758
+ this.pDWrite = blockStart + sampleCount & pDMask;
36759
+ this.lp1 = lp1;
36760
+ this.lp2 = lp2;
36761
+ this.lp3 = lp3;
36762
+ this.excPhase1 = p1;
36763
+ this.excPhase2 = p2;
36764
+ this.delayWrite[0] = w0;
36765
+ this.delayRead[0] = r0;
36766
+ this.delayWrite[1] = w1;
36767
+ this.delayRead[1] = r1;
36768
+ this.delayWrite[2] = w2;
36769
+ this.delayRead[2] = r2;
36770
+ this.delayWrite[3] = w3;
36771
+ this.delayRead[3] = r3;
36772
+ this.delayWrite[4] = w4;
36773
+ this.delayRead[4] = r4;
36774
+ this.delayWrite[5] = w5;
36775
+ this.delayRead[5] = r5;
36776
+ this.delayWrite[6] = w6;
36777
+ this.delayRead[6] = r6;
36778
+ this.delayWrite[7] = w7;
36779
+ this.delayRead[7] = r7;
36780
+ this.delayWrite[8] = w8;
36781
+ this.delayRead[8] = r8;
36782
+ this.delayWrite[9] = w9;
36783
+ this.delayRead[9] = r9;
36784
+ this.delayWrite[10] = w10;
36785
+ this.delayRead[10] = r10;
36786
+ this.delayWrite[11] = w11;
36787
+ this.delayRead[11] = r11;
36788
+ }
36789
+ makeDelayLine(length, index) {
36790
+ const len = Math.round(length * this.sampleRate);
36791
+ const nextPow2 = 2 ** Math.ceil(Math.log2(len));
36792
+ this.delayBuffers[index] = new Float32Array(nextPow2);
36793
+ this.delayWrite[index] = len - 1;
36794
+ this.delayRead[index] = 0;
36795
+ this.delayMask[index] = nextPow2 - 1;
36796
+ }
36797
+ };
36407
36798
  // src/synthesizer/audio_engine/effects/gs/implementation/dsp/blocks/kaiser.ts
36408
36799
  /**
36409
36800
  * The modified Bessel function I0, for the Kaiser window.
@@ -36986,6 +37377,15 @@ const CHARACTERS$1 = [
36986
37377
  */
36987
37378
  const CHARACTER_DELAY = 6;
36988
37379
  const CHARACTER_PANNING_DELAY = 7;
37380
+ /**
37381
+ * The pre v4.4.11 GS Reverb.
37382
+ */
37383
+ const CHARACTER_DATTORRO = 8;
37384
+ /**
37385
+ * The pre v4.4.11 GS Reverb's output gain per LEVEL step.
37386
+ * It is tuned without the gain of the GS sends, so we take it out.
37387
+ */
37388
+ const DATTORRO_LEVEL_GAIN = 1 / (345 * GS_SENDS_GAIN);
36989
37389
  const MAX_DIFFUSER = [
36990
37390
  0,
36991
37391
  1,
@@ -37109,6 +37509,7 @@ var ReverbTank = class {
37109
37509
  * The characters differ in the delays, the taps and the damping.
37110
37510
  * The two delay characters are a single delay line with a feedback. The DLL's 1/4 input gain and four equal 1/4
37111
37511
  * taps cancel there, so neither appears.
37512
+ * Character 8 is the pre v4.4.11 GS Reverb (a Dattorro reverb tuned as Hall 2).
37112
37513
  *
37113
37514
  * The delays are the 32 kHz sample counts of the Sound Canvas, rounded to whole samples at the host rate.
37114
37515
  *
@@ -37138,6 +37539,7 @@ var DefaultGSReverb = class {
37138
37539
  * @private
37139
37540
  */
37140
37541
  delayLine;
37542
+ dattorro;
37141
37543
  inputGain = 0;
37142
37544
  /**
37143
37545
  * The gain per pass through a tank, before the damping.
@@ -37180,6 +37582,7 @@ var DefaultGSReverb = class {
37180
37582
  ];
37181
37583
  this.taps = new Array(8).fill(this.lines[0]);
37182
37584
  this.delayLine = new DelayLine(Math.ceil(14237 * step));
37585
+ this.dattorro = new DattorroReverb(sampleRate);
37183
37586
  this.reset();
37184
37587
  }
37185
37588
  _level = 64;
@@ -37189,6 +37592,7 @@ var DefaultGSReverb = class {
37189
37592
  set level(value) {
37190
37593
  this._level = value;
37191
37594
  this.outputGain = value / 64;
37595
+ this.dattorro.gain = value * DATTORRO_LEVEL_GAIN;
37192
37596
  }
37193
37597
  _delayFeedback = 0;
37194
37598
  get delayFeedback() {
@@ -37228,6 +37632,7 @@ var DefaultGSReverb = class {
37228
37632
  this._time = value;
37229
37633
  value = Math.max(0, Math.min(value, 127));
37230
37634
  this.timeGain = FEEDBACK_LIMIT * Math.min(value, TIME_AT_LIMIT) / TIME_AT_LIMIT;
37635
+ this.dattorro.decay = 1.2 * (.05 + .65 * value / 127);
37231
37636
  this.delaySamples = toHostSamples(DELAY_BASE + DELAY_STEP$1 * value, this.step);
37232
37637
  this.delayHalfSamples = toHostSamples(DELAY_BASE + DELAY_STEP$1 / 2 * value, this.step);
37233
37638
  }
@@ -37238,6 +37643,7 @@ var DefaultGSReverb = class {
37238
37643
  set preDelayTime(value) {
37239
37644
  this._preDelayTime = value;
37240
37645
  this.preDelaySamples = Math.round(Math.max(0, Math.min(value, MAX_PRE_DELAY)) * this.sampleRate / 1e3);
37646
+ this.dattorro.preDelay = this.preDelaySamples;
37241
37647
  }
37242
37648
  _preLowpass = 0;
37243
37649
  get preLowpass() {
@@ -37246,6 +37652,7 @@ var DefaultGSReverb = class {
37246
37652
  set preLowpass(value) {
37247
37653
  this._preLowpass = value;
37248
37654
  this.input.setPreLowPass(value);
37655
+ this.dattorro.preLPF = Math.min(1, .2 + (7 - Math.max(0, Math.min(value, 7))) / 14);
37249
37656
  }
37250
37657
  /**
37251
37658
  * Process the effect and **adds** it to the output.
@@ -37256,6 +37663,10 @@ var DefaultGSReverb = class {
37256
37663
  * @param sampleCount The amount of samples to mix.
37257
37664
  */
37258
37665
  process(input, outputLeft, outputRight, startIndex, sampleCount) {
37666
+ if (this._character === CHARACTER_DATTORRO) {
37667
+ this.dattorro.process(input, outputLeft, outputRight, startIndex, sampleCount);
37668
+ return;
37669
+ }
37259
37670
  if (this.delayCharacter) {
37260
37671
  this.processDelay(input, outputLeft, outputRight, startIndex, sampleCount);
37261
37672
  return;
@@ -37313,6 +37724,7 @@ var DefaultGSReverb = class {
37313
37724
  this.left.clear();
37314
37725
  this.right.clear();
37315
37726
  this.delayLine.clear();
37727
+ this.dattorro.clear();
37316
37728
  }
37317
37729
  /**
37318
37730
  * The delay characters: one delay line that feeds back.
@@ -63988,14 +64400,16 @@ function readModulators(modulatorChunk, allowSFe, curves = [], extendedChunk) {
63988
64400
  }
63989
64401
  mods.pop();
63990
64402
  flags.pop();
63991
- const flaggedCount = flags.filter(Boolean).length;
64403
+ let flaggedCount = 0;
64404
+ for (const flag of flags) if (flag) flaggedCount++;
63992
64405
  const ext = allowSFe && extendedChunk && extendedChunk.data.length % 16 === 0 && extendedChunk.data.length / 16 - 1 === flaggedCount ? extendedChunk.data : void 0;
63993
64406
  let record = 0;
63994
64407
  const resolveCurve = (source, index) => {
63995
64408
  if (source.curveType === ModulatorCurveTypes.custom && allowSFe) return curves[index];
63996
64409
  return source.curveType <= ModulatorCurveTypes.switch ? source.curve : void 0;
63997
64410
  };
63998
- for (const [m, mod] of mods.entries()) {
64411
+ for (let m = 0; m < mods.length; m++) {
64412
+ const mod = mods[m];
63999
64413
  let sourceCurve = 0;
64000
64414
  let amountCurve = 0;
64001
64415
  let understood = true;
@@ -64035,21 +64449,14 @@ function readCurves(curveChunk) {
64035
64449
  const name = readBinaryStringIndexed(data, 40);
64036
64450
  const pointCount = readLittleEndianIndexed(data, 2);
64037
64451
  if (data.currentIndex + pointCount * 4 > data.length) throw new Error(`The CURV chunk is truncated at curve ${c}.`);
64038
- const points = new Array(pointCount);
64039
- for (let i = 0; i < pointCount; i++) {
64040
- const x = readLittleEndianIndexed(data, 2);
64041
- const y = readLittleEndianIndexed(data, 2);
64042
- points[i] = {
64043
- x,
64044
- y
64045
- };
64046
- }
64452
+ const recordEnd = data.currentIndex + pointCount * 4;
64047
64453
  try {
64048
- curves.push(new CustomCurve(points, name));
64454
+ curves.push(CustomCurve.read(data, pointCount, name));
64049
64455
  } catch (error) {
64050
64456
  SpessaLog.warn(`Custom curve ${c} "${name}" is invalid, ignoring: ${error.message}`);
64051
64457
  curves.push(void 0);
64052
64458
  }
64459
+ data.currentIndex = recordEnd;
64053
64460
  }
64054
64461
  if (data.currentIndex !== data.length) throw new Error(`The CURV chunk has ${data.length - data.currentIndex} bytes after its last curve.`);
64055
64462
  return curves;
@@ -65963,7 +66370,7 @@ var SpessaSynthProcessor = class {
65963
66370
  */
65964
66371
  setReverbMacro(macro) {
65965
66372
  if (this.systemParameters.gsReverbLock) return;
65966
- if (macro > 7) {
66373
+ if (macro > 8) {
65967
66374
  SpessaLog.warn(`Invalid reverb macro: ${macro}`);
65968
66375
  return;
65969
66376
  }
@@ -65979,16 +66386,23 @@ var SpessaSynthProcessor = class {
65979
66386
  * Room1, Room2, Room3
65980
66387
  * These reverbs simulate the reverberation of a room. They provide a well-defined
65981
66388
  * spacious reverberation.
66389
+ *
65982
66390
  * Hall1, Hall2
65983
66391
  * These reverbs simulate the reverberation of a concert hall. They provide a deeper
65984
66392
  * reverberation than the Room reverbs.
66393
+ *
65985
66394
  * Plate
65986
66395
  * This simulates a plate reverb (a studio device using a metal plate).
66396
+ *
65987
66397
  * Delay
65988
66398
  * This is a conventional delay that produces echo effects.
66399
+ *
65989
66400
  * Panning Delay
65990
66401
  * This is a special delay in which the delayed sounds move left and right.
65991
66402
  * It is effective when you are listening in stereo.
66403
+ *
66404
+ * Spessa 1
66405
+ * Not a Roland macro. Hall2 with the pre v4.4.11 GS Reverb.
65992
66406
  */
65993
66407
  case 0:
65994
66408
  rev.character = 0;
@@ -66038,6 +66452,12 @@ var SpessaSynthProcessor = class {
66038
66452
  rev.preLowpass = 0;
66039
66453
  rev.time = 64;
66040
66454
  rev.delayFeedback = 32;
66455
+ break;
66456
+ case 8:
66457
+ rev.character = 8;
66458
+ rev.preLowpass = 0;
66459
+ rev.time = 64;
66460
+ rev.delayFeedback = 0;
66041
66461
  }
66042
66462
  for (const parameter of GS_REVERB_MACRO_PARAMETERS) this.callEvent("effectChange", {
66043
66463
  effect: "gsReverb",