spessasynth_core 4.0.20 → 4.0.22

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
@@ -151,26 +151,6 @@ declare const generatorLimits: {
151
151
  nrpn: number;
152
152
  }[];
153
153
 
154
- declare class Generator {
155
- /**
156
- * The generator's SF2 type.
157
- */
158
- generatorType: GeneratorType;
159
- /**
160
- * The generator's 16-bit value.
161
- */
162
- generatorValue: number;
163
- /**
164
- * Constructs a new generator
165
- * @param type generator type
166
- * @param value generator value
167
- * @param validate if the limits should be validated
168
- */
169
- constructor(type: GeneratorType, value: number, validate?: boolean);
170
- write(genData: IndexedByteArray): void;
171
- toString(): string;
172
- }
173
-
174
154
  declare const sampleTypes: {
175
155
  readonly monoSample: 1;
176
156
  readonly rightSample: 2;
@@ -265,116 +245,32 @@ declare const DLSLoopTypes: {
265
245
  };
266
246
  type DLSLoopType = (typeof DLSLoopTypes)[keyof typeof DLSLoopTypes];
267
247
 
268
- declare class BasicZone {
269
- /**
270
- * The zone's velocity range.
271
- * min -1 means that it is a default value
272
- */
273
- velRange: GenericRange;
274
- /**
275
- * The zone's key range.
276
- * min -1 means that it is a default value.
277
- */
278
- keyRange: GenericRange;
279
- /**
280
- * The zone's generators.
281
- */
282
- generators: Generator[];
283
- /**
284
- * The zone's modulators.
285
- */
286
- modulators: Modulator[];
287
- get hasKeyRange(): boolean;
288
- get hasVelRange(): boolean;
289
- /**
290
- * The current tuning in cents, taking in both coarse and fine generators.
291
- */
292
- get fineTuning(): number;
293
- /**
294
- * The current tuning in cents, taking in both coarse and fine generators.
295
- */
296
- set fineTuning(tuningCents: number);
297
- /**
298
- * Adds to a given generator, or its default value.
299
- */
300
- addToGenerator(type: GeneratorType, value: number, validate?: boolean): void;
301
- /**
302
- * Sets a generator to a given value if preset, otherwise adds a new one.
303
- */
304
- setGenerator(type: GeneratorType, value: number | null, validate?: boolean): void;
305
- /**
306
- * Adds generators to the zone.
307
- * @param generators
308
- */
309
- addGenerators(...generators: Generator[]): void;
310
- addModulators(...modulators: Modulator[]): void;
311
- getGenerator<K>(generatorType: GeneratorType, notFoundValue: number | K): number | K;
312
- copyFrom(zone: BasicZone): void;
313
- /**
314
- * Filters the generators and prepends the range generators.
315
- */
316
- getWriteGenerators(bank: BasicSoundBank): Generator[];
317
- }
318
-
319
- declare class BasicGlobalZone extends BasicZone {
320
- }
321
-
322
- declare class BasicInstrumentZone extends BasicZone {
323
- /**
324
- * The instrument this zone belongs to.
325
- */
326
- readonly parentInstrument: BasicInstrument;
327
- /**
328
- * For tracking on the individual zone level, since multiple presets can refer to the same instrument.
329
- */
330
- useCount: number;
331
- /**
332
- * Creates a new instrument zone.
333
- * @param instrument The parent instrument.
334
- * @param sample The sample to use in this zone.
335
- */
336
- constructor(instrument: BasicInstrument, sample: BasicSample);
337
- /**
338
- * Zone's sample.
339
- */
340
- private _sample;
341
- /**
342
- * Zone's sample.
343
- */
344
- get sample(): BasicSample;
345
- /**
346
- * Sets a sample for this zone.
347
- * @param sample the sample to set.
348
- */
349
- set sample(sample: BasicSample);
350
- getWriteGenerators(bank: BasicSoundBank): Generator[];
351
- }
352
-
353
- declare class BasicPresetZone extends BasicZone {
354
- /**
355
- * The preset this zone belongs to.
356
- */
357
- readonly parentPreset: BasicPreset;
358
- /**
359
- * Creates a new preset zone.
360
- * @param preset the preset this zone belongs to.
361
- * @param instrument the instrument to use in this zone.
362
- */
363
- constructor(preset: BasicPreset, instrument: BasicInstrument);
364
- /**
365
- * Zone's instrument.
366
- */
367
- private _instrument;
368
- /**
369
- * Zone's instrument.
370
- */
371
- get instrument(): BasicInstrument;
372
- /**
373
- * Zone's instrument.
374
- */
375
- set instrument(instrument: BasicInstrument);
376
- getWriteGenerators(bank: BasicSoundBank): Generator[];
377
- }
248
+ declare const interpolationTypes: {
249
+ readonly linear: 0;
250
+ readonly nearestNeighbor: 1;
251
+ readonly hermite: 2;
252
+ };
253
+ type InterpolationType = (typeof interpolationTypes)[keyof typeof interpolationTypes];
254
+ declare const dataEntryStates: {
255
+ readonly Idle: 0;
256
+ readonly RPCoarse: 1;
257
+ readonly RPFine: 2;
258
+ readonly NRPCoarse: 3;
259
+ readonly NRPFine: 4;
260
+ readonly DataCoarse: 5;
261
+ readonly DataFine: 6;
262
+ };
263
+ type DataEntryState = (typeof dataEntryStates)[keyof typeof dataEntryStates];
264
+ declare const customControllers: {
265
+ readonly channelTuning: 0;
266
+ readonly channelTransposeFine: 1;
267
+ readonly modulationMultiplier: 2;
268
+ readonly masterTuning: 3;
269
+ readonly channelTuningSemitones: 4;
270
+ readonly channelKeyShift: 5;
271
+ readonly sf2NPRNGeneratorLSB: 6;
272
+ };
273
+ type CustomController = (typeof customControllers)[keyof typeof customControllers];
378
274
 
379
275
  interface MIDIPatch {
380
276
  /**
@@ -429,244 +325,460 @@ declare class MIDIPatchTools {
429
325
  static sorter(a: MIDIPatch, b: MIDIPatch): number;
430
326
  }
431
327
 
432
- /**
433
- * Returned structure containing extended SF2 chunks.
434
- */
435
- interface ExtendedSF2Chunks {
436
- /**
437
- * The PDTA part of the chunk.
438
- */
439
- pdta: IndexedByteArray;
328
+ type SynthSystem = "gm" | "gm2" | "gs" | "xg";
329
+ interface NoteOnCallback {
330
+ /** The MIDI note number. */
331
+ midiNote: number;
332
+ /** The MIDI channel number. */
333
+ channel: number;
334
+ /** The velocity of the note. */
335
+ velocity: number;
336
+ }
337
+ interface NoteOffCallback {
338
+ /** The MIDI note number. */
339
+ midiNote: number;
340
+ /** The MIDI channel number. */
341
+ channel: number;
342
+ }
343
+ interface DrumChangeCallback {
344
+ /** The MIDI channel number. */
345
+ channel: number;
346
+ /** Indicates if the channel is a drum channel. */
347
+ isDrumChannel: boolean;
348
+ }
349
+ interface ProgramChangeCallback extends MIDIPatch {
350
+ /** The MIDI channel number. */
351
+ channel: number;
352
+ }
353
+ interface ControllerChangeCallback {
354
+ /** The MIDI channel number. */
355
+ channel: number;
356
+ /** The controller number. */
357
+ controllerNumber: number;
358
+ /** The value of the controller. */
359
+ controllerValue: number;
360
+ }
361
+ interface MuteChannelCallback {
362
+ /** The MIDI channel number. */
363
+ channel: number;
364
+ /** Indicates if the channel is muted. */
365
+ isMuted: boolean;
366
+ }
367
+ interface PresetListEntry extends MIDIPatchNamed {
440
368
  /**
441
- * The XDTA (https://github.com/spessasus/soundfont-proposals/blob/main/extended_limits.md) part of the chunk.
369
+ * Indicates if this preset is any kind of drum preset.
442
370
  */
443
- xdta: IndexedByteArray;
371
+ isAnyDrums: boolean;
444
372
  }
445
373
  /**
446
- * Write indexes for tracking writing a SoundFont file.
374
+ * A list of preset changes, each with a name, bank, and program number.
447
375
  */
448
- interface SoundFontWriteIndexes {
449
- /**
450
- * Generator start index.
451
- */
452
- gen: number;
376
+ type PresetList = PresetListEntry[];
377
+ /**
378
+ * The synthesizer display system exclusive data, EXCLUDING THE F0 BYTE!
379
+ */
380
+ type SynthDisplayCallback = number[];
381
+ interface PitchWheelCallback {
382
+ /** The MIDI channel number. */
383
+ channel: number;
453
384
  /**
454
- * Modulator start index.
385
+ * The unsigned 14-bit value of the pitch: 0 - 16383.
455
386
  */
456
- mod: number;
387
+ pitch: number;
388
+ }
389
+ interface ChannelPressureCallback {
390
+ /** The MIDI channel number. */
391
+ channel: number;
392
+ /** The pressure value. */
393
+ pressure: number;
394
+ }
395
+ interface PolyPressureCallback {
396
+ /** The MIDI channel number. */
397
+ channel: number;
398
+ /** The MIDI note number. */
399
+ midiNote: number;
400
+ /** The pressure value. */
401
+ pressure: number;
402
+ }
403
+ /**
404
+ * The error message for sound bank errors.
405
+ */
406
+ type SoundBankErrorCallback = Error;
407
+ interface StopAllCallback {
457
408
  /**
458
- * Zone start index.
409
+ * The MIDI channel number.
459
410
  */
460
- bag: number;
411
+ channel: number;
461
412
  /**
462
- * Preset/instrument start index.
413
+ * If the channel was force stopped. (no release time)
463
414
  */
464
- hdr: number;
415
+ force: boolean;
465
416
  }
466
-
467
- declare class BasicPreset implements MIDIPatchNamed {
417
+ type MasterParameterChangeCallback = {
418
+ [P in keyof MasterParameterType]: {
419
+ /**
420
+ * The parameter that was changed.
421
+ */
422
+ parameter: P;
423
+ /**
424
+ * The new value of this parameter.
425
+ */
426
+ value: MasterParameterType[P];
427
+ };
428
+ }[keyof MasterParameterType];
429
+ interface ChannelPropertyChangeCallback {
468
430
  /**
469
- * The parent soundbank instance
470
- * Currently used for determining default modulators and XG status
431
+ * The channel number of the new property.
471
432
  */
472
- readonly parentSoundBank: BasicSoundBank;
433
+ channel: number;
473
434
  /**
474
- * The preset's name
435
+ * The updated property.
475
436
  */
476
- name: string;
477
- program: number;
478
- bankMSB: number;
479
- bankLSB: number;
480
- isGMGSDrum: boolean;
437
+ property: ChannelProperty;
438
+ }
439
+ interface SynthProcessorEventData {
481
440
  /**
482
- * The preset's zones
441
+ * This event fires when a note is played.
483
442
  */
484
- zones: BasicPresetZone[];
443
+ noteOn: NoteOnCallback;
485
444
  /**
486
- * Preset's global zone
445
+ * This event fires when a note is released.
487
446
  */
488
- readonly globalZone: BasicGlobalZone;
447
+ noteOff: NoteOffCallback;
489
448
  /**
490
- * Unused metadata
449
+ * This event fires when a pitch wheel is changed.
491
450
  */
492
- library: number;
451
+ pitchWheel: PitchWheelCallback;
493
452
  /**
494
- * Unused metadata
453
+ * This event fires when a controller is changed.
495
454
  */
496
- genre: number;
455
+ controllerChange: ControllerChangeCallback;
497
456
  /**
498
- * Unused metadata
457
+ * This event fires when a program is changed.
499
458
  */
500
- morphology: number;
459
+ programChange: ProgramChangeCallback;
501
460
  /**
502
- * Creates a new preset representation.
503
- * @param parentSoundBank the sound bank this preset belongs to.
504
- * @param globalZone optional, a global zone to use.
461
+ * This event fires when a channel pressure is changed.
505
462
  */
506
- constructor(parentSoundBank: BasicSoundBank, globalZone?: BasicGlobalZone);
507
- get isXGDrums(): boolean;
463
+ channelPressure: ChannelPressureCallback;
508
464
  /**
509
- * Checks if this preset is a drum preset
465
+ * This event fires when a polyphonic pressure is changed.
510
466
  */
511
- get isAnyDrums(): boolean;
467
+ polyPressure: PolyPressureCallback;
512
468
  /**
513
- * Unlinks everything from this preset.
469
+ * This event fires when a drum channel is changed.
514
470
  */
515
- delete(): void;
471
+ drumChange: DrumChangeCallback;
516
472
  /**
517
- * Deletes an instrument zone from this preset.
518
- * @param index the zone's index to delete.
473
+ * This event fires when all notes on a channel are stopped.
519
474
  */
520
- deleteZone(index: number): void;
475
+ stopAll: StopAllCallback;
521
476
  /**
522
- * Creates a new preset zone and returns it.
523
- * @param instrument the instrument to use in the zone.
477
+ * This event fires when a new channel is created. There is no data for this event.
524
478
  */
525
- createZone(instrument: BasicInstrument): BasicPresetZone;
479
+ newChannel: void;
526
480
  /**
527
- * Preloads (loads and caches synthesis data) for a given key range.
481
+ * This event fires when a channel is muted or unmuted.
528
482
  */
529
- preload(keyMin: number, keyMax: number): void;
483
+ muteChannel: MuteChannelCallback;
530
484
  /**
531
- * Checks if the bank and program numbers are the same for the given preset as this one.
532
- * @param preset The preset to check.
485
+ * This event fires when the preset list is changed.
533
486
  */
534
- matches(preset: MIDIPatch): boolean;
487
+ presetListChange: PresetList;
535
488
  /**
536
- * Returns the synthesis data from this preset
537
- * @param midiNote the MIDI note number
538
- * @param velocity the MIDI velocity
539
- * @returns the returned sound data
489
+ * This event fires when all controllers on all channels are reset. There is no data for this event.
540
490
  */
541
- getSynthesisData(midiNote: number, velocity: number): VoiceSynthesisData[];
491
+ allControllerReset: void;
542
492
  /**
543
- * BankMSB:bankLSB:program:isGMGSDrum
493
+ * This event fires when a sound bank parsing error occurs.
544
494
  */
545
- toMIDIString(): string;
546
- toString(): string;
495
+ soundBankError: SoundBankErrorCallback;
547
496
  /**
548
- * Combines preset into an instrument, flattening the preset zones into instrument zones.
549
- * This is a really complex function that attempts to work around the DLS limitations of only having the instrument layer.
550
- * @returns The instrument containing the flattened zones. In theory, it should exactly the same as this preset.
497
+ * This event fires when the synthesizer receives a display message.
551
498
  */
552
- toFlattenedInstrument(): BasicInstrument;
499
+ synthDisplay: SynthDisplayCallback;
553
500
  /**
554
- * Writes the SF2 header
555
- * @param phdrData
556
- * @param index
501
+ * This event fires when a master parameter changes.
557
502
  */
558
- write(phdrData: ExtendedSF2Chunks, index: number): void;
503
+ masterParameterChange: MasterParameterChangeCallback;
504
+ /**
505
+ * This event fires when a channel property changes.
506
+ */
507
+ channelPropertyChange: ChannelPropertyChangeCallback;
508
+ }
509
+ type SynthProcessorEvent = {
510
+ [K in keyof SynthProcessorEventData]: {
511
+ type: K;
512
+ data: SynthProcessorEventData[K];
513
+ };
514
+ }[keyof SynthProcessorEventData];
515
+ interface SynthMethodOptions {
516
+ /**
517
+ * The audio context time when the event should execute, in seconds.
518
+ */
519
+ time: number;
559
520
  }
560
-
561
521
  /**
562
- * Represents a single instrument
522
+ * KeyNum: tuning.
563
523
  */
564
- declare class BasicInstrument {
524
+ type MTSProgramTuning = MTSNoteTuning[];
525
+ interface MTSNoteTuning {
565
526
  /**
566
- * The instrument's name
527
+ * The base MIDI note to use, -1 means no change.
567
528
  */
568
- name: string;
529
+ midiNote: number;
569
530
  /**
570
- * The instrument's zones
531
+ * Additional tuning.
571
532
  */
572
- zones: BasicInstrumentZone[];
533
+ centTuning: number | null;
534
+ }
535
+ /**
536
+ * Looping mode of the sample.
537
+ * 0 - no loop.
538
+ * 1 - loop.
539
+ * 2 - UNOFFICIAL: polyphone 2.4 added start on release.
540
+ * 3 - loop then play when released.
541
+ */
542
+ type SampleLoopingMode = 0 | 1 | 2 | 3;
543
+ /**
544
+ * A list of voices for a given key:velocity.
545
+ */
546
+ type VoiceList = Voice[];
547
+ interface ChannelProperty {
573
548
  /**
574
- * Instrument's global zone
549
+ * The channel's current voice amount.
575
550
  */
576
- readonly globalZone: BasicGlobalZone;
551
+ voicesAmount: number;
577
552
  /**
578
- * Instrument's linked presets (the presets that use it)
579
- * note that duplicates are allowed since one preset can use the same instrument multiple times.
553
+ * The channel's current pitch wheel 0 - 16384.
580
554
  */
581
- readonly linkedTo: BasicPreset[];
555
+ pitchWheel: number;
582
556
  /**
583
- * How many presets is this instrument used by
557
+ * The pitch wheel's range, in semitones.
584
558
  */
585
- get useCount(): number;
559
+ pitchWheelRange: number;
586
560
  /**
587
- * Creates a new instrument zone and returns it.
588
- * @param sample The sample to use in the zone.
561
+ * Indicates whether the channel is muted.
589
562
  */
590
- createZone(sample: BasicSample): BasicInstrumentZone;
563
+ isMuted: boolean;
591
564
  /**
592
- * Links the instrument ta a given preset
593
- * @param preset the preset to link to
565
+ * Indicates whether the channel is a drum channel.
594
566
  */
595
- linkTo(preset: BasicPreset): void;
567
+ isDrum: boolean;
596
568
  /**
597
- * Unlinks the instrument from a given preset
598
- * @param preset the preset to unlink from
569
+ * The channel's transposition, in semitones.
599
570
  */
600
- unlinkFrom(preset: BasicPreset): void;
601
- deleteUnusedZones(): void;
602
- delete(): void;
571
+ transposition: number;
572
+ }
573
+ interface SynthProcessorOptions {
603
574
  /**
604
- * Deletes a given instrument zone if it has no uses
605
- * @param index the index of the zone to delete
606
- * @param force ignores the use count and deletes forcibly
607
- * @returns if the zone has been deleted
575
+ * Indicates if the event system is enabled. This can be changed later.
608
576
  */
609
- deleteZone(index: number, force?: boolean): boolean;
577
+ enableEventSystem: boolean;
610
578
  /**
611
- * Globalizes the instrument *in-place.*
612
- * This means trying to move as many generators and modulators
613
- * to the global zone as possible to reduce clutter and the count of parameters.
579
+ * The initial time of the synth, in seconds.
614
580
  */
615
- globalize(): void;
616
- write(instData: ExtendedSF2Chunks, index: number): void;
617
- }
618
-
619
- declare class BasicSample {
581
+ initialTime: number;
620
582
  /**
621
- * The sample's name.
583
+ * Indicates if the effects are enabled. This can be changed later.
622
584
  */
623
- name: string;
585
+ enableEffects: boolean;
586
+ }
587
+ /**
588
+ * The master parameters of the synthesizer.
589
+ */
590
+ interface MasterParameterType {
624
591
  /**
625
- * Sample rate in Hz.
592
+ * The master gain, from 0 to any number. 1 is 100% volume.
626
593
  */
627
- sampleRate: number;
594
+ masterGain: number;
628
595
  /**
629
- * Original pitch of the sample as a MIDI note number.
596
+ * The master pan, from -1 (left) to 1 (right). 0 is center.
630
597
  */
631
- originalKey: number;
598
+ masterPan: number;
632
599
  /**
633
- * Pitch correction, in cents. Can be negative.
600
+ * The maximum number of voices that can be played at once.
634
601
  */
635
- pitchCorrection: number;
602
+ voiceCap: number;
636
603
  /**
637
- * Linked sample, unused if mono.
604
+ * The interpolation type used for sample playback.
638
605
  */
639
- linkedSample?: BasicSample;
606
+ interpolationType: InterpolationType;
640
607
  /**
641
- * The type of the sample.
608
+ * The MIDI system used by the synthesizer for bank selects and system exclusives. (GM, GM2, GS, XG)
642
609
  */
643
- sampleType: SampleType;
610
+ midiSystem: SynthSystem;
644
611
  /**
645
- * Relative to the start of the sample in sample points.
612
+ * Indicates whether the synthesizer is in monophonic retrigger mode.
613
+ * This emulates the behavior of Microsoft GS Wavetable Synth,
614
+ * Where a new note will kill the previous one if it is still playing.
646
615
  */
647
- loopStart: number;
616
+ monophonicRetriggerMode: boolean;
648
617
  /**
649
- * Relative to the start of the sample in sample points.
618
+ * The reverb gain, from 0 to any number. 1 is 100% reverb.
650
619
  */
651
- loopEnd: number;
620
+ reverbGain: number;
652
621
  /**
653
- * Sample's linked instruments (the instruments that use it)
654
- * note that duplicates are allowed since one instrument can use the same sample multiple times.
622
+ * The chorus gain, from 0 to any number. 1 is 100% chorus.
655
623
  */
656
- linkedTo: BasicInstrument[];
624
+ chorusGain: number;
657
625
  /**
658
- * Indicates if the data was overridden, so it cannot be copied back unchanged.
626
+ * Forces note killing instead of releasing. Improves performance in black MIDIs.
659
627
  */
660
- protected dataOverridden: boolean;
628
+ blackMIDIMode: boolean;
661
629
  /**
662
- * The compressed sample data if the sample has been compressed.
630
+ * The global transposition in semitones. It can be decimal to provide microtonal tuning.
663
631
  */
664
- protected compressedData?: Uint8Array;
632
+ transposition: number;
665
633
  /**
666
- * The sample's audio data.
634
+ * Synthesizer's device ID for system exclusive messages. Set to -1 to accept all.
667
635
  */
668
- protected audioData?: Float32Array;
669
- /**
636
+ deviceID: number;
637
+ }
638
+
639
+ /**
640
+ * Sets a master parameter of the synthesizer.
641
+ * @param parameter The type of the master parameter to set.
642
+ * @param value The value to set for the master parameter.
643
+ */
644
+ declare function setMasterParameterInternal<P extends keyof MasterParameterType>(this: SpessaSynthProcessor, parameter: P, value: MasterParameterType[P]): void;
645
+ /**
646
+ * Gets a master parameter of the synthesizer.
647
+ * @param type The type of the master parameter to get.
648
+ * @returns The value of the master parameter.
649
+ */
650
+ declare function getMasterParameterInternal<P extends keyof MasterParameterType>(this: SpessaSynthProcessor, type: P): MasterParameterType[P];
651
+ /**
652
+ * Gets all master parameters of the synthesizer.
653
+ * @returns All the master parameters.
654
+ */
655
+ declare function getAllMasterParametersInternal(this: SpessaSynthProcessor): MasterParameterType;
656
+
657
+ declare class Generator {
658
+ /**
659
+ * The generator's SF2 type.
660
+ */
661
+ generatorType: GeneratorType;
662
+ /**
663
+ * The generator's 16-bit value.
664
+ */
665
+ generatorValue: number;
666
+ /**
667
+ * Constructs a new generator
668
+ * @param type generator type
669
+ * @param value generator value
670
+ * @param validate if the limits should be validated
671
+ */
672
+ constructor(type: GeneratorType, value: number, validate?: boolean);
673
+ write(genData: IndexedByteArray): void;
674
+ toString(): string;
675
+ }
676
+
677
+ declare class BasicZone {
678
+ /**
679
+ * The zone's velocity range.
680
+ * min -1 means that it is a default value
681
+ */
682
+ velRange: GenericRange;
683
+ /**
684
+ * The zone's key range.
685
+ * min -1 means that it is a default value.
686
+ */
687
+ keyRange: GenericRange;
688
+ /**
689
+ * The zone's generators.
690
+ */
691
+ generators: Generator[];
692
+ /**
693
+ * The zone's modulators.
694
+ */
695
+ modulators: Modulator[];
696
+ get hasKeyRange(): boolean;
697
+ get hasVelRange(): boolean;
698
+ /**
699
+ * The current tuning in cents, taking in both coarse and fine generators.
700
+ */
701
+ get fineTuning(): number;
702
+ /**
703
+ * The current tuning in cents, taking in both coarse and fine generators.
704
+ */
705
+ set fineTuning(tuningCents: number);
706
+ /**
707
+ * Adds to a given generator, or its default value.
708
+ */
709
+ addToGenerator(type: GeneratorType, value: number, validate?: boolean): void;
710
+ /**
711
+ * Sets a generator to a given value if preset, otherwise adds a new one.
712
+ */
713
+ setGenerator(type: GeneratorType, value: number | null, validate?: boolean): void;
714
+ /**
715
+ * Adds generators to the zone.
716
+ * @param generators
717
+ */
718
+ addGenerators(...generators: Generator[]): void;
719
+ addModulators(...modulators: Modulator[]): void;
720
+ getGenerator<K>(generatorType: GeneratorType, notFoundValue: number | K): number | K;
721
+ copyFrom(zone: BasicZone): void;
722
+ /**
723
+ * Filters the generators and prepends the range generators.
724
+ */
725
+ getWriteGenerators(bank: BasicSoundBank): Generator[];
726
+ }
727
+
728
+ declare class BasicGlobalZone extends BasicZone {
729
+ }
730
+
731
+ declare class BasicSample {
732
+ /**
733
+ * The sample's name.
734
+ */
735
+ name: string;
736
+ /**
737
+ * Sample rate in Hz.
738
+ */
739
+ sampleRate: number;
740
+ /**
741
+ * Original pitch of the sample as a MIDI note number.
742
+ */
743
+ originalKey: number;
744
+ /**
745
+ * Pitch correction, in cents. Can be negative.
746
+ */
747
+ pitchCorrection: number;
748
+ /**
749
+ * Linked sample, unused if mono.
750
+ */
751
+ linkedSample?: BasicSample;
752
+ /**
753
+ * The type of the sample.
754
+ */
755
+ sampleType: SampleType;
756
+ /**
757
+ * Relative to the start of the sample in sample points.
758
+ */
759
+ loopStart: number;
760
+ /**
761
+ * Relative to the start of the sample in sample points.
762
+ */
763
+ loopEnd: number;
764
+ /**
765
+ * Sample's linked instruments (the instruments that use it)
766
+ * note that duplicates are allowed since one instrument can use the same sample multiple times.
767
+ */
768
+ linkedTo: BasicInstrument[];
769
+ /**
770
+ * Indicates if the data was overridden, so it cannot be copied back unchanged.
771
+ */
772
+ protected dataOverridden: boolean;
773
+ /**
774
+ * The compressed sample data if the sample has been compressed.
775
+ */
776
+ protected compressedData?: Uint8Array;
777
+ /**
778
+ * The sample's audio data.
779
+ */
780
+ protected audioData?: Float32Array;
781
+ /**
670
782
  * The basic representation of a sample
671
783
  * @param sampleName The sample's name
672
784
  * @param sampleRate The sample's rate in Hz
@@ -764,690 +876,250 @@ declare class EmptySample extends BasicSample {
764
876
  constructor();
765
877
  }
766
878
 
767
- declare const midiMessageTypes: {
768
- readonly noteOff: 128;
769
- readonly noteOn: 144;
770
- readonly polyPressure: 160;
771
- readonly controllerChange: 176;
772
- readonly programChange: 192;
773
- readonly channelPressure: 208;
774
- readonly pitchWheel: 224;
775
- readonly systemExclusive: 240;
776
- readonly timecode: 241;
777
- readonly songPosition: 242;
778
- readonly songSelect: 243;
779
- readonly tuneRequest: 246;
780
- readonly clock: 248;
781
- readonly start: 250;
782
- readonly continue: 251;
783
- readonly stop: 252;
784
- readonly activeSensing: 254;
785
- readonly reset: 255;
786
- readonly sequenceNumber: 0;
787
- readonly text: 1;
788
- readonly copyright: 2;
789
- readonly trackName: 3;
790
- readonly instrumentName: 4;
791
- readonly lyric: 5;
792
- readonly marker: 6;
793
- readonly cuePoint: 7;
794
- readonly programName: 8;
795
- readonly midiChannelPrefix: 32;
796
- readonly midiPort: 33;
797
- readonly endOfTrack: 47;
798
- readonly setTempo: 81;
799
- readonly smpteOffset: 84;
800
- readonly timeSignature: 88;
801
- readonly keySignature: 89;
802
- readonly sequenceSpecific: 127;
803
- };
804
- type MIDIMessageType = (typeof midiMessageTypes)[keyof typeof midiMessageTypes];
805
- declare const midiControllers: {
806
- readonly bankSelect: 0;
807
- readonly modulationWheel: 1;
808
- readonly breathController: 2;
809
- readonly undefinedCC3: 3;
810
- readonly footController: 4;
811
- readonly portamentoTime: 5;
812
- readonly dataEntryMSB: 6;
813
- readonly mainVolume: 7;
814
- readonly balance: 8;
815
- readonly undefinedCC9: 9;
816
- readonly pan: 10;
817
- readonly expressionController: 11;
818
- readonly effectControl1: 12;
819
- readonly effectControl2: 13;
820
- readonly undefinedCC14: 14;
821
- readonly undefinedCC15: 15;
822
- readonly generalPurposeController1: 16;
823
- readonly generalPurposeController2: 17;
824
- readonly generalPurposeController3: 18;
825
- readonly generalPurposeController4: 19;
826
- readonly undefinedCC20: 20;
827
- readonly undefinedCC21: 21;
828
- readonly undefinedCC22: 22;
829
- readonly undefinedCC23: 23;
830
- readonly undefinedCC24: 24;
831
- readonly undefinedCC25: 25;
832
- readonly undefinedCC26: 26;
833
- readonly undefinedCC27: 27;
834
- readonly undefinedCC28: 28;
835
- readonly undefinedCC29: 29;
836
- readonly undefinedCC30: 30;
837
- readonly undefinedCC31: 31;
838
- readonly bankSelectLSB: 32;
839
- readonly modulationWheelLSB: 33;
840
- readonly breathControllerLSB: 34;
841
- readonly undefinedCC3LSB: 35;
842
- readonly footControllerLSB: 36;
843
- readonly portamentoTimeLSB: 37;
844
- readonly dataEntryLSB: 38;
845
- readonly mainVolumeLSB: 39;
846
- readonly balanceLSB: 40;
847
- readonly undefinedCC9LSB: 41;
848
- readonly panLSB: 42;
849
- readonly expressionControllerLSB: 43;
850
- readonly effectControl1LSB: 44;
851
- readonly effectControl2LSB: 45;
852
- readonly undefinedCC14LSB: 46;
853
- readonly undefinedCC15LSB: 47;
854
- readonly undefinedCC16LSB: 48;
855
- readonly undefinedCC17LSB: 49;
856
- readonly undefinedCC18LSB: 50;
857
- readonly undefinedCC19LSB: 51;
858
- readonly undefinedCC20LSB: 52;
859
- readonly undefinedCC21LSB: 53;
860
- readonly undefinedCC22LSB: 54;
861
- readonly undefinedCC23LSB: 55;
862
- readonly undefinedCC24LSB: 56;
863
- readonly undefinedCC25LSB: 57;
864
- readonly undefinedCC26LSB: 58;
865
- readonly undefinedCC27LSB: 59;
866
- readonly undefinedCC28LSB: 60;
867
- readonly undefinedCC29LSB: 61;
868
- readonly undefinedCC30LSB: 62;
869
- readonly undefinedCC31LSB: 63;
870
- readonly sustainPedal: 64;
871
- readonly portamentoOnOff: 65;
872
- readonly sostenutoPedal: 66;
873
- readonly softPedal: 67;
874
- readonly legatoFootswitch: 68;
875
- readonly hold2Pedal: 69;
876
- readonly soundVariation: 70;
877
- readonly filterResonance: 71;
878
- readonly releaseTime: 72;
879
- readonly attackTime: 73;
880
- readonly brightness: 74;
881
- readonly decayTime: 75;
882
- readonly vibratoRate: 76;
883
- readonly vibratoDepth: 77;
884
- readonly vibratoDelay: 78;
885
- readonly soundController10: 79;
886
- readonly generalPurposeController5: 80;
887
- readonly generalPurposeController6: 81;
888
- readonly generalPurposeController7: 82;
889
- readonly generalPurposeController8: 83;
890
- readonly portamentoControl: 84;
891
- readonly undefinedCC85: 85;
892
- readonly undefinedCC86: 86;
893
- readonly undefinedCC87: 87;
894
- readonly undefinedCC88: 88;
895
- readonly undefinedCC89: 89;
896
- readonly undefinedCC90: 90;
897
- readonly reverbDepth: 91;
898
- readonly tremoloDepth: 92;
899
- readonly chorusDepth: 93;
900
- readonly detuneDepth: 94;
901
- readonly phaserDepth: 95;
902
- readonly dataIncrement: 96;
903
- readonly dataDecrement: 97;
904
- readonly nonRegisteredParameterLSB: 98;
905
- readonly nonRegisteredParameterMSB: 99;
906
- readonly registeredParameterLSB: 100;
907
- readonly registeredParameterMSB: 101;
908
- readonly undefinedCC102LSB: 102;
909
- readonly undefinedCC103LSB: 103;
910
- readonly undefinedCC104LSB: 104;
911
- readonly undefinedCC105LSB: 105;
912
- readonly undefinedCC106LSB: 106;
913
- readonly undefinedCC107LSB: 107;
914
- readonly undefinedCC108LSB: 108;
915
- readonly undefinedCC109LSB: 109;
916
- readonly undefinedCC110LSB: 110;
917
- readonly undefinedCC111LSB: 111;
918
- readonly undefinedCC112LSB: 112;
919
- readonly undefinedCC113LSB: 113;
920
- readonly undefinedCC114LSB: 114;
921
- readonly undefinedCC115LSB: 115;
922
- readonly undefinedCC116LSB: 116;
923
- readonly undefinedCC117LSB: 117;
924
- readonly undefinedCC118LSB: 118;
925
- readonly undefinedCC119LSB: 119;
926
- readonly allSoundOff: 120;
927
- readonly resetAllControllers: 121;
928
- readonly localControlOnOff: 122;
929
- readonly allNotesOff: 123;
930
- readonly omniModeOff: 124;
931
- readonly omniModeOn: 125;
932
- readonly monoModeOn: 126;
933
- readonly polyModeOn: 127;
934
- };
935
- type MIDIController = (typeof midiControllers)[keyof typeof midiControllers];
936
-
937
- type GenericRIFFFourCC = "RIFF" | "LIST" | "INFO";
938
- type WAVFourCC = "wave" | "cue " | "fmt ";
939
- type FourCC = GenericRIFFFourCC | SoundBankInfoFourCC | SF2InfoFourCC | SF2ChunkFourCC | DLSInfoFourCC | DLSChunkFourCC | RMIDInfoFourCC | WAVFourCC;
940
-
941
- interface SoundBankManagerListEntry {
942
- /**
943
- * The unique string identifier of the sound bank.
944
- */
945
- id: string;
946
- /**
947
- * The sound bank itself.
948
- */
949
- soundBank: BasicSoundBank;
950
- /**
951
- * The bank MSB offset for this sound bank.
952
- */
953
- bankOffset: number;
954
- }
955
- interface SF2VersionTag {
956
- /**
957
- * The major revision number of the sound bank.
958
- */
959
- major: number;
960
- /**
961
- * The minor revision number of this sound bank.
962
- */
963
- minor: number;
964
- }
965
- type GenericBankInfoFourCC = "INAM" | "ICRD" | "IENG" | "IPRD" | "ICOP" | "ICMT" | "ISFT";
966
- type SF2InfoFourCC = GenericBankInfoFourCC | "ifil" | "isng" | "irom" | "iver" | "DMOD" | "LIST";
967
- type SF2ChunkFourCC = "pdta" | "xdta" | "sdta" | "smpl" | "sm24" | "phdr" | "pbag" | "pmod" | "pgen" | "inst" | "ibag" | "imod" | "igen" | "shdr";
968
- type DLSInfoFourCC = GenericBankInfoFourCC | "ISBJ";
969
- type DLSChunkFourCC = WAVFourCC | "dls " | "dlid" | "cdl " | "ptbl" | "vers" | "colh" | "wvpl" | "wsmp" | "data" | "lart" | "lar2" | "art2" | "art1" | "lrgn" | "rgnh" | "wlnk" | "lins" | "ins " | "insh" | "rgn " | "rgn2" | "pgal";
970
- interface SoundBankInfoData {
971
- /**
972
- * Name.
973
- */
974
- name: string;
975
- /**
976
- * The sound bank's version.
977
- */
978
- version: SF2VersionTag;
979
- /**
980
- * Creation date.
981
- */
982
- creationDate: Date;
983
- /**
984
- * Sound engine.
985
- */
986
- soundEngine: string;
987
- /**
988
- * Author.
989
- */
990
- engineer?: string;
991
- /**
992
- * Product.
993
- */
994
- product?: string;
995
- /**
996
- * Copyright.
997
- */
998
- copyright?: string;
999
- /**
1000
- * Comment.
1001
- */
1002
- comment?: string;
1003
- /**
1004
- * Subject.
1005
- */
1006
- subject?: string;
1007
- /**
1008
- * ROM information.
1009
- */
1010
- romInfo?: string;
1011
- /**
1012
- * Software used to edit the file.
1013
- */
1014
- software?: string;
1015
- /**
1016
- * A tag that only applies to SF2 and will usually be undefined.
1017
- */
1018
- romVersion?: SF2VersionTag;
1019
- }
1020
- type SoundBankInfoFourCC = keyof SoundBankInfoData;
1021
- interface VoiceSynthesisData {
1022
- instrumentGenerators: Generator[];
1023
- presetGenerators: Generator[];
1024
- modulators: Modulator[];
1025
- sample: BasicSample;
1026
- }
1027
- type SampleEncodingFunction = (audioData: Float32Array, sampleRate: number) => Promise<Uint8Array>;
1028
- type ModulatorSourceIndex = ModulatorSourceEnum | MIDIController;
1029
- /**
1030
- * A function to track progress during writing.
1031
- */
1032
- type ProgressFunction = (
1033
- /**
1034
- * The written sample name.
1035
- */
1036
- sampleName: string,
1037
- /**
1038
- * The sample's index.
1039
- */
1040
- sampleIndex: number,
1041
- /**
1042
- * The total sample count for progress displaying.
1043
- */
1044
- sampleCount: number) => Promise<unknown>;
1045
- /**
1046
- * Options for writing a SoundFont2 file.
1047
- */
1048
- interface SoundFont2WriteOptions {
879
+ declare class BasicInstrumentZone extends BasicZone {
1049
880
  /**
1050
- * If the soundfont should be compressed with a given function.
881
+ * The instrument this zone belongs to.
1051
882
  */
1052
- compress: boolean;
883
+ readonly parentInstrument: BasicInstrument;
1053
884
  /**
1054
- * The function for compressing samples. It can be undefined if not compressed.
885
+ * For tracking on the individual zone level, since multiple presets can refer to the same instrument.
1055
886
  */
1056
- compressionFunction?: SampleEncodingFunction;
887
+ useCount: number;
1057
888
  /**
1058
- * A function to show progress for writing large banks. It can be undefined.
889
+ * Creates a new instrument zone.
890
+ * @param instrument The parent instrument.
891
+ * @param sample The sample to use in this zone.
1059
892
  */
1060
- progressFunction?: ProgressFunction;
893
+ constructor(instrument: BasicInstrument, sample: BasicSample);
1061
894
  /**
1062
- * If the DMOD chunk should be written. Recommended.
1063
- * Note that it will only be written if the modulators are unchanged.
895
+ * Zone's sample.
1064
896
  */
1065
- writeDefaultModulators: boolean;
897
+ private _sample;
1066
898
  /**
1067
- * If the XDTA chunk should be written to allow virtually infinite parameters. Recommended.
1068
- * Note that it will only be written needed.
899
+ * Zone's sample.
1069
900
  */
1070
- writeExtendedLimits: boolean;
901
+ get sample(): BasicSample;
1071
902
  /**
1072
- * If an SF3 bank should be decompressed back to SF2. Not recommended.
903
+ * Sets a sample for this zone.
904
+ * @param sample the sample to set.
1073
905
  */
1074
- decompress: boolean;
906
+ set sample(sample: BasicSample);
907
+ getWriteGenerators(bank: BasicSoundBank): Generator[];
1075
908
  }
909
+
1076
910
  /**
1077
- * Options for writing a DLS file.
911
+ * Returned structure containing extended SF2 chunks.
1078
912
  */
1079
- interface DLSWriteOptions {
1080
- /**
1081
- * A function to show progress for writing large banks. It can be undefined.
1082
- */
1083
- progressFunction?: ProgressFunction;
1084
- }
1085
- interface GenericRange {
1086
- min: number;
1087
- max: number;
1088
- }
1089
- interface DLSLoop {
1090
- loopType: DLSLoopType;
1091
- loopStart: number;
1092
- loopLength: number;
1093
- }
1094
-
1095
- declare const interpolationTypes: {
1096
- readonly linear: 0;
1097
- readonly nearestNeighbor: 1;
1098
- readonly hermite: 2;
1099
- };
1100
- type InterpolationType = (typeof interpolationTypes)[keyof typeof interpolationTypes];
1101
- declare const dataEntryStates: {
1102
- readonly Idle: 0;
1103
- readonly RPCoarse: 1;
1104
- readonly RPFine: 2;
1105
- readonly NRPCoarse: 3;
1106
- readonly NRPFine: 4;
1107
- readonly DataCoarse: 5;
1108
- readonly DataFine: 6;
1109
- };
1110
- type DataEntryState = (typeof dataEntryStates)[keyof typeof dataEntryStates];
1111
- declare const customControllers: {
1112
- readonly channelTuning: 0;
1113
- readonly channelTransposeFine: 1;
1114
- readonly modulationMultiplier: 2;
1115
- readonly masterTuning: 3;
1116
- readonly channelTuningSemitones: 4;
1117
- readonly channelKeyShift: 5;
1118
- readonly sf2NPRNGeneratorLSB: 6;
1119
- };
1120
- type CustomController = (typeof customControllers)[keyof typeof customControllers];
1121
-
1122
- type SynthSystem = "gm" | "gm2" | "gs" | "xg";
1123
- interface NoteOnCallback {
1124
- /** The MIDI note number. */
1125
- midiNote: number;
1126
- /** The MIDI channel number. */
1127
- channel: number;
1128
- /** The velocity of the note. */
1129
- velocity: number;
1130
- }
1131
- interface NoteOffCallback {
1132
- /** The MIDI note number. */
1133
- midiNote: number;
1134
- /** The MIDI channel number. */
1135
- channel: number;
1136
- }
1137
- interface DrumChangeCallback {
1138
- /** The MIDI channel number. */
1139
- channel: number;
1140
- /** Indicates if the channel is a drum channel. */
1141
- isDrumChannel: boolean;
1142
- }
1143
- interface ProgramChangeCallback extends MIDIPatch {
1144
- /** The MIDI channel number. */
1145
- channel: number;
1146
- }
1147
- interface ControllerChangeCallback {
1148
- /** The MIDI channel number. */
1149
- channel: number;
1150
- /** The controller number. */
1151
- controllerNumber: number;
1152
- /** The value of the controller. */
1153
- controllerValue: number;
1154
- }
1155
- interface MuteChannelCallback {
1156
- /** The MIDI channel number. */
1157
- channel: number;
1158
- /** Indicates if the channel is muted. */
1159
- isMuted: boolean;
1160
- }
1161
- interface PresetListEntry extends MIDIPatchNamed {
913
+ interface ExtendedSF2Chunks {
1162
914
  /**
1163
- * Indicates if this preset is any kind of drum preset.
915
+ * The PDTA part of the chunk.
1164
916
  */
1165
- isAnyDrums: boolean;
1166
- }
1167
- /**
1168
- * A list of preset changes, each with a name, bank, and program number.
1169
- */
1170
- type PresetList = PresetListEntry[];
1171
- /**
1172
- * The synthesizer display system exclusive data, EXCLUDING THE F0 BYTE!
1173
- */
1174
- type SynthDisplayCallback = number[];
1175
- interface PitchWheelCallback {
1176
- /** The MIDI channel number. */
1177
- channel: number;
917
+ pdta: IndexedByteArray;
1178
918
  /**
1179
- * The unsigned 14-bit value of the pitch: 0 - 16383.
919
+ * The XDTA (https://github.com/spessasus/soundfont-proposals/blob/main/extended_limits.md) part of the chunk.
1180
920
  */
1181
- pitch: number;
1182
- }
1183
- interface ChannelPressureCallback {
1184
- /** The MIDI channel number. */
1185
- channel: number;
1186
- /** The pressure value. */
1187
- pressure: number;
1188
- }
1189
- interface PolyPressureCallback {
1190
- /** The MIDI channel number. */
1191
- channel: number;
1192
- /** The MIDI note number. */
1193
- midiNote: number;
1194
- /** The pressure value. */
1195
- pressure: number;
921
+ xdta: IndexedByteArray;
1196
922
  }
1197
923
  /**
1198
- * The error message for sound bank errors.
924
+ * Write indexes for tracking writing a SoundFont file.
1199
925
  */
1200
- type SoundBankErrorCallback = Error;
1201
- interface StopAllCallback {
926
+ interface SoundFontWriteIndexes {
1202
927
  /**
1203
- * The MIDI channel number.
928
+ * Generator start index.
1204
929
  */
1205
- channel: number;
930
+ gen: number;
1206
931
  /**
1207
- * If the channel was force stopped. (no release time)
932
+ * Modulator start index.
1208
933
  */
1209
- force: boolean;
1210
- }
1211
- type MasterParameterChangeCallback = {
1212
- [P in keyof MasterParameterType]: {
1213
- /**
1214
- * The parameter that was changed.
1215
- */
1216
- parameter: P;
1217
- /**
1218
- * The new value of this parameter.
1219
- */
1220
- value: MasterParameterType[P];
1221
- };
1222
- }[keyof MasterParameterType];
1223
- interface ChannelPropertyChangeCallback {
934
+ mod: number;
1224
935
  /**
1225
- * The channel number of the new property.
936
+ * Zone start index.
1226
937
  */
1227
- channel: number;
938
+ bag: number;
1228
939
  /**
1229
- * The updated property.
940
+ * Preset/instrument start index.
1230
941
  */
1231
- property: ChannelProperty;
942
+ hdr: number;
1232
943
  }
1233
- interface SynthProcessorEventData {
1234
- /**
1235
- * This event fires when a note is played.
1236
- */
1237
- noteOn: NoteOnCallback;
1238
- /**
1239
- * This event fires when a note is released.
1240
- */
1241
- noteOff: NoteOffCallback;
1242
- /**
1243
- * This event fires when a pitch wheel is changed.
1244
- */
1245
- pitchWheel: PitchWheelCallback;
1246
- /**
1247
- * This event fires when a controller is changed.
1248
- */
1249
- controllerChange: ControllerChangeCallback;
1250
- /**
1251
- * This event fires when a program is changed.
1252
- */
1253
- programChange: ProgramChangeCallback;
1254
- /**
1255
- * This event fires when a channel pressure is changed.
1256
- */
1257
- channelPressure: ChannelPressureCallback;
1258
- /**
1259
- * This event fires when a polyphonic pressure is changed.
1260
- */
1261
- polyPressure: PolyPressureCallback;
944
+
945
+ /**
946
+ * Represents a single instrument
947
+ */
948
+ declare class BasicInstrument {
1262
949
  /**
1263
- * This event fires when a drum channel is changed.
950
+ * The instrument's name
1264
951
  */
1265
- drumChange: DrumChangeCallback;
952
+ name: string;
1266
953
  /**
1267
- * This event fires when all notes on a channel are stopped.
954
+ * The instrument's zones
1268
955
  */
1269
- stopAll: StopAllCallback;
956
+ zones: BasicInstrumentZone[];
1270
957
  /**
1271
- * This event fires when a new channel is created. There is no data for this event.
958
+ * Instrument's global zone
1272
959
  */
1273
- newChannel: void;
960
+ readonly globalZone: BasicGlobalZone;
1274
961
  /**
1275
- * This event fires when a channel is muted or unmuted.
962
+ * Instrument's linked presets (the presets that use it)
963
+ * note that duplicates are allowed since one preset can use the same instrument multiple times.
1276
964
  */
1277
- muteChannel: MuteChannelCallback;
965
+ readonly linkedTo: BasicPreset[];
1278
966
  /**
1279
- * This event fires when the preset list is changed.
967
+ * How many presets is this instrument used by
1280
968
  */
1281
- presetListChange: PresetList;
969
+ get useCount(): number;
1282
970
  /**
1283
- * This event fires when all controllers on all channels are reset. There is no data for this event.
971
+ * Creates a new instrument zone and returns it.
972
+ * @param sample The sample to use in the zone.
1284
973
  */
1285
- allControllerReset: void;
974
+ createZone(sample: BasicSample): BasicInstrumentZone;
1286
975
  /**
1287
- * This event fires when a sound bank parsing error occurs.
976
+ * Links the instrument ta a given preset
977
+ * @param preset the preset to link to
1288
978
  */
1289
- soundBankError: SoundBankErrorCallback;
979
+ linkTo(preset: BasicPreset): void;
1290
980
  /**
1291
- * This event fires when the synthesizer receives a display message.
981
+ * Unlinks the instrument from a given preset
982
+ * @param preset the preset to unlink from
1292
983
  */
1293
- synthDisplay: SynthDisplayCallback;
984
+ unlinkFrom(preset: BasicPreset): void;
985
+ deleteUnusedZones(): void;
986
+ delete(): void;
1294
987
  /**
1295
- * This event fires when a master parameter changes.
988
+ * Deletes a given instrument zone if it has no uses
989
+ * @param index the index of the zone to delete
990
+ * @param force ignores the use count and deletes forcibly
991
+ * @returns if the zone has been deleted
1296
992
  */
1297
- masterParameterChange: MasterParameterChangeCallback;
993
+ deleteZone(index: number, force?: boolean): boolean;
1298
994
  /**
1299
- * This event fires when a channel property changes.
995
+ * Globalizes the instrument *in-place.*
996
+ * This means trying to move as many generators and modulators
997
+ * to the global zone as possible to reduce clutter and the count of parameters.
1300
998
  */
1301
- channelPropertyChange: ChannelPropertyChangeCallback;
999
+ globalize(): void;
1000
+ write(instData: ExtendedSF2Chunks, index: number): void;
1302
1001
  }
1303
- type SynthProcessorEvent = {
1304
- [K in keyof SynthProcessorEventData]: {
1305
- type: K;
1306
- data: SynthProcessorEventData[K];
1307
- };
1308
- }[keyof SynthProcessorEventData];
1309
- interface SynthMethodOptions {
1002
+
1003
+ declare class BasicPresetZone extends BasicZone {
1310
1004
  /**
1311
- * The audio context time when the event should execute, in seconds.
1005
+ * The preset this zone belongs to.
1312
1006
  */
1313
- time: number;
1314
- }
1315
- /**
1316
- * KeyNum: tuning.
1317
- */
1318
- type MTSProgramTuning = MTSNoteTuning[];
1319
- interface MTSNoteTuning {
1007
+ readonly parentPreset: BasicPreset;
1320
1008
  /**
1321
- * The base MIDI note to use, -1 means no change.
1009
+ * Creates a new preset zone.
1010
+ * @param preset the preset this zone belongs to.
1011
+ * @param instrument the instrument to use in this zone.
1322
1012
  */
1323
- midiNote: number;
1013
+ constructor(preset: BasicPreset, instrument: BasicInstrument);
1324
1014
  /**
1325
- * Additional tuning.
1015
+ * Zone's instrument.
1326
1016
  */
1327
- centTuning: number | null;
1328
- }
1329
- /**
1330
- * Looping mode of the sample.
1331
- * 0 - no loop.
1332
- * 1 - loop.
1333
- * 2 - UNOFFICIAL: polyphone 2.4 added start on release.
1334
- * 3 - loop then play when released.
1335
- */
1336
- type SampleLoopingMode = 0 | 1 | 2 | 3;
1337
- /**
1338
- * A list of voices for a given key:velocity.
1339
- */
1340
- type VoiceList = Voice[];
1341
- interface ChannelProperty {
1017
+ private _instrument;
1342
1018
  /**
1343
- * The channel's current voice amount.
1019
+ * Zone's instrument.
1344
1020
  */
1345
- voicesAmount: number;
1021
+ get instrument(): BasicInstrument;
1346
1022
  /**
1347
- * The channel's current pitch wheel 0 - 16384.
1023
+ * Zone's instrument.
1348
1024
  */
1349
- pitchWheel: number;
1025
+ set instrument(instrument: BasicInstrument);
1026
+ getWriteGenerators(bank: BasicSoundBank): Generator[];
1027
+ }
1028
+
1029
+ declare class BasicPreset implements MIDIPatchNamed {
1350
1030
  /**
1351
- * The pitch wheel's range, in semitones.
1031
+ * The parent soundbank instance
1032
+ * Currently used for determining default modulators and XG status
1352
1033
  */
1353
- pitchWheelRange: number;
1034
+ readonly parentSoundBank: BasicSoundBank;
1354
1035
  /**
1355
- * Indicates whether the channel is muted.
1036
+ * The preset's name
1356
1037
  */
1357
- isMuted: boolean;
1038
+ name: string;
1039
+ program: number;
1040
+ bankMSB: number;
1041
+ bankLSB: number;
1042
+ isGMGSDrum: boolean;
1358
1043
  /**
1359
- * Indicates whether the channel is a drum channel.
1044
+ * The preset's zones
1360
1045
  */
1361
- isDrum: boolean;
1046
+ zones: BasicPresetZone[];
1362
1047
  /**
1363
- * The channel's transposition, in semitones.
1048
+ * Preset's global zone
1364
1049
  */
1365
- transposition: number;
1366
- }
1367
- interface SynthProcessorOptions {
1050
+ readonly globalZone: BasicGlobalZone;
1368
1051
  /**
1369
- * Indicates if the event system is enabled. This can be changed later.
1052
+ * Unused metadata
1370
1053
  */
1371
- enableEventSystem: boolean;
1054
+ library: number;
1372
1055
  /**
1373
- * The initial time of the synth, in seconds.
1056
+ * Unused metadata
1374
1057
  */
1375
- initialTime: number;
1058
+ genre: number;
1376
1059
  /**
1377
- * Indicates if the effects are enabled. This can be changed later.
1060
+ * Unused metadata
1378
1061
  */
1379
- enableEffects: boolean;
1380
- }
1381
- /**
1382
- * The master parameters of the synthesizer.
1383
- */
1384
- interface MasterParameterType {
1062
+ morphology: number;
1385
1063
  /**
1386
- * The master gain, from 0 to any number. 1 is 100% volume.
1064
+ * Creates a new preset representation.
1065
+ * @param parentSoundBank the sound bank this preset belongs to.
1066
+ * @param globalZone optional, a global zone to use.
1387
1067
  */
1388
- masterGain: number;
1068
+ constructor(parentSoundBank: BasicSoundBank, globalZone?: BasicGlobalZone);
1069
+ get isXGDrums(): boolean;
1389
1070
  /**
1390
- * The master pan, from -1 (left) to 1 (right). 0 is center.
1071
+ * Checks if this preset is a drum preset
1391
1072
  */
1392
- masterPan: number;
1073
+ get isAnyDrums(): boolean;
1393
1074
  /**
1394
- * The maximum number of voices that can be played at once.
1075
+ * Unlinks everything from this preset.
1395
1076
  */
1396
- voiceCap: number;
1077
+ delete(): void;
1397
1078
  /**
1398
- * The interpolation type used for sample playback.
1079
+ * Deletes an instrument zone from this preset.
1080
+ * @param index the zone's index to delete.
1399
1081
  */
1400
- interpolationType: InterpolationType;
1082
+ deleteZone(index: number): void;
1401
1083
  /**
1402
- * The MIDI system used by the synthesizer for bank selects and system exclusives. (GM, GM2, GS, XG)
1084
+ * Creates a new preset zone and returns it.
1085
+ * @param instrument the instrument to use in the zone.
1403
1086
  */
1404
- midiSystem: SynthSystem;
1087
+ createZone(instrument: BasicInstrument): BasicPresetZone;
1405
1088
  /**
1406
- * Indicates whether the synthesizer is in monophonic retrigger mode.
1407
- * This emulates the behavior of Microsoft GS Wavetable Synth,
1408
- * Where a new note will kill the previous one if it is still playing.
1089
+ * Preloads (loads and caches synthesis data) for a given key range.
1409
1090
  */
1410
- monophonicRetriggerMode: boolean;
1091
+ preload(keyMin: number, keyMax: number): void;
1411
1092
  /**
1412
- * The reverb gain, from 0 to any number. 1 is 100% reverb.
1093
+ * Checks if the bank and program numbers are the same for the given preset as this one.
1094
+ * @param preset The preset to check.
1413
1095
  */
1414
- reverbGain: number;
1096
+ matches(preset: MIDIPatch): boolean;
1415
1097
  /**
1416
- * The chorus gain, from 0 to any number. 1 is 100% chorus.
1098
+ * Returns the synthesis data from this preset
1099
+ * @param midiNote the MIDI note number
1100
+ * @param velocity the MIDI velocity
1101
+ * @returns the returned sound data
1417
1102
  */
1418
- chorusGain: number;
1103
+ getSynthesisData(midiNote: number, velocity: number): VoiceSynthesisData[];
1419
1104
  /**
1420
- * Forces note killing instead of releasing. Improves performance in black MIDIs.
1105
+ * BankMSB:bankLSB:program:isGMGSDrum
1421
1106
  */
1422
- blackMIDIMode: boolean;
1107
+ toMIDIString(): string;
1108
+ toString(): string;
1423
1109
  /**
1424
- * The global transposition in semitones. It can be decimal to provide microtonal tuning.
1110
+ * Combines preset into an instrument, flattening the preset zones into instrument zones.
1111
+ * This is a really complex function that attempts to work around the DLS limitations of only having the instrument layer.
1112
+ * @returns The instrument containing the flattened zones. In theory, it should exactly the same as this preset.
1425
1113
  */
1426
- transposition: number;
1114
+ toFlattenedInstrument(): BasicInstrument;
1427
1115
  /**
1428
- * Synthesizer's device ID for system exclusive messages. Set to -1 to accept all.
1116
+ * Writes the SF2 header
1117
+ * @param phdrData
1118
+ * @param index
1429
1119
  */
1430
- deviceID: number;
1120
+ write(phdrData: ExtendedSF2Chunks, index: number): void;
1431
1121
  }
1432
1122
 
1433
- /**
1434
- * Sets a master parameter of the synthesizer.
1435
- * @param parameter The type of the master parameter to set.
1436
- * @param value The value to set for the master parameter.
1437
- */
1438
- declare function setMasterParameterInternal<P extends keyof MasterParameterType>(this: SpessaSynthProcessor, parameter: P, value: MasterParameterType[P]): void;
1439
- /**
1440
- * Gets a master parameter of the synthesizer.
1441
- * @param type The type of the master parameter to get.
1442
- * @returns The value of the master parameter.
1443
- */
1444
- declare function getMasterParameterInternal<P extends keyof MasterParameterType>(this: SpessaSynthProcessor, type: P): MasterParameterType[P];
1445
- /**
1446
- * Gets all master parameters of the synthesizer.
1447
- * @returns All the master parameters.
1448
- */
1449
- declare function getAllMasterParametersInternal(this: SpessaSynthProcessor): MasterParameterType;
1450
-
1451
1123
  declare class SoundBankManager {
1452
1124
  /**
1453
1125
  * All the sound banks, ordered from the most important to the least.
@@ -1516,6 +1188,176 @@ type TypedArray = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Arra
1516
1188
  */
1517
1189
  declare function systemExclusiveInternal(this: SpessaSynthProcessor, syx: number[] | IndexedByteArray | TypedArray, channelOffset?: number): void;
1518
1190
 
1191
+ declare const midiMessageTypes: {
1192
+ readonly noteOff: 128;
1193
+ readonly noteOn: 144;
1194
+ readonly polyPressure: 160;
1195
+ readonly controllerChange: 176;
1196
+ readonly programChange: 192;
1197
+ readonly channelPressure: 208;
1198
+ readonly pitchWheel: 224;
1199
+ readonly systemExclusive: 240;
1200
+ readonly timecode: 241;
1201
+ readonly songPosition: 242;
1202
+ readonly songSelect: 243;
1203
+ readonly tuneRequest: 246;
1204
+ readonly clock: 248;
1205
+ readonly start: 250;
1206
+ readonly continue: 251;
1207
+ readonly stop: 252;
1208
+ readonly activeSensing: 254;
1209
+ readonly reset: 255;
1210
+ readonly sequenceNumber: 0;
1211
+ readonly text: 1;
1212
+ readonly copyright: 2;
1213
+ readonly trackName: 3;
1214
+ readonly instrumentName: 4;
1215
+ readonly lyric: 5;
1216
+ readonly marker: 6;
1217
+ readonly cuePoint: 7;
1218
+ readonly programName: 8;
1219
+ readonly midiChannelPrefix: 32;
1220
+ readonly midiPort: 33;
1221
+ readonly endOfTrack: 47;
1222
+ readonly setTempo: 81;
1223
+ readonly smpteOffset: 84;
1224
+ readonly timeSignature: 88;
1225
+ readonly keySignature: 89;
1226
+ readonly sequenceSpecific: 127;
1227
+ };
1228
+ type MIDIMessageType = (typeof midiMessageTypes)[keyof typeof midiMessageTypes];
1229
+ declare const midiControllers: {
1230
+ readonly bankSelect: 0;
1231
+ readonly modulationWheel: 1;
1232
+ readonly breathController: 2;
1233
+ readonly undefinedCC3: 3;
1234
+ readonly footController: 4;
1235
+ readonly portamentoTime: 5;
1236
+ readonly dataEntryMSB: 6;
1237
+ readonly mainVolume: 7;
1238
+ readonly balance: 8;
1239
+ readonly undefinedCC9: 9;
1240
+ readonly pan: 10;
1241
+ readonly expressionController: 11;
1242
+ readonly effectControl1: 12;
1243
+ readonly effectControl2: 13;
1244
+ readonly undefinedCC14: 14;
1245
+ readonly undefinedCC15: 15;
1246
+ readonly generalPurposeController1: 16;
1247
+ readonly generalPurposeController2: 17;
1248
+ readonly generalPurposeController3: 18;
1249
+ readonly generalPurposeController4: 19;
1250
+ readonly undefinedCC20: 20;
1251
+ readonly undefinedCC21: 21;
1252
+ readonly undefinedCC22: 22;
1253
+ readonly undefinedCC23: 23;
1254
+ readonly undefinedCC24: 24;
1255
+ readonly undefinedCC25: 25;
1256
+ readonly undefinedCC26: 26;
1257
+ readonly undefinedCC27: 27;
1258
+ readonly undefinedCC28: 28;
1259
+ readonly undefinedCC29: 29;
1260
+ readonly undefinedCC30: 30;
1261
+ readonly undefinedCC31: 31;
1262
+ readonly bankSelectLSB: 32;
1263
+ readonly modulationWheelLSB: 33;
1264
+ readonly breathControllerLSB: 34;
1265
+ readonly undefinedCC3LSB: 35;
1266
+ readonly footControllerLSB: 36;
1267
+ readonly portamentoTimeLSB: 37;
1268
+ readonly dataEntryLSB: 38;
1269
+ readonly mainVolumeLSB: 39;
1270
+ readonly balanceLSB: 40;
1271
+ readonly undefinedCC9LSB: 41;
1272
+ readonly panLSB: 42;
1273
+ readonly expressionControllerLSB: 43;
1274
+ readonly effectControl1LSB: 44;
1275
+ readonly effectControl2LSB: 45;
1276
+ readonly undefinedCC14LSB: 46;
1277
+ readonly undefinedCC15LSB: 47;
1278
+ readonly undefinedCC16LSB: 48;
1279
+ readonly undefinedCC17LSB: 49;
1280
+ readonly undefinedCC18LSB: 50;
1281
+ readonly undefinedCC19LSB: 51;
1282
+ readonly undefinedCC20LSB: 52;
1283
+ readonly undefinedCC21LSB: 53;
1284
+ readonly undefinedCC22LSB: 54;
1285
+ readonly undefinedCC23LSB: 55;
1286
+ readonly undefinedCC24LSB: 56;
1287
+ readonly undefinedCC25LSB: 57;
1288
+ readonly undefinedCC26LSB: 58;
1289
+ readonly undefinedCC27LSB: 59;
1290
+ readonly undefinedCC28LSB: 60;
1291
+ readonly undefinedCC29LSB: 61;
1292
+ readonly undefinedCC30LSB: 62;
1293
+ readonly undefinedCC31LSB: 63;
1294
+ readonly sustainPedal: 64;
1295
+ readonly portamentoOnOff: 65;
1296
+ readonly sostenutoPedal: 66;
1297
+ readonly softPedal: 67;
1298
+ readonly legatoFootswitch: 68;
1299
+ readonly hold2Pedal: 69;
1300
+ readonly soundVariation: 70;
1301
+ readonly filterResonance: 71;
1302
+ readonly releaseTime: 72;
1303
+ readonly attackTime: 73;
1304
+ readonly brightness: 74;
1305
+ readonly decayTime: 75;
1306
+ readonly vibratoRate: 76;
1307
+ readonly vibratoDepth: 77;
1308
+ readonly vibratoDelay: 78;
1309
+ readonly soundController10: 79;
1310
+ readonly generalPurposeController5: 80;
1311
+ readonly generalPurposeController6: 81;
1312
+ readonly generalPurposeController7: 82;
1313
+ readonly generalPurposeController8: 83;
1314
+ readonly portamentoControl: 84;
1315
+ readonly undefinedCC85: 85;
1316
+ readonly undefinedCC86: 86;
1317
+ readonly undefinedCC87: 87;
1318
+ readonly undefinedCC88: 88;
1319
+ readonly undefinedCC89: 89;
1320
+ readonly undefinedCC90: 90;
1321
+ readonly reverbDepth: 91;
1322
+ readonly tremoloDepth: 92;
1323
+ readonly chorusDepth: 93;
1324
+ readonly detuneDepth: 94;
1325
+ readonly phaserDepth: 95;
1326
+ readonly dataIncrement: 96;
1327
+ readonly dataDecrement: 97;
1328
+ readonly nonRegisteredParameterLSB: 98;
1329
+ readonly nonRegisteredParameterMSB: 99;
1330
+ readonly registeredParameterLSB: 100;
1331
+ readonly registeredParameterMSB: 101;
1332
+ readonly undefinedCC102LSB: 102;
1333
+ readonly undefinedCC103LSB: 103;
1334
+ readonly undefinedCC104LSB: 104;
1335
+ readonly undefinedCC105LSB: 105;
1336
+ readonly undefinedCC106LSB: 106;
1337
+ readonly undefinedCC107LSB: 107;
1338
+ readonly undefinedCC108LSB: 108;
1339
+ readonly undefinedCC109LSB: 109;
1340
+ readonly undefinedCC110LSB: 110;
1341
+ readonly undefinedCC111LSB: 111;
1342
+ readonly undefinedCC112LSB: 112;
1343
+ readonly undefinedCC113LSB: 113;
1344
+ readonly undefinedCC114LSB: 114;
1345
+ readonly undefinedCC115LSB: 115;
1346
+ readonly undefinedCC116LSB: 116;
1347
+ readonly undefinedCC117LSB: 117;
1348
+ readonly undefinedCC118LSB: 118;
1349
+ readonly undefinedCC119LSB: 119;
1350
+ readonly allSoundOff: 120;
1351
+ readonly resetAllControllers: 121;
1352
+ readonly localControlOnOff: 122;
1353
+ readonly allNotesOff: 123;
1354
+ readonly omniModeOff: 124;
1355
+ readonly omniModeOn: 125;
1356
+ readonly monoModeOn: 126;
1357
+ readonly polyModeOn: 127;
1358
+ };
1359
+ type MIDIController = (typeof midiControllers)[keyof typeof midiControllers];
1360
+
1519
1361
  /**
1520
1362
  * Executes a data entry fine (LSB) change for the current channel.
1521
1363
  * @param dataValue The value to set for the data entry fine controller (0-127).
@@ -3002,43 +2844,210 @@ declare class Modulator {
3002
2844
  * @param mod The modulator to copy.
3003
2845
  * @returns The copied modulator.
3004
2846
  */
3005
- static copyFrom(mod: Modulator): Modulator;
3006
- toString(): string;
3007
- write(modData: IndexedByteArray, indexes?: SoundFontWriteIndexes): void;
2847
+ static copyFrom(mod: Modulator): Modulator;
2848
+ toString(): string;
2849
+ write(modData: IndexedByteArray, indexes?: SoundFontWriteIndexes): void;
2850
+ /**
2851
+ * Sums transform and create a NEW modulator
2852
+ * @param modulator the modulator to sum with
2853
+ * @returns the new modulator
2854
+ */
2855
+ sumTransform(modulator: Modulator): Modulator;
2856
+ }
2857
+
2858
+ /**
2859
+ * Midi_message.ts
2860
+ * purpose: contains enums for midi events and controllers and functions to parse them
2861
+ */
2862
+
2863
+ declare class MIDIMessage {
2864
+ /**
2865
+ * Absolute number of MIDI ticks from the start of the track.
2866
+ */
2867
+ ticks: number;
2868
+ /**
2869
+ * The MIDI message status byte. Note that for meta events, it is the second byte. (not 0xFF)
2870
+ */
2871
+ statusByte: MIDIMessageType;
2872
+ /**
2873
+ * Message's binary data
2874
+ */
2875
+ data: Uint8Array<ArrayBuffer>;
2876
+ /**
2877
+ * Creates a new MIDI message
2878
+ * @param ticks time of this message in absolute MIDI ticks
2879
+ * @param byte the message status byte
2880
+ * @param data the message's binary data
2881
+ */
2882
+ constructor(ticks: number, byte: MIDIMessageType, data: Uint8Array<ArrayBuffer>);
2883
+ }
2884
+
2885
+ /**
2886
+ * RMIDInfoData type represents metadata for an RMIDI file.
2887
+ */
2888
+ interface RMIDInfoData {
2889
+ /**
2890
+ * The name of the song.
2891
+ */
2892
+ name: string;
2893
+ /**
2894
+ * The engineer who worked on the sound bank file.
2895
+ */
2896
+ engineer: string;
2897
+ /**
2898
+ * The artist of the MIDI file.
2899
+ */
2900
+ artist: string;
2901
+ /**
2902
+ * The album of the song.
2903
+ */
2904
+ album: string;
2905
+ /**
2906
+ * The genre of the song.
2907
+ */
2908
+ genre: string;
2909
+ /**
2910
+ * The image for the file (album cover).
2911
+ */
2912
+ picture: ArrayBuffer;
2913
+ /**
2914
+ * The comment of the file.
2915
+ */
2916
+ comment: string;
2917
+ /**
2918
+ * The creation date of the file.
2919
+ */
2920
+ creationDate: Date;
2921
+ /**
2922
+ * The copyright of the file.
2923
+ */
2924
+ copyright: string;
2925
+ /**
2926
+ * The encoding of the RMIDI info.
2927
+ */
2928
+ infoEncoding: string;
2929
+ /**
2930
+ * The encoding of the MIDI file's text messages.
2931
+ */
2932
+ midiEncoding: string;
2933
+ /**
2934
+ * The software used to write the file.
2935
+ */
2936
+ software: string;
2937
+ /**
2938
+ * The subject of the file.
2939
+ */
2940
+ subject: string;
2941
+ }
2942
+ interface TempoChange {
2943
+ /**
2944
+ * MIDI ticks of the change, absolute value from the start of the MIDI file.
2945
+ */
2946
+ ticks: number;
2947
+ /**
2948
+ * New tempo in BPM.
2949
+ */
2950
+ tempo: number;
2951
+ }
2952
+ type MIDILoopType = "soft" | "hard";
2953
+ interface MIDILoop {
2954
+ /**
2955
+ * Start of the loop, in MIDI ticks.
2956
+ */
2957
+ start: number;
2958
+ /**
2959
+ * End of the loop, in MIDI ticks.
2960
+ */
2961
+ end: number;
2962
+ /**
2963
+ * The type of the loop detected:
2964
+ * - Soft - the playback will immediately jump to the loop start pointer without any further processing.
2965
+ * - Hard - the playback will quickly process all messages from
2966
+ * the start of the file to ensure that synthesizer is in the correct state.
2967
+ * This is the default behavior.
2968
+ *
2969
+ * Soft loop types are enabled for Touhou and GameMaker loop points.
2970
+ */
2971
+ type: MIDILoopType;
2972
+ }
2973
+ type MIDIFormat = 0 | 1 | 2;
2974
+ interface NoteTime {
2975
+ /**
2976
+ * The MIDI key number.
2977
+ */
2978
+ midiNote: number;
2979
+ /**
2980
+ * Start of the note, in seconds.
2981
+ */
2982
+ start: number;
2983
+ /**
2984
+ * Length of the note, in seconds.
2985
+ */
2986
+ length: number;
2987
+ /**
2988
+ * The MIDI velocity of the note.
2989
+ */
2990
+ velocity: number;
2991
+ }
2992
+ /**
2993
+ * Represents a desired program change for a MIDI channel.
2994
+ */
2995
+ interface DesiredProgramChange extends MIDIPatch {
2996
+ /**
2997
+ * The channel number.
2998
+ */
2999
+ channel: number;
3000
+ }
3001
+ /**
3002
+ * Represents a desired controller change for a MIDI channel.
3003
+ */
3004
+ interface DesiredControllerChange {
3005
+ /**
3006
+ * The channel number.
3007
+ */
3008
+ channel: number;
3009
+ /**
3010
+ * The MIDI controller number.
3011
+ */
3012
+ controllerNumber: number;
3008
3013
  /**
3009
- * Sums transform and create a NEW modulator
3010
- * @param modulator the modulator to sum with
3011
- * @returns the new modulator
3014
+ * The new controller value.
3012
3015
  */
3013
- sumTransform(modulator: Modulator): Modulator;
3016
+ controllerValue: number;
3014
3017
  }
3015
-
3016
3018
  /**
3017
- * Midi_message.ts
3018
- * purpose: contains enums for midi events and controllers and functions to parse them
3019
+ * Represents a desired channel transpose change.
3019
3020
  */
3020
-
3021
- declare class MIDIMessage {
3021
+ interface DesiredChannelTranspose {
3022
3022
  /**
3023
- * Absolute number of MIDI ticks from the start of the track.
3023
+ * The channel number.
3024
3024
  */
3025
- ticks: number;
3025
+ channel: number;
3026
3026
  /**
3027
- * The MIDI message status byte. Note that for meta events, it is the second byte. (not 0xFF)
3027
+ * The number of semitones to transpose.
3028
+ * This can use floating point numbers, which will be used to fine-tune the pitch in cents using RPN.
3028
3029
  */
3029
- statusByte: MIDIMessageType;
3030
+ keyShift: number;
3031
+ }
3032
+ interface RMIDIWriteOptions {
3030
3033
  /**
3031
- * Message's binary data
3034
+ * The bank offset for RMIDI.
3032
3035
  */
3033
- data: Uint8Array<ArrayBuffer>;
3036
+ bankOffset: number;
3034
3037
  /**
3035
- * Creates a new MIDI message
3036
- * @param ticks time of this message in absolute MIDI ticks
3037
- * @param byte the message status byte
3038
- * @param data the message's binary data
3038
+ * The metadata of the file. Optional.
3039
3039
  */
3040
- constructor(ticks: number, byte: MIDIMessageType, data: Uint8Array<ArrayBuffer>);
3040
+ metadata: Partial<Omit<RMIDInfoData, "infoEncoding">>;
3041
+ /**
3042
+ * If the MIDI file should internally be corrected to work with the set bank offset.
3043
+ */
3044
+ correctBankOffset: boolean;
3045
+ /**
3046
+ * The optional sound bank instance used to correct bank offset.
3047
+ */
3048
+ soundBank?: BasicSoundBank;
3041
3049
  }
3050
+ type RMIDInfoFourCC = "INAM" | "IPRD" | "IALB" | "IART" | "IGNR" | "IPIC" | "ICOP" | "ICRD" | "ICRT" | "ICMT" | "IENG" | "ISFT" | "ISBJ" | "IENC" | "MENC" | "DBNK";
3042
3051
 
3043
3052
  declare class MIDITrack {
3044
3053
  /**
@@ -3405,161 +3414,163 @@ declare class BasicSoundBank {
3405
3414
  protected printInfo(): void;
3406
3415
  }
3407
3416
 
3408
- /**
3409
- * RMIDInfoData type represents metadata for an RMIDI file.
3410
- */
3411
- interface RMIDInfoData {
3417
+ interface SoundBankManagerListEntry {
3412
3418
  /**
3413
- * The name of the song.
3419
+ * The unique string identifier of the sound bank.
3414
3420
  */
3415
- name: string;
3421
+ id: string;
3416
3422
  /**
3417
- * The engineer who worked on the sound bank file.
3423
+ * The sound bank itself.
3418
3424
  */
3419
- engineer: string;
3425
+ soundBank: BasicSoundBank;
3420
3426
  /**
3421
- * The artist of the MIDI file.
3427
+ * The bank MSB offset for this sound bank.
3422
3428
  */
3423
- artist: string;
3429
+ bankOffset: number;
3430
+ }
3431
+ interface SF2VersionTag {
3424
3432
  /**
3425
- * The album of the song.
3433
+ * The major revision number of the sound bank.
3426
3434
  */
3427
- album: string;
3435
+ major: number;
3428
3436
  /**
3429
- * The genre of the song.
3437
+ * The minor revision number of this sound bank.
3430
3438
  */
3431
- genre: string;
3439
+ minor: number;
3440
+ }
3441
+ type GenericBankInfoFourCC = "INAM" | "ICRD" | "IENG" | "IPRD" | "ICOP" | "ICMT" | "ISFT";
3442
+ type SF2InfoFourCC = GenericBankInfoFourCC | "ifil" | "isng" | "irom" | "iver" | "DMOD" | "LIST";
3443
+ type SF2ChunkFourCC = "pdta" | "xdta" | "sdta" | "smpl" | "sm24" | "phdr" | "pbag" | "pmod" | "pgen" | "inst" | "ibag" | "imod" | "igen" | "shdr";
3444
+ type DLSInfoFourCC = GenericBankInfoFourCC | "ISBJ";
3445
+ type DLSChunkFourCC = WAVFourCC | "dls " | "dlid" | "cdl " | "ptbl" | "vers" | "colh" | "wvpl" | "wsmp" | "data" | "lart" | "lar2" | "art2" | "art1" | "lrgn" | "rgnh" | "wlnk" | "lins" | "ins " | "insh" | "rgn " | "rgn2" | "pgal";
3446
+ interface SoundBankInfoData {
3432
3447
  /**
3433
- * The image for the file (album cover).
3448
+ * Name.
3434
3449
  */
3435
- picture: ArrayBuffer;
3450
+ name: string;
3436
3451
  /**
3437
- * The comment of the file.
3452
+ * The sound bank's version.
3438
3453
  */
3439
- comment: string;
3454
+ version: SF2VersionTag;
3440
3455
  /**
3441
- * The creation date of the file.
3456
+ * Creation date.
3442
3457
  */
3443
3458
  creationDate: Date;
3444
3459
  /**
3445
- * The copyright of the file.
3460
+ * Sound engine.
3446
3461
  */
3447
- copyright: string;
3462
+ soundEngine: string;
3448
3463
  /**
3449
- * The encoding of the RMIDI info.
3464
+ * Author.
3450
3465
  */
3451
- infoEncoding: string;
3466
+ engineer?: string;
3452
3467
  /**
3453
- * The encoding of the MIDI file's text messages.
3468
+ * Product.
3454
3469
  */
3455
- midiEncoding: string;
3470
+ product?: string;
3456
3471
  /**
3457
- * The software used to write the file.
3472
+ * Copyright.
3458
3473
  */
3459
- software: string;
3474
+ copyright?: string;
3460
3475
  /**
3461
- * The subject of the file.
3476
+ * Comment.
3462
3477
  */
3463
- subject: string;
3464
- }
3465
- interface TempoChange {
3478
+ comment?: string;
3466
3479
  /**
3467
- * MIDI ticks of the change, absolute value from the start of the MIDI file.
3480
+ * Subject.
3468
3481
  */
3469
- ticks: number;
3482
+ subject?: string;
3470
3483
  /**
3471
- * New tempo in BPM.
3484
+ * ROM information.
3472
3485
  */
3473
- tempo: number;
3474
- }
3475
- interface MIDILoop {
3486
+ romInfo?: string;
3476
3487
  /**
3477
- * Start of the loop, in MIDI ticks.
3488
+ * Software used to edit the file.
3478
3489
  */
3479
- start: number;
3490
+ software?: string;
3480
3491
  /**
3481
- * End of the loop, in MIDI ticks.
3492
+ * A tag that only applies to SF2 and will usually be undefined.
3482
3493
  */
3483
- end: number;
3494
+ romVersion?: SF2VersionTag;
3484
3495
  }
3485
- type MIDIFormat = 0 | 1 | 2;
3486
- interface NoteTime {
3487
- /**
3488
- * The MIDI key number.
3489
- */
3490
- midiNote: number;
3491
- /**
3492
- * Start of the note, in seconds.
3493
- */
3494
- start: number;
3495
- /**
3496
- * Length of the note, in seconds.
3497
- */
3498
- length: number;
3499
- /**
3500
- * The MIDI velocity of the note.
3501
- */
3502
- velocity: number;
3496
+ type SoundBankInfoFourCC = keyof SoundBankInfoData;
3497
+ interface VoiceSynthesisData {
3498
+ instrumentGenerators: Generator[];
3499
+ presetGenerators: Generator[];
3500
+ modulators: Modulator[];
3501
+ sample: BasicSample;
3503
3502
  }
3503
+ type SampleEncodingFunction = (audioData: Float32Array, sampleRate: number) => Promise<Uint8Array>;
3504
+ type ModulatorSourceIndex = ModulatorSourceEnum | MIDIController;
3504
3505
  /**
3505
- * Represents a desired program change for a MIDI channel.
3506
+ * A function to track progress during writing.
3506
3507
  */
3507
- interface DesiredProgramChange extends MIDIPatch {
3508
- /**
3509
- * The channel number.
3510
- */
3511
- channel: number;
3512
- }
3508
+ type ProgressFunction = (
3513
3509
  /**
3514
- * Represents a desired controller change for a MIDI channel.
3510
+ * The written sample name.
3515
3511
  */
3516
- interface DesiredControllerChange {
3517
- /**
3518
- * The channel number.
3519
- */
3520
- channel: number;
3521
- /**
3522
- * The MIDI controller number.
3523
- */
3524
- controllerNumber: number;
3525
- /**
3526
- * The new controller value.
3527
- */
3528
- controllerValue: number;
3529
- }
3512
+ sampleName: string,
3530
3513
  /**
3531
- * Represents a desired channel transpose change.
3514
+ * The sample's index.
3532
3515
  */
3533
- interface DesiredChannelTranspose {
3516
+ sampleIndex: number,
3517
+ /**
3518
+ * The total sample count for progress displaying.
3519
+ */
3520
+ sampleCount: number) => Promise<unknown>;
3521
+ /**
3522
+ * Options for writing a SoundFont2 file.
3523
+ */
3524
+ interface SoundFont2WriteOptions {
3534
3525
  /**
3535
- * The channel number.
3526
+ * If the soundfont should be compressed with a given function.
3536
3527
  */
3537
- channel: number;
3528
+ compress: boolean;
3538
3529
  /**
3539
- * The number of semitones to transpose.
3540
- * This can use floating point numbers, which will be used to fine-tune the pitch in cents using RPN.
3530
+ * The function for compressing samples. It can be undefined if not compressed.
3541
3531
  */
3542
- keyShift: number;
3543
- }
3544
- interface RMIDIWriteOptions {
3532
+ compressionFunction?: SampleEncodingFunction;
3545
3533
  /**
3546
- * The bank offset for RMIDI.
3534
+ * A function to show progress for writing large banks. It can be undefined.
3547
3535
  */
3548
- bankOffset: number;
3536
+ progressFunction?: ProgressFunction;
3549
3537
  /**
3550
- * The metadata of the file. Optional.
3538
+ * If the DMOD chunk should be written. Recommended.
3539
+ * Note that it will only be written if the modulators are unchanged.
3551
3540
  */
3552
- metadata: Partial<Omit<RMIDInfoData, "infoEncoding">>;
3541
+ writeDefaultModulators: boolean;
3553
3542
  /**
3554
- * If the MIDI file should internally be corrected to work with the set bank offset.
3543
+ * If the XDTA chunk should be written to allow virtually infinite parameters. Recommended.
3544
+ * Note that it will only be written needed.
3555
3545
  */
3556
- correctBankOffset: boolean;
3546
+ writeExtendedLimits: boolean;
3557
3547
  /**
3558
- * The optional sound bank instance used to correct bank offset.
3548
+ * If an SF3 bank should be decompressed back to SF2. Not recommended.
3559
3549
  */
3560
- soundBank?: BasicSoundBank;
3550
+ decompress: boolean;
3561
3551
  }
3562
- type RMIDInfoFourCC = "INAM" | "IPRD" | "IALB" | "IART" | "IGNR" | "IPIC" | "ICOP" | "ICRD" | "ICRT" | "ICMT" | "IENG" | "ISFT" | "ISBJ" | "IENC" | "MENC" | "DBNK";
3552
+ /**
3553
+ * Options for writing a DLS file.
3554
+ */
3555
+ interface DLSWriteOptions {
3556
+ /**
3557
+ * A function to show progress for writing large banks. It can be undefined.
3558
+ */
3559
+ progressFunction?: ProgressFunction;
3560
+ }
3561
+ interface GenericRange {
3562
+ min: number;
3563
+ max: number;
3564
+ }
3565
+ interface DLSLoop {
3566
+ loopType: DLSLoopType;
3567
+ loopStart: number;
3568
+ loopLength: number;
3569
+ }
3570
+
3571
+ type GenericRIFFFourCC = "RIFF" | "LIST" | "INFO";
3572
+ type WAVFourCC = "wave" | "cue " | "fmt ";
3573
+ type FourCC = GenericRIFFFourCC | SoundBankInfoFourCC | SF2InfoFourCC | SF2ChunkFourCC | DLSInfoFourCC | DLSChunkFourCC | RMIDInfoFourCC | WAVFourCC;
3563
3574
 
3564
3575
  declare const SpessaSynthCoreUtils: {
3565
3576
  consoleColors: {
@@ -3590,7 +3601,16 @@ interface WaveWriteOptions {
3590
3601
  /**
3591
3602
  * The loop start and end points in seconds. Undefined if no loop should be written.
3592
3603
  */
3593
- loop?: MIDILoop;
3604
+ loop?: {
3605
+ /**
3606
+ * The start point in seconds.
3607
+ */
3608
+ start: number;
3609
+ /**
3610
+ * The end point in seconds.
3611
+ */
3612
+ end: number;
3613
+ };
3594
3614
  /**
3595
3615
  * The metadata to write into the file.
3596
3616
  */
@@ -3831,8 +3851,8 @@ declare class SpessaSynthSequencer {
3831
3851
  retriggerPausedNotes: boolean;
3832
3852
  /**
3833
3853
  * The loop count of the sequencer.
3834
- * If infinite, it will loop forever.
3835
- * If zero, the loop is disabled.
3854
+ * If set to Infinity, it will loop forever.
3855
+ * If set to zero, the loop is disabled.
3836
3856
  */
3837
3857
  loopCount: number;
3838
3858
  /**
@@ -4022,6 +4042,12 @@ declare class SpessaSynthSequencer {
4022
4042
  * @param time the time in seconds to recalculate the start time for.
4023
4043
  */
4024
4044
  protected recalculateStartTime(time: number): void;
4045
+ /**
4046
+ * Jumps to a MIDI tick without any further processing.
4047
+ * @param tick The MIDI tick to jump to.
4048
+ * @protected
4049
+ */
4050
+ protected jumpToTick(tick: number): void;
4025
4051
  protected sendMIDINoteOn(channel: number, midiNote: number, velocity: number): void;
4026
4052
  protected sendMIDINoteOff(channel: number, midiNote: number): void;
4027
4053
  protected sendMIDICC(channel: number, type: MIDIController, value: number): void;
@@ -4063,4 +4089,4 @@ declare class SoundBankLoader {
4063
4089
  private static loadDLS;
4064
4090
  }
4065
4091
 
4066
- export { ALL_CHANNELS_OR_DIFFERENT_ACTION, BasicGlobalZone, BasicInstrument, BasicInstrumentZone, BasicMIDI, BasicPreset, BasicPresetZone, BasicSample, BasicSoundBank, BasicZone, CONTROLLER_TABLE_SIZE, CUSTOM_CONTROLLER_TABLE_SIZE, type ChannelPressureCallback, type ChannelProperty, type ChannelPropertyChangeCallback, ChannelSnapshot, type ControllerChangeCallback, type CustomController, DEFAULT_MASTER_PARAMETERS, DEFAULT_PERCUSSION, DEFAULT_WAV_WRITE_OPTIONS, type DLSChunkFourCC, type DLSDestination, type DLSInfoFourCC, type DLSLoop, type DLSLoopType, DLSLoopTypes, type DLSSource, type DLSTransform, type DLSWriteOptions, type DataEntryState, type DesiredChannelTranspose, type DesiredControllerChange, type DesiredProgramChange, type DrumChangeCallback, EmptySample, type FourCC, GENERATORS_AMOUNT, Generator, type GeneratorType, type GenericBankInfoFourCC, type GenericRIFFFourCC, type GenericRange, IndexedByteArray, type InterpolationType, KeyModifier, MAX_GENERATOR, MIDIBuilder, type MIDIController, type MIDIFormat, type MIDILoop, MIDIMessage, type MIDIMessageType, type MIDIPatch, type MIDIPatchNamed, MIDIPatchTools, MIDITrack, type MTSNoteTuning, type MTSProgramTuning, type MasterParameterChangeCallback, type MasterParameterType, Modulator, type ModulatorCurveType, ModulatorSource, type ModulatorSourceEnum, type ModulatorSourceIndex, type ModulatorTransformType, type MuteChannelCallback, NON_CC_INDEX_OFFSET, type NoteOffCallback, type NoteOnCallback, type NoteTime, PORTAMENTO_CONTROL_UNSET, type PitchWheelCallback, type PolyPressureCallback, type PresetList, type PresetListEntry, type ProgramChangeCallback, type ProgressFunction, type RMIDIWriteOptions, type RMIDInfoData, type RMIDInfoFourCC, type SF2ChunkFourCC, type SF2InfoFourCC, type SF2VersionTag, type SampleEncodingFunction, type SampleLoopingMode, type SampleType, type SequencerEvent, type SequencerEventData, type SoundBankErrorCallback, type SoundBankInfoData, type SoundBankInfoFourCC, SoundBankLoader, type SoundBankManagerListEntry, type SoundFont2WriteOptions, SpessaSynthCoreUtils, SpessaSynthLogging, SpessaSynthProcessor, SpessaSynthSequencer, type StopAllCallback, type SynthMethodOptions, type SynthProcessorEvent, type SynthProcessorEventData, type SynthProcessorOptions, type SynthSystem, SynthesizerSnapshot, type TempoChange, type VoiceList, type VoiceSynthesisData, type WaveMetadata, type WaveWriteOptions, audioToWav, customControllers, customResetArray, dataEntryStates, defaultMIDIControllerValues, dlsDestinations, dlsSources, generatorLimits, generatorTypes, interpolationTypes, midiControllers, midiMessageTypes, modulatorCurveTypes, modulatorSources, modulatorTransformTypes, sampleTypes, setResetValue };
4092
+ export { ALL_CHANNELS_OR_DIFFERENT_ACTION, BasicGlobalZone, BasicInstrument, BasicInstrumentZone, BasicMIDI, BasicPreset, BasicPresetZone, BasicSample, BasicSoundBank, BasicZone, CONTROLLER_TABLE_SIZE, CUSTOM_CONTROLLER_TABLE_SIZE, type ChannelPressureCallback, type ChannelProperty, type ChannelPropertyChangeCallback, ChannelSnapshot, type ControllerChangeCallback, type CustomController, DEFAULT_MASTER_PARAMETERS, DEFAULT_PERCUSSION, DEFAULT_WAV_WRITE_OPTIONS, type DLSChunkFourCC, type DLSDestination, type DLSInfoFourCC, type DLSLoop, type DLSLoopType, DLSLoopTypes, type DLSSource, type DLSTransform, type DLSWriteOptions, type DataEntryState, type DesiredChannelTranspose, type DesiredControllerChange, type DesiredProgramChange, type DrumChangeCallback, EmptySample, type FourCC, GENERATORS_AMOUNT, Generator, type GeneratorType, type GenericBankInfoFourCC, type GenericRIFFFourCC, type GenericRange, IndexedByteArray, type InterpolationType, KeyModifier, MAX_GENERATOR, MIDIBuilder, type MIDIController, type MIDIFormat, type MIDILoop, type MIDILoopType, MIDIMessage, type MIDIMessageType, type MIDIPatch, type MIDIPatchNamed, MIDIPatchTools, MIDITrack, type MTSNoteTuning, type MTSProgramTuning, type MasterParameterChangeCallback, type MasterParameterType, Modulator, type ModulatorCurveType, ModulatorSource, type ModulatorSourceEnum, type ModulatorSourceIndex, type ModulatorTransformType, type MuteChannelCallback, NON_CC_INDEX_OFFSET, type NoteOffCallback, type NoteOnCallback, type NoteTime, PORTAMENTO_CONTROL_UNSET, type PitchWheelCallback, type PolyPressureCallback, type PresetList, type PresetListEntry, type ProgramChangeCallback, type ProgressFunction, type RMIDIWriteOptions, type RMIDInfoData, type RMIDInfoFourCC, type SF2ChunkFourCC, type SF2InfoFourCC, type SF2VersionTag, type SampleEncodingFunction, type SampleLoopingMode, type SampleType, type SequencerEvent, type SequencerEventData, type SoundBankErrorCallback, type SoundBankInfoData, type SoundBankInfoFourCC, SoundBankLoader, type SoundBankManagerListEntry, type SoundFont2WriteOptions, SpessaSynthCoreUtils, SpessaSynthLogging, SpessaSynthProcessor, SpessaSynthSequencer, type StopAllCallback, type SynthMethodOptions, type SynthProcessorEvent, type SynthProcessorEventData, type SynthProcessorOptions, type SynthSystem, SynthesizerSnapshot, type TempoChange, type VoiceList, type VoiceSynthesisData, type WaveMetadata, type WaveWriteOptions, audioToWav, customControllers, customResetArray, dataEntryStates, defaultMIDIControllerValues, dlsDestinations, dlsSources, generatorLimits, generatorTypes, interpolationTypes, midiControllers, midiMessageTypes, modulatorCurveTypes, modulatorSources, modulatorTransformTypes, sampleTypes, setResetValue };