spessasynth_core 4.0.2 → 4.0.4

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.d.ts CHANGED
@@ -336,7 +336,7 @@ declare class BasicZone {
336
336
  /**
337
337
  * Sets a generator to a given value if preset, otherwise adds a new one.
338
338
  */
339
- setGenerator(type: GeneratorType, value: number | undefined, validate?: boolean): void;
339
+ setGenerator(type: GeneratorType, value: number | null, validate?: boolean): void;
340
340
  /**
341
341
  * Adds generators to the zone.
342
342
  * @param generators
package/dist/index.js CHANGED
@@ -7064,7 +7064,6 @@ var BasicZone = class {
7064
7064
  const genValue = this.getGenerator(type, generatorLimits[type].def);
7065
7065
  this.setGenerator(type, value + genValue, validate);
7066
7066
  }
7067
- // noinspection JSUnusedGlobalSymbols
7068
7067
  /**
7069
7068
  * Sets a generator to a given value if preset, otherwise adds a new one.
7070
7069
  */
@@ -7078,7 +7077,7 @@ var BasicZone = class {
7078
7077
  case generatorTypes.keyRange:
7079
7078
  throw new Error("Set the range manually");
7080
7079
  }
7081
- if (value === void 0) {
7080
+ if (value === null) {
7082
7081
  this.generators = this.generators.filter(
7083
7082
  (g) => g.generatorType !== type
7084
7083
  );
@@ -7087,7 +7086,7 @@ var BasicZone = class {
7087
7086
  const index = this.generators.findIndex(
7088
7087
  (g) => g.generatorType === type
7089
7088
  );
7090
- if (index > 0) {
7089
+ if (index >= 0) {
7091
7090
  this.generators[index] = new Generator(type, value, validate);
7092
7091
  } else {
7093
7092
  this.addGenerators(new Generator(type, value, validate));
@@ -7242,12 +7241,14 @@ var BasicPresetZone = class extends BasicZone {
7242
7241
  "Instrument ID cannot be determined without the sound bank itself."
7243
7242
  );
7244
7243
  }
7244
+ const instrumentID = bank.instruments.indexOf(this.instrument);
7245
+ if (instrumentID < 0) {
7246
+ throw new Error(
7247
+ `${this.instrument.name} does not exist in ${bank.soundBankInfo.name}! Cannot write instrument generator.`
7248
+ );
7249
+ }
7245
7250
  gens.push(
7246
- new Generator(
7247
- generatorTypes.instrument,
7248
- bank.instruments.indexOf(this.instrument),
7249
- false
7250
- )
7251
+ new Generator(generatorTypes.instrument, instrumentID, false)
7251
7252
  );
7252
7253
  return gens;
7253
7254
  }
@@ -7302,13 +7303,13 @@ var BasicInstrumentZone = class extends BasicZone {
7302
7303
  }
7303
7304
  getWriteGenerators(bank) {
7304
7305
  const gens = super.getWriteGenerators(bank);
7305
- gens.push(
7306
- new Generator(
7307
- generatorTypes.sampleID,
7308
- bank.samples.indexOf(this.sample),
7309
- false
7310
- )
7311
- );
7306
+ const sampleID = bank.samples.indexOf(this.sample);
7307
+ if (sampleID < 0) {
7308
+ throw new Error(
7309
+ `${this.sample.name} does not exist in ${bank.soundBankInfo.name}! Cannot write sampleID generator.`
7310
+ );
7311
+ }
7312
+ gens.push(new Generator(generatorTypes.sampleID, sampleID, false));
7312
7313
  return gens;
7313
7314
  }
7314
7315
  };
@@ -7506,7 +7507,7 @@ var BasicInstrument = class {
7506
7507
  const genValue = z.getGenerator(checkedType, void 0);
7507
7508
  if (genValue !== void 0) {
7508
7509
  if (genValue === targetValue) {
7509
- z.setGenerator(checkedType, void 0);
7510
+ z.setGenerator(checkedType, null);
7510
7511
  }
7511
7512
  } else {
7512
7513
  if (targetValue !== defaultForChecked) {
@@ -12684,7 +12685,7 @@ var SoundFontSample = class extends BasicSample {
12684
12685
  } else {
12685
12686
  if (linked.linkedSample) {
12686
12687
  SpessaSynthInfo(
12687
- `%cInvalid linked sample for ${this.name}: Already linked to ${linked.linkedSample.name}`,
12688
+ `%cInvalid linked sample for ${this.name}: ${linked.name} is already linked to ${linked.linkedSample.name}`,
12688
12689
  consoleColors.warn
12689
12690
  );
12690
12691
  this.unlinkSample();
@@ -16053,6 +16054,11 @@ var SoundFontPresetZone = class extends BasicPresetZone {
16053
16054
  } else {
16054
16055
  throw new Error("No instrument ID found in preset zone.");
16055
16056
  }
16057
+ if (!instrument) {
16058
+ throw new Error(
16059
+ `Invalid instrument ID: ${instrumentID.generatorValue}, available instruments: ${instruments.length}`
16060
+ );
16061
+ }
16056
16062
  super(preset, instrument);
16057
16063
  this.addGenerators(...generators);
16058
16064
  this.addModulators(...modulators);
@@ -16146,6 +16152,11 @@ var SoundFontInstrumentZone = class extends BasicInstrumentZone {
16146
16152
  } else {
16147
16153
  throw new Error("No sample ID found in instrument zone.");
16148
16154
  }
16155
+ if (!sample) {
16156
+ throw new Error(
16157
+ `Invalid sample ID: ${sampleID.generatorValue}, available samples: ${samples.length}`
16158
+ );
16159
+ }
16149
16160
  super(inst, sample);
16150
16161
  this.addGenerators(...generators);
16151
16162
  this.addModulators(...modulators);