spessasynth_lib 3.16.5 → 3.17.0
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/@types/index.d.ts +5 -4
- package/@types/midi_parser/basic_midi.d.ts +125 -0
- package/@types/midi_parser/midi_builder.d.ts +69 -0
- package/@types/midi_parser/midi_data.d.ts +2 -2
- package/@types/midi_parser/midi_editor.d.ts +4 -4
- package/@types/midi_parser/midi_loader.d.ts +3 -100
- package/@types/midi_parser/midi_writer.d.ts +2 -2
- package/@types/midi_parser/rmidi_writer.d.ts +3 -3
- package/@types/midi_parser/used_keys_loaded.d.ts +2 -2
- package/@types/sequencer/sequencer.d.ts +1 -1
- package/@types/soundfont/basic_soundfont/write_sf2/soundfont_trimmer.d.ts +2 -2
- package/@types/soundfont/dls/dls_preset.d.ts +11 -0
- package/@types/soundfont/dls/dls_soundfont.d.ts +24 -0
- package/@types/soundfont/dls/read_instrument.d.ts +5 -0
- package/@types/soundfont/dls/read_instrument_list.d.ts +5 -0
- package/@types/soundfont/load_soundfont.d.ts +6 -0
- package/@types/soundfont/soundfont.d.ts +2 -1
- package/@types/synthetizer/synthetizer.d.ts +2 -2
- package/@types/utils/byte_functions/little_endian.d.ts +1 -1
- package/README.md +17 -15
- package/index.js +6 -4
- package/midi_parser/basic_midi.js +146 -0
- package/midi_parser/midi_builder.js +281 -0
- package/midi_parser/midi_data.js +1 -1
- package/midi_parser/midi_editor.js +2 -2
- package/midi_parser/midi_loader.js +8 -53
- package/midi_parser/midi_writer.js +1 -1
- package/midi_parser/rmidi_writer.js +2 -2
- package/midi_parser/used_keys_loaded.js +1 -1
- package/package.json +1 -1
- package/sequencer/sequencer.js +1 -1
- package/sequencer/worklet_sequencer/song_control.js +3 -3
- package/sequencer/worklet_sequencer/worklet_sequencer.js +1 -1
- package/soundfont/basic_soundfont/riff_chunk.js +2 -2
- package/soundfont/basic_soundfont/write_sf2/soundfont_trimmer.js +1 -1
- package/soundfont/dls/dls_preset.js +25 -0
- package/soundfont/dls/dls_soundfont.js +93 -0
- package/soundfont/dls/read_instrument.js +22 -0
- package/soundfont/dls/read_instrument_list.js +17 -0
- package/soundfont/load_soundfont.js +21 -0
- package/soundfont/read_sf2/instruments.js +2 -2
- package/soundfont/read_sf2/modulators.js +5 -5
- package/soundfont/read_sf2/presets.js +7 -7
- package/soundfont/read_sf2/samples.js +8 -8
- package/soundfont/read_sf2/zones.js +5 -5
- package/soundfont/soundfont.js +8 -3
- package/synthetizer/synthetizer.js +1 -1
- package/synthetizer/worklet_processor.min.js +7 -6
- package/synthetizer/worklet_system/main_processor.js +1 -2
- package/synthetizer/worklet_system/worklet_methods/program_control.js +6 -3
- package/synthetizer/worklet_system/worklet_methods/worklet_soundfont_manager/worklet_soundfont_manager.js +5 -5
- package/utils/byte_functions/little_endian.js +1 -1
- /package/@types/{midi_handler → external_midi}/midi_handler.d.ts +0 -0
- /package/@types/{midi_handler → external_midi}/web_midi_link.d.ts +0 -0
- /package/{midi_handler → external_midi}/README.md +0 -0
- /package/{midi_handler → external_midi}/midi_handler.js +0 -0
- /package/{midi_handler → external_midi}/web_midi_link.js +0 -0
package/@types/index.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { Sequencer } from './sequencer/sequencer.js';
|
|
|
2
2
|
import { Synthetizer } from './synthetizer/synthetizer.js';
|
|
3
3
|
import { DEFAULT_PERCUSSION } from './synthetizer/synthetizer.js';
|
|
4
4
|
import { VOICE_CAP } from './synthetizer/synthetizer.js';
|
|
5
|
-
import {
|
|
5
|
+
import { loadSoundFont } from "./soundfont/load_soundfont.js";
|
|
6
6
|
import { trimSoundfont } from "./soundfont/basic_soundfont/write_sf2/soundfont_trimmer.js";
|
|
7
7
|
import { modulatorSources } from "./soundfont/read_sf2/modulators.js";
|
|
8
8
|
import { encodeVorbis } from "./utils/encode_vorbis.js";
|
|
9
9
|
import { MIDI } from './midi_parser/midi_loader.js';
|
|
10
|
+
import { MIDIBuilder } from "./midi_parser/midi_builder.js";
|
|
10
11
|
import { IndexedByteArray } from './utils/indexed_array.js';
|
|
11
12
|
import { writeMIDIFile } from './midi_parser/midi_writer.js';
|
|
12
13
|
import { writeRMIDI } from './midi_parser/rmidi_writer.js';
|
|
@@ -22,8 +23,8 @@ import { SpessaSynthWarn } from './utils/loggin.js';
|
|
|
22
23
|
import { SpessaSynthGroupCollapsed } from './utils/loggin.js';
|
|
23
24
|
import { midiControllers } from './midi_parser/midi_message.js';
|
|
24
25
|
import { messageTypes } from './midi_parser/midi_message.js';
|
|
25
|
-
import { MIDIDeviceHandler } from
|
|
26
|
-
import { WebMidiLinkHandler } from
|
|
26
|
+
import { MIDIDeviceHandler } from "./external_midi/midi_handler.js";
|
|
27
|
+
import { WebMidiLinkHandler } from "./external_midi/web_midi_link.js";
|
|
27
28
|
import { arrayToHexString } from './utils/other.js';
|
|
28
29
|
import { consoleColors } from './utils/other.js';
|
|
29
30
|
import { formatTitle } from './utils/other.js';
|
|
@@ -32,4 +33,4 @@ import { readBytesAsUintBigEndian } from './utils/byte_functions/big_endian.js';
|
|
|
32
33
|
import { NON_CC_INDEX_OFFSET } from './synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js';
|
|
33
34
|
import { ALL_CHANNELS_OR_DIFFERENT_ACTION } from './synthetizer/worklet_system/message_protocol/worklet_message.js';
|
|
34
35
|
import { WORKLET_URL_ABSOLUTE } from './synthetizer/worklet_url.js';
|
|
35
|
-
export { Sequencer, Synthetizer, DEFAULT_PERCUSSION, VOICE_CAP,
|
|
36
|
+
export { Sequencer, Synthetizer, DEFAULT_PERCUSSION, VOICE_CAP, loadSoundFont, trimSoundfont, modulatorSources, encodeVorbis, MIDI, MIDIBuilder, IndexedByteArray, writeMIDIFile, writeRMIDI, applySnapshotToMIDI, modifyMIDI, audioBufferToWav, SpessaSynthLogging, SpessaSynthGroup, SpessaSynthTable, SpessaSynthGroupEnd, SpessaSynthInfo, SpessaSynthWarn, SpessaSynthGroupCollapsed, midiControllers, messageTypes, MIDIDeviceHandler, WebMidiLinkHandler, arrayToHexString, consoleColors, formatTitle, formatTime, readBytesAsUintBigEndian, NON_CC_INDEX_OFFSET, ALL_CHANNELS_OR_DIFFERENT_ACTION, WORKLET_URL_ABSOLUTE };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export class BasicMIDI {
|
|
2
|
+
/**
|
|
3
|
+
* The time division of the sequence
|
|
4
|
+
* @type {number}
|
|
5
|
+
*/
|
|
6
|
+
timeDivision: number;
|
|
7
|
+
/**
|
|
8
|
+
* The duration of the sequence, in seconds
|
|
9
|
+
* @type {number}
|
|
10
|
+
*/
|
|
11
|
+
duration: number;
|
|
12
|
+
/**
|
|
13
|
+
* The tempo changes in the sequence, ordered from last to first
|
|
14
|
+
* @type {{ticks: number, tempo: number}[]}
|
|
15
|
+
*/
|
|
16
|
+
tempoChanges: {
|
|
17
|
+
ticks: number;
|
|
18
|
+
tempo: number;
|
|
19
|
+
}[];
|
|
20
|
+
/**
|
|
21
|
+
* Contains the copyright strings
|
|
22
|
+
* @type {string}
|
|
23
|
+
*/
|
|
24
|
+
copyright: string;
|
|
25
|
+
/**
|
|
26
|
+
* The amount of tracks in the sequence
|
|
27
|
+
* @type {number}
|
|
28
|
+
*/
|
|
29
|
+
tracksAmount: number;
|
|
30
|
+
/**
|
|
31
|
+
* The lyrics of the sequence as binary chunks
|
|
32
|
+
* @type {Uint8Array[]}
|
|
33
|
+
*/
|
|
34
|
+
lyrics: Uint8Array[];
|
|
35
|
+
/**
|
|
36
|
+
* First note on of the MIDI file
|
|
37
|
+
* @type {number}
|
|
38
|
+
*/
|
|
39
|
+
firstNoteOn: number;
|
|
40
|
+
/**
|
|
41
|
+
* The MIDI's key range
|
|
42
|
+
* @type {{min: number, max: number}}
|
|
43
|
+
*/
|
|
44
|
+
keyRange: {
|
|
45
|
+
min: number;
|
|
46
|
+
max: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The last voice (note on, off, cc change etc.) event tick
|
|
50
|
+
* @type {number}
|
|
51
|
+
*/
|
|
52
|
+
lastVoiceEventTick: number;
|
|
53
|
+
/**
|
|
54
|
+
* Midi port numbers for each track
|
|
55
|
+
* @type {number[]}
|
|
56
|
+
*/
|
|
57
|
+
midiPorts: number[];
|
|
58
|
+
/**
|
|
59
|
+
* Channel offsets for each port, using the SpessaSynth method
|
|
60
|
+
* @type {number[]}
|
|
61
|
+
*/
|
|
62
|
+
midiPortChannelOffsets: number[];
|
|
63
|
+
/**
|
|
64
|
+
* All channels that each track uses
|
|
65
|
+
* @type {Set<number>[]}
|
|
66
|
+
*/
|
|
67
|
+
usedChannelsOnTrack: Set<number>[];
|
|
68
|
+
/**
|
|
69
|
+
* The loop points (in ticks) of the sequence
|
|
70
|
+
* @type {{start: number, end: number}}
|
|
71
|
+
*/
|
|
72
|
+
loop: {
|
|
73
|
+
start: number;
|
|
74
|
+
end: number;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The sequence's name
|
|
78
|
+
* @type {string}
|
|
79
|
+
*/
|
|
80
|
+
midiName: string;
|
|
81
|
+
/**
|
|
82
|
+
* The file name of the sequence, if provided in the MIDI class
|
|
83
|
+
* @type {string}
|
|
84
|
+
*/
|
|
85
|
+
fileName: string;
|
|
86
|
+
/**
|
|
87
|
+
* The raw, encoded MIDI name.
|
|
88
|
+
* @type {Uint8Array}
|
|
89
|
+
*/
|
|
90
|
+
rawMidiName: Uint8Array;
|
|
91
|
+
/**
|
|
92
|
+
* The MIDI's embedded soundfont
|
|
93
|
+
* @type {ArrayBuffer|undefined}
|
|
94
|
+
*/
|
|
95
|
+
embeddedSoundFont: ArrayBuffer | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The MIDI file's format
|
|
98
|
+
* @type {number}
|
|
99
|
+
*/
|
|
100
|
+
format: number;
|
|
101
|
+
/**
|
|
102
|
+
* The RMID Info data if RMID, otherwise undefined
|
|
103
|
+
* @type {Object<string, IndexedByteArray>}
|
|
104
|
+
*/
|
|
105
|
+
RMIDInfo: {
|
|
106
|
+
[x: string]: IndexedByteArray;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* The bank offset for RMIDI
|
|
110
|
+
* @type {number}
|
|
111
|
+
*/
|
|
112
|
+
bankOffset: number;
|
|
113
|
+
/**
|
|
114
|
+
* The actual track data of the MIDI file
|
|
115
|
+
* @type {MidiMessage[][]}
|
|
116
|
+
*/
|
|
117
|
+
tracks: MidiMessage[][];
|
|
118
|
+
/**
|
|
119
|
+
* Coverts ticks to time in seconds
|
|
120
|
+
* @param ticks {number}
|
|
121
|
+
* @returns {number}
|
|
122
|
+
* @protected
|
|
123
|
+
*/
|
|
124
|
+
protected _ticksToSeconds(ticks: number): number;
|
|
125
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class MIDIBuilder extends BasicMIDI {
|
|
2
|
+
/**
|
|
3
|
+
* @param name {string} The MIDI's name
|
|
4
|
+
* @param timeDivision {number} the file's time division
|
|
5
|
+
* @param initialTempo {number} the file's initial tempo
|
|
6
|
+
*/
|
|
7
|
+
constructor(name: string, timeDivision?: number, initialTempo?: number);
|
|
8
|
+
encoder: TextEncoder;
|
|
9
|
+
/**
|
|
10
|
+
* Updates all internal values
|
|
11
|
+
*/
|
|
12
|
+
flush(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Adds a new "set tempo" message
|
|
15
|
+
* @param ticks {number} the tick number of the event
|
|
16
|
+
* @param tempo {number} the tempo in beats per minute (BPM)
|
|
17
|
+
*/
|
|
18
|
+
addSetTempo(ticks: number, tempo: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Adds a new MIDI track
|
|
21
|
+
* @param name {string} the new track's name
|
|
22
|
+
* @param port {number} the new track's port
|
|
23
|
+
*/
|
|
24
|
+
addNewTrack(name: string, port?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Adds a new MIDI Event
|
|
27
|
+
* @param ticks {number} the tick time of the event
|
|
28
|
+
* @param track {number} the track number to use
|
|
29
|
+
* @param event {number} the MIDI event number
|
|
30
|
+
* @param eventData {Uint8Array|Iterable<number>} the raw event data
|
|
31
|
+
*/
|
|
32
|
+
addEvent(ticks: number, track: number, event: number, eventData: Uint8Array | Iterable<number>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a new Note On event
|
|
35
|
+
* @param ticks {number} the tick time of the event
|
|
36
|
+
* @param track {number} the track number to use
|
|
37
|
+
* @param channel {number} the channel to use
|
|
38
|
+
* @param midiNote {number} the midi note of the keypress
|
|
39
|
+
* @param velocity {number} the velocity of the keypress
|
|
40
|
+
*/
|
|
41
|
+
addNoteOn(ticks: number, track: number, channel: number, midiNote: number, velocity: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Adds a new Note Off event
|
|
44
|
+
* @param ticks {number} the tick time of the event
|
|
45
|
+
* @param track {number} the track number to use
|
|
46
|
+
* @param channel {number} the channel to use
|
|
47
|
+
* @param midiNote {number} the midi note of the key release
|
|
48
|
+
*/
|
|
49
|
+
addNoteOff(ticks: number, track: number, channel: number, midiNote: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Adds a new Controller Change event
|
|
52
|
+
* @param ticks {number} the tick time of the event
|
|
53
|
+
* @param track {number} the track number to use
|
|
54
|
+
* @param channel {number} the channel to use
|
|
55
|
+
* @param controllerNumber {number} the MIDI CC to use
|
|
56
|
+
* @param controllerValue {number} the new CC value
|
|
57
|
+
*/
|
|
58
|
+
addControllerChange(ticks: number, track: number, channel: number, controllerNumber: number, controllerValue: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* Adds a new Pitch Wheel event
|
|
61
|
+
* @param ticks {number} the tick time of the event
|
|
62
|
+
* @param track {number} the track to use
|
|
63
|
+
* @param channel {number} the channel to use
|
|
64
|
+
* @param MSB {number} SECOND byte of the MIDI pitchWheel message
|
|
65
|
+
* @param LSB {number} FIRST byte of the MIDI pitchWheel message
|
|
66
|
+
*/
|
|
67
|
+
addPitchWheel(ticks: number, track: number, channel: number, MSB: number, LSB: number): void;
|
|
68
|
+
}
|
|
69
|
+
import { BasicMIDI } from './basic_midi.js';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export function getGsOn(ticks: number): MidiMessage;
|
|
6
6
|
/**
|
|
7
7
|
* Allows easy editing of the file
|
|
8
|
-
* @param midi {
|
|
8
|
+
* @param midi {BasicMIDI}
|
|
9
9
|
* @param desiredProgramChanges {{
|
|
10
10
|
* channel: number,
|
|
11
11
|
* program: number,
|
|
@@ -23,7 +23,7 @@ export function getGsOn(ticks: number): MidiMessage;
|
|
|
23
23
|
* keyShift: number
|
|
24
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
|
|
25
25
|
*/
|
|
26
|
-
export function modifyMIDI(midi:
|
|
26
|
+
export function modifyMIDI(midi: BasicMIDI, desiredProgramChanges?: {
|
|
27
27
|
channel: number;
|
|
28
28
|
program: number;
|
|
29
29
|
bank: number;
|
|
@@ -38,8 +38,8 @@ export function modifyMIDI(midi: MIDI, desiredProgramChanges?: {
|
|
|
38
38
|
}[]): void;
|
|
39
39
|
/**
|
|
40
40
|
* Modifies the sequence according to the locked presets and controllers in the given snapshot
|
|
41
|
-
* @param midi {
|
|
41
|
+
* @param midi {BasicMIDI}
|
|
42
42
|
* @param snapshot {SynthesizerSnapshot}
|
|
43
43
|
*/
|
|
44
|
-
export function applySnapshotToMIDI(midi:
|
|
44
|
+
export function applySnapshotToMIDI(midi: BasicMIDI, snapshot: SynthesizerSnapshot): void;
|
|
45
45
|
import { MidiMessage } from './midi_message.js';
|
|
@@ -2,104 +2,14 @@
|
|
|
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
|
-
export class MIDI {
|
|
5
|
+
export class MIDI extends BasicMIDI {
|
|
6
6
|
/**
|
|
7
7
|
* Parses a given midi file
|
|
8
8
|
* @param arrayBuffer {ArrayBuffer}
|
|
9
9
|
* @param fileName {string} optional, replaces the decoded title if empty
|
|
10
10
|
*/
|
|
11
11
|
constructor(arrayBuffer: ArrayBuffer, fileName?: string);
|
|
12
|
-
|
|
13
|
-
* If the RMI file has an embedded sf2 in it, it will appeear here, otherwise undefined
|
|
14
|
-
* @type {ArrayBuffer}
|
|
15
|
-
*/
|
|
16
|
-
embeddedSoundFont: ArrayBuffer;
|
|
17
|
-
/**
|
|
18
|
-
* The RMID Info data if RMID, otherwise undefined
|
|
19
|
-
* @type {Object<string, IndexedByteArray>}
|
|
20
|
-
*/
|
|
21
|
-
RMIDInfo: {
|
|
22
|
-
[x: string]: IndexedByteArray;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* The bank offset for RMIDI
|
|
26
|
-
* @type {number}
|
|
27
|
-
*/
|
|
28
|
-
bankOffset: number;
|
|
29
|
-
/**
|
|
30
|
-
* Contains the copyright strings
|
|
31
|
-
* @type {string}
|
|
32
|
-
*/
|
|
33
|
-
copyright: string;
|
|
34
|
-
/**
|
|
35
|
-
* The MIDI name
|
|
36
|
-
* @type {string}
|
|
37
|
-
*/
|
|
38
|
-
midiName: string;
|
|
39
|
-
rawMidiName: Uint8Array;
|
|
40
|
-
format: number;
|
|
41
|
-
tracksAmount: number;
|
|
42
|
-
timeDivision: number;
|
|
43
|
-
/**
|
|
44
|
-
* The MIDI's key range
|
|
45
|
-
* @type {{min: number, max: number}}
|
|
46
|
-
*/
|
|
47
|
-
keyRange: {
|
|
48
|
-
min: number;
|
|
49
|
-
max: number;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Contains the lyrics as binary chunks
|
|
53
|
-
* @type {Uint8Array[]}
|
|
54
|
-
*/
|
|
55
|
-
lyrics: Uint8Array[];
|
|
56
|
-
/**
|
|
57
|
-
* Contains all the tempo changes in the file. (Ordered from last to first)
|
|
58
|
-
* @type {{
|
|
59
|
-
* ticks: number,
|
|
60
|
-
* tempo: number
|
|
61
|
-
* }[]}
|
|
62
|
-
*/
|
|
63
|
-
tempoChanges: {
|
|
64
|
-
ticks: number;
|
|
65
|
-
tempo: number;
|
|
66
|
-
}[];
|
|
67
|
-
lastVoiceEventTick: number;
|
|
68
|
-
/**
|
|
69
|
-
* Midi port numbers for each tracks
|
|
70
|
-
* @type {number[]}
|
|
71
|
-
*/
|
|
72
|
-
midiPorts: number[];
|
|
73
|
-
/**
|
|
74
|
-
* Channel offsets for each port, using the SpessaSynth method
|
|
75
|
-
* @type {number[]}
|
|
76
|
-
*/
|
|
77
|
-
midiPortChannelOffsets: number[];
|
|
78
|
-
/**
|
|
79
|
-
* All channels that each track uses. Note: these channels range from 0 to 15, excluding the port offsets!
|
|
80
|
-
* @type {Set<number>[]}
|
|
81
|
-
*/
|
|
82
|
-
usedChannelsOnTrack: Set<number>[];
|
|
83
|
-
/**
|
|
84
|
-
* Read all the tracks
|
|
85
|
-
* @type {MidiMessage[][]}
|
|
86
|
-
*/
|
|
87
|
-
tracks: MidiMessage[][];
|
|
88
|
-
firstNoteOn: number;
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @type {{start: number, end: number}}
|
|
92
|
-
*/
|
|
93
|
-
loop: {
|
|
94
|
-
start: number;
|
|
95
|
-
end: number;
|
|
96
|
-
};
|
|
97
|
-
fileName: string;
|
|
98
|
-
/**
|
|
99
|
-
* The total playback time, in seconds
|
|
100
|
-
* @type {number}
|
|
101
|
-
*/
|
|
102
|
-
duration: number;
|
|
12
|
+
rawMidiName: any;
|
|
103
13
|
/**
|
|
104
14
|
* @param fileByteArray {IndexedByteArray}
|
|
105
15
|
* @returns {{type: string, size: number, data: IndexedByteArray}}
|
|
@@ -109,13 +19,6 @@ export class MIDI {
|
|
|
109
19
|
size: number;
|
|
110
20
|
data: IndexedByteArray;
|
|
111
21
|
};
|
|
112
|
-
/**
|
|
113
|
-
* Coverts ticks to time in seconds
|
|
114
|
-
* @param ticks {number}
|
|
115
|
-
* @returns {number}
|
|
116
|
-
* @private
|
|
117
|
-
*/
|
|
118
|
-
private _ticksToSeconds;
|
|
119
22
|
}
|
|
23
|
+
import { BasicMIDI } from './basic_midi.js';
|
|
120
24
|
import { IndexedByteArray } from '../utils/indexed_array.js';
|
|
121
|
-
import { MidiMessage } from './midi_message.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Exports the midi as a .mid file
|
|
3
|
-
* @param midi {
|
|
3
|
+
* @param midi {BasicMIDI}
|
|
4
4
|
* @returns {Uint8Array} the binary .mid file data
|
|
5
5
|
*/
|
|
6
|
-
export function writeMIDIFile(midi:
|
|
6
|
+
export function writeMIDIFile(midi: BasicMIDI): Uint8Array;
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* Writes an RMIDI file
|
|
16
16
|
* @param soundfontBinary {Uint8Array}
|
|
17
|
-
* @param mid {
|
|
18
|
-
* @param soundfont {
|
|
17
|
+
* @param mid {BasicMIDI}
|
|
18
|
+
* @param soundfont {BasicSoundFont}
|
|
19
19
|
* @param bankOffset {number} the bank offset for RMIDI
|
|
20
20
|
* @param encoding {string} the encoding of the RMIDI info chunk
|
|
21
21
|
* @param metadata {RMIDMetadata} the metadata of the file. Optional. If provided, the encoding is forced to utf-8/
|
|
22
22
|
* @param correctBankOffset {boolean}
|
|
23
23
|
* @returns {IndexedByteArray}
|
|
24
24
|
*/
|
|
25
|
-
export function writeRMIDI(soundfontBinary: Uint8Array, mid:
|
|
25
|
+
export function writeRMIDI(soundfontBinary: Uint8Array, mid: BasicMIDI, soundfont: BasicSoundFont, bankOffset?: number, encoding?: string, metadata?: RMIDMetadata, correctBankOffset?: boolean): IndexedByteArray;
|
|
26
26
|
export type RMIDINFOChunks = string;
|
|
27
27
|
export namespace RMIDINFOChunks {
|
|
28
28
|
let name: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param mid {
|
|
2
|
+
* @param mid {BasicMIDI}
|
|
3
3
|
* @param soundfont {{getPreset: function(number, number): BasicPreset}}
|
|
4
4
|
* @returns {Object<string, Set<string>>}
|
|
5
5
|
*/
|
|
6
|
-
export function getUsedProgramsAndKeys(mid:
|
|
6
|
+
export function getUsedProgramsAndKeys(mid: BasicMIDI, soundfont: {
|
|
7
7
|
getPreset: (arg0: number, arg1: number) => BasicPreset;
|
|
8
8
|
}): {
|
|
9
9
|
[x: string]: Set<string>;
|
|
@@ -194,7 +194,7 @@ export type MidFile = {
|
|
|
194
194
|
*/
|
|
195
195
|
altName: string | undefined;
|
|
196
196
|
};
|
|
197
|
-
export type MIDIFile =
|
|
197
|
+
export type MIDIFile = BasicMIDI | MidFile;
|
|
198
198
|
export type SequencerOptions = {
|
|
199
199
|
/**
|
|
200
200
|
* - if true, the sequencer will skip to the first note
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param soundfont {BasicSoundFont}
|
|
3
|
-
* @param mid {
|
|
3
|
+
* @param mid {BasicMIDI}
|
|
4
4
|
* @returns {Uint8Array}
|
|
5
5
|
*/
|
|
6
|
-
export function trimSoundfont(soundfont: BasicSoundFont, mid:
|
|
6
|
+
export function trimSoundfont(soundfont: BasicSoundFont, mid: BasicMIDI): Uint8Array;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class DLSPreset extends BasicPreset {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new DLS preset
|
|
4
|
+
* @param ulBank {number} the ULONG value
|
|
5
|
+
* @param ulInstrument {number} the ULONG value
|
|
6
|
+
* @param regionsAmount {number}
|
|
7
|
+
*/
|
|
8
|
+
constructor(ulBank: number, ulInstrument: number, regionsAmount: number);
|
|
9
|
+
regionsAmount: number;
|
|
10
|
+
}
|
|
11
|
+
import { BasicPreset } from '../basic_soundfont/basic_preset.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class DLSSoundFont extends BasicSoundFont {
|
|
2
|
+
/**
|
|
3
|
+
* Loads a new DLS (Downloadable sounds) soundfont
|
|
4
|
+
* @param buffer {ArrayBuffer}
|
|
5
|
+
*/
|
|
6
|
+
constructor(buffer: ArrayBuffer);
|
|
7
|
+
dataArray: any;
|
|
8
|
+
instrumentAmount: any;
|
|
9
|
+
/**
|
|
10
|
+
* @param chunk {RiffChunk}
|
|
11
|
+
* @param expected {string}
|
|
12
|
+
*/
|
|
13
|
+
verifyHeader(chunk: RiffChunk, expected: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* @param text {string}
|
|
16
|
+
* @param expected {string}
|
|
17
|
+
*/
|
|
18
|
+
verifyText(text: string, expected: string): void;
|
|
19
|
+
readDLSInstrumentList: typeof readDLSInstrumentList;
|
|
20
|
+
readDLSInstrument: typeof readDLSInstrument;
|
|
21
|
+
}
|
|
22
|
+
import { BasicSoundFont } from '../basic_soundfont/basic_soundfont.js';
|
|
23
|
+
import { readDLSInstrumentList } from './read_instrument_list.js';
|
|
24
|
+
import { readDLSInstrument } from './read_instrument.js';
|
|
@@ -6,8 +6,9 @@ export class SoundFont2 extends BasicSoundFont {
|
|
|
6
6
|
/**
|
|
7
7
|
* Initializes a new SoundFont2 Parser and parses the given data array
|
|
8
8
|
* @param arrayBuffer {ArrayBuffer}
|
|
9
|
+
* @param warnDeprecated {boolean}
|
|
9
10
|
*/
|
|
10
|
-
constructor(arrayBuffer: ArrayBuffer);
|
|
11
|
+
constructor(arrayBuffer: ArrayBuffer, warnDeprecated?: boolean);
|
|
11
12
|
dataArray: IndexedByteArray;
|
|
12
13
|
sampleDataStartIndex: number;
|
|
13
14
|
instruments: import("./read_sf2/instruments.js").Instrument[];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {Object} StartRenderingDataConfig
|
|
7
|
-
* @property {
|
|
7
|
+
* @property {BasicMIDI} parsedMIDI - the MIDI to render
|
|
8
8
|
* @property {SynthesizerSnapshot} snapshot - the snapshot to apply
|
|
9
9
|
* @property {boolean|undefined} oneOutput - if synth should use one output with 32 channels (2 audio channels for each midi channel). this disables chorus and reverb.
|
|
10
10
|
*/
|
|
@@ -290,7 +290,7 @@ export type StartRenderingDataConfig = {
|
|
|
290
290
|
/**
|
|
291
291
|
* - the MIDI to render
|
|
292
292
|
*/
|
|
293
|
-
parsedMIDI:
|
|
293
|
+
parsedMIDI: BasicMIDI;
|
|
294
294
|
/**
|
|
295
295
|
* - the snapshot to apply
|
|
296
296
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param bytesAmount {number}
|
|
5
5
|
* @returns {number}
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function readLittleEndian(dataArray: IndexedByteArray, bytesAmount: number): number;
|
|
8
8
|
/**
|
|
9
9
|
* Writes a number as little endian seems to also work for negative numbers so yay?
|
|
10
10
|
* @param dataArray {IndexedByteArray}
|
package/README.md
CHANGED
|
@@ -36,24 +36,24 @@ document.getElementById("button").onclick = async () => {
|
|
|
36
36
|
### Powerful SoundFont Synthesizer
|
|
37
37
|
- Suitable for both **real-time** and **offline** synthesis
|
|
38
38
|
- **Excellent SoundFont support:**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
- **Generator Support**
|
|
40
|
+
- **Modulator Support:** *First (to my knowledge) JavaScript SoundFont synth with that feature!*
|
|
41
|
+
- **SoundFont3 Support:** Play compressed SoundFonts!
|
|
42
|
+
- **Experimental SF2Pack Support:** Play soundfonts compressed with BASSMIDI! (*Note: only works with vorbis compression*)
|
|
43
|
+
- **Can load very large SoundFonts:** up to 4GB! *Note: Only Firefox handles this well; Chromium has a hard-coded memory limit*
|
|
44
|
+
- **Soundfont manager:** Stack multiple soundfonts!
|
|
44
45
|
- **Reverb and chorus support:** [customizable!](https://github.com/spessasus/SpessaSynth/wiki/Synthetizer-Class#effects-configuration-object)
|
|
45
46
|
- **Export audio files** using [OfflineAudioContext](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext)
|
|
46
47
|
- **[Custom modulators for additional controllers](https://github.com/spessasus/SpessaSynth/wiki/Modulator-Class#default-modulators):** Why not?
|
|
47
48
|
- **Written using AudioWorklets:**
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
- Runs in a **separate thread** for maximum performance
|
|
50
|
+
- Supported by all modern browsers
|
|
50
51
|
- **Unlimited channel count:** Your CPU is the limit!
|
|
51
52
|
- **Excellent MIDI Standards Support:**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- Supports some [**Roland GS** and **Yamaha XG** system exclusives](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-system-exclusives)
|
|
53
|
+
- **MIDI Controller Support:** Default supported controllers [here](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-controllers)
|
|
54
|
+
- **MIDI Tuning Standard Support:** [more info here](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#midi-tuning-standard)
|
|
55
|
+
- [Full **RPN** and limited **NRPN** support](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-registered-parameters)
|
|
56
|
+
- Supports some [**Roland GS** and **Yamaha XG** system exclusives](https://github.com/spessasus/SpessaSynth/wiki/MIDI-Implementation#supported-system-exclusives)
|
|
57
57
|
|
|
58
58
|
- **High-performance mode:** Play Rush E! _note: may kill your browser ;)_
|
|
59
59
|
|
|
@@ -76,8 +76,9 @@ document.getElementById("button").onclick = async () => {
|
|
|
76
76
|
- **Easy MIDI editing:** Use [helper functions](https://github.com/spessasus/SpessaSynth/wiki/Writing-MIDI-Files#modifymidi) to modify the song to your needs!
|
|
77
77
|
- **Loop detection:** Automatically detects loops in MIDIs (e.g., from _Touhou Project_)
|
|
78
78
|
- **First note detection:** Skip unnecessary silence at the start by jumping to the first note!
|
|
79
|
+
- **[Write MIDI files from scratch](https://github.com/spessasus/SpessaSynth/wiki/Creating-MIDI-Files.md)**
|
|
79
80
|
- **Easy saving:** Save with just [one function!](https://github.com/spessasus/SpessaSynth/wiki/Writing-MIDI-Files#writemidifile)
|
|
80
|
-
|
|
81
|
+
|
|
81
82
|
#### Read and write [RMID files with embedded SF2 soundfonts](https://github.com/spessasus/sf2-rmidi-specification#readme)
|
|
82
83
|
- **[Level 4](https://github.com/spessasus/sf2-rmidi-specification#level-4) compliance:** Reads and writes *everything!*
|
|
83
84
|
- **Compression and trimming support:** Reduce a MIDI file with a 1GB soundfont to **as small as 5MB**!
|
|
@@ -85,16 +86,17 @@ document.getElementById("button").onclick = async () => {
|
|
|
85
86
|
- **Metadata support:** Add title, artist, album name and cover and more! And of course read them too! *(In any encoding!)*
|
|
86
87
|
- **Compatible with [Falcosoft Midi Player 6!](https://falcosoft.hu/softwares.html#midiplayer)**
|
|
87
88
|
- **Easy saving:** [As simple as saving a MIDI file!](https://github.com/spessasus/SpessaSynth/wiki/Writing-MIDI-Files#writermidi)
|
|
88
|
-
|
|
89
|
+
|
|
89
90
|
#### Read and write SoundFont2 files
|
|
90
91
|
- **Easy info access:** Just an [object of strings!](https://github.com/spessasus/SpessaSynth/wiki/SoundFont2-Class#soundfontinfo)
|
|
91
92
|
- **Smart trimming:** Trim the SoundFont to only include samples used in the MIDI *(down to key and velocity!)*
|
|
92
93
|
- **sf3 conversion:** Compress SoundFont2 files to SoundFont3 with variable quality!
|
|
93
94
|
- **Easy saving:** Also just [one function!](https://github.com/spessasus/SpessaSynth/wiki/SoundFont2-Class#write)
|
|
94
|
-
|
|
95
|
+
|
|
95
96
|
#### Read and write SoundFont3 files
|
|
96
97
|
- Same features as SoundFont2 but with now with **Ogg Vorbis compression!**
|
|
97
98
|
- **Variable compression quality:** You choose between file size and quality!
|
|
98
99
|
- **Compression preserving:** Avoid decompressing and recompressing uncompressed samples for minimal quality loss!
|
|
100
|
+
|
|
99
101
|
## License
|
|
100
102
|
MIT License, except for the stbvorbis_sync.js in the `externals` folder which is licensed under the Apache-2.0 license.
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Import modules
|
|
2
|
-
import {
|
|
2
|
+
import { loadSoundFont } from "./soundfont/load_soundfont.js";
|
|
3
3
|
import { MIDI } from './midi_parser/midi_loader.js';
|
|
4
|
+
import { MIDIBuilder } from "./midi_parser/midi_builder.js";
|
|
4
5
|
import { Synthetizer, VOICE_CAP, DEFAULT_PERCUSSION } from './synthetizer/synthetizer.js';
|
|
5
6
|
import { Sequencer } from './sequencer/sequencer.js';
|
|
6
7
|
import { IndexedByteArray } from './utils/indexed_array.js';
|
|
@@ -18,8 +19,8 @@ import {
|
|
|
18
19
|
SpessaSynthGroup
|
|
19
20
|
} from './utils/loggin.js';
|
|
20
21
|
import { midiControllers, messageTypes } from './midi_parser/midi_message.js';
|
|
21
|
-
import { MIDIDeviceHandler
|
|
22
|
-
import { WebMidiLinkHandler
|
|
22
|
+
import { MIDIDeviceHandler} from "./external_midi/midi_handler.js";
|
|
23
|
+
import { WebMidiLinkHandler} from "./external_midi/web_midi_link.js";
|
|
23
24
|
import { formatTime, formatTitle, consoleColors, arrayToHexString } from './utils/other.js';
|
|
24
25
|
import { readBytesAsUintBigEndian } from './utils/byte_functions/big_endian.js';
|
|
25
26
|
import { NON_CC_INDEX_OFFSET } from './synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js';
|
|
@@ -38,13 +39,14 @@ export {
|
|
|
38
39
|
VOICE_CAP,
|
|
39
40
|
|
|
40
41
|
// SoundFont
|
|
41
|
-
|
|
42
|
+
loadSoundFont,
|
|
42
43
|
trimSoundfont,
|
|
43
44
|
modulatorSources,
|
|
44
45
|
encodeVorbis,
|
|
45
46
|
|
|
46
47
|
// MIDI
|
|
47
48
|
MIDI,
|
|
49
|
+
MIDIBuilder,
|
|
48
50
|
IndexedByteArray,
|
|
49
51
|
writeMIDIFile,
|
|
50
52
|
writeRMIDI,
|