spessasynth_lib 3.22.11 → 3.22.12

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.
@@ -85,6 +85,7 @@ export class BasicSoundFont {
85
85
  * @param error {string}
86
86
  */
87
87
  parsingError(error: string): void;
88
+ destroySoundfont(): void;
88
89
  write: typeof write;
89
90
  }
90
91
  import { Modulator } from "./modulator.js";
@@ -40,6 +40,7 @@ export class Synthetizer {
40
40
  */
41
41
  eventHandler: EventHandler;
42
42
  _voiceCap: number;
43
+ _destroyed: boolean;
43
44
  /**
44
45
  * the new channels will have their audio sent to the moduled output by this constant.
45
46
  * what does that mean? e.g. if outputsAmount is 16, then channel's 16 audio will be sent to channel 0
@@ -314,8 +315,9 @@ export class Synthetizer {
314
315
  /**
315
316
  * sends a raw MIDI message to the synthesizer
316
317
  * @param message {number[]|Uint8Array} the midi message, each number is a byte
318
+ * @param channelOffset {number} the channel offset of the message
317
319
  */
318
- sendMessage(message: number[] | Uint8Array): void;
320
+ sendMessage(message: number[] | Uint8Array, channelOffset?: number): void;
319
321
  /**
320
322
  * Updates the reverb processor with a new impulse response
321
323
  * @param buffer {AudioBuffer} the new reverb impulse response
@@ -326,6 +328,16 @@ export class Synthetizer {
326
328
  * @param config {ChorusConfig} the new chorus
327
329
  */
328
330
  setChorusConfig(config: ChorusConfig): void;
331
+ /**
332
+ * Changes the effects gain
333
+ * @param reverbGain {number} the reverb gain, 0-1
334
+ * @param chorusGain {number} the chorus gain, 0-1
335
+ */
336
+ setEffectsGain(reverbGain: number, chorusGain: number): void;
337
+ /**
338
+ * Destroys the synthesizer instance
339
+ */
340
+ destroy(): void;
329
341
  reverbateEverythingBecauseWhyNot(): string;
330
342
  }
331
343
  export type StartRenderingDataConfig = {
@@ -30,6 +30,8 @@ export namespace workletMessageType {
30
30
  let requestSynthesizerSnapshot: number;
31
31
  let setLogLevel: number;
32
32
  let keyModifierManager: number;
33
+ let setEffectsGain: number;
34
+ let destroyWorklet: number;
33
35
  }
34
36
  export type masterParameterType = number;
35
37
  export namespace masterParameterType {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.22.11",
3
+ "version": "3.22.12",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "browser": "index.js",
6
6
  "types": "@types/index.d.ts",
@@ -18,6 +18,12 @@ import { MIDIticksToSeconds } from "../../midi_parser/basic_midi.js";
18
18
  */
19
19
  export function assignMIDIPort(trackNum, port)
20
20
  {
21
+ // do not assign ports to empty tracks
22
+ if (this.midiData.usedChannelsOnTrack[trackNum].size === 0)
23
+ {
24
+ return;
25
+ }
26
+
21
27
  // assign new 16 channels if the port is not occupied yet
22
28
  if (this.midiPortChannelOffset === 0)
23
29
  {
@@ -233,6 +233,13 @@ class BasicSoundFont
233
233
  {
234
234
  throw new Error(`SF parsing error: ${error} The file may be corrupted.`);
235
235
  }
236
+
237
+ destroySoundfont()
238
+ {
239
+ delete this.presets;
240
+ delete this.instruments;
241
+ delete this.samples;
242
+ }
236
243
  }
237
244
 
238
245
  BasicSoundFont.prototype.write = write;
@@ -317,11 +317,12 @@ export function getSF2ModulatorFromArticulator(
317
317
  // value,
318
318
  // transform
319
319
  // );
320
- // invert only if the actual transform value is not negative.
321
- // if it is, it's already inverted
322
- if (value > 0)
320
+ // if the value is negative, the source shall be negative!
321
+ // why?
322
+ // Idk, it makes it work with ROCK.RMI and NOKIA_S30.dls
323
+ if (value < 0)
323
324
  {
324
- sourceIsNegative = !sourceIsNegative;
325
+ sourceIsNegative = 1;
325
326
  }
326
327
  }
327
328
  sourceEnumFinal = getModSourceEnum(
@@ -164,6 +164,12 @@ class DLSSoundFont extends BasicSoundFont
164
164
  {
165
165
  throw new Error(`DLS parse error: ${error} The file may be corrupted.`);
166
166
  }
167
+
168
+ destroySoundfont()
169
+ {
170
+ super.destroySoundfont();
171
+ delete this.dataArray;
172
+ }
167
173
  }
168
174
 
169
175
  DLSSoundFont.prototype.readDLSInstrumentList = readDLSInstrumentList;
@@ -296,4 +296,10 @@ export class SoundFont2 extends BasicSoundFont
296
296
  this.parsingError(`Invalid FourCC: Expected "${expected.toLowerCase()}" got "${text.toLowerCase()}"\``);
297
297
  }
298
298
  }
299
+
300
+ destroySoundfont()
301
+ {
302
+ super.destroySoundfont();
303
+ delete this.dataArray;
304
+ }
299
305
  }
@@ -74,6 +74,7 @@ export class Synthetizer
74
74
  this.eventHandler = new EventHandler();
75
75
 
76
76
  this._voiceCap = VOICE_CAP;
77
+ this._destroyed = false;
77
78
 
78
79
  /**
79
80
  * the new channels will have their audio sent to the moduled output by this constant.
@@ -599,6 +600,10 @@ export class Synthetizer
599
600
  */
600
601
  post(data)
601
602
  {
603
+ if (this._destroyed)
604
+ {
605
+ throw new Error("This synthesizer instance has been destroyed!");
606
+ }
602
607
  this.worklet.port.postMessage(data);
603
608
  }
604
609
 
@@ -780,13 +785,14 @@ export class Synthetizer
780
785
  /**
781
786
  * sends a raw MIDI message to the synthesizer
782
787
  * @param message {number[]|Uint8Array} the midi message, each number is a byte
788
+ * @param channelOffset {number} the channel offset of the message
783
789
  */
784
- sendMessage(message)
790
+ sendMessage(message, channelOffset = 0)
785
791
  {
786
792
  // discard as soon as possible if high perf
787
793
  const statusByteData = getEvent(message[0]);
788
794
 
789
-
795
+ statusByteData.channel += channelOffset;
790
796
  // process the event
791
797
  switch (statusByteData.status)
792
798
  {
@@ -864,6 +870,37 @@ export class Synthetizer
864
870
  this.effectsConfig.chorusConfig = config;
865
871
  }
866
872
 
873
+ /**
874
+ * Changes the effects gain
875
+ * @param reverbGain {number} the reverb gain, 0-1
876
+ * @param chorusGain {number} the chorus gain, 0-1
877
+ */
878
+ setEffectsGain(reverbGain, chorusGain)
879
+ {
880
+ this.post({
881
+ messageType: workletMessageType.setEffectsGain,
882
+ messageData: [reverbGain, chorusGain]
883
+ });
884
+ }
885
+
886
+ /**
887
+ * Destroys the synthesizer instance
888
+ */
889
+ destroy()
890
+ {
891
+ this.reverbProcessor.disconnect();
892
+ this.chorusProcessor.delete();
893
+ this.post({
894
+ messageType: workletMessageType.destroyWorklet,
895
+ messageData: undefined
896
+ });
897
+ this.worklet.disconnect();
898
+ delete this.worklet;
899
+ delete this.reverbProcessor;
900
+ delete this.chorusProcessor;
901
+ this._destroyed = true;
902
+ }
903
+
867
904
  reverbateEverythingBecauseWhyNot()
868
905
  {
869
906
  for (let i = 0; i < this.channelsAmount; i++)