spessasynth_core 3.26.31 → 3.26.32

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.31",
3
+ "version": "3.26.32",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -54,6 +54,13 @@ export function readRIFFChunk(dataArray, readData = true, forceShift = false)
54
54
  let header = readBytesAsString(dataArray, 4);
55
55
 
56
56
  let size = readLittleEndian(dataArray, 4);
57
+ if (header === "")
58
+ {
59
+ // safeguard against evil DLS files
60
+ // The test case: CrysDLS v1.23.dls
61
+ // https://github.com/spessasus/spessasynth_core/issues/5
62
+ size = 0;
63
+ }
57
64
  /**
58
65
  * @type {IndexedByteArray}
59
66
  */
@@ -8,7 +8,6 @@ import { readLittleEndian } from "../../utils/byte_functions/little_endian.js";
8
8
  import { readDLSInstrumentList } from "./read_instrument_list.js";
9
9
  import { readDLSInstrument } from "./read_instrument.js";
10
10
  import { readLart } from "./read_lart.js";
11
- import { readRegion } from "./read_region.js";
12
11
  import { readDLSSamples } from "./read_samples.js";
13
12
 
14
13
  class DLSSoundFont extends BasicSoundBank
@@ -178,7 +177,6 @@ class DLSSoundFont extends BasicSoundBank
178
177
 
179
178
  DLSSoundFont.prototype.readDLSInstrumentList = readDLSInstrumentList;
180
179
  DLSSoundFont.prototype.readDLSInstrument = readDLSInstrument;
181
- DLSSoundFont.prototype.readRegion = readRegion;
182
180
  DLSSoundFont.prototype.readLart = readLart;
183
181
  DLSSoundFont.prototype.readDLSSamples = readDLSSamples;
184
182
 
@@ -7,6 +7,7 @@ import { consoleColors } from "../../utils/other.js";
7
7
  import { Modulator } from "../basic_soundfont/modulator.js";
8
8
  import { DEFAULT_DLS_CHORUS, DEFAULT_DLS_REVERB } from "./dls_sources.js";
9
9
  import { generatorLimits, generatorTypes } from "../basic_soundfont/generator_types.js";
10
+ import { readRegion } from "./read_region.js";
10
11
 
11
12
  /**
12
13
  * @this {DLSSoundFont}
@@ -40,7 +41,7 @@ export function readDLSInstrument(chunk)
40
41
  const preset = new DLSPreset(this, ulBank, ulInstrument);
41
42
 
42
43
  // read preset name in INFO
43
- let presetName = "unnamedPreset";
44
+ let presetName = ``;
44
45
  const infoChunk = findRIFFListType(chunks, "INFO");
45
46
  if (infoChunk)
46
47
  {
@@ -51,6 +52,10 @@ export function readDLSInstrument(chunk)
51
52
  }
52
53
  presetName = readBytesAsString(info.chunkData, info.chunkData.length).trim();
53
54
  }
55
+ if (presetName.length < 1)
56
+ {
57
+ presetName = `unnamed ${(ulBank >> 8) & 127}:${ulInstrument & 127}`;
58
+ }
54
59
  preset.presetName = presetName;
55
60
  preset.dlsInstrument.instrumentName = presetName;
56
61
  SpessaSynthGroupCollapsed(
@@ -105,8 +110,7 @@ export function readDLSInstrument(chunk)
105
110
  }
106
111
 
107
112
 
108
- const zone = preset.dlsInstrument.createZone();
109
- this.readRegion(chunk, zone);
113
+ readRegion.call(this, chunk, preset.dlsInstrument);
110
114
  }
111
115
  this.addPresets(preset);
112
116
  this.addInstruments(preset.dlsInstrument);
@@ -2,13 +2,14 @@ import { readLittleEndian, signedInt16 } from "../../utils/byte_functions/little
2
2
  import { findRIFFListType, readRIFFChunk } from "../basic_soundfont/riff_chunk.js";
3
3
  import { Generator } from "../basic_soundfont/generator.js";
4
4
  import { generatorTypes } from "../basic_soundfont/generator_types.js";
5
+ import { SpessaSynthWarn } from "../../utils/loggin.js";
5
6
 
6
7
  /**
7
8
  * @this {DLSSoundFont}
8
9
  * @param chunk {RiffChunk}
9
- * @param zone {DLSZone}
10
+ * @param instrument {DLSInstrument}
10
11
  */
11
- export function readRegion(chunk, zone)
12
+ export function readRegion(chunk, instrument)
12
13
  {
13
14
  // regions are essentially instrument zones
14
15
 
@@ -24,6 +25,12 @@ export function readRegion(chunk, zone)
24
25
 
25
26
  // region header
26
27
  const regionHeader = regionChunks.find(c => c.header === "rgnh");
28
+
29
+ if (!regionHeader)
30
+ {
31
+ SpessaSynthWarn("Invalid DLS region: missing 'rgnh' chunk! Discarding...");
32
+ return;
33
+ }
27
34
  // key range
28
35
  let keyMin = readLittleEndian(regionHeader.chunkData, 2);
29
36
  let keyMax = readLittleEndian(regionHeader.chunkData, 2);
@@ -38,7 +45,8 @@ export function readRegion(chunk, zone)
38
45
  velMin = 0;
39
46
  }
40
47
  // cannot do the same to key zones sadly
41
-
48
+ // create zone
49
+ const zone = instrument.createZone();
42
50
  // apply ranges
43
51
  zone.keyRange = { min: keyMin, max: keyMax };
44
52
  zone.velRange = { min: velMin, max: velMax };