spessasynth_core 3.26.40 → 3.26.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_core",
3
- "version": "3.26.40",
3
+ "version": "3.26.41",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -271,6 +271,11 @@ export class BasicSample
271
271
  */
272
272
  setLinkedSample(sample, type)
273
273
  {
274
+ // sanity check
275
+ if (sample.linkedSample)
276
+ {
277
+ throw new Error(`${sample.sampleName} is linked tp ${sample.linkedSample.sampleName}. Unlink it first.`);
278
+ }
274
279
  this.linkedSample = sample;
275
280
  sample.linkedSample = this;
276
281
  if (type === sampleTypes.leftSample)
@@ -263,7 +263,11 @@ class BasicSoundBank
263
263
  if (sample.linkedSample)
264
264
  {
265
265
  const clonedLinked = this.cloneSample(sample.linkedSample);
266
- newSample.setLinkedSample(clonedLinked, newSample.sampleType);
266
+ // sanity check
267
+ if (!clonedLinked.linkedSample)
268
+ {
269
+ newSample.setLinkedSample(clonedLinked, newSample.sampleType);
270
+ }
267
271
  }
268
272
  return newSample;
269
273
  }
@@ -3,7 +3,7 @@ import { IndexedByteArray } from "../../utils/indexed_array.js";
3
3
  import { readLittleEndian, signedInt8 } from "../../utils/byte_functions/little_endian.js";
4
4
  import { SpessaSynthInfo, SpessaSynthWarn } from "../../utils/loggin.js";
5
5
  import { readBytesAsString } from "../../utils/byte_functions/string.js";
6
- import { BasicSample, sampleTypes } from "../basic_soundfont/basic_sample.js";
6
+ import { BasicSample } from "../basic_soundfont/basic_sample.js";
7
7
  import { consoleColors } from "../../utils/other.js";
8
8
 
9
9
  /**
@@ -130,16 +130,28 @@ export class SoundFontSample extends BasicSample
130
130
  {
131
131
  return;
132
132
  }
133
- const linkedSample = samplesArray[this.linkedSampleIndex];
134
- if (!linkedSample)
133
+ const linked = samplesArray[this.linkedSampleIndex];
134
+ if (!linked)
135
135
  {
136
136
  // log as info because it's common and not really dangerous
137
137
  SpessaSynthInfo(`%cInvalid linked sample for ${this.sampleName}. Setting to mono.`, consoleColors.warn);
138
- this.setSampleType(sampleTypes.monoSample);
138
+ this.unlinkSample();
139
139
  }
140
140
  else
141
141
  {
142
- this.setLinkedSample(samplesArray[this.linkedSampleIndex], this.sampleType);
142
+ // check for corrupted files (like FluidR3_GM.sf2 that link EVERYTHING to a single sample)
143
+ if (linked.linkedSample)
144
+ {
145
+ SpessaSynthInfo(
146
+ `%cInvalid linked sample for ${this.sampleName}: Already linked to ${linked.linkedSample.sampleName}`,
147
+ consoleColors.warn
148
+ );
149
+ this.unlinkSample();
150
+ }
151
+ else
152
+ {
153
+ this.setLinkedSample(linked, this.sampleType);
154
+ }
143
155
  }
144
156
  }
145
157