spessasynth_lib 0.0.1

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 (154) hide show
  1. package/.idea/modules.xml +8 -0
  2. package/.idea/spessasynth_lib.iml +12 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/copy_version.sh +38 -0
  5. package/index.js +73 -0
  6. package/package/@types/externals/stbvorbis_sync/stbvorbis_sync.min.d.ts +1 -0
  7. package/package/@types/index.d.ts +34 -0
  8. package/package/@types/midi_handler/midi_handler.d.ts +39 -0
  9. package/package/@types/midi_handler/web_midi_link.d.ts +12 -0
  10. package/package/@types/midi_parser/midi_data.d.ts +95 -0
  11. package/package/@types/midi_parser/midi_editor.d.ts +45 -0
  12. package/package/@types/midi_parser/midi_loader.d.ts +100 -0
  13. package/package/@types/midi_parser/midi_message.d.ts +154 -0
  14. package/package/@types/midi_parser/midi_writer.d.ts +6 -0
  15. package/package/@types/midi_parser/rmidi_writer.d.ts +9 -0
  16. package/package/@types/midi_parser/used_keys_loaded.d.ts +7 -0
  17. package/package/@types/sequencer/sequencer.d.ts +180 -0
  18. package/package/@types/sequencer/worklet_sequencer/sequencer_message.d.ts +28 -0
  19. package/package/@types/soundfont/read/generators.d.ts +98 -0
  20. package/package/@types/soundfont/read/instruments.d.ts +50 -0
  21. package/package/@types/soundfont/read/modulators.d.ts +73 -0
  22. package/package/@types/soundfont/read/presets.d.ts +87 -0
  23. package/package/@types/soundfont/read/riff_chunk.d.ts +31 -0
  24. package/package/@types/soundfont/read/samples.d.ts +134 -0
  25. package/package/@types/soundfont/read/zones.d.ts +141 -0
  26. package/package/@types/soundfont/soundfont.d.ts +76 -0
  27. package/package/@types/soundfont/write/ibag.d.ts +6 -0
  28. package/package/@types/soundfont/write/igen.d.ts +6 -0
  29. package/package/@types/soundfont/write/imod.d.ts +6 -0
  30. package/package/@types/soundfont/write/inst.d.ts +6 -0
  31. package/package/@types/soundfont/write/pbag.d.ts +6 -0
  32. package/package/@types/soundfont/write/pgen.d.ts +6 -0
  33. package/package/@types/soundfont/write/phdr.d.ts +6 -0
  34. package/package/@types/soundfont/write/pmod.d.ts +6 -0
  35. package/package/@types/soundfont/write/sdta.d.ts +11 -0
  36. package/package/@types/soundfont/write/shdr.d.ts +8 -0
  37. package/package/@types/soundfont/write/soundfont_trimmer.d.ts +6 -0
  38. package/package/@types/soundfont/write/write.d.ts +21 -0
  39. package/package/@types/synthetizer/audio_effects/effects_config.d.ts +29 -0
  40. package/package/@types/synthetizer/audio_effects/fancy_chorus.d.ts +93 -0
  41. package/package/@types/synthetizer/audio_effects/reverb.d.ts +7 -0
  42. package/package/@types/synthetizer/synth_event_handler.d.ts +161 -0
  43. package/package/@types/synthetizer/synthetizer.d.ts +294 -0
  44. package/package/@types/synthetizer/worklet_system/message_protocol/worklet_message.d.ts +89 -0
  45. package/package/@types/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.d.ts +134 -0
  46. package/package/@types/synthetizer/worklet_url.d.ts +5 -0
  47. package/package/@types/utils/buffer_to_wav.d.ts +8 -0
  48. package/package/@types/utils/byte_functions/big_endian.d.ts +13 -0
  49. package/package/@types/utils/byte_functions/little_endian.d.ts +35 -0
  50. package/package/@types/utils/byte_functions/string.d.ts +22 -0
  51. package/package/@types/utils/byte_functions/variable_length_quantity.d.ts +12 -0
  52. package/package/@types/utils/indexed_array.d.ts +21 -0
  53. package/package/@types/utils/loggin.d.ts +26 -0
  54. package/package/@types/utils/other.d.ts +32 -0
  55. package/package/LICENSE +26 -0
  56. package/package/README.md +84 -0
  57. package/package/externals/NOTICE +9 -0
  58. package/package/externals/libvorbis/@types/OggVorbisEncoder.d.ts +34 -0
  59. package/package/externals/libvorbis/OggVorbisEncoder.min.js +1 -0
  60. package/package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +12 -0
  61. package/package/externals/stbvorbis_sync/LICENSE +202 -0
  62. package/package/externals/stbvorbis_sync/stbvorbis_sync.min.js +1 -0
  63. package/package/index.js +73 -0
  64. package/package/midi_handler/README.md +3 -0
  65. package/package/midi_handler/midi_handler.js +118 -0
  66. package/package/midi_handler/web_midi_link.js +41 -0
  67. package/package/midi_parser/README.md +3 -0
  68. package/package/midi_parser/midi_data.js +121 -0
  69. package/package/midi_parser/midi_editor.js +557 -0
  70. package/package/midi_parser/midi_loader.js +502 -0
  71. package/package/midi_parser/midi_message.js +234 -0
  72. package/package/midi_parser/midi_writer.js +95 -0
  73. package/package/midi_parser/rmidi_writer.js +271 -0
  74. package/package/midi_parser/used_keys_loaded.js +172 -0
  75. package/package/package.json +43 -0
  76. package/package/sequencer/README.md +23 -0
  77. package/package/sequencer/sequencer.js +439 -0
  78. package/package/sequencer/worklet_sequencer/events.js +92 -0
  79. package/package/sequencer/worklet_sequencer/play.js +309 -0
  80. package/package/sequencer/worklet_sequencer/process_event.js +167 -0
  81. package/package/sequencer/worklet_sequencer/process_tick.js +85 -0
  82. package/package/sequencer/worklet_sequencer/sequencer_message.js +39 -0
  83. package/package/sequencer/worklet_sequencer/song_control.js +193 -0
  84. package/package/sequencer/worklet_sequencer/worklet_sequencer.js +218 -0
  85. package/package/soundfont/README.md +8 -0
  86. package/package/soundfont/read/generators.js +212 -0
  87. package/package/soundfont/read/instruments.js +125 -0
  88. package/package/soundfont/read/modulators.js +249 -0
  89. package/package/soundfont/read/presets.js +300 -0
  90. package/package/soundfont/read/riff_chunk.js +81 -0
  91. package/package/soundfont/read/samples.js +398 -0
  92. package/package/soundfont/read/zones.js +310 -0
  93. package/package/soundfont/soundfont.js +357 -0
  94. package/package/soundfont/write/ibag.js +39 -0
  95. package/package/soundfont/write/igen.js +75 -0
  96. package/package/soundfont/write/imod.js +46 -0
  97. package/package/soundfont/write/inst.js +34 -0
  98. package/package/soundfont/write/pbag.js +39 -0
  99. package/package/soundfont/write/pgen.js +77 -0
  100. package/package/soundfont/write/phdr.js +42 -0
  101. package/package/soundfont/write/pmod.js +46 -0
  102. package/package/soundfont/write/sdta.js +72 -0
  103. package/package/soundfont/write/shdr.js +54 -0
  104. package/package/soundfont/write/soundfont_trimmer.js +169 -0
  105. package/package/soundfont/write/write.js +180 -0
  106. package/package/synthetizer/README.md +6 -0
  107. package/package/synthetizer/audio_effects/effects_config.js +21 -0
  108. package/package/synthetizer/audio_effects/fancy_chorus.js +120 -0
  109. package/package/synthetizer/audio_effects/impulse_response_2.flac +0 -0
  110. package/package/synthetizer/audio_effects/reverb.js +24 -0
  111. package/package/synthetizer/synth_event_handler.js +156 -0
  112. package/package/synthetizer/synthetizer.js +766 -0
  113. package/package/synthetizer/worklet_processor.min.js +13 -0
  114. package/package/synthetizer/worklet_system/README.md +6 -0
  115. package/package/synthetizer/worklet_system/main_processor.js +363 -0
  116. package/package/synthetizer/worklet_system/message_protocol/handle_message.js +197 -0
  117. package/package/synthetizer/worklet_system/message_protocol/message_sending.js +74 -0
  118. package/package/synthetizer/worklet_system/message_protocol/worklet_message.js +121 -0
  119. package/package/synthetizer/worklet_system/minify_processor.sh +4 -0
  120. package/package/synthetizer/worklet_system/worklet_methods/controller_control.js +230 -0
  121. package/package/synthetizer/worklet_system/worklet_methods/data_entry.js +277 -0
  122. package/package/synthetizer/worklet_system/worklet_methods/note_off.js +109 -0
  123. package/package/synthetizer/worklet_system/worklet_methods/note_on.js +91 -0
  124. package/package/synthetizer/worklet_system/worklet_methods/program_control.js +183 -0
  125. package/package/synthetizer/worklet_system/worklet_methods/reset_controllers.js +177 -0
  126. package/package/synthetizer/worklet_system/worklet_methods/snapshot.js +129 -0
  127. package/package/synthetizer/worklet_system/worklet_methods/system_exclusive.js +272 -0
  128. package/package/synthetizer/worklet_system/worklet_methods/tuning_control.js +195 -0
  129. package/package/synthetizer/worklet_system/worklet_methods/vibrato_control.js +29 -0
  130. package/package/synthetizer/worklet_system/worklet_methods/voice_control.js +233 -0
  131. package/package/synthetizer/worklet_system/worklet_processor.js +9 -0
  132. package/package/synthetizer/worklet_system/worklet_utilities/lfo.js +23 -0
  133. package/package/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js +130 -0
  134. package/package/synthetizer/worklet_system/worklet_utilities/modulation_envelope.js +73 -0
  135. package/package/synthetizer/worklet_system/worklet_utilities/modulator_curves.js +86 -0
  136. package/package/synthetizer/worklet_system/worklet_utilities/stereo_panner.js +81 -0
  137. package/package/synthetizer/worklet_system/worklet_utilities/unit_converter.js +66 -0
  138. package/package/synthetizer/worklet_system/worklet_utilities/volume_envelope.js +265 -0
  139. package/package/synthetizer/worklet_system/worklet_utilities/wavetable_oscillator.js +83 -0
  140. package/package/synthetizer/worklet_system/worklet_utilities/worklet_modulator.js +234 -0
  141. package/package/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +116 -0
  142. package/package/synthetizer/worklet_system/worklet_utilities/worklet_voice.js +272 -0
  143. package/package/synthetizer/worklet_url.js +5 -0
  144. package/package/utils/README.md +4 -0
  145. package/package/utils/buffer_to_wav.js +101 -0
  146. package/package/utils/byte_functions/big_endian.js +28 -0
  147. package/package/utils/byte_functions/little_endian.js +74 -0
  148. package/package/utils/byte_functions/string.js +97 -0
  149. package/package/utils/byte_functions/variable_length_quantity.js +37 -0
  150. package/package/utils/encode_vorbis.js +30 -0
  151. package/package/utils/indexed_array.js +41 -0
  152. package/package/utils/loggin.js +79 -0
  153. package/package/utils/other.js +54 -0
  154. package/package.json +43 -0
@@ -0,0 +1,294 @@
1
+ /**
2
+ * synthesizer.js
3
+ * purpose: responds to midi messages and called functions, managing the channels and passing the messages to them
4
+ */
5
+ /**
6
+ * @typedef {Object} StartRenderingDataConfig
7
+ * @property {MIDI} parsedMIDI - the MIDI to render
8
+ * @property {SynthesizerSnapshot} snapshot - the snapshot to apply
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
+ */
11
+ export const WORKLET_PROCESSOR_NAME: "spessasynth-worklet-system";
12
+ export const VOICE_CAP: 450;
13
+ export const DEFAULT_PERCUSSION: 9;
14
+ export const MIDI_CHANNEL_COUNT: 16;
15
+ export const DEFAULT_SYNTH_MODE: "gs";
16
+ /**
17
+ * Creates a new instance of the SpessaSynth synthesizer
18
+ * @param targetNode {AudioNode}
19
+ * @param soundFontBuffer {ArrayBuffer} the soundfont file array buffer
20
+ * @param enableEventSystem {boolean} enables the event system. Defaults to true
21
+ * @param startRenderingData {StartRenderingDataConfig} if set, starts playing this immediately and restores the values
22
+ * @param effectsConfig {EffectsConfig} optional configuration for the audio effects.
23
+ */
24
+ export class Synthetizer {
25
+ /**
26
+ * Creates a new instance of the SpessaSynth synthesizer
27
+ * @param targetNode {AudioNode}
28
+ * @param soundFontBuffer {ArrayBuffer} the soundfont file array buffer
29
+ * @param enableEventSystem {boolean} enables the event system. Defaults to true
30
+ * @param startRenderingData {StartRenderingDataConfig} if set, starts playing this immediately and restores the values
31
+ * @param effectsConfig {EffectsConfig} optional configuration for the audio effects.
32
+ */
33
+ constructor(targetNode: AudioNode, soundFontBuffer: ArrayBuffer, enableEventSystem?: boolean, startRenderingData?: StartRenderingDataConfig, effectsConfig?: EffectsConfig);
34
+ context: BaseAudioContext;
35
+ /**
36
+ * Allows to set up custom event listeners for the synthesizer
37
+ * @type {EventHandler}
38
+ */
39
+ eventHandler: EventHandler;
40
+ _voiceCap: number;
41
+ /**
42
+ * the new channels will have their audio sent to the moduled output by this constant.
43
+ * what does that mean? e.g. if outputsAmount is 16, then channel's 16 audio will be sent to channel 0
44
+ * @type {number}
45
+ * @private
46
+ */
47
+ private _outputsAmount;
48
+ /**
49
+ * the amount of midi channels
50
+ * @type {number}
51
+ */
52
+ channelsAmount: number;
53
+ /**
54
+ * Indicates if the synth is fully ready
55
+ * @type {Promise<void>}
56
+ */
57
+ isReady: Promise<void>;
58
+ _resolveReady: (value: void | PromiseLike<void>) => void;
59
+ /**
60
+ * individual channel voices amount
61
+ * @type {ChannelProperty[]}
62
+ */
63
+ channelProperties: ChannelProperty[];
64
+ _voicesAmount: number;
65
+ /**
66
+ * For Black MIDI's - forces release time to 50ms
67
+ * @type {boolean}
68
+ */
69
+ _highPerformanceMode: boolean;
70
+ worklet: AudioWorkletNode;
71
+ /**
72
+ * @type {function(SynthesizerSnapshot)}
73
+ * @private
74
+ */
75
+ private _snapshotCallback;
76
+ /**
77
+ * for the worklet sequencer's messages
78
+ * @type {function(WorkletSequencerReturnMessageType, any)}
79
+ */
80
+ sequencerCallbackFunction: (arg0: WorkletSequencerReturnMessageType, arg1: any) => any;
81
+ reverbProcessor: ConvolverNode;
82
+ chorusProcessor: FancyChorus;
83
+ /**
84
+ * The maximum amount of voices allowed at once
85
+ * @param value {number}
86
+ */
87
+ set voiceCap(value: number);
88
+ /**
89
+ * The maximum amount of voices allowed at once
90
+ * @returns {number}
91
+ */
92
+ get voiceCap(): number;
93
+ /**
94
+ * For Black MIDI's - forces release time to 50ms
95
+ * @param {boolean} value
96
+ */
97
+ set highPerformanceMode(value: boolean);
98
+ get highPerformanceMode(): boolean;
99
+ /**
100
+ * Sets the SpessaSynth's log level
101
+ * @param enableInfo {boolean} - enable info (verbose)
102
+ * @param enableWarning {boolean} - enable warnings (unrecognized messages)
103
+ * @param enableGroup {boolean} - enable groups (recomended)
104
+ * @param enableTable {boolean} - enable table (debug message)
105
+ */
106
+ setLogLevel(enableInfo: boolean, enableWarning: boolean, enableGroup: boolean, enableTable: boolean): void;
107
+ /**
108
+ * Handles the messages received from the worklet
109
+ * @param message {WorkletReturnMessage}
110
+ * @private
111
+ */
112
+ private handleMessage;
113
+ /**
114
+ * Gets a complete snapshot of the synthesizer, including controllers
115
+ * @returns {Promise<SynthesizerSnapshot>}
116
+ */
117
+ getSynthesizerSnapshot(): Promise<SynthesizerSnapshot>;
118
+ /**
119
+ * Adds a new channel to the synthesizer
120
+ * @param postMessage {boolean} leave at true, set to false only at initialization
121
+ */
122
+ addNewChannel(postMessage?: boolean): void;
123
+ /**
124
+ * @param channel {number}
125
+ * @param value {{delay: number, depth: number, rate: number}}
126
+ */
127
+ setVibrato(channel: number, value: {
128
+ delay: number;
129
+ depth: number;
130
+ rate: number;
131
+ }): void;
132
+ /**
133
+ * Connects the individual audio outputs to the given audio nodes. In the app it's used by the renderer.
134
+ * @param audioNodes {AudioNode[]}
135
+ */
136
+ connectIndividualOutputs(audioNodes: AudioNode[]): void;
137
+ lockAndResetChannelVibrato(): void;
138
+ /**
139
+ * A message for debugging
140
+ */
141
+ debugMessage(): void;
142
+ /**
143
+ * Starts playing a note
144
+ * @param channel {number} usually 0-15: the channel to play the note
145
+ * @param midiNote {number} 0-127 the key number of the note
146
+ * @param velocity {number} 0-127 the velocity of the note (generally controls loudness)
147
+ * @param enableDebugging {boolean} set to true to log technical details to console
148
+ */
149
+ noteOn(channel: number, midiNote: number, velocity: number, enableDebugging?: boolean): void;
150
+ /**
151
+ * Stops playing a note
152
+ * @param channel {number} usually 0-15: the channel of the note
153
+ * @param midiNote {number} 0-127 the key number of the note
154
+ * @param force {boolean} instantly kills the note if true
155
+ */
156
+ noteOff(channel: number, midiNote: number, force?: boolean): void;
157
+ /**
158
+ * Stops all notes
159
+ * @param force {boolean} if we should instantly kill the note, defaults to false
160
+ */
161
+ stopAll(force?: boolean): void;
162
+ /**
163
+ * Changes the given controller
164
+ * @param channel {number} usually 0-15: the channel to change the controller
165
+ * @param controllerNumber {number} 0-127 the MIDI CC number
166
+ * @param controllerValue {number} 0-127 the controller value
167
+ * @param force {boolean} forces the controller change, even if it's locked or gm system is set and the cc is bank select
168
+ */
169
+ controllerChange(channel: number, controllerNumber: number, controllerValue: number, force?: boolean): void;
170
+ /**
171
+ * Resets all controllers (for every channel)
172
+ */
173
+ resetControllers(): void;
174
+ /**
175
+ * Applies pressure to a given channel
176
+ * @param channel {number} usually 0-15: the channel to change the controller
177
+ * @param pressure {number} 0-127: the pressure to apply
178
+ */
179
+ channelPressure(channel: number, pressure: number): void;
180
+ /**
181
+ * Applies pressure to a given note
182
+ * @param channel {number} usually 0-15: the channel to change the controller
183
+ * @param midiNote {number} 0-127: the MIDI note
184
+ * @param pressure {number} 0-127: the pressure to apply
185
+ */
186
+ polyPressure(channel: number, midiNote: number, pressure: number): void;
187
+ /**
188
+ * @param data {WorkletMessage}
189
+ */
190
+ post(data: WorkletMessage): void;
191
+ /**
192
+ * Sets the pitch of the given channel
193
+ * @param channel {number} usually 0-15: the channel to change pitch
194
+ * @param MSB {number} SECOND byte of the MIDI pitchWheel message
195
+ * @param LSB {number} FIRST byte of the MIDI pitchWheel message
196
+ */
197
+ pitchWheel(channel: number, MSB: number, LSB: number): void;
198
+ /**
199
+ * Transposes the synthetizer's pitch by given semitones amount (percussion channels do not get affected)
200
+ * @param semitones {number} the semitones to transpose by. Can be a floating point number for more precision
201
+ */
202
+ transpose(semitones: number): void;
203
+ /**
204
+ * Transposes the channel by given amount of semitones
205
+ * @param channel {number} the channel number
206
+ * @param semitones {number} the transposition of the channel, can be a float
207
+ * @param force {boolean} defaults to false, if true transposes the channel even if it's a drum channel
208
+ */
209
+ transposeChannel(channel: number, semitones: number, force?: boolean): void;
210
+ /**
211
+ * Sets the main volume
212
+ * @param volume {number} 0-1 the volume
213
+ */
214
+ setMainVolume(volume: number): void;
215
+ /**
216
+ * Sets the master stereo panning
217
+ * @param pan {number} -1 to 1, the pan (-1 is left, 0 is midde, 1 is right)
218
+ */
219
+ setMasterPan(pan: number): void;
220
+ /**
221
+ * Sets the channel's pitch bend range, in semitones
222
+ * @param channel {number} usually 0-15: the channel to change
223
+ * @param pitchBendRangeSemitones {number} the bend range in semitones
224
+ */
225
+ setPitchBendRange(channel: number, pitchBendRangeSemitones: number): void;
226
+ /**
227
+ * Changes the patch for a given channel
228
+ * @param channel {number} usually 0-15: the channel to change
229
+ * @param programNumber {number} 0-127 the MIDI patch number
230
+ * @param userChange {boolean} indicates if the program change has been called by user. defaults to false
231
+ */
232
+ programChange(channel: number, programNumber: number, userChange?: boolean): void;
233
+ /**
234
+ * Causes the given midi channel to ignore controller messages for the given controller number
235
+ * @param channel {number} usually 0-15: the channel to lock
236
+ * @param controllerNumber {number} 0-127 MIDI CC number NOTE: -1 locks the preset
237
+ * @param isLocked {boolean} true if locked, false if unlocked
238
+ */
239
+ lockController(channel: number, controllerNumber: number, isLocked: boolean): void;
240
+ /**
241
+ * Mutes or unmutes the given channel
242
+ * @param channel {number} usually 0-15: the channel to lock
243
+ * @param isMuted {boolean} indicates if the channel is muted
244
+ */
245
+ muteChannel(channel: number, isMuted: boolean): void;
246
+ /**
247
+ * Reloads the sounfont.
248
+ * @param soundFontBuffer {ArrayBuffer} the new soundfont file array buffer
249
+ * @return {Promise<void>}
250
+ */
251
+ reloadSoundFont(soundFontBuffer: ArrayBuffer): Promise<void>;
252
+ /**
253
+ * Sends a MIDI Sysex message to the synthesizer
254
+ * @param messageData {IndexedByteArray} the message's data (excluding the F0 byte, but including the F7 at the end)
255
+ */
256
+ systemExclusive(messageData: IndexedByteArray): void;
257
+ /**
258
+ * Toggles drums on a given channel
259
+ * @param channel {number}
260
+ * @param isDrum {boolean}
261
+ */
262
+ setDrums(channel: number, isDrum: boolean): void;
263
+ /**
264
+ * sends a raw MIDI message to the synthesizer
265
+ * @param message {ArrayLike<number>} the midi message, each number is a byte
266
+ */
267
+ sendMessage(message: ArrayLike<number>): void;
268
+ /**
269
+ * @returns {number} the audioContext's current time
270
+ */
271
+ get currentTime(): number;
272
+ /**
273
+ * @returns {number} the current amount of voices playing
274
+ */
275
+ get voicesAmount(): number;
276
+ reverbateEverythingBecauseWhyNot(): string;
277
+ }
278
+ export type StartRenderingDataConfig = {
279
+ /**
280
+ * - the MIDI to render
281
+ */
282
+ parsedMIDI: MIDI;
283
+ /**
284
+ * - the snapshot to apply
285
+ */
286
+ snapshot: SynthesizerSnapshot;
287
+ /**
288
+ * - if synth should use one output with 32 channels (2 audio channels for each midi channel). this disables chorus and reverb.
289
+ */
290
+ oneOutput: boolean | undefined;
291
+ };
292
+ import { EventHandler } from './synth_event_handler.js';
293
+ import { FancyChorus } from './audio_effects/fancy_chorus.js';
294
+ import { IndexedByteArray } from '../utils/indexed_array.js';
@@ -0,0 +1,89 @@
1
+ /**
2
+ * * // NOTE: Every message needs a channel number (if not relevant or all, set to -1)
3
+ */
4
+ export type workletMessageType = number;
5
+ export namespace workletMessageType {
6
+ let noteOff: number;
7
+ let noteOn: number;
8
+ let ccChange: number;
9
+ let programChange: number;
10
+ let channelPressure: number;
11
+ let polyPressure: number;
12
+ let killNote: number;
13
+ let ccReset: number;
14
+ let setChannelVibrato: number;
15
+ let reloadSoundFont: number;
16
+ let stopAll: number;
17
+ let killNotes: number;
18
+ let muteChannel: number;
19
+ let addNewChannel: number;
20
+ let customcCcChange: number;
21
+ let debugMessage: number;
22
+ let systemExclusive: number;
23
+ let setMasterParameter: number;
24
+ let setDrums: number;
25
+ let pitchWheel: number;
26
+ let transpose: number;
27
+ let highPerformanceMode: number;
28
+ let lockController: number;
29
+ let sequencerSpecific: number;
30
+ let requestSynthesizerSnapshot: number;
31
+ let setLogLevel: number;
32
+ }
33
+ export type masterParameterType = number;
34
+ export namespace masterParameterType {
35
+ let mainVolume: number;
36
+ let masterPan: number;
37
+ let voicesCap: number;
38
+ }
39
+ export const ALL_CHANNELS_OR_DIFFERENT_ACTION: -1;
40
+ export type returnMessageType = number;
41
+ export namespace returnMessageType {
42
+ export let channelProperties: number;
43
+ export let eventCall: number;
44
+ export let reportedCurrentTime: number;
45
+ let sequencerSpecific_1: number;
46
+ export { sequencerSpecific_1 as sequencerSpecific };
47
+ export let synthesizerSnapshot: number;
48
+ export let ready: number;
49
+ export let soundfontError: number;
50
+ }
51
+ export type WorkletMessage = {
52
+ channelNumber: number;
53
+ messageType: workletMessageType;
54
+ messageData: (number[] | boolean[] | WorkletVoice[] | number | {
55
+ sampleData: Float32Array;
56
+ sampleID: number;
57
+ } | {
58
+ rate: number;
59
+ depth: number;
60
+ delay: number;
61
+ } | boolean | ArrayBuffer | {
62
+ messageType: WorkletSequencerMessageType;
63
+ messageData: any;
64
+ });
65
+ };
66
+ export type WorkletReturnMessage = {
67
+ /**
68
+ * - the message's type
69
+ */
70
+ messageType: returnMessageType;
71
+ /**
72
+ * - the message's data
73
+ *
74
+ * 0 - channel properties -> [...<ChannelProperty>] see message_sending.js line 29
75
+ * 1 - event call -> {eventName<string>, eventData:<the event's data>}
76
+ * 2 - reported current time -> currentTime<number>
77
+ * 3 - sequencer specific -> [messageType<WorkletSequencerReturnMessageType> messageData<any>] note: refer to sequencer_message.js
78
+ * 4 - synthesizer snapshot -> snapshot<SynthesizerSnapshot> note: refer to snapshot.js
79
+ * 5 - ready -> (no data)
80
+ * 6 - soundfontError -> errorMessage<string>
81
+ */
82
+ messageData: {
83
+ eventName: string;
84
+ eventData: any;
85
+ } | ChannelProperty[] | PresetListElement[] | string | {
86
+ messageType: WorkletSequencerReturnMessageType;
87
+ messageData: any;
88
+ } | SynthesizerSnapshot;
89
+ };
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @typedef {Object} WorkletProcessorChannel
3
+ * @property {Int16Array} midiControllers - array of MIDI controller values + the values used by modulators as source (pitch bend, bend range etc.)
4
+ * @property {boolean[]} lockedControllers - array indicating if a controller is locked
5
+ * @property {Float32Array} customControllers - array of custom (not sf2) control values such as RPN pitch tuning, transpose, modulation depth, etc.
6
+ *
7
+ * @property {number} channelTransposeKeyShift - key shift of the channel
8
+ * @property {boolean} holdPedal - indicates whether the hold pedal is active
9
+ * @property {boolean} drumChannel - indicates whether the channel is a drum channel
10
+ *
11
+ * @property {dataEntryStates} dataEntryState - the current state of the data entry
12
+ * @property {number} NRPCoarse - the current coarse value of the Non-Registered Parameter
13
+ * @property {number} NRPFine - the current fine value of the Non-Registered Parameter
14
+ * @property {number} RPValue - the current value of the Registered Parameter
15
+ *
16
+ * @property {Preset} preset - the channel's preset
17
+ * @property {boolean} lockPreset - indicates whether the program on the channel is locked
18
+ *
19
+ * @property {boolean} lockVibrato - indicates whether the custom vibrato is locked
20
+ * @property {Object} channelVibrato - vibrato settings for the channel
21
+ * @property {number} channelVibrato.depth - depth of the vibrato effect (cents)
22
+ * @property {number} channelVibrato.delay - delay before the vibrato effect starts (seconds)
23
+ * @property {number} channelVibrato.rate - rate of the vibrato oscillation (Hz)
24
+
25
+ * @property {boolean} isMuted - indicates whether the channel is muted
26
+ * @property {WorkletVoice[]} voices - array of voices currently active on the channel
27
+ * @property {WorkletVoice[]} sustainedVoices - array of voices that are sustained on the channel
28
+ * @property {WorkletVoice[][][]} cachedVoices - first is midi note, second is velocity. output is an array of WorkletVoices
29
+ */
30
+ /**
31
+ * @param sendEvent {boolean}
32
+ * @this {SpessaSynthProcessor}
33
+ */
34
+ export function createWorkletChannel(this: SpessaSynthProcessor, sendEvent?: boolean): void;
35
+ export const NON_CC_INDEX_OFFSET: 128;
36
+ export const CONTROLLER_TABLE_SIZE: 147;
37
+ export const resetArray: Int16Array;
38
+ export type dataEntryStates = number;
39
+ export namespace dataEntryStates {
40
+ let Idle: number;
41
+ let RPCoarse: number;
42
+ let RPFine: number;
43
+ let NRPCoarse: number;
44
+ let NRPFine: number;
45
+ let DataCoarse: number;
46
+ let DataFine: number;
47
+ }
48
+ export namespace customControllers {
49
+ let channelTuning: number;
50
+ let channelTransposeFine: number;
51
+ let modulationMultiplier: number;
52
+ let masterTuning: number;
53
+ let channelTuningSemitones: number;
54
+ }
55
+ export const CUSTOM_CONTROLLER_TABLE_SIZE: number;
56
+ export const customResetArray: Float32Array;
57
+ export type WorkletProcessorChannel = {
58
+ /**
59
+ * - array of MIDI controller values + the values used by modulators as source (pitch bend, bend range etc.)
60
+ */
61
+ midiControllers: Int16Array;
62
+ /**
63
+ * - array indicating if a controller is locked
64
+ */
65
+ lockedControllers: boolean[];
66
+ /**
67
+ * - array of custom (not sf2) control values such as RPN pitch tuning, transpose, modulation depth, etc.
68
+ */
69
+ customControllers: Float32Array;
70
+ /**
71
+ * - key shift of the channel
72
+ */
73
+ channelTransposeKeyShift: number;
74
+ /**
75
+ * - indicates whether the hold pedal is active
76
+ */
77
+ holdPedal: boolean;
78
+ /**
79
+ * - indicates whether the channel is a drum channel
80
+ */
81
+ drumChannel: boolean;
82
+ /**
83
+ * - the current state of the data entry
84
+ */
85
+ dataEntryState: dataEntryStates;
86
+ /**
87
+ * - the current coarse value of the Non-Registered Parameter
88
+ */
89
+ NRPCoarse: number;
90
+ /**
91
+ * - the current fine value of the Non-Registered Parameter
92
+ */
93
+ NRPFine: number;
94
+ /**
95
+ * - the current value of the Registered Parameter
96
+ */
97
+ RPValue: number;
98
+ /**
99
+ * - the channel's preset
100
+ */
101
+ preset: Preset;
102
+ /**
103
+ * - indicates whether the program on the channel is locked
104
+ */
105
+ lockPreset: boolean;
106
+ /**
107
+ * - indicates whether the custom vibrato is locked
108
+ */
109
+ lockVibrato: boolean;
110
+ /**
111
+ * - vibrato settings for the channel
112
+ */
113
+ channelVibrato: {
114
+ depth: number;
115
+ delay: number;
116
+ rate: number;
117
+ };
118
+ /**
119
+ * - indicates whether the channel is muted
120
+ */
121
+ isMuted: boolean;
122
+ /**
123
+ * - array of voices currently active on the channel
124
+ */
125
+ voices: WorkletVoice[];
126
+ /**
127
+ * - array of voices that are sustained on the channel
128
+ */
129
+ sustainedVoices: WorkletVoice[];
130
+ /**
131
+ * - first is midi note, second is velocity. output is an array of WorkletVoices
132
+ */
133
+ cachedVoices: WorkletVoice[][][];
134
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The absolute path (from the spessasynth_lib folder) to the worklet module
3
+ * @type {string}
4
+ */
5
+ export const WORKLET_URL_ABSOLUTE: string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @param audioBuffer {AudioBuffer}
4
+ * @param normalizeAudio {boolean} find the max sample point and set it to 1, and scale others with it
5
+ * @param channelOffset {number} channel offset and channel offset + 1 get saved
6
+ * @returns {Blob}
7
+ */
8
+ export function audioBufferToWav(audioBuffer: AudioBuffer, normalizeAudio?: boolean, channelOffset?: number): Blob;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Reads as Big endian
3
+ * @param dataArray {IndexedByteArray}
4
+ * @param bytesAmount {number}
5
+ * @returns {number}
6
+ */
7
+ export function readBytesAsUintBigEndian(dataArray: IndexedByteArray, bytesAmount: number): number;
8
+ /**
9
+ * @param number {number}
10
+ * @param bytesAmount {number}
11
+ * @returns {number[]}
12
+ */
13
+ export function writeBytesAsUintBigEndian(number: number, bytesAmount: number): number[];
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Reads as little endian
3
+ * @param dataArray {IndexedByteArray}
4
+ * @param bytesAmount {number}
5
+ * @returns {number}
6
+ */
7
+ export function readBytesAsUintLittleEndian(dataArray: IndexedByteArray, bytesAmount: number): number;
8
+ /**
9
+ * Writes a number as little endian seems to also work for negative numbers so yay?
10
+ * @param dataArray {IndexedByteArray}
11
+ * @param number {number}
12
+ * @param byteTarget {number}
13
+ */
14
+ export function writeLittleEndian(dataArray: IndexedByteArray, number: number, byteTarget: number): void;
15
+ /**
16
+ * @param dataArray {IndexedByteArray}
17
+ * @param word {number}
18
+ */
19
+ export function writeWord(dataArray: IndexedByteArray, word: number): void;
20
+ /**
21
+ * @param dataArray {IndexedByteArray}
22
+ * @param dword {number}
23
+ */
24
+ export function writeDword(dataArray: IndexedByteArray, dword: number): void;
25
+ /**
26
+ * @param byte1 {number}
27
+ * @param byte2 {number}
28
+ * @returns {number}
29
+ */
30
+ export function signedInt16(byte1: number, byte2: number): number;
31
+ /**
32
+ * @param byte {number}
33
+ * @returns {number}
34
+ */
35
+ export function signedInt8(byte: number): number;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @param dataArray {IndexedByteArray}
3
+ * @param bytes {number}
4
+ * @param encoding {string} the textElement encoding
5
+ * @param trimEnd {boolean} if we should trim once we reach an invalid byte
6
+ * @returns {string}
7
+ */
8
+ export function readBytesAsString(dataArray: IndexedByteArray, bytes: number, encoding?: string, trimEnd?: boolean): string;
9
+ /**
10
+ * @param string {string}
11
+ * @param padLength {number}
12
+ * @returns {IndexedByteArray}
13
+ */
14
+ export function getStringBytes(string: string, padLength?: number): IndexedByteArray;
15
+ /**
16
+ * @param string {string}
17
+ * @param outArray {IndexedByteArray}
18
+ * @param padLength {number}
19
+ * @returns {IndexedByteArray} modified IN PLACE
20
+ */
21
+ export function writeStringAsBytes(outArray: IndexedByteArray, string: string, padLength?: number): IndexedByteArray;
22
+ import { IndexedByteArray } from '../indexed_array.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Reads VLQ From a MIDI byte array
3
+ * @param MIDIbyteArray {IndexedByteArray}
4
+ * @returns {number}
5
+ */
6
+ export function readVariableLengthQuantity(MIDIbyteArray: IndexedByteArray): number;
7
+ /**
8
+ * Write a VLQ from a number to a byte array
9
+ * @param number {number}
10
+ * @returns {number[]}
11
+ */
12
+ export function writeVariableLengthQuantity(number: number): number[];
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @param arrs {(IndexedByteArray|Uint8Array)[]}
3
+ * @returns {IndexedByteArray|Uint8Array}
4
+ */
5
+ export function combineArrays(arrs: (IndexedByteArray | Uint8Array)[]): IndexedByteArray | Uint8Array;
6
+ /**
7
+ * indexed_array.js
8
+ * purpose: exteds Uint8Array with a currentIndex property
9
+ */
10
+ export class IndexedByteArray extends Uint8Array {
11
+ /**
12
+ * Creates a new instance of an Uint8Array with a currentIndex property
13
+ * @param args {any} same as for Uint8Array
14
+ */
15
+ constructor(args: any);
16
+ /**
17
+ * The current index of the array
18
+ * @type {number}
19
+ */
20
+ currentIndex: number;
21
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Enables or disables looging
3
+ * @param enableInfo {boolean} - enables info
4
+ * @param enableWarn {boolean} - enables warning
5
+ * @param enableGroup {boolean} - enables groups
6
+ * @param enableTable {boolean} - enables tables
7
+ */
8
+ export function SpessaSynthLogging(enableInfo: boolean, enableWarn: boolean, enableGroup: boolean, enableTable: boolean): void;
9
+ /**
10
+ * @param message {...any}
11
+ */
12
+ export function SpessaSynthInfo(...message: any[]): void;
13
+ /**
14
+ * @param message {...any}
15
+ */
16
+ export function SpessaSynthWarn(...message: any[]): void;
17
+ export function SpessaSynthTable(...args: any[]): void;
18
+ /**
19
+ * @param message {...any} the message
20
+ */
21
+ export function SpessaSynthGroup(...message: any[]): void;
22
+ /**
23
+ * @param message {...any} the message
24
+ */
25
+ export function SpessaSynthGroupCollapsed(...message: any[]): void;
26
+ export function SpessaSynthGroupEnd(): void;