spessasynth_lib 3.21.14 → 3.22.1

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.
@@ -81,6 +81,10 @@ export class BasicSoundFont {
81
81
  * @returns {BasicPreset}
82
82
  */
83
83
  getPresetByName(presetName: string): BasicPreset;
84
+ /**
85
+ * @param error {string}
86
+ */
87
+ parsingError(error: string): void;
84
88
  write: typeof write;
85
89
  }
86
90
  import { Modulator } from "./modulator.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.21.14",
3
+ "version": "3.22.1",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "browser": "index.js",
6
6
  "types": "@types/index.d.ts",
@@ -459,7 +459,7 @@ export class Sequencer
459
459
  }
460
460
  else
461
461
  {
462
- throw new Error(messageData);
462
+ throw new Error("Sequencer error: " + messageData);
463
463
  }
464
464
  return;
465
465
 
@@ -49,7 +49,7 @@ export function loadNewSequence(parsedMidi, autoPlay = true)
49
49
  this.stop();
50
50
  if (!parsedMidi.tracks)
51
51
  {
52
- throw "No tracks supplied!";
52
+ throw new Error("This MIDI has no tracks!");
53
53
  }
54
54
 
55
55
  this.oneTickToSeconds = 60 / (120 * parsedMidi.timeDivision);
@@ -225,6 +225,14 @@ class BasicSoundFont
225
225
  }
226
226
  return preset;
227
227
  }
228
+
229
+ /**
230
+ * @param error {string}
231
+ */
232
+ parsingError(error)
233
+ {
234
+ throw new Error(`SF parsing error: ${error} The file may be corrupted.`);
235
+ }
228
236
  }
229
237
 
230
238
  BasicSoundFont.prototype.write = write;
@@ -71,7 +71,7 @@ function getSF2SourceFromDLS(source)
71
71
  }
72
72
  if (sourceEnum === undefined)
73
73
  {
74
- throw `not known?? ${source}`;
74
+ throw new Error(`Unknown DLS Source: ${source}`);
75
75
  }
76
76
  return { enum: sourceEnum, isCC: isCC };
77
77
  }
@@ -58,7 +58,7 @@ export class DLSSample extends BasicSample
58
58
  {
59
59
  if (!this.compressedData)
60
60
  {
61
- throw new Error("Compressed but no data??");
61
+ throw new Error("Compressed but no data?? This shouldn't happen!!");
62
62
  }
63
63
  return this.compressedData;
64
64
  }
@@ -25,7 +25,7 @@ class DLSSoundFont extends BasicSoundFont
25
25
  if (!this.dataArray)
26
26
  {
27
27
  SpessaSynthGroupEnd();
28
- throw new TypeError("No data!");
28
+ this.parsingError("No data provided!");
29
29
  }
30
30
 
31
31
  // read the main chunk
@@ -85,7 +85,7 @@ class DLSSoundFont extends BasicSoundFont
85
85
  if (!colhChunk)
86
86
  {
87
87
  SpessaSynthGroupEnd();
88
- throw new Error("No colh chunk!");
88
+ this.parsingError("No colh chunk!");
89
89
  }
90
90
  this.instrumentAmount = readLittleEndian(colhChunk.chunkData, 4);
91
91
  SpessaSynthInfo(
@@ -96,6 +96,11 @@ class DLSSoundFont extends BasicSoundFont
96
96
 
97
97
  // read wave list
98
98
  let waveListChunk = findRIFFListType(chunks, "wvpl");
99
+ if (!waveListChunk)
100
+ {
101
+ SpessaSynthGroupEnd();
102
+ this.parsingError("No wvpl chunk!");
103
+ }
99
104
  this.readDLSSamples(waveListChunk);
100
105
 
101
106
  // read instrument list
@@ -103,7 +108,7 @@ class DLSSoundFont extends BasicSoundFont
103
108
  if (!instrumentListChunk)
104
109
  {
105
110
  SpessaSynthGroupEnd();
106
- throw new Error("No lins chunk!");
111
+ this.parsingError("No lins chunk!");
107
112
  }
108
113
  this.readDLSInstrumentList(instrumentListChunk);
109
114
 
@@ -135,7 +140,7 @@ class DLSSoundFont extends BasicSoundFont
135
140
  if (chunk.header.toLowerCase() !== expected.toLowerCase())
136
141
  {
137
142
  SpessaSynthGroupEnd();
138
- throw new SyntaxError(`Invalid DLS chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
143
+ this.parsingError(`Invalid DLS chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
139
144
  }
140
145
  }
141
146
 
@@ -148,9 +153,17 @@ class DLSSoundFont extends BasicSoundFont
148
153
  if (text.toLowerCase() !== expected.toLowerCase())
149
154
  {
150
155
  SpessaSynthGroupEnd();
151
- throw new SyntaxError(`Invalid DLS soundfont! Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"`);
156
+ this.parsingError(`FourCC error: Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"`);
152
157
  }
153
158
  }
159
+
160
+ /**
161
+ * @param error {string}
162
+ */
163
+ parsingError(error)
164
+ {
165
+ throw new Error(`DLS parse error: ${error} The file may be corrupted.`);
166
+ }
154
167
  }
155
168
 
156
169
  DLSSoundFont.prototype.readDLSInstrumentList = readDLSInstrumentList;
@@ -85,7 +85,7 @@ export function readDLSInstrument(chunk)
85
85
  if (type !== "rgn " && type !== "rgn2")
86
86
  {
87
87
  SpessaSynthGroupEnd();
88
- throw new SyntaxError(`Invalid DLS region! Expected "rgn " or "rgn2" got "${type}"`);
88
+ this.parsingError(`Invalid DLS region! Expected "rgn " or "rgn2" got "${type}"`);
89
89
  }
90
90
 
91
91
 
@@ -80,7 +80,7 @@ export function readDLSSamples(waveListChunk)
80
80
  const dataChunk = waveChunks.find(c => c.header === "data");
81
81
  if (!dataChunk)
82
82
  {
83
- throw new Error("No data chunk in the wave chunk!");
83
+ this.parsingError("No data chunk in the WAVE chunk!");
84
84
  }
85
85
  const sampleLength = dataChunk.size / bytesPerSample;
86
86
  const sampleData = new Float32Array(sampleLength);
@@ -113,11 +113,18 @@ export class LoadedSample extends BasicSample
113
113
  const buff = smplArr.slice(this.sampleStartIndex / 2 + smplStart, this.sampleEndIndex / 2 + smplStart);
114
114
  // reset array and being decoding
115
115
  this.sampleData = new Float32Array(0);
116
- /**
117
- * @type {{data: Float32Array[], error: (string|null), sampleRate: number, eof: boolean}}
118
- */
119
- const vorbis = stbvorbis.decode(buff.buffer);
120
- this.sampleData = vorbis.data[0];
116
+ try
117
+ {
118
+ /**
119
+ * @type {{data: Float32Array[], error: (string|null), sampleRate: number, eof: boolean}}
120
+ */
121
+ const vorbis = stbvorbis.decode(buff.buffer);
122
+ this.sampleData = vorbis.data[0];
123
+ }
124
+ catch (e)
125
+ {
126
+ throw new Error(`Ogg Vorbis decode error: ${e}`);
127
+ }
121
128
  }
122
129
 
123
130
  /**
@@ -39,7 +39,7 @@ export class SoundFont2 extends BasicSoundFont
39
39
  if (!this.dataArray)
40
40
  {
41
41
  SpessaSynthGroupEnd();
42
- throw new TypeError("No data!");
42
+ this.parsingError("No data provided!");
43
43
  }
44
44
 
45
45
  // read the main read
@@ -280,7 +280,7 @@ export class SoundFont2 extends BasicSoundFont
280
280
  if (chunk.header.toLowerCase() !== expected.toLowerCase())
281
281
  {
282
282
  SpessaSynthGroupEnd();
283
- throw new SyntaxError(`Invalid chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
283
+ this.parsingError(`Invalid chunk header! Expected "${expected.toLowerCase()}" got "${chunk.header.toLowerCase()}"`);
284
284
  }
285
285
  }
286
286
 
@@ -293,7 +293,7 @@ export class SoundFont2 extends BasicSoundFont
293
293
  if (text.toLowerCase() !== expected.toLowerCase())
294
294
  {
295
295
  SpessaSynthGroupEnd();
296
- throw new SyntaxError(`Invalid soundFont! Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"`);
296
+ this.parsingError(`Invalid FourCC: Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"\``);
297
297
  }
298
298
  }
299
299
  }