spessasynth_lib 3.23.8 → 3.23.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,137 +1,27 @@
1
1
  /**
2
2
  * Converts ticks to time in seconds
3
3
  * @param ticks {number} time in MIDI ticks
4
- * @param mid {BasicMIDI} the MIDI
4
+ * @param mid {BasicMIDI|MidiData} the MIDI
5
5
  * @returns {number} time in seconds
6
6
  */
7
- export function MIDIticksToSeconds(ticks: number, mid: BasicMIDI): number;
8
- export class BasicMIDI {
7
+ export function MIDIticksToSeconds(ticks: number, mid: BasicMIDI | MidiData): number;
8
+ /**
9
+ * BasicMIDI is the base of a complete MIDI file, used by the sequencer internally.
10
+ * BasicMIDI is not available on the main thread, as it contains the actual track data which can be large.
11
+ * It can be accessed by calling getMIDI() on the Sequencer.
12
+ */
13
+ export class BasicMIDI extends MIDISequenceData {
9
14
  /**
10
15
  * Copies a MIDI
11
16
  * @param mid {BasicMIDI}
12
17
  * @returns {BasicMIDI}
13
18
  */
14
19
  static copyFrom(mid: BasicMIDI): BasicMIDI;
15
- /**
16
- * The time division of the sequence, representing the number of ticks per beat.
17
- * @type {number}
18
- */
19
- timeDivision: number;
20
- /**
21
- * The duration of the sequence, in seconds.
22
- * @type {number}
23
- */
24
- duration: number;
25
- /**
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.
28
- * @type {{ticks: number, tempo: number}[]}
29
- */
30
- tempoChanges: {
31
- ticks: number;
32
- tempo: number;
33
- }[];
34
- /**
35
- * A string containing the copyright information for the MIDI sequence if detected.
36
- * @type {string}
37
- */
38
- copyright: string;
39
- /**
40
- * The number of tracks in the MIDI sequence.
41
- * @type {number}
42
- */
43
- tracksAmount: number;
44
- /**
45
- * An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
46
- * @type {Uint8Array[]}
47
- */
48
- lyrics: Uint8Array[];
49
- /**
50
- * The tick position of the first note-on event in the MIDI sequence.
51
- * @type {number}
52
- */
53
- firstNoteOn: number;
54
- /**
55
- * The MIDI key range used in the sequence, represented by a minimum and maximum note value.
56
- * @type {{min: number, max: number}}
57
- */
58
- keyRange: {
59
- min: number;
60
- max: number;
61
- };
62
- /**
63
- * The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
64
- * @type {number}
65
- */
66
- lastVoiceEventTick: number;
67
- /**
68
- * An array of MIDI port numbers used by each track in the sequence.
69
- * @type {number[]}
70
- */
71
- midiPorts: number[];
72
- /**
73
- * An array of channel offsets for each MIDI port, using the SpessaSynth method.
74
- * @type {number[]}
75
- */
76
- midiPortChannelOffsets: number[];
77
- /**
78
- * A list of sets, where each set contains the MIDI channels used by each track in the sequence.
79
- * @type {Set<number>[]}
80
- */
81
- usedChannelsOnTrack: Set<number>[];
82
- /**
83
- * The loop points (in ticks) of the sequence, including both start and end points.
84
- * @type {{start: number, end: number}}
85
- */
86
- loop: {
87
- start: number;
88
- end: number;
89
- };
90
- /**
91
- * The name of the MIDI sequence.
92
- * @type {string}
93
- */
94
- midiName: string;
95
- /**
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.
102
- * @type {string}
103
- */
104
- fileName: string;
105
- /**
106
- * The raw, encoded MIDI name, represented as a Uint8Array.
107
- * Useful when the MIDI file uses a different code page.
108
- * @type {Uint8Array}
109
- */
110
- rawMidiName: Uint8Array;
111
20
  /**
112
21
  * The embedded soundfont in the MIDI file, represented as an ArrayBuffer, if available.
113
22
  * @type {ArrayBuffer|undefined}
114
23
  */
115
24
  embeddedSoundFont: ArrayBuffer | undefined;
116
- /**
117
- * The format of the MIDI file, which can be 0, 1, or 2, indicating the type of the MIDI file.
118
- * @type {number}
119
- */
120
- format: number;
121
- /**
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.
125
- * @type {Object<string, IndexedByteArray>}
126
- */
127
- RMIDInfo: {
128
- [x: string]: IndexedByteArray;
129
- };
130
- /**
131
- * The bank offset used for RMID files.
132
- * @type {number}
133
- */
134
- bankOffset: number;
135
25
  /**
136
26
  * The actual track data of the MIDI file, represented as an array of tracks.
137
27
  * Tracks are arrays of MidiMessage objects.
@@ -143,3 +33,4 @@ export class BasicMIDI {
143
33
  */
144
34
  flush(): void;
145
35
  }
36
+ import { MIDISequenceData } from "./midi_sequence.js";
@@ -1,3 +1,6 @@
1
+ /**
2
+ * A class that helps to build a MIDI file from scratch.
3
+ */
1
4
  export class MIDIBuilder extends BasicMIDI {
2
5
  /**
3
6
  * @param name {string} The MIDI's name
@@ -1,135 +1,44 @@
1
1
  /**
2
- * A simplified version of the MIDI, accessible at all times from the Sequencer. use getMIDI() to get the actual sequence
3
- * This class contains all properties that MIDI does, except for tracks, which is the track data.
2
+ * A simplified version of the MIDI, accessible at all times from the Sequencer.
3
+ * Use getMIDI() to get the actual sequence.
4
+ * This class contains all properties that MIDI does, except for tracks and the embedded soundfont.
4
5
  */
5
- export class MidiData {
6
+ export class MidiData extends MIDISequenceData {
6
7
  /**
7
- * Constructor that copies data from a BasicMIDI instance, except for tracks and embeddedSoundFont.
8
+ * Constructor that copies data from a BasicMIDI instance.
8
9
  * @param {BasicMIDI} midi - The BasicMIDI instance to copy data from.
9
10
  */
10
11
  constructor(midi: BasicMIDI);
11
- /**
12
- * The time division of the sequence, representing the number of ticks per beat.
13
- * @type {number}
14
- */
15
- timeDivision: number;
16
- /**
17
- * The duration of the sequence, in seconds.
18
- * @type {number}
19
- */
20
- duration: number;
21
- /**
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.
24
- * @type {{ticks: number, tempo: number}[]}
25
- */
26
- tempoChanges: {
27
- ticks: number;
28
- tempo: number;
29
- }[];
30
- /**
31
- * A string containing the copyright information for the MIDI sequence.
32
- * @type {string}
33
- */
34
- copyright: string;
35
- /**
36
- * The number of tracks in the MIDI sequence.
37
- * @type {number}
38
- */
39
- tracksAmount: number;
40
- /**
41
- * An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
42
- * @type {Uint8Array[]}
43
- */
44
- lyrics: Uint8Array[];
45
- /**
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.
52
- * @type {{min: number, max: number}}
53
- */
54
- keyRange: {
55
- min: number;
56
- max: number;
57
- };
58
- /**
59
- * The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
60
- * @type {number}
61
- */
62
- lastVoiceEventTick: number;
63
- /**
64
- * An array of MIDI port numbers used by each track in the sequence.
65
- * @type {number[]}
66
- */
67
- midiPorts: number[];
68
- /**
69
- * An array of channel offsets for each MIDI port, using the SpessaSynth method.
70
- * @type {number[]}
71
- */
72
- midiPortChannelOffsets: number[];
73
- /**
74
- * A list of sets, where each set contains the MIDI channels used by each track in the sequence.
75
- * @type {Set<number>[]}
76
- */
77
- usedChannelsOnTrack: Set<number>[];
78
- /**
79
- * The loop points (in ticks) of the sequence, including both start and end points.
80
- * @type {{start: number, end: number}}
81
- */
82
- loop: {
83
- start: number;
84
- end: number;
85
- };
86
- /**
87
- * The name of the MIDI sequence.
88
- * @type {string}
89
- */
90
- midiName: string;
91
- /**
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.
98
- * @type {string}
99
- */
100
- fileName: string;
101
- /**
102
- * The raw, encoded MIDI name, represented as a Uint8Array.
103
- * @type {Uint8Array}
104
- */
105
- rawMidiName: Uint8Array;
106
12
  /**
107
13
  * A boolean indicating if the MIDI file contains an embedded soundfont.
108
14
  * If the embedded soundfont is undefined, this will be false.
109
15
  * @type {boolean}
110
16
  */
111
17
  isEmbedded: boolean;
112
- /**
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.
120
- * @type {Object<string, IndexedByteArray>}
121
- */
122
- RMIDInfo: {
123
- [x: string]: IndexedByteArray;
124
- };
125
- /**
126
- * The bank offset used for RMID files.
127
- * @type {number}
128
- */
129
- bankOffset: number;
18
+ timeDivision: any;
19
+ duration: any;
20
+ tempoChanges: any;
21
+ copyright: any;
22
+ tracksAmount: any;
23
+ lyrics: any;
24
+ firstNoteOn: any;
25
+ keyRange: any;
26
+ lastVoiceEventTick: any;
27
+ midiPorts: any;
28
+ midiPortChannelOffsets: any;
29
+ usedChannelsOnTrack: any;
30
+ loop: any;
31
+ midiName: any;
32
+ midiNameUsesFileName: any;
33
+ fileName: any;
34
+ rawMidiName: any;
35
+ format: any;
36
+ RMIDInfo: any;
37
+ bankOffset: any;
130
38
  }
131
39
  /**
132
- *
40
+ * Temporary MIDI data used when the MIDI is not loaded.
133
41
  * @type {MidiData}
134
42
  */
135
43
  export const DUMMY_MIDI_DATA: MidiData;
44
+ import { MIDISequenceData } from "./midi_sequence.js";
@@ -4,42 +4,86 @@
4
4
  */
5
5
  export function getGsOn(ticks: number): MidiMessage;
6
6
  /**
7
- * Allows easy editing of the file
7
+ * @typedef {Object} DesiredProgramChange
8
+ * @property {number} channel - The channel number.
9
+ * @property {number} program - The program number.
10
+ * @property {number} bank - The bank number.
11
+ * @property {boolean} isDrum - Indicates if the channel is a drum channel.
12
+ * If it is, then the bank number is ignored.
13
+ */
14
+ /**
15
+ * @typedef {Object} DesiredControllerChange
16
+ * @property {number} channel - The channel number.
17
+ * @property {number} controllerNumber - The MIDI controller number.
18
+ * @property {number} controllerValue - The new controller value.
19
+ */
20
+ /**
21
+ * @typedef {Object} DesiredChanneltranspose
22
+ * @property {number} channel - The channel number.
23
+ * @property {number} keyShift - The number of semitones to transpose.
24
+ * Note that this can use floating point numbers,
25
+ * which will be used to fine-tune the pitch in cents using RPN.
26
+ */
27
+ /**
28
+ * Allows easy editing of the file by removing channels, changing programs,
29
+ * changing controllers and transposing channels. Note that this modifies the MIDI in-place.
30
+ *
31
+ * @param {BasicMIDI} midi - The MIDI file to modify.
32
+ * @param {DesiredProgramChange[]} desiredProgramChanges - The programs to set on given channels.
33
+ * @param {DesiredControllerChange[]} desiredControllerChanges - The controllers to set on given channels.
34
+ * @param {number[]} desiredChannelsToClear - The channels to remove from the sequence.
35
+ * @param {DesiredChanneltranspose[]} desiredChannelsToTranspose - The channels to transpose.
36
+ */
37
+ export function modifyMIDI(midi: BasicMIDI, desiredProgramChanges?: DesiredProgramChange[], desiredControllerChanges?: DesiredControllerChange[], desiredChannelsToClear?: number[], desiredChannelsToTranspose?: DesiredChanneltranspose[]): void;
38
+ /**
39
+ * Modifies the sequence according to the locked presets and controllers in the given snapshot
8
40
  * @param midi {BasicMIDI}
9
- * @param desiredProgramChanges {{
10
- * channel: number,
11
- * program: number,
12
- * bank: number,
13
- * isDrum: boolean
14
- * }[]} the programs to set on given channels. Note that the channel may be more than 16, function will adjust midi ports automatically
15
- * @param desiredControllerChanges {{
16
- * channel: number,
17
- * controllerNumber: number,
18
- * controllerValue: number,
19
- * }[]} the controllers to set on given channels. Note that the channel may be more than 16, function will adjust midi ports automatically
20
- * @param desiredChannelsToClear {number[]} the channels to remove from the sequence. Note that the channel may be more than 16, function will adjust midi ports automatically
21
- * @param desiredChannelsToTranspose {{
22
- * channel: number,
23
- * keyShift: number
24
- * }[]} the channels to transpose. if keyShift is float, rpn fine tuning will be applied as well. Note that the channel may be more than 16, function will adjust midi ports automatically
41
+ * @param snapshot {SynthesizerSnapshot}
25
42
  */
26
- export function modifyMIDI(midi: BasicMIDI, desiredProgramChanges?: {
43
+ export function applySnapshotToMIDI(midi: BasicMIDI, snapshot: SynthesizerSnapshot): void;
44
+ export type DesiredProgramChange = {
45
+ /**
46
+ * - The channel number.
47
+ */
27
48
  channel: number;
49
+ /**
50
+ * - The program number.
51
+ */
28
52
  program: number;
53
+ /**
54
+ * - The bank number.
55
+ */
29
56
  bank: number;
57
+ /**
58
+ * - Indicates if the channel is a drum channel.
59
+ * If it is, then the bank number is ignored.
60
+ */
30
61
  isDrum: boolean;
31
- }[], desiredControllerChanges?: {
62
+ };
63
+ export type DesiredControllerChange = {
64
+ /**
65
+ * - The channel number.
66
+ */
32
67
  channel: number;
68
+ /**
69
+ * - The MIDI controller number.
70
+ */
33
71
  controllerNumber: number;
72
+ /**
73
+ * - The new controller value.
74
+ */
34
75
  controllerValue: number;
35
- }[], desiredChannelsToClear?: number[], desiredChannelsToTranspose?: {
76
+ };
77
+ export type DesiredChanneltranspose = {
78
+ /**
79
+ * - The channel number.
80
+ */
36
81
  channel: number;
82
+ /**
83
+ * - The number of semitones to transpose.
84
+ * Note that this can use floating point numbers,
85
+ * which will be used to fine-tune the pitch in cents using RPN.
86
+ */
37
87
  keyShift: number;
38
- }[]): void;
39
- /**
40
- * Modifies the sequence according to the locked presets and controllers in the given snapshot
41
- * @param midi {BasicMIDI}
42
- * @param snapshot {SynthesizerSnapshot}
43
- */
44
- export function applySnapshotToMIDI(midi: BasicMIDI, snapshot: SynthesizerSnapshot): void;
88
+ };
45
89
  import { MidiMessage } from "./midi_message.js";
@@ -2,6 +2,10 @@
2
2
  * midi_loader.js
3
3
  * purpose: parses a midi file for the seqyencer, including things like marker or CC 2/4 loop detection, copyright detection etc.
4
4
  */
5
+ /**
6
+ * The MIDI class is a MIDI file parser that reads a MIDI file and extracts all the necessary information from it.
7
+ * Supported formats are .mid and .rmi files.
8
+ */
5
9
  export class MIDI extends BasicMIDI {
6
10
  /**
7
11
  * Parses a given midi file
@@ -0,0 +1,124 @@
1
+ /**
2
+ * This is the base type for MIDI files. It contains all the "metadata" and information.
3
+ * It extends to:
4
+ * - BasicMIDI, which contains the actual track data of the MIDI file. Essentially the MIDI file itself.
5
+ * - MidiData, which contains all properties that MIDI does, except for tracks and the embedded soundfont.
6
+ * MidiData is the "shell" of the file which is available on the main thread at all times, containing the metadata.
7
+ */
8
+ export class MIDISequenceData {
9
+ /**
10
+ * The time division of the sequence, representing the number of ticks per beat.
11
+ * @type {number}
12
+ */
13
+ timeDivision: number;
14
+ /**
15
+ * The duration of the sequence, in seconds.
16
+ * @type {number}
17
+ */
18
+ duration: number;
19
+ /**
20
+ * The tempo changes in the sequence, ordered from the last change to the first.
21
+ * Each change is represented by an object with a tick position and a tempo value in beats per minute.
22
+ * @type {{ticks: number, tempo: number}[]}
23
+ */
24
+ tempoChanges: {
25
+ ticks: number;
26
+ tempo: number;
27
+ }[];
28
+ /**
29
+ * A string containing the copyright information for the MIDI sequence if detected.
30
+ * @type {string}
31
+ */
32
+ copyright: string;
33
+ /**
34
+ * The number of tracks in the MIDI sequence.
35
+ * @type {number}
36
+ */
37
+ tracksAmount: number;
38
+ /**
39
+ * An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
40
+ * @type {Uint8Array[]}
41
+ */
42
+ lyrics: Uint8Array[];
43
+ /**
44
+ * The tick position of the first note-on event in the MIDI sequence.
45
+ * @type {number}
46
+ */
47
+ firstNoteOn: number;
48
+ /**
49
+ * The MIDI key range used in the sequence, represented by a minimum and maximum note value.
50
+ * @type {{min: number, max: number}}
51
+ */
52
+ keyRange: {
53
+ min: number;
54
+ max: number;
55
+ };
56
+ /**
57
+ * The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
58
+ * @type {number}
59
+ */
60
+ lastVoiceEventTick: number;
61
+ /**
62
+ * An array of MIDI port numbers used by each track in the sequence.
63
+ * @type {number[]}
64
+ */
65
+ midiPorts: number[];
66
+ /**
67
+ * An array of channel offsets for each MIDI port, using the SpessaSynth method.
68
+ * @type {number[]}
69
+ */
70
+ midiPortChannelOffsets: number[];
71
+ /**
72
+ * A list of sets, where each set contains the MIDI channels used by each track in the sequence.
73
+ * @type {Set<number>[]}
74
+ */
75
+ usedChannelsOnTrack: Set<number>[];
76
+ /**
77
+ * The loop points (in ticks) of the sequence, including both start and end points.
78
+ * @type {{start: number, end: number}}
79
+ */
80
+ loop: {
81
+ start: number;
82
+ end: number;
83
+ };
84
+ /**
85
+ * The name of the MIDI sequence.
86
+ * @type {string}
87
+ */
88
+ midiName: string;
89
+ /**
90
+ * A boolean indicating if the sequence's name is the same as the file name.
91
+ * @type {boolean}
92
+ */
93
+ midiNameUsesFileName: boolean;
94
+ /**
95
+ * The file name of the MIDI sequence, if provided during parsing.
96
+ * @type {string}
97
+ */
98
+ fileName: string;
99
+ /**
100
+ * The raw, encoded MIDI name, represented as a Uint8Array.
101
+ * Useful when the MIDI file uses a different code page.
102
+ * @type {Uint8Array}
103
+ */
104
+ rawMidiName: Uint8Array;
105
+ /**
106
+ * The format of the MIDI file, which can be 0, 1, or 2, indicating the type of the MIDI file.
107
+ * @type {number}
108
+ */
109
+ format: number;
110
+ /**
111
+ * The RMID (Resource Interchangeable MIDI) info data, if the file is RMID formatted.
112
+ * Otherwise, this field is undefined.
113
+ * Chunk type (e.g. "INAM"): Chunk data as binary array.
114
+ * @type {Object<string, IndexedByteArray>}
115
+ */
116
+ RMIDInfo: {
117
+ [x: string]: IndexedByteArray;
118
+ };
119
+ /**
120
+ * The bank offset used for RMID files.
121
+ * @type {number}
122
+ */
123
+ bankOffset: number;
124
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Exports the midi as a .mid file
3
- * @param midi {BasicMIDI}
3
+ * @param midi {BasicMIDI} the midi to export
4
4
  * @returns {Uint8Array} the binary .mid file data
5
5
  */
6
6
  export function writeMIDIFile(midi: BasicMIDI): Uint8Array;
@@ -27,6 +27,7 @@ export type RMIDINFOChunks = string;
27
27
  export namespace RMIDINFOChunks {
28
28
  let name: string;
29
29
  let album: string;
30
+ let album2: string;
30
31
  let artist: string;
31
32
  let genre: string;
32
33
  let picture: string;
@@ -1,14 +1,14 @@
1
1
  export class BasicSample {
2
2
  /**
3
3
  * The basic representation of a soundfont sample
4
- * @param sampleName {string}
5
- * @param sampleRate {number}
6
- * @param samplePitch {number}
7
- * @param samplePitchCorrection {number}
8
- * @param sampleLink {number}
9
- * @param sampleType {number}
10
- * @param loopStart {number} relative to sample start
11
- * @param loopEnd {number} relative to sample start
4
+ * @param sampleName {string} The sample's name
5
+ * @param sampleRate {number} The sample's rate in Hz
6
+ * @param samplePitch {number} The sample's pitch as a MIDI note number
7
+ * @param samplePitchCorrection {number} The sample's pitch correction in cents
8
+ * @param sampleLink {number} The sample's link, currently unused
9
+ * @param sampleType {number} The sample's type, an enum
10
+ * @param loopStart {number} The sample's loop start relative to the sample start in sample points
11
+ * @param loopEnd {number} The sample's loop end relative to the sample start in sample points
12
12
  */
13
13
  constructor(sampleName: string, sampleRate: number, samplePitch: number, samplePitchCorrection: number, sampleLink: number, sampleType: number, loopStart: number, loopEnd: number);
14
14
  /**
@@ -75,6 +75,7 @@ export class BasicSample {
75
75
  * @returns {Uint8Array|IndexedByteArray}
76
76
  */
77
77
  getRawData(): Uint8Array | IndexedByteArray;
78
+ resampleData(newSampleRate: any): void;
78
79
  /**
79
80
  * @param quality {number}
80
81
  * @param encodeVorbis {EncodeVorbisFunction}
@@ -34,7 +34,7 @@ export class LoadedSample extends BasicSample {
34
34
  isDataRaw: boolean;
35
35
  /**
36
36
  * Get raw data, whether it's compressed or not as we simply write it to the file
37
- * @return {Uint8Array}
37
+ * @return {Uint8Array} either s16 or vorbis data
38
38
  */
39
39
  getRawData(): Uint8Array;
40
40
  /**