spessasynth_core 4.4.7 → 4.4.9

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
@@ -31,6 +31,35 @@ export interface WaveWriteOptions {
31
31
  */
32
32
  metadata: Partial<WaveMetadata>;
33
33
  }
34
+ /**
35
+ * The result of reading a WAVE file with {@link wavToAudio}.
36
+ *
37
+ * @group Utilities
38
+ */
39
+ export interface WaveReadResult {
40
+ /**
41
+ * The PCM audio data, one array per channel.
42
+ */
43
+ audioData: Float32Array[];
44
+ /**
45
+ * The sample rate, in Hertz.
46
+ */
47
+ sampleRate: number;
48
+ /**
49
+ * The loop of the file, undefined if it has none.
50
+ * The points are in sample frames, not seconds.
51
+ */
52
+ loop?: {
53
+ /**
54
+ * The loop start, in sample frames.
55
+ */
56
+ start: number;
57
+ /**
58
+ * The loop end, in sample frames.
59
+ */
60
+ end: number;
61
+ };
62
+ }
34
63
  /**
35
64
  * Metadata to write into a WAVE file.
36
65
  *
@@ -148,6 +177,24 @@ declare function readVariableLengthQuantity(midiByteArray: IndexedByteArray): nu
148
177
  * @group Utilities
149
178
  */
150
179
  export declare function audioToWav(audioData: Float32Array[], sampleRate: number, options?: Partial<WaveWriteOptions>): ArrayBuffer;
180
+ /**
181
+ * Reads a WAVE file into PCM audio data, the counterpart of {@link audioToWav}.
182
+ *
183
+ * It reads 8, 16, 24 and 32-bit integer PCM and 32 and 64-bit float files (including `WAVE_FORMAT_EXTENSIBLE`).
184
+ * The loop is read from the first loop of the `smpl` chunk. Without one, a `cue ` chunk with exactly two points
185
+ * is taken as the loop start and end, which is how {@link audioToWav} writes it.
186
+ *
187
+ * > **Note**
188
+ * >
189
+ * > The returned loop end is exclusive, like the SoundFont loop end.
190
+ *
191
+ * @param buffer The binary WAVE file.
192
+ * @returns The audio data (one array per channel), the sample rate and the loop, if the file has one.
193
+ * @throws Error if the file is not a valid or supported WAVE file.
194
+ *
195
+ * @group Utilities
196
+ */
197
+ export declare function wavToAudio(buffer: ArrayBuffer): WaveReadResult;
151
198
  /**
152
199
  * SpessaSynth can print out additional info to the console or print nothing at all.
153
200
  *
@@ -353,17 +400,6 @@ export interface GeneratorLimit {
353
400
  * SoundFont2 NRPN scale factor for this generator type.
354
401
  */
355
402
  nrpn: number;
356
- /**
357
- * Minimum value of this generator in a preset zone.
358
- * Preset generators are offsets added to the instrument, so they can go below the instrument range.
359
- * If not set, it is the same as `min`.
360
- */
361
- presetMin?: number;
362
- /**
363
- * Maximum value of this generator in a preset zone.
364
- * If not set, it is the same as `max`.
365
- */
366
- presetMax?: number;
367
403
  }
368
404
  /**
369
405
  * Limits and defaults for all the {@link BasicSoundBank} generator types.
@@ -524,6 +560,15 @@ export declare class ModulatorSource {
524
560
  * This field specifies how the minimum value approaches the maximum value.
525
561
  */
526
562
  curveType: ModulatorCurveType;
563
+ /**
564
+ * Creates a new modulator source.
565
+ * @param index The controller or MIDI CC number, see `isCC`.
566
+ * @param curveType How the minimum value approaches the maximum value.
567
+ * @param isCC If the index is a MIDI CC instead of a general controller.
568
+ * @param isBipolar If the source is bipolar (-1 to 1) instead of unipolar (0 to 1).
569
+ * @param isNegative If the direction of the source is flipped.
570
+ */
571
+ constructor(index?: ModulatorSourceIndex, curveType?: ModulatorCurveType, isCC?: boolean, isBipolar?: boolean, isNegative?: boolean);
527
572
  private get sourceName();
528
573
  private get curveTypeName();
529
574
  toString(): string;
@@ -1090,6 +1135,7 @@ export declare class BasicSoundBank {
1090
1135
  * @param options Options associated with setting the sample format.
1091
1136
  * @returns The samples whose sample rate or loop points changed.
1092
1137
  * Compressing resamples samples outside 8000 to 96000 Hz.
1138
+ * @throws Error if `rejectOnFailure` is set and one of the samples has failed to compress.
1093
1139
  */
1094
1140
  setSampleFormat(options: SetSampleFormatOptions): Promise<BasicSample[]>;
1095
1141
  /**
@@ -1187,8 +1233,10 @@ export declare class BasicSoundBank {
1187
1233
  clonePreset(preset: BasicPreset, options?: Partial<SoundBankCloneOptions>): BasicPreset;
1188
1234
  /**
1189
1235
  * Updates internal values. Call after updating the preset list.
1236
+ * @param sort If the presets should be sorted. Set it to `false` to keep a custom order,
1237
+ * only the internal values (like {@link isXGBank}) are then recomputed.
1190
1238
  */
1191
- flush(): void;
1239
+ flush(sort?: boolean): void;
1192
1240
  /**
1193
1241
  * Trims the sound bank _in-place_ to only contain samples in a given MIDI file.
1194
1242
  *
@@ -1236,6 +1284,7 @@ export declare class BasicSoundBank {
1236
1284
  * Deletes everything irreversibly.
1237
1285
  */
1238
1286
  destroySoundBank(): void;
1287
+ protected addElements<T>(list: T[], elements: readonly T[]): void;
1239
1288
  protected parsingError(error: string): never;
1240
1289
  /**
1241
1290
  * Parses the bank after loading is done
@@ -1254,16 +1303,6 @@ interface LinkableZoneChild<P> {
1254
1303
  * The element's name.
1255
1304
  */
1256
1305
  name: string;
1257
- /**
1258
- * Links the element to a parent.
1259
- * @param parent The parent that uses the element.
1260
- */
1261
- linkTo(parent: P): void;
1262
- /**
1263
- * Unlinks the element from a parent.
1264
- * @param parent The parent that no longer uses the element.
1265
- */
1266
- unlinkFrom(parent: P): void;
1267
1306
  }
1268
1307
  /**
1269
1308
  * A zone that belongs to a parent and uses a child: a preset zone with its instrument,
@@ -1297,6 +1336,15 @@ export declare abstract class BasicLinkedZone<P, C extends LinkableZoneChild<P>>
1297
1336
  * @param link If the child should be linked to the parent.
1298
1337
  */
1299
1338
  protected constructor(parent: P, child: C, link: boolean);
1339
+ /**
1340
+ * Links the child to the parent, unless this zone was created without linking.
1341
+ * Use it to put a zone back after {@link unlinkChild}, for example when undoing a zone deletion.
1342
+ */
1343
+ linkChild(): void;
1344
+ /**
1345
+ * Unlinks the child from the parent, unless this zone was created without linking.
1346
+ */
1347
+ unlinkChild(): void;
1300
1348
  /**
1301
1349
  * Replaces the child, moving the link from the previous one to the new one.
1302
1350
  * @param child The new child.
@@ -1378,11 +1426,6 @@ export declare class BasicInstrument {
1378
1426
  * > An instrument with unlinked zones must not be added to a sound bank!
1379
1427
  */
1380
1428
  createZone(sample: BasicSample, link?: boolean): BasicInstrumentZone;
1381
- /**
1382
- * Unlinks the instrument from a given preset.
1383
- * @param preset The preset to unlink from.
1384
- */
1385
- unlinkFrom(preset: BasicPreset): void;
1386
1429
  /**
1387
1430
  * Unlinks everything from this instrument.
1388
1431
  * This is what {@link BasicSoundBank.deleteInstrument} calls, the instrument itself stays intact.
@@ -1549,6 +1592,12 @@ export declare class BasicSample {
1549
1592
  * How many instruments is this sample used by.
1550
1593
  */
1551
1594
  get useCount(): number;
1595
+ /**
1596
+ * If the decoded float data is currently held in memory.
1597
+ * Check it before {@link getAudioData} to know if the call has to decode,
1598
+ * then use {@link releaseDecoded} to drop the copy again.
1599
+ */
1600
+ get isDecoded(): boolean;
1552
1601
  /**
1553
1602
  * Get raw data for writing the file, either a compressed bit stream or signed 16-bit little endian PCM data.
1554
1603
  * @param allowVorbis if vorbis file data is allowed.
@@ -1603,11 +1652,6 @@ export declare class BasicSample {
1603
1652
  * @param type Either left, right or linked. The linked sample will be set appropriately as well.
1604
1653
  */
1605
1654
  setLinkedSample(sample: BasicSample, type: SampleType): void;
1606
- /**
1607
- * Unlinks the sample from a given instrument
1608
- * @param instrument the instrument to unlink from
1609
- */
1610
- unlinkFrom(instrument: BasicInstrument): void;
1611
1655
  /**
1612
1656
  * Get the PCM Float32 audio data of this sample.
1613
1657
  * This either decodes the compressed data or passes the ready sampleData.
@@ -2216,6 +2260,13 @@ export type SetSampleFormatOptions = {
2216
2260
  * It must be provided if `compressed` format is chosen.
2217
2261
  */
2218
2262
  compressionFunction: SampleEncodingFunction;
2263
+ /**
2264
+ * If the returned promise should reject when a sample fails to compress.
2265
+ * By default, such a sample is left uncompressed (and a warning is logged),
2266
+ * but the bank is still set to version 3.0.
2267
+ * With this on, the method throws after trying every sample and the bank's version stays the same.
2268
+ */
2269
+ rejectOnFailure?: boolean;
2219
2270
  });
2220
2271
  /**
2221
2272
  * Options for writing a sound bank file.
@@ -2361,11 +2412,15 @@ export interface SoundBankCloneOptions {
2361
2412
  */
2362
2413
  reuseByName: boolean;
2363
2414
  /**
2364
- * If the instruments and samples used by a cloned element are reused when one with the same name exists.
2365
- * When false, they are copied under a free name as well.
2415
+ * How the instruments and samples used by a cloned element are reused instead of copied.
2416
+ * - `name` - reuse the first element in the bank with the same name.
2417
+ * - `identity` - reuse the element itself if it is already in the bank.
2418
+ * Use it to duplicate elements within one bank, as names often repeat in real banks.
2419
+ * - `none` - always copy them, under a free name if needed.
2420
+ *
2366
2421
  * A stereo partner of a copied sample is always copied with it.
2367
2422
  */
2368
- reuseChildrenByName: boolean;
2423
+ reuseChildren: "name" | "identity" | "none";
2369
2424
  /**
2370
2425
  * If the new elements are added to the bank.
2371
2426
  * When false, they are only listed in {@link SoundBankCloner.created}.
@@ -3731,6 +3786,7 @@ export declare class SoundBankManager {
3731
3786
  */
3732
3787
  soundBankList: SoundBankManagerListEntry[];
3733
3788
  private readonly presetListChangeCallback;
3789
+ private readonly bankRemovedCallback?;
3734
3790
  private selectablePresetList;
3735
3791
  private _presetList;
3736
3792
  /**
@@ -3760,17 +3816,21 @@ export declare class SoundBankManager {
3760
3816
  /**
3761
3817
  * This method removes a sound bank with a given ID from the sound bank list.
3762
3818
  * @param id The ID of the sound bank to delete.
3819
+ * @param reset If the synthesizer should reset (put every channel's controllers back to defaults) after the change.
3820
+ * Set it to `false` to keep a song playing, the channels then only update to the new presets.
3763
3821
  * @throws Error An error if there's no sound bank with the given ID.
3764
3822
  */
3765
- deleteSoundBank(id: string): void;
3823
+ deleteSoundBank(id: string, reset?: boolean): void;
3766
3824
  /**
3767
3825
  * Adds a new sound bank with a given ID, or replaces an existing one.
3768
3826
  * @param bank The sound bank to add.
3769
3827
  * @param id The unique ID to assign to the sound bank.
3770
3828
  * If a sound bank with this ID already exists, it will be replaced.
3771
3829
  * @param bankOffset The bank offset of the sound bank. Offsets the bank MSB value of all presets in this sound bank.
3830
+ * @param reset If the synthesizer should reset (put every channel's controllers back to defaults) after the change.
3831
+ * Set it to `false` to keep a song playing, the channels then only update to the new presets.
3772
3832
  */
3773
- addSoundBank(bank: BasicSoundBank, id: string, bankOffset?: number): void;
3833
+ addSoundBank(bank: BasicSoundBank, id: string, bankOffset?: number, reset?: boolean): void;
3774
3834
  /**
3775
3835
  * Rebuilds the preset list from the current sound banks.
3776
3836
  * Call it after editing a sound bank that is already added,
@@ -3780,6 +3840,7 @@ export declare class SoundBankManager {
3780
3840
  * see {@link SpessaSynthProcessor.refreshPresets}.
3781
3841
  */
3782
3842
  refresh(): void;
3843
+ private bankRemoved;
3783
3844
  private generatePresetList;
3784
3845
  }
3785
3846
  /**
@@ -4115,10 +4176,6 @@ export declare class SpessaSynthProcessor {
4115
4176
  * All MIDI channels of the synthesizer.
4116
4177
  */
4117
4178
  readonly midiChannels: MIDIChannel[];
4118
- /**
4119
- * The sound bank manager, which manages all sound banks and presets.
4120
- */
4121
- readonly soundBankManager: SoundBankManager;
4122
4179
  /**
4123
4180
  * The sample rate, in Hertz.
4124
4181
  */
@@ -4147,6 +4204,10 @@ export declare class SpessaSynthProcessor {
4147
4204
  * @param event The event that occurred.
4148
4205
  */
4149
4206
  onEventCall?: (event: SynthesizerEventCallback) => unknown;
4207
+ /**
4208
+ * The sound bank manager, which manages all sound banks and presets.
4209
+ */
4210
+ readonly soundBankManager: SoundBankManager;
4150
4211
  /**
4151
4212
  * Left float32 buffer for processing XG insertion effects in-place.
4152
4213
  * (channel outputs are double precision)
@@ -8724,6 +8785,19 @@ export declare class SoundBankCloner {
8724
8785
  * @param options The options for this session.
8725
8786
  */
8726
8787
  constructor(bank: BasicSoundBank, options?: Partial<SoundBankCloneOptions>);
8788
+ private get ownReuse();
8789
+ /**
8790
+ * Gets the clone this session made of an element.
8791
+ * @param source The sample or instrument that was cloned.
8792
+ * @returns The clone, or undefined if the session has not cloned the element.
8793
+ */
8794
+ getClone(source: BasicSample): BasicSample | undefined;
8795
+ /**
8796
+ * Gets the clone this session made of an element.
8797
+ * @param source The sample or instrument that was cloned.
8798
+ * @returns The clone, or undefined if the session has not cloned the element.
8799
+ */
8800
+ getClone(source: BasicInstrument): BasicInstrument | undefined;
8727
8801
  /**
8728
8802
  * Clones a sample and its stereo partner.
8729
8803
  * The data is shared with the original, not copied.
@@ -8745,6 +8819,10 @@ export declare class SoundBankCloner {
8745
8819
  clonePreset(preset: BasicPreset): BasicPreset;
8746
8820
  private copyInstrument;
8747
8821
  private copySample;
8822
+ /**
8823
+ * Finds the element to use instead of a copy, if the options allow one.
8824
+ */
8825
+ private findReused;
8748
8826
  private getFreeName;
8749
8827
  }
8750
8828
  /**