spessasynth_lib 3.23.6 → 3.23.8

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.
@@ -7,17 +7,24 @@
7
7
  export function MIDIticksToSeconds(ticks: number, mid: BasicMIDI): number;
8
8
  export class BasicMIDI {
9
9
  /**
10
- * The time division of the sequence
10
+ * Copies a MIDI
11
+ * @param mid {BasicMIDI}
12
+ * @returns {BasicMIDI}
13
+ */
14
+ static copyFrom(mid: BasicMIDI): BasicMIDI;
15
+ /**
16
+ * The time division of the sequence, representing the number of ticks per beat.
11
17
  * @type {number}
12
18
  */
13
19
  timeDivision: number;
14
20
  /**
15
- * The duration of the sequence, in seconds
21
+ * The duration of the sequence, in seconds.
16
22
  * @type {number}
17
23
  */
18
24
  duration: number;
19
25
  /**
20
- * The tempo changes in the sequence, ordered from last to first
26
+ * The tempo changes in the sequence, ordered from the last change to the first.
27
+ * Each change is represented by an object with a tick position and a tempo value in beats per minute.
21
28
  * @type {{ticks: number, tempo: number}[]}
22
29
  */
23
30
  tempoChanges: {
@@ -25,27 +32,27 @@ export class BasicMIDI {
25
32
  tempo: number;
26
33
  }[];
27
34
  /**
28
- * Contains the copyright strings
35
+ * A string containing the copyright information for the MIDI sequence if detected.
29
36
  * @type {string}
30
37
  */
31
38
  copyright: string;
32
39
  /**
33
- * The amount of tracks in the sequence
40
+ * The number of tracks in the MIDI sequence.
34
41
  * @type {number}
35
42
  */
36
43
  tracksAmount: number;
37
44
  /**
38
- * The lyrics of the sequence as binary chunks
45
+ * An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
39
46
  * @type {Uint8Array[]}
40
47
  */
41
48
  lyrics: Uint8Array[];
42
49
  /**
43
- * First note on of the MIDI file
50
+ * The tick position of the first note-on event in the MIDI sequence.
44
51
  * @type {number}
45
52
  */
46
53
  firstNoteOn: number;
47
54
  /**
48
- * The MIDI's key range
55
+ * The MIDI key range used in the sequence, represented by a minimum and maximum note value.
49
56
  * @type {{min: number, max: number}}
50
57
  */
51
58
  keyRange: {
@@ -53,27 +60,27 @@ export class BasicMIDI {
53
60
  max: number;
54
61
  };
55
62
  /**
56
- * The last voice (note on, off, cc change etc.) event tick
63
+ * The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
57
64
  * @type {number}
58
65
  */
59
66
  lastVoiceEventTick: number;
60
67
  /**
61
- * Midi port numbers for each track
68
+ * An array of MIDI port numbers used by each track in the sequence.
62
69
  * @type {number[]}
63
70
  */
64
71
  midiPorts: number[];
65
72
  /**
66
- * Channel offsets for each port, using the SpessaSynth method
73
+ * An array of channel offsets for each MIDI port, using the SpessaSynth method.
67
74
  * @type {number[]}
68
75
  */
69
76
  midiPortChannelOffsets: number[];
70
77
  /**
71
- * All channels that each track uses
78
+ * A list of sets, where each set contains the MIDI channels used by each track in the sequence.
72
79
  * @type {Set<number>[]}
73
80
  */
74
81
  usedChannelsOnTrack: Set<number>[];
75
82
  /**
76
- * The loop points (in ticks) of the sequence
83
+ * The loop points (in ticks) of the sequence, including both start and end points.
77
84
  * @type {{start: number, end: number}}
78
85
  */
79
86
  loop: {
@@ -81,45 +88,58 @@ export class BasicMIDI {
81
88
  end: number;
82
89
  };
83
90
  /**
84
- * The sequence's name
91
+ * The name of the MIDI sequence.
85
92
  * @type {string}
86
93
  */
87
94
  midiName: string;
88
95
  /**
89
- * The file name of the sequence, if provided in the MIDI class
96
+ * A boolean indicating if the sequence's name is the same as the file name.
97
+ * @type {boolean}
98
+ */
99
+ midiNameUsesFileName: boolean;
100
+ /**
101
+ * The file name of the MIDI sequence, if provided during parsing.
90
102
  * @type {string}
91
103
  */
92
104
  fileName: string;
93
105
  /**
94
- * The raw, encoded MIDI name.
106
+ * The raw, encoded MIDI name, represented as a Uint8Array.
107
+ * Useful when the MIDI file uses a different code page.
95
108
  * @type {Uint8Array}
96
109
  */
97
110
  rawMidiName: Uint8Array;
98
111
  /**
99
- * The MIDI's embedded soundfont
112
+ * The embedded soundfont in the MIDI file, represented as an ArrayBuffer, if available.
100
113
  * @type {ArrayBuffer|undefined}
101
114
  */
102
115
  embeddedSoundFont: ArrayBuffer | undefined;
103
116
  /**
104
- * The MIDI file's format
117
+ * The format of the MIDI file, which can be 0, 1, or 2, indicating the type of the MIDI file.
105
118
  * @type {number}
106
119
  */
107
120
  format: number;
108
121
  /**
109
- * The RMID Info data if RMID, otherwise undefined
122
+ * The RMID (Resource Interchangeable MIDI) info data, if the file is RMID formatted.
123
+ * Otherwise, this field is undefined.
124
+ * Chunk type (e.g. "INAM"): Chunk data as binary array.
110
125
  * @type {Object<string, IndexedByteArray>}
111
126
  */
112
127
  RMIDInfo: {
113
128
  [x: string]: IndexedByteArray;
114
129
  };
115
130
  /**
116
- * The bank offset for RMIDI
131
+ * The bank offset used for RMID files.
117
132
  * @type {number}
118
133
  */
119
134
  bankOffset: number;
120
135
  /**
121
- * The actual track data of the MIDI file
136
+ * The actual track data of the MIDI file, represented as an array of tracks.
137
+ * Tracks are arrays of MidiMessage objects.
122
138
  * @type {MidiMessage[][]}
123
139
  */
124
140
  tracks: MidiMessage[][];
141
+ /**
142
+ * Updates all internal values
143
+ */
144
+ flush(): void;
125
145
  }
@@ -6,10 +6,6 @@ export class MIDIBuilder extends BasicMIDI {
6
6
  */
7
7
  constructor(name: string, timeDivision?: number, initialTempo?: number);
8
8
  encoder: TextEncoder;
9
- /**
10
- * Updates all internal values
11
- */
12
- flush(): void;
13
9
  /**
14
10
  * Adds a new "set tempo" message
15
11
  * @param ticks {number} the tick number of the event
@@ -4,21 +4,23 @@
4
4
  */
5
5
  export class MidiData {
6
6
  /**
7
- * @param midi {BasicMIDI}
7
+ * Constructor that copies data from a BasicMIDI instance, except for tracks and embeddedSoundFont.
8
+ * @param {BasicMIDI} midi - The BasicMIDI instance to copy data from.
8
9
  */
9
10
  constructor(midi: BasicMIDI);
10
11
  /**
11
- * The time division of the sequence
12
+ * The time division of the sequence, representing the number of ticks per beat.
12
13
  * @type {number}
13
14
  */
14
15
  timeDivision: number;
15
16
  /**
16
- * The duration of the sequence, in seconds
17
+ * The duration of the sequence, in seconds.
17
18
  * @type {number}
18
19
  */
19
20
  duration: number;
20
21
  /**
21
- * The tempo changes in the sequence, ordered from last to first
22
+ * The tempo changes in the sequence, ordered from the last change to the first.
23
+ * Each change is represented by an object with a tick position and a tempo value in beats per minute.
22
24
  * @type {{ticks: number, tempo: number}[]}
23
25
  */
24
26
  tempoChanges: {
@@ -26,23 +28,27 @@ export class MidiData {
26
28
  tempo: number;
27
29
  }[];
28
30
  /**
29
- * Contains the copyright strings
31
+ * A string containing the copyright information for the MIDI sequence.
30
32
  * @type {string}
31
33
  */
32
34
  copyright: string;
33
35
  /**
34
- * The amount of tracks in the sequence
36
+ * The number of tracks in the MIDI sequence.
35
37
  * @type {number}
36
38
  */
37
39
  tracksAmount: number;
38
40
  /**
39
- * The lyrics of the sequence as binary chunks
41
+ * An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
40
42
  * @type {Uint8Array[]}
41
43
  */
42
44
  lyrics: Uint8Array[];
43
- firstNoteOn: any;
44
45
  /**
45
- * The MIDI's key range
46
+ * The tick position of the first note-on event in the MIDI sequence.
47
+ * @type {number}
48
+ */
49
+ firstNoteOn: number;
50
+ /**
51
+ * The MIDI key range used in the sequence, represented by a minimum and maximum note value.
46
52
  * @type {{min: number, max: number}}
47
53
  */
48
54
  keyRange: {
@@ -50,27 +56,27 @@ export class MidiData {
50
56
  max: number;
51
57
  };
52
58
  /**
53
- * The last voice (note on, off, cc change etc.) event tick
59
+ * The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
54
60
  * @type {number}
55
61
  */
56
62
  lastVoiceEventTick: number;
57
63
  /**
58
- * Midi port numbers for each track
64
+ * An array of MIDI port numbers used by each track in the sequence.
59
65
  * @type {number[]}
60
66
  */
61
67
  midiPorts: number[];
62
68
  /**
63
- * Channel offsets for each port, using the SpessaSynth method
69
+ * An array of channel offsets for each MIDI port, using the SpessaSynth method.
64
70
  * @type {number[]}
65
71
  */
66
72
  midiPortChannelOffsets: number[];
67
73
  /**
68
- * All channels that each track uses
74
+ * A list of sets, where each set contains the MIDI channels used by each track in the sequence.
69
75
  * @type {Set<number>[]}
70
76
  */
71
77
  usedChannelsOnTrack: Set<number>[];
72
78
  /**
73
- * The loop points (in ticks) of the sequence
79
+ * The loop points (in ticks) of the sequence, including both start and end points.
74
80
  * @type {{start: number, end: number}}
75
81
  */
76
82
  loop: {
@@ -78,34 +84,46 @@ export class MidiData {
78
84
  end: number;
79
85
  };
80
86
  /**
81
- * The sequence's name
87
+ * The name of the MIDI sequence.
82
88
  * @type {string}
83
89
  */
84
90
  midiName: string;
85
91
  /**
86
- * The file name of the sequence, if provided in the MIDI class
92
+ * A boolean indicating if the sequence's name is the same as the file name.
93
+ * @type {boolean}
94
+ */
95
+ midiNameUsesFileName: boolean;
96
+ /**
97
+ * The file name of the MIDI sequence, if provided by the MIDI class.
87
98
  * @type {string}
88
99
  */
89
100
  fileName: string;
90
101
  /**
91
- * The raw, encoded MIDI name.
102
+ * The raw, encoded MIDI name, represented as a Uint8Array.
92
103
  * @type {Uint8Array}
93
104
  */
94
105
  rawMidiName: Uint8Array;
95
106
  /**
96
- * Indicates if the midi has an embedded soundfont
107
+ * A boolean indicating if the MIDI file contains an embedded soundfont.
108
+ * If the embedded soundfont is undefined, this will be false.
97
109
  * @type {boolean}
98
110
  */
99
111
  isEmbedded: boolean;
100
112
  /**
101
- * The RMID Info data if RMID, otherwise undefined
113
+ * The MIDI file's format, which can be 0, 1, or 2, indicating the type of the MIDI file.
114
+ * @type {number}
115
+ */
116
+ format: number;
117
+ /**
118
+ * The RMID (Resource Interchangeable MIDI) info data, if the file is RMID formatted.
119
+ * Otherwise, this field is undefined.
102
120
  * @type {Object<string, IndexedByteArray>}
103
121
  */
104
122
  RMIDInfo: {
105
123
  [x: string]: IndexedByteArray;
106
124
  };
107
125
  /**
108
- * The bank offset for RMIDI
126
+ * The bank offset used for RMID files.
109
127
  * @type {number}
110
128
  */
111
129
  bankOffset: number;
@@ -47,7 +47,7 @@ export class Sequencer {
47
47
  */
48
48
  absoluteStartTime: number;
49
49
  /**
50
- * @type {function(MIDI)}
50
+ * @type {function(BasicMIDI)}
51
51
  * @private
52
52
  */
53
53
  private _getMIDIResolve;
@@ -237,3 +237,4 @@ export type SequencerOptions = {
237
237
  import { MidiData } from "../midi_parser/midi_data.js";
238
238
  import { Synthetizer } from "../synthetizer/synthetizer.js";
239
239
  import { MIDI } from "../midi_parser/midi_loader.js";
240
+ import { BasicMIDI } from "../midi_parser/basic_midi.js";
@@ -66,6 +66,11 @@ export class BasicSample {
66
66
  * @type {number}
67
67
  */
68
68
  useCount: number;
69
+ /**
70
+ * The sample's audio data
71
+ * @type {Float32Array}
72
+ */
73
+ sampleData: Float32Array;
69
74
  /**
70
75
  * @returns {Uint8Array|IndexedByteArray}
71
76
  */
@@ -5,6 +5,11 @@ export class BasicSoundFont {
5
5
  * @returns {BasicSoundFont}
6
6
  */
7
7
  static mergeSoundfonts(...soundfonts: BasicSoundFont[]): BasicSoundFont;
8
+ /**
9
+ * Creates a simple soundfont with one saw wave preset.
10
+ * @returns {ArrayBufferLike}
11
+ */
12
+ static getDummySoundfontFile(): ArrayBufferLike;
8
13
  /**
9
14
  * Creates a new basic soundfont template
10
15
  * @param data {undefined|{presets: BasicPreset[], info: Object<string, string>}}
@@ -89,6 +94,9 @@ export class BasicSoundFont {
89
94
  write: typeof write;
90
95
  writeDLS: typeof writeDLS;
91
96
  }
97
+ import { BasicPreset } from "./basic_preset.js";
98
+ import { BasicSample } from "./basic_sample.js";
99
+ import { BasicInstrument } from "./basic_instrument.js";
92
100
  import { Modulator } from "./modulator.js";
93
101
  import { write } from "./write_sf2/write.js";
94
102
  import { writeDLS } from "./write_dls/write_dls.js";
@@ -15,10 +15,5 @@ export class DLSSample extends BasicSample {
15
15
  * @type {number}
16
16
  */
17
17
  sampleDbAttenuation: number;
18
- /**
19
- * @type {Float32Array}
20
- */
21
- sampleData: Float32Array;
22
- getRawData(): Uint8Array<ArrayBuffer>;
23
18
  }
24
19
  import { BasicSample } from "../basic_soundfont/basic_sample.js";
@@ -31,7 +31,6 @@ export class LoadedSample extends BasicSample {
31
31
  sampleID: number;
32
32
  sampleLength: number;
33
33
  sampleDataArray: Float32Array<ArrayBuffer> | IndexedByteArray;
34
- sampleData: Float32Array<ArrayBuffer>;
35
34
  isDataRaw: boolean;
36
35
  /**
37
36
  * Get raw data, whether it's compressed or not as we simply write it to the file