spessasynth_lib 3.25.22 → 3.26.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.
Files changed (168) hide show
  1. package/README.md +29 -114
  2. package/index.js +33 -33
  3. package/package.json +16 -6
  4. package/external_midi/README.md +0 -4
  5. package/external_midi/midi_handler.js +0 -130
  6. package/external_midi/web_midi_link.js +0 -43
  7. package/externals/fflate/LICENSE +0 -21
  8. package/externals/fflate/fflate.min.js +0 -1
  9. package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  10. package/externals/stbvorbis_sync/LICENSE +0 -202
  11. package/externals/stbvorbis_sync/NOTICE +0 -6
  12. package/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  13. package/midi/README.md +0 -32
  14. package/midi/basic_midi.js +0 -565
  15. package/midi/midi_builder.js +0 -202
  16. package/midi/midi_data.js +0 -63
  17. package/midi/midi_loader.js +0 -324
  18. package/midi/midi_message.js +0 -254
  19. package/midi/midi_sequence.js +0 -225
  20. package/midi/midi_tools/get_note_times.js +0 -154
  21. package/midi/midi_tools/midi_editor.js +0 -611
  22. package/midi/midi_tools/midi_writer.js +0 -99
  23. package/midi/midi_tools/rmidi_writer.js +0 -567
  24. package/midi/midi_tools/used_keys_loaded.js +0 -238
  25. package/midi/xmf_loader.js +0 -454
  26. package/sequencer/README.md +0 -32
  27. package/sequencer/sequencer_engine/events.js +0 -207
  28. package/sequencer/sequencer_engine/play.js +0 -353
  29. package/sequencer/sequencer_engine/process_event.js +0 -169
  30. package/sequencer/sequencer_engine/process_tick.js +0 -106
  31. package/sequencer/sequencer_engine/sequencer_engine.js +0 -337
  32. package/sequencer/sequencer_engine/song_control.js +0 -229
  33. package/sequencer/worklet_wrapper/default_sequencer_options.js +0 -8
  34. package/sequencer/worklet_wrapper/sequencer.js +0 -807
  35. package/sequencer/worklet_wrapper/sequencer_message.js +0 -53
  36. package/soundfont/README.md +0 -13
  37. package/soundfont/basic_soundfont/basic_instrument.js +0 -77
  38. package/soundfont/basic_soundfont/basic_preset.js +0 -336
  39. package/soundfont/basic_soundfont/basic_sample.js +0 -197
  40. package/soundfont/basic_soundfont/basic_soundfont.js +0 -565
  41. package/soundfont/basic_soundfont/basic_zone.js +0 -64
  42. package/soundfont/basic_soundfont/basic_zones.js +0 -43
  43. package/soundfont/basic_soundfont/generator.js +0 -220
  44. package/soundfont/basic_soundfont/modulator.js +0 -378
  45. package/soundfont/basic_soundfont/riff_chunk.js +0 -149
  46. package/soundfont/basic_soundfont/write_dls/art2.js +0 -173
  47. package/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  48. package/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -400
  49. package/soundfont/basic_soundfont/write_dls/ins.js +0 -103
  50. package/soundfont/basic_soundfont/write_dls/lins.js +0 -18
  51. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  52. package/soundfont/basic_soundfont/write_dls/rgn2.js +0 -121
  53. package/soundfont/basic_soundfont/write_dls/wave.js +0 -94
  54. package/soundfont/basic_soundfont/write_dls/write_dls.js +0 -119
  55. package/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  56. package/soundfont/basic_soundfont/write_dls/wvpl.js +0 -32
  57. package/soundfont/basic_soundfont/write_sf2/ibag.js +0 -39
  58. package/soundfont/basic_soundfont/write_sf2/igen.js +0 -80
  59. package/soundfont/basic_soundfont/write_sf2/imod.js +0 -46
  60. package/soundfont/basic_soundfont/write_sf2/inst.js +0 -34
  61. package/soundfont/basic_soundfont/write_sf2/pbag.js +0 -39
  62. package/soundfont/basic_soundfont/write_sf2/pgen.js +0 -82
  63. package/soundfont/basic_soundfont/write_sf2/phdr.js +0 -42
  64. package/soundfont/basic_soundfont/write_sf2/pmod.js +0 -46
  65. package/soundfont/basic_soundfont/write_sf2/sdta.js +0 -80
  66. package/soundfont/basic_soundfont/write_sf2/shdr.js +0 -55
  67. package/soundfont/basic_soundfont/write_sf2/write.js +0 -222
  68. package/soundfont/dls/articulator_converter.js +0 -396
  69. package/soundfont/dls/dls_destinations.js +0 -38
  70. package/soundfont/dls/dls_preset.js +0 -44
  71. package/soundfont/dls/dls_sample.js +0 -75
  72. package/soundfont/dls/dls_soundfont.js +0 -186
  73. package/soundfont/dls/dls_sources.js +0 -62
  74. package/soundfont/dls/dls_zone.js +0 -95
  75. package/soundfont/dls/read_articulation.js +0 -299
  76. package/soundfont/dls/read_instrument.js +0 -121
  77. package/soundfont/dls/read_instrument_list.js +0 -17
  78. package/soundfont/dls/read_lart.js +0 -35
  79. package/soundfont/dls/read_region.js +0 -152
  80. package/soundfont/dls/read_samples.js +0 -270
  81. package/soundfont/load_soundfont.js +0 -21
  82. package/soundfont/read_sf2/generators.js +0 -46
  83. package/soundfont/read_sf2/instruments.js +0 -66
  84. package/soundfont/read_sf2/modulators.js +0 -36
  85. package/soundfont/read_sf2/presets.js +0 -80
  86. package/soundfont/read_sf2/samples.js +0 -304
  87. package/soundfont/read_sf2/soundfont.js +0 -305
  88. package/soundfont/read_sf2/zones.js +0 -263
  89. package/synthetizer/README.md +0 -10
  90. package/synthetizer/audio_effects/effects_config.js +0 -25
  91. package/synthetizer/audio_effects/fancy_chorus.js +0 -162
  92. package/synthetizer/audio_effects/rb_compressed.min.js +0 -1
  93. package/synthetizer/audio_effects/reverb.js +0 -35
  94. package/synthetizer/audio_effects/reverb_as_binary.js +0 -18
  95. package/synthetizer/audio_engine/README.md +0 -25
  96. package/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -266
  97. package/synthetizer/audio_engine/engine_components/controller_tables.js +0 -88
  98. package/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -149
  99. package/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  100. package/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  101. package/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -471
  102. package/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  103. package/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  104. package/synthetizer/audio_engine/engine_components/soundfont_manager/sfman_message.js +0 -9
  105. package/synthetizer/audio_engine/engine_components/soundfont_manager/soundfont_manager.js +0 -254
  106. package/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -120
  107. package/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  108. package/synthetizer/audio_engine/engine_components/voice.js +0 -519
  109. package/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -401
  110. package/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -263
  111. package/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -132
  112. package/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -48
  113. package/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -241
  114. package/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -27
  115. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -253
  116. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -66
  117. package/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  118. package/synthetizer/audio_engine/engine_methods/note_on.js +0 -174
  119. package/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  120. package/synthetizer/audio_engine/engine_methods/program_change.js +0 -61
  121. package/synthetizer/audio_engine/engine_methods/render_voice.js +0 -196
  122. package/synthetizer/audio_engine/engine_methods/soundfont_management/clear_sound_font.js +0 -30
  123. package/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -22
  124. package/synthetizer/audio_engine/engine_methods/soundfont_management/reload_sound_font.js +0 -40
  125. package/synthetizer/audio_engine/engine_methods/soundfont_management/send_preset_list.js +0 -34
  126. package/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js +0 -21
  127. package/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -20
  128. package/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -55
  129. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  130. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  131. package/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  132. package/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -744
  133. package/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -24
  134. package/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -33
  135. package/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -31
  136. package/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  137. package/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -27
  138. package/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  139. package/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  140. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  141. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  142. package/synthetizer/audio_engine/main_processor.js +0 -765
  143. package/synthetizer/audio_engine/message_protocol/README.md +0 -13
  144. package/synthetizer/audio_engine/message_protocol/message_sending.js +0 -22
  145. package/synthetizer/audio_engine/message_protocol/worklet_message.js +0 -107
  146. package/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -14
  147. package/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  148. package/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -122
  149. package/synthetizer/synth_constants.js +0 -20
  150. package/synthetizer/worklet_processor.min.js +0 -21
  151. package/synthetizer/worklet_wrapper/key_modifier_manager.js +0 -104
  152. package/synthetizer/worklet_wrapper/synth_event_handler.js +0 -214
  153. package/synthetizer/worklet_wrapper/synth_soundfont_manager.js +0 -111
  154. package/synthetizer/worklet_wrapper/synthetizer.js +0 -1027
  155. package/synthetizer/worklet_wrapper/worklet_processor.js +0 -340
  156. package/synthetizer/worklet_wrapper/worklet_url.js +0 -16
  157. package/utils/README.md +0 -5
  158. package/utils/buffer_to_wav.js +0 -186
  159. package/utils/byte_functions/big_endian.js +0 -32
  160. package/utils/byte_functions/little_endian.js +0 -77
  161. package/utils/byte_functions/string.js +0 -107
  162. package/utils/byte_functions/variable_length_quantity.js +0 -42
  163. package/utils/fill_with_defaults.js +0 -21
  164. package/utils/indexed_array.js +0 -52
  165. package/utils/loggin.js +0 -79
  166. package/utils/other.js +0 -92
  167. package/utils/sysex_detector.js +0 -58
  168. package/utils/xg_hacks.js +0 -193
@@ -1,104 +0,0 @@
1
- import { workletMessageType } from "../audio_engine/message_protocol/worklet_message.js";
2
- import { KeyModifier, workletKeyModifierMessageType } from "../audio_engine/engine_components/key_modifier_manager.js";
3
-
4
- export class WorkletKeyModifierManagerWrapper
5
- {
6
- /**
7
- * @param synth {Synthetizer}
8
- */
9
- constructor(synth)
10
- {
11
- this.synth = synth;
12
- /**
13
- * The velocity override mappings for MIDI keys
14
- * @type {KeyModifier[][]}
15
- * @private
16
- */
17
- this._keyModifiers = [];
18
- }
19
-
20
- /**
21
- * @private
22
- * @param type {workletKeyModifierMessageType}
23
- * @param data {any}
24
- */
25
- _sendToWorklet(type, data)
26
- {
27
- this.synth.post({
28
- messageType: workletMessageType.keyModifierManager,
29
- messageData: [
30
- type,
31
- data
32
- ]
33
- });
34
- }
35
-
36
- /**
37
- * Modifies a single key
38
- * @param channel {number} the channel affected. Usually 0-15
39
- * @param midiNote {number} the MIDI note to change. 0-127
40
- * @param options {{
41
- * velocity: number|undefined,
42
- * patch: {
43
- * bank: number,
44
- * program: number
45
- * }|undefined,
46
- * gain: number|undefined
47
- * }} the key's modifiers
48
- */
49
- addModifier(channel, midiNote, options)
50
- {
51
- const velocity = options?.velocity ?? -1;
52
- const program = options?.patch?.program ?? -1;
53
- const bank = options?.patch?.bank ?? -1;
54
- const gain = options?.gain ?? 1;
55
- const mod = new KeyModifier(velocity, bank, program, gain);
56
- if (this._keyModifiers[channel] === undefined)
57
- {
58
- this._keyModifiers[channel] = [];
59
- }
60
- this._keyModifiers[channel][midiNote] = mod;
61
- this._sendToWorklet(
62
- workletKeyModifierMessageType.addMapping,
63
- [channel, midiNote, mod]
64
- );
65
- }
66
-
67
- /**
68
- * Gets a key modifier
69
- * @param channel {number} the channel affected. Usually 0-15
70
- * @param midiNote {number} the MIDI note to change. 0-127
71
- * @returns {KeyModifier|undefined}
72
- */
73
- getModifier(channel, midiNote)
74
- {
75
- return this._keyModifiers?.[channel]?.[midiNote];
76
- }
77
-
78
- /**
79
- * Deletes a key modifier
80
- * @param channel {number} the channel affected. Usually 0-15
81
- * @param midiNote {number} the MIDI note to change. 0-127
82
- */
83
- deleteModifier(channel, midiNote)
84
- {
85
- this._sendToWorklet(
86
- workletKeyModifierMessageType.deleteMapping,
87
- [channel, midiNote]
88
- );
89
- if (this._keyModifiers[channel]?.[midiNote] === undefined)
90
- {
91
- return;
92
- }
93
- this._keyModifiers[channel][midiNote] = undefined;
94
- }
95
-
96
- /**
97
- * Clears ALL Modifiers
98
- */
99
- clearModifiers()
100
- {
101
- this._sendToWorklet(workletKeyModifierMessageType.clearMappings, undefined);
102
- this._keyModifiers = [];
103
- }
104
- }
@@ -1,214 +0,0 @@
1
- /**
2
- * synth_event_handler.js
3
- * purpose: manages the synthesizer's event system, calling assinged functions when synthesizer requests dispatching the event
4
- */
5
-
6
- /**
7
- * @typedef {Object} NoteOnCallback
8
- * @property {number} midiNote - The MIDI note number.
9
- * @property {number} channel - The MIDI channel number.
10
- * @property {number} velocity - The velocity of the note.
11
- */
12
-
13
- /**
14
- * @typedef {Object} NoteOffCallback
15
- * @property {number} midiNote - The MIDI note number.
16
- * @property {number} channel - The MIDI channel number.
17
- */
18
-
19
- /**
20
- * @typedef {Object} DrumChangeCallback
21
- * @property {number} channel - The MIDI channel number.
22
- * @property {boolean} isDrumChannel - Indicates if the channel is a drum channel.
23
- */
24
-
25
- /**
26
- * @typedef {Object} ProgramChangeCallback
27
- * @property {number} channel - The MIDI channel number.
28
- * @property {number} program - The program number.
29
- * @property {number} bank - The bank number.
30
- */
31
-
32
- /**
33
- * @typedef {Object} ControllerChangeCallback
34
- * @property {number} channel - The MIDI channel number.
35
- * @property {number} controllerNumber - The controller number.
36
- * @property {number} controllerValue - The value of the controller.
37
- */
38
-
39
- /**
40
- * @typedef {Object} MuteChannelCallback
41
- * @property {number} channel - The MIDI channel number.
42
- * @property {boolean} isMuted - Indicates if the channel is muted.
43
- */
44
-
45
- /**
46
- * @typedef {Object} PresetListChangeCallbackSingle
47
- * @property {string} presetName - The name of the preset.
48
- * @property {number} bank - The bank number.
49
- * @property {number} program - The program number.
50
- */
51
-
52
- /**
53
- * @typedef {PresetListChangeCallbackSingle[]} PresetListChangeCallback - A list of preset objects.
54
- */
55
-
56
- /**
57
- * @typedef {Object} SynthDisplayCallback
58
- * @property {Uint8Array} displayData - The data to display.
59
- * @property {SynthDisplayType} displayType - The type of display.
60
- */
61
-
62
- /**
63
- * @typedef {Object} PitchWheelCallback
64
- * @property {number} channel - The MIDI channel number.
65
- * @property {number} MSB - The most significant byte of the pitch wheel value.
66
- * @property {number} LSB - The least significant byte of the pitch wheel value.
67
- */
68
-
69
- /**
70
- * @typedef {Object} ChannelPressureCallback
71
- * @property {number} channel - The MIDI channel number.
72
- * @property {number} pressure - The pressure value.
73
- */
74
-
75
- /**
76
- * @typedef {Error} SoundfontErrorCallback - The error message for soundfont errors.
77
- */
78
-
79
- /**
80
- * @typedef {
81
- * NoteOnCallback |
82
- * NoteOffCallback |
83
- * DrumChangeCallback |
84
- * ProgramChangeCallback |
85
- * ControllerChangeCallback |
86
- * MuteChannelCallback |
87
- * PresetListChangeCallback |
88
- * PitchWheelCallback |
89
- * SoundfontErrorCallback |
90
- * ChannelPressureCallback |
91
- * SynthDisplayCallback |
92
- * undefined
93
- * } EventCallbackData
94
- */
95
-
96
- /**
97
- * @typedef {
98
- * "noteon"|
99
- * "noteoff"|
100
- * "pitchwheel"|
101
- * "controllerchange"|
102
- * "programchange"|
103
- * "channelpressure"|
104
- * "polypressure" |
105
- * "drumchange"|
106
- * "stopall"|
107
- * "newchannel"|
108
- * "mutechannel"|
109
- * "presetlistchange"|
110
- * "allcontrollerreset"|
111
- * "soundfonterror"|
112
- * "synthdisplay"} EventTypes
113
- */
114
- export class EventHandler
115
- {
116
- /**
117
- * A new synthesizer event handler
118
- */
119
- constructor()
120
- {
121
- /**
122
- * The main list of events
123
- * @type {Object<EventTypes, Object<string, function(EventCallbackData)>>}
124
- */
125
- this.events = {
126
- "noteoff": {}, // called on note off message
127
- "noteon": {}, // called on note on message
128
- "pitchwheel": {}, // called on pitch wheel change
129
- "controllerchange": {}, // called on controller change
130
- "programchange": {}, // called on program change
131
- "channelpressure": {}, // called on channel pressure message
132
- "polypressure": {}, // called on poly pressure message
133
- "drumchange": {}, // called when channel type changes
134
- "stopall": {}, // called when synth receives stop all command
135
- "newchannel": {}, // called when a new channel is created
136
- "mutechannel": {}, // called when a channel is muted/unmuted
137
- "presetlistchange": {}, // called when the preset list changes (soundfont gets reloaded)
138
- "allcontrollerreset": {}, // called when all controllers are reset
139
- "soundfonterror": {}, // called when a soundfont parsing error occurs
140
- "synthdisplay": {} // called when there's a SysEx message to display some text
141
- };
142
-
143
- /**
144
- * Set to 0 to disabled, otherwise in seconds
145
- * @type {number}
146
- */
147
- this.timeDelay = 0;
148
- }
149
-
150
- /**
151
- * Adds a new event listener
152
- * @param name {EventTypes}
153
- * @param id {string} the unique identifier for the event (to delete it
154
- * @param callback {function(EventCallbackData)}
155
- */
156
- addEvent(name, id, callback)
157
- {
158
- this.events[name][id] = callback;
159
- }
160
-
161
- /**
162
- * Removes an event listener
163
- * @param name {EventTypes}
164
- * @param id {string}
165
- */
166
- removeEvent(name, id)
167
- {
168
- delete this.events[name][id];
169
- }
170
-
171
- /**
172
- * Calls the given event
173
- * @param name {EventTypes}
174
- * @param eventData {EventCallbackData}
175
- */
176
- callEvent(name, eventData)
177
- {
178
- if (this.events[name])
179
- {
180
- if (this.timeDelay > 0)
181
- {
182
- setTimeout(() =>
183
- {
184
- Object.values(this.events[name]).forEach(ev =>
185
- {
186
- try
187
- {
188
- ev(eventData);
189
- }
190
- catch (e)
191
- {
192
- console.error(`Error while executing an event callback for ${name}:`, e);
193
- }
194
- });
195
- }, this.timeDelay * 1000);
196
- }
197
- else
198
- {
199
- Object.values(this.events[name]).forEach(ev =>
200
- {
201
- try
202
- {
203
- ev(eventData);
204
- }
205
- catch (e)
206
- {
207
- console.error(`Error while executing an event callback for ${name}:`, e);
208
- }
209
- }
210
- );
211
- }
212
- }
213
- }
214
- }
@@ -1,111 +0,0 @@
1
- import { workletMessageType } from "../audio_engine/message_protocol/worklet_message.js";
2
- import {
3
- WorkletSoundfontManagerMessageType
4
- } from "../audio_engine/engine_components/soundfont_manager/sfman_message.js";
5
- import { SpessaSynthWarn } from "../../utils/loggin.js";
6
-
7
- export class SoundfontManager
8
- {
9
- /**
10
- * Creates a new instance of the soundfont manager
11
- * @param synth {Synthetizer}
12
- */
13
- constructor(synth)
14
- {
15
- /**
16
- * The current list of soundfonts, in order from the most important to the least.
17
- * @type {{
18
- * id: string,
19
- * bankOffset: number
20
- * }[]}
21
- */
22
- this.soundfontList = [{
23
- id: "main",
24
- bankOffset: 0
25
- }];
26
-
27
- /**
28
- * @type {MessagePort}
29
- * @private
30
- */
31
- this._port = synth.worklet.port;
32
- this.synth = synth;
33
- }
34
-
35
- /**
36
- * @private
37
- * @param type {WorkletSoundfontManagerMessageType}
38
- * @param data {any}
39
- */
40
- _sendToWorklet(type, data)
41
- {
42
- this._port.postMessage({
43
- messageType: workletMessageType.soundFontManager,
44
- messageData: [
45
- type,
46
- data
47
- ]
48
- });
49
- }
50
-
51
- /**
52
- * Adds a new soundfont buffer with a given ID
53
- * @param soundfontBuffer {ArrayBuffer} - the soundfont's buffer
54
- * @param id {string} - the soundfont's unique identifier
55
- * @param bankOffset {number} - the soundfont's bank offset. Default is 0
56
- */
57
- async addNewSoundFont(soundfontBuffer, id, bankOffset = 0)
58
- {
59
- if (this.soundfontList.find(s => s.id === id) !== undefined)
60
- {
61
- throw new Error("Cannot overwrite the existing soundfont. Use soundfontManager.delete(id) instead.");
62
- }
63
- this._sendToWorklet(WorkletSoundfontManagerMessageType.addNewSoundFont, [soundfontBuffer, id, bankOffset]);
64
- await new Promise(r => this.synth._resolveWhenReady = r);
65
- this.soundfontList.push({
66
- id: id,
67
- bankOffset: bankOffset
68
- });
69
- }
70
-
71
- /**
72
- * Deletes a soundfont with the given ID
73
- * @param id {string} - the soundfont to delete
74
- */
75
- deleteSoundFont(id)
76
- {
77
- if (this.soundfontList.length === 0)
78
- {
79
- SpessaSynthWarn("1 soundfont left. Aborting!");
80
- return;
81
- }
82
- if (this.soundfontList.findIndex(s => s.id === id) === -1)
83
- {
84
- SpessaSynthWarn(`No soundfont with id of "${id}" found. Aborting!`);
85
- return;
86
- }
87
- this._sendToWorklet(WorkletSoundfontManagerMessageType.deleteSoundFont, id);
88
- }
89
-
90
- /**
91
- * Rearranges the soundfonts in a given order
92
- * @param newList {string[]} the order of soundfonts, a list of identifiers, first overwrites second
93
- */
94
- rearrangeSoundFonts(newList)
95
- {
96
- this._sendToWorklet(WorkletSoundfontManagerMessageType.rearrangeSoundFonts, newList);
97
- this.soundfontList.sort((a, b) =>
98
- newList.indexOf(a.id) - newList.indexOf(b.id)
99
- );
100
- }
101
-
102
- /**
103
- * DELETES ALL SOUNDFONTS!! and creates a new one with id "main"
104
- * @param newBuffer {ArrayBuffer}
105
- */
106
- async reloadManager(newBuffer)
107
- {
108
- this._sendToWorklet(WorkletSoundfontManagerMessageType.reloadSoundFont, newBuffer);
109
- await new Promise(r => this.synth._resolveWhenReady = r);
110
- }
111
- }