spessasynth_lib 3.25.23 → 3.26.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 (162) hide show
  1. package/README.md +29 -114
  2. package/external_midi/midi_handler.js +14 -14
  3. package/external_midi/web_midi_link.js +3 -3
  4. package/index.js +33 -33
  5. package/package.json +19 -6
  6. package/{midi → sequencer}/midi_data.js +1 -1
  7. package/sequencer/{worklet_wrapper/sequencer.js → sequencer.js} +13 -12
  8. package/sequencer/{worklet_wrapper/sequencer_message.js → sequencer_message.js} +1 -1
  9. package/synthetizer/README.md +29 -1
  10. package/synthetizer/audio_effects/reverb_as_binary.js +2 -2
  11. package/synthetizer/{worklet_wrapper/key_modifier_manager.js → key_modifier_manager.js} +11 -2
  12. package/synthetizer/{worklet_wrapper/synth_event_handler.js → synth_event_handler.js} +16 -13
  13. package/synthetizer/{worklet_wrapper/synth_soundfont_manager.js → synth_soundfont_manager.js} +8 -5
  14. package/synthetizer/{worklet_wrapper/synthetizer.js → synthetizer.js} +29 -23
  15. package/synthetizer/{audio_engine/message_protocol/worklet_message.js → worklet_message.js} +15 -2
  16. package/synthetizer/{worklet_wrapper/worklet_processor.js → worklet_processor.js} +214 -31
  17. package/synthetizer/worklet_processor.min.js +13 -12
  18. package/synthetizer/worklet_processor.min.js.map +7 -0
  19. package/synthetizer/{worklet_wrapper/worklet_url.js → worklet_url.js} +2 -0
  20. package/utils/buffer_to_wav.js +7 -165
  21. package/utils/other.js +3 -84
  22. package/externals/fflate/LICENSE +0 -21
  23. package/externals/fflate/fflate.min.js +0 -1
  24. package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  25. package/externals/stbvorbis_sync/LICENSE +0 -202
  26. package/externals/stbvorbis_sync/NOTICE +0 -6
  27. package/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  28. package/midi/README.md +0 -32
  29. package/midi/basic_midi.js +0 -565
  30. package/midi/midi_builder.js +0 -202
  31. package/midi/midi_loader.js +0 -324
  32. package/midi/midi_message.js +0 -254
  33. package/midi/midi_sequence.js +0 -225
  34. package/midi/midi_tools/get_note_times.js +0 -154
  35. package/midi/midi_tools/midi_editor.js +0 -611
  36. package/midi/midi_tools/midi_writer.js +0 -99
  37. package/midi/midi_tools/rmidi_writer.js +0 -567
  38. package/midi/midi_tools/used_keys_loaded.js +0 -238
  39. package/midi/xmf_loader.js +0 -454
  40. package/sequencer/sequencer_engine/events.js +0 -104
  41. package/sequencer/sequencer_engine/play.js +0 -353
  42. package/sequencer/sequencer_engine/process_event.js +0 -169
  43. package/sequencer/sequencer_engine/process_tick.js +0 -106
  44. package/sequencer/sequencer_engine/sequencer_engine.js +0 -335
  45. package/sequencer/sequencer_engine/song_control.js +0 -229
  46. package/soundfont/README.md +0 -13
  47. package/soundfont/basic_soundfont/basic_instrument.js +0 -77
  48. package/soundfont/basic_soundfont/basic_preset.js +0 -336
  49. package/soundfont/basic_soundfont/basic_sample.js +0 -197
  50. package/soundfont/basic_soundfont/basic_soundfont.js +0 -565
  51. package/soundfont/basic_soundfont/basic_zone.js +0 -64
  52. package/soundfont/basic_soundfont/basic_zones.js +0 -43
  53. package/soundfont/basic_soundfont/generator.js +0 -220
  54. package/soundfont/basic_soundfont/modulator.js +0 -378
  55. package/soundfont/basic_soundfont/riff_chunk.js +0 -149
  56. package/soundfont/basic_soundfont/write_dls/art2.js +0 -173
  57. package/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  58. package/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -400
  59. package/soundfont/basic_soundfont/write_dls/ins.js +0 -103
  60. package/soundfont/basic_soundfont/write_dls/lins.js +0 -18
  61. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  62. package/soundfont/basic_soundfont/write_dls/rgn2.js +0 -121
  63. package/soundfont/basic_soundfont/write_dls/wave.js +0 -94
  64. package/soundfont/basic_soundfont/write_dls/write_dls.js +0 -119
  65. package/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  66. package/soundfont/basic_soundfont/write_dls/wvpl.js +0 -32
  67. package/soundfont/basic_soundfont/write_sf2/ibag.js +0 -39
  68. package/soundfont/basic_soundfont/write_sf2/igen.js +0 -80
  69. package/soundfont/basic_soundfont/write_sf2/imod.js +0 -46
  70. package/soundfont/basic_soundfont/write_sf2/inst.js +0 -34
  71. package/soundfont/basic_soundfont/write_sf2/pbag.js +0 -39
  72. package/soundfont/basic_soundfont/write_sf2/pgen.js +0 -82
  73. package/soundfont/basic_soundfont/write_sf2/phdr.js +0 -42
  74. package/soundfont/basic_soundfont/write_sf2/pmod.js +0 -46
  75. package/soundfont/basic_soundfont/write_sf2/sdta.js +0 -80
  76. package/soundfont/basic_soundfont/write_sf2/shdr.js +0 -55
  77. package/soundfont/basic_soundfont/write_sf2/write.js +0 -222
  78. package/soundfont/dls/articulator_converter.js +0 -396
  79. package/soundfont/dls/dls_destinations.js +0 -38
  80. package/soundfont/dls/dls_preset.js +0 -44
  81. package/soundfont/dls/dls_sample.js +0 -75
  82. package/soundfont/dls/dls_soundfont.js +0 -186
  83. package/soundfont/dls/dls_sources.js +0 -62
  84. package/soundfont/dls/dls_zone.js +0 -95
  85. package/soundfont/dls/read_articulation.js +0 -299
  86. package/soundfont/dls/read_instrument.js +0 -121
  87. package/soundfont/dls/read_instrument_list.js +0 -17
  88. package/soundfont/dls/read_lart.js +0 -35
  89. package/soundfont/dls/read_region.js +0 -152
  90. package/soundfont/dls/read_samples.js +0 -270
  91. package/soundfont/load_soundfont.js +0 -21
  92. package/soundfont/read_sf2/generators.js +0 -46
  93. package/soundfont/read_sf2/instruments.js +0 -66
  94. package/soundfont/read_sf2/modulators.js +0 -36
  95. package/soundfont/read_sf2/presets.js +0 -80
  96. package/soundfont/read_sf2/samples.js +0 -304
  97. package/soundfont/read_sf2/soundfont.js +0 -305
  98. package/soundfont/read_sf2/zones.js +0 -263
  99. package/synthetizer/audio_engine/README.md +0 -25
  100. package/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -266
  101. package/synthetizer/audio_engine/engine_components/controller_tables.js +0 -88
  102. package/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -149
  103. package/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  104. package/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  105. package/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -471
  106. package/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  107. package/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  108. package/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -228
  109. package/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -120
  110. package/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  111. package/synthetizer/audio_engine/engine_components/voice.js +0 -519
  112. package/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -401
  113. package/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -263
  114. package/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -132
  115. package/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -48
  116. package/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -241
  117. package/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -27
  118. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -253
  119. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -66
  120. package/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  121. package/synthetizer/audio_engine/engine_methods/note_on.js +0 -175
  122. package/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  123. package/synthetizer/audio_engine/engine_methods/program_change.js +0 -61
  124. package/synthetizer/audio_engine/engine_methods/render_voice.js +0 -196
  125. package/synthetizer/audio_engine/engine_methods/soundfont_management/clear_sound_font.js +0 -30
  126. package/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -22
  127. package/synthetizer/audio_engine/engine_methods/soundfont_management/reload_sound_font.js +0 -40
  128. package/synthetizer/audio_engine/engine_methods/soundfont_management/send_preset_list.js +0 -34
  129. package/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js +0 -21
  130. package/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -20
  131. package/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -55
  132. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  133. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  134. package/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  135. package/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -776
  136. package/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -24
  137. package/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -33
  138. package/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -31
  139. package/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  140. package/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -27
  141. package/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  142. package/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  143. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  144. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  145. package/synthetizer/audio_engine/main_processor.js +0 -765
  146. package/synthetizer/audio_engine/message_protocol/README.md +0 -13
  147. package/synthetizer/audio_engine/message_protocol/message_sending.js +0 -22
  148. package/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -14
  149. package/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  150. package/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -122
  151. package/synthetizer/synth_constants.js +0 -20
  152. package/utils/README.md +0 -5
  153. package/utils/byte_functions/big_endian.js +0 -32
  154. package/utils/byte_functions/little_endian.js +0 -77
  155. package/utils/byte_functions/string.js +0 -107
  156. package/utils/byte_functions/variable_length_quantity.js +0 -42
  157. package/utils/indexed_array.js +0 -52
  158. package/utils/loggin.js +0 -79
  159. package/utils/sysex_detector.js +0 -58
  160. package/utils/xg_hacks.js +0 -193
  161. /package/sequencer/{worklet_wrapper/default_sequencer_options.js → default_sequencer_options.js} +0 -0
  162. /package/synthetizer/{worklet_wrapper/sfman_message.js → sfman_message.js} +0 -0
@@ -1,13 +0,0 @@
1
- # About the message protocol
2
- Since spessasynth runs in the audioWorklet thread, here is an explanation of how it works:
3
-
4
- There's one processor per synthesizer, with a `MessagePort` for communication.
5
- Each processor has a single `WorkletSequencer` instance that is idle by default.
6
-
7
- The `Synthetizer`,
8
- `Sequencer` and `SoundFontManager` classes are all interfaces
9
- that do not do anything except sending the commands to te processor.
10
-
11
- The synthesizer sends the commands (note on, off, etc.) directly to the processor where they are processed and executed.
12
-
13
- The sequencer sends the commands through the connected synthesizer's messagePort, which then get processed as sequencer messages and routed
@@ -1,22 +0,0 @@
1
- import { returnMessageType } from "./worklet_message.js";
2
-
3
- /**
4
- * Calls synth event from the worklet side
5
- * @param eventName {EventTypes} the event name
6
- * @param eventData {EventCallbackData}
7
- * @this {SpessaSynthProcessor}
8
- */
9
- export function callEvent(eventName, eventData)
10
- {
11
- if (!this.enableEventSystem)
12
- {
13
- return;
14
- }
15
- this.post({
16
- messageType: returnMessageType.eventCall,
17
- messageData: {
18
- eventName: eventName,
19
- eventData: eventData
20
- }
21
- });
22
- }
@@ -1,14 +0,0 @@
1
- import { SpessaSynthInfo } from "../../../utils/loggin.js";
2
- import { consoleColors } from "../../../utils/other.js";
3
- import { SynthesizerSnapshot } from "./synthesizer_snapshot.js";
4
-
5
- /**
6
- * Applies the snapshot to the synth
7
- * @param snapshot {SynthesizerSnapshot}
8
- * @this {SpessaSynthProcessor}
9
- */
10
- export function applySynthesizerSnapshot(snapshot)
11
- {
12
- SynthesizerSnapshot.applySnapshot(this, snapshot);
13
- SpessaSynthInfo("%cFinished applying snapshot!", consoleColors.info);
14
- }
@@ -1,175 +0,0 @@
1
- /**
2
- * Represents a snapshot of a single channel's state in the synthesizer.
3
- */
4
- export class ChannelSnapshot
5
- {
6
- /**
7
- * The channel's MIDI program number.
8
- * @type {number}
9
- */
10
- program;
11
-
12
- /**
13
- * The channel's bank number.
14
- * @type {number}
15
- */
16
- bank;
17
-
18
- /**
19
- * If the bank is LSB. For restoring.
20
- * @type {boolean}
21
- */
22
- isBankLSB;
23
-
24
- /**
25
- * The name of the patch currently loaded in the channel.
26
- * @type {string}
27
- */
28
- patchName;
29
-
30
- /**
31
- * Indicates whether the channel's program change is disabled.
32
- * @type {boolean}
33
- */
34
- lockPreset;
35
-
36
- /**
37
- * Indicates the MIDI system when the preset was locked
38
- * @type {SynthSystem}
39
- */
40
- lockedSystem;
41
-
42
- /**
43
- * The array of all MIDI controllers (in 14-bit values) with the modulator sources at the end.
44
- * @type {Int16Array}
45
- */
46
- midiControllers;
47
-
48
- /**
49
- * An array of booleans, indicating if the controller with a current index is locked.
50
- * @type {boolean[]}
51
- */
52
- lockedControllers;
53
-
54
- /**
55
- * Array of custom (not SF2) control values such as RPN pitch tuning, transpose, modulation depth, etc.
56
- * @type {Float32Array}
57
- */
58
- customControllers;
59
-
60
- /**
61
- * Indicates whether the channel vibrato is locked.
62
- * @type {boolean}
63
- */
64
- lockVibrato;
65
-
66
- /**
67
- * The channel's vibrato settings.
68
- * @type {Object}
69
- * @property {number} depth - Vibrato depth, in gain.
70
- * @property {number} delay - Vibrato delay from note on in seconds.
71
- * @property {number} rate - Vibrato rate in Hz.
72
- */
73
- channelVibrato;
74
-
75
- /**
76
- * Key shift for the channel.
77
- * @type {number}
78
- */
79
- channelTransposeKeyShift;
80
-
81
- /**
82
- * The channel's octave tuning in cents.
83
- * @type {Int8Array}
84
- */
85
- channelOctaveTuning;
86
-
87
- /**
88
- * Indicates whether the channel is muted.
89
- * @type {boolean}
90
- */
91
- isMuted;
92
-
93
- /**
94
- * Overrides velocity if greater than 0, otherwise disabled.
95
- * @type {number}
96
- */
97
- velocityOverride;
98
-
99
- /**
100
- * Indicates whether the channel is a drum channel.
101
- * @type {boolean}
102
- */
103
- drumChannel;
104
-
105
- /**
106
- * Creates a snapshot of a single channel's state in the synthesizer.
107
- * @param workletProcessor {SpessaSynthProcessor}
108
- * @param channelNumber {number}
109
- * @returns {ChannelSnapshot}
110
- */
111
- static getChannelSnapshot(workletProcessor, channelNumber)
112
- {
113
- const channelObject = workletProcessor.midiAudioChannels[channelNumber];
114
- const channelSnapshot = new ChannelSnapshot();
115
- // program data
116
- channelSnapshot.program = channelObject.preset.program;
117
- channelSnapshot.bank = channelObject.getBankSelect();
118
- channelSnapshot.isBankLSB = channelSnapshot.bank !== channelObject.bank;
119
- channelSnapshot.lockPreset = channelObject.lockPreset;
120
- channelSnapshot.lockedSystem = channelObject.lockedSystem;
121
- channelSnapshot.patchName = channelObject.preset.presetName;
122
-
123
- // controller data
124
- channelSnapshot.midiControllers = channelObject.midiControllers;
125
- channelSnapshot.lockedControllers = channelObject.lockedControllers;
126
- channelSnapshot.customControllers = channelObject.customControllers;
127
-
128
- // vibrato data
129
- channelSnapshot.channelVibrato = channelObject.channelVibrato;
130
- channelSnapshot.lockVibrato = channelObject.lockGSNRPNParams;
131
-
132
- // tuning and transpose data
133
- channelSnapshot.channelTransposeKeyShift = channelObject.channelTransposeKeyShift;
134
- channelSnapshot.channelOctaveTuning = channelObject.channelOctaveTuning;
135
-
136
- // other data
137
- channelSnapshot.isMuted = channelObject.isMuted;
138
- channelSnapshot.velocityOverride = channelObject.velocityOverride;
139
- channelSnapshot.drumChannel = channelObject.drumChannel;
140
- return channelSnapshot;
141
- }
142
-
143
- /**
144
- * Applies the snapshot to the specified channel.
145
- * @param workletProcessor {SpessaSynthProcessor}
146
- * @param channelNumber {number}
147
- * @param channelSnapshot {ChannelSnapshot}
148
- */
149
- static applyChannelSnapshot(workletProcessor, channelNumber, channelSnapshot)
150
- {
151
- const channelObject = workletProcessor.midiAudioChannels[channelNumber];
152
- channelObject.muteChannel(channelSnapshot.isMuted);
153
- channelObject.setDrums(channelSnapshot.drumChannel);
154
-
155
- // restore controllers
156
- channelObject.midiControllers = channelSnapshot.midiControllers;
157
- channelObject.lockedControllers = channelSnapshot.lockedControllers;
158
- channelObject.customControllers = channelSnapshot.customControllers;
159
- channelObject.updateChannelTuning();
160
-
161
- // restore vibrato and transpose
162
- channelObject.channelVibrato = channelSnapshot.channelVibrato;
163
- channelObject.lockGSNRPNParams = channelSnapshot.lockVibrato;
164
- channelObject.channelTransposeKeyShift = channelSnapshot.channelTransposeKeyShift;
165
- channelObject.channelOctaveTuning = channelSnapshot.channelOctaveTuning;
166
- channelObject.velocityOverride = channelSnapshot.velocityOverride;
167
-
168
- // restore preset and lock
169
- channelObject.setPresetLock(false);
170
- channelObject.setBankSelect(channelSnapshot.bank, channelSnapshot.isBankLSB);
171
- channelObject.programChange(channelSnapshot.program);
172
- channelObject.setPresetLock(channelSnapshot.lockPreset);
173
- channelObject.lockedSystem = channelSnapshot.lockedSystem;
174
- }
175
- }
@@ -1,122 +0,0 @@
1
- import { SpessaSynthInfo } from "../../../utils/loggin.js";
2
- import { consoleColors } from "../../../utils/other.js";
3
- import { ChannelSnapshot } from "./channel_snapshot.js";
4
- import { masterParameterType } from "../engine_methods/controller_control/master_parameters.js";
5
-
6
- /**
7
- * Represents a snapshot of the synthesizer's state.
8
- */
9
- export class SynthesizerSnapshot
10
- {
11
- /**
12
- * The individual channel snapshots.
13
- * @type {ChannelSnapshot[]}
14
- */
15
- channelSnapshots;
16
-
17
- /**
18
- * Key modifiers.
19
- * @type {KeyModifier[][]}
20
- */
21
- keyMappings;
22
-
23
- /**
24
- * Main synth volume (set by MIDI), from 0 to 1.
25
- * @type {number}
26
- */
27
- mainVolume;
28
-
29
- /**
30
- * Master stereo panning, from -1 to 1.
31
- * @type {number}
32
- */
33
- pan;
34
-
35
- /**
36
- * The synth's interpolation type.
37
- * @type {interpolationTypes}
38
- */
39
- interpolation;
40
-
41
- /**
42
- * The synth's system. Values can be "gs", "gm", "gm2" or "xg".
43
- * @type {SynthSystem}
44
- */
45
- system;
46
-
47
- /**
48
- * The current synth transposition in semitones. Can be a float.
49
- * @type {number}
50
- */
51
- transposition;
52
-
53
- /**
54
- * The effect configuration object.
55
- * @type {SynthConfig}
56
- */
57
- effectsConfig;
58
-
59
-
60
- /**
61
- * Creates a snapshot of the synthesizer's state.
62
- * @param workletProcessor {SpessaSynthProcessor}
63
- * @returns {SynthesizerSnapshot}
64
- */
65
- static createSynthesizerSnapshot(workletProcessor)
66
- {
67
- const snapshot = new SynthesizerSnapshot();
68
- // channel snapshots
69
- snapshot.channelSnapshots =
70
- workletProcessor.midiAudioChannels.map((_, i) =>
71
- ChannelSnapshot.getChannelSnapshot(workletProcessor, i));
72
-
73
- // key mappings
74
- snapshot.keyMappings = workletProcessor.keyModifierManager.getMappings();
75
- // pan and volume
76
- snapshot.mainVolume = workletProcessor.midiVolume;
77
- snapshot.pan = workletProcessor.pan;
78
-
79
- // others
80
- snapshot.system = workletProcessor.system;
81
- snapshot.interpolation = workletProcessor.interpolationType;
82
- snapshot.transposition = workletProcessor.transposition;
83
-
84
- // effect config is stored on the main thread, leave it empty
85
- snapshot.effectsConfig = {};
86
- return snapshot;
87
-
88
- }
89
-
90
- /**
91
- * Applies the snapshot to the synthesizer.
92
- * @param workletProcessor {SpessaSynthProcessor}
93
- * @param snapshot {SynthesizerSnapshot}
94
- */
95
- static applySnapshot(workletProcessor, snapshot)
96
- {
97
- // restore system
98
- workletProcessor.setSystem(snapshot.system);
99
-
100
- // restore pan and volume
101
- workletProcessor.setMasterParameter(masterParameterType.mainVolume, snapshot.mainVolume);
102
- workletProcessor.setMasterParameter(masterParameterType.masterPan, snapshot.pan);
103
- workletProcessor.transposeAllChannels(snapshot.transposition);
104
- workletProcessor.interpolationType = snapshot.interpolation;
105
- workletProcessor.keyModifierManager.setMappings(snapshot.keyMappings);
106
-
107
- // add channels if more needed
108
- while (workletProcessor.midiAudioChannels.length < snapshot.channelSnapshots.length)
109
- {
110
- workletProcessor.createWorkletChannel();
111
- }
112
-
113
- // restore channels
114
- snapshot.channelSnapshots.forEach((channelSnapshot, index) =>
115
- {
116
- ChannelSnapshot.applyChannelSnapshot(workletProcessor, index, channelSnapshot);
117
- });
118
-
119
- SpessaSynthInfo("%cFinished restoring controllers!", consoleColors.info);
120
- }
121
- }
122
-
@@ -1,20 +0,0 @@
1
- /**
2
- * Synthesizer's default voice cap
3
- * @type {number}
4
- */
5
- export const VOICE_CAP = 350;
6
- /**
7
- * Default MIDI drum channel
8
- * @type {number}
9
- */
10
- export const DEFAULT_PERCUSSION = 9;
11
- /**
12
- * MIDI channel count
13
- * @type {number}
14
- */
15
- export const MIDI_CHANNEL_COUNT = 16;
16
- /**
17
- * Default bank select and SysEx mode
18
- * @type {string}
19
- */
20
- export const DEFAULT_SYNTH_MODE = "gs";
package/utils/README.md DELETED
@@ -1,5 +0,0 @@
1
- ## This is the utility folder.
2
-
3
- There are various utilites here used by the SpessaSynth library.
4
-
5
- ### Note that the stbvorbis_sync.js is licensed under Apache-2.0.
@@ -1,32 +0,0 @@
1
- /**
2
- * Reads as Big endian
3
- * @param dataArray {IndexedByteArray}
4
- * @param bytesAmount {number}
5
- * @returns {number}
6
- */
7
- export function readBytesAsUintBigEndian(dataArray, bytesAmount)
8
- {
9
- let out = 0;
10
- for (let i = 8 * (bytesAmount - 1); i >= 0; i -= 8)
11
- {
12
- out |= (dataArray[dataArray.currentIndex++] << i);
13
- }
14
- return out >>> 0;
15
- }
16
-
17
- /**
18
- * @param number {number}
19
- * @param bytesAmount {number}
20
- * @returns {number[]}
21
- */
22
- export function writeBytesAsUintBigEndian(number, bytesAmount)
23
- {
24
- const bytes = new Array(bytesAmount).fill(0);
25
- for (let i = bytesAmount - 1; i >= 0; i--)
26
- {
27
- bytes[i] = number & 0xFF;
28
- number >>= 8;
29
- }
30
-
31
- return bytes;
32
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * Reads as little endian
3
- * @param dataArray {IndexedByteArray}
4
- * @param bytesAmount {number}
5
- * @returns {number}
6
- */
7
- export function readLittleEndian(dataArray, bytesAmount)
8
- {
9
- let out = 0;
10
- for (let i = 0; i < bytesAmount; i++)
11
- {
12
- out |= (dataArray[dataArray.currentIndex++] << i * 8);
13
- }
14
- // make sure it stays unsigned
15
- return out >>> 0;
16
- }
17
-
18
- /**
19
- * Writes a number as little endian seems to also work for negative numbers so yay?
20
- * @param dataArray {IndexedByteArray}
21
- * @param number {number}
22
- * @param byteTarget {number}
23
- */
24
- export function writeLittleEndian(dataArray, number, byteTarget)
25
- {
26
- for (let i = 0; i < byteTarget; i++)
27
- {
28
- dataArray[dataArray.currentIndex++] = (number >> (i * 8)) & 0xFF;
29
- }
30
- }
31
-
32
- /**
33
- * @param dataArray {IndexedByteArray}
34
- * @param word {number}
35
- */
36
- export function writeWord(dataArray, word)
37
- {
38
- dataArray[dataArray.currentIndex++] = word & 0xFF;
39
- dataArray[dataArray.currentIndex++] = word >> 8;
40
- }
41
-
42
- /**
43
- * @param dataArray {IndexedByteArray}
44
- * @param dword {number}
45
- */
46
- export function writeDword(dataArray, dword)
47
- {
48
- writeLittleEndian(dataArray, dword, 4);
49
- }
50
-
51
- /**
52
- * @param byte1 {number}
53
- * @param byte2 {number}
54
- * @returns {number}
55
- */
56
- export function signedInt16(byte1, byte2)
57
- {
58
- let val = (byte2 << 8) | byte1;
59
- if (val > 32767)
60
- {
61
- return val - 65536;
62
- }
63
- return val;
64
- }
65
-
66
- /**
67
- * @param byte {number}
68
- * @returns {number}
69
- */
70
- export function signedInt8(byte)
71
- {
72
- if (byte > 127)
73
- {
74
- return byte - 256;
75
- }
76
- return byte;
77
- }
@@ -1,107 +0,0 @@
1
- import { IndexedByteArray } from "../indexed_array.js";
2
-
3
- /**
4
- * @param dataArray {IndexedByteArray}
5
- * @param bytes {number}
6
- * @param encoding {string} the textElement encoding
7
- * @param trimEnd {boolean} if we should trim once we reach an invalid byte
8
- * @returns {string}
9
- */
10
- export function readBytesAsString(dataArray, bytes, encoding = undefined, trimEnd = true)
11
- {
12
- if (!encoding)
13
- {
14
- let finished = false;
15
- let string = "";
16
- for (let i = 0; i < bytes; i++)
17
- {
18
- let byte = dataArray[dataArray.currentIndex++];
19
- if (finished)
20
- {
21
- continue;
22
- }
23
- if ((byte < 32 || byte > 127) && byte !== 10) // 10 is "\n"
24
- {
25
- if (trimEnd)
26
- {
27
- finished = true;
28
- continue;
29
- }
30
- else
31
- {
32
- if (byte === 0)
33
- {
34
- finished = true;
35
- continue;
36
- }
37
- }
38
- }
39
- string += String.fromCharCode(byte);
40
- }
41
- return string;
42
- }
43
- else
44
- {
45
- let byteBuffer = dataArray.slice(dataArray.currentIndex, dataArray.currentIndex + bytes);
46
- dataArray.currentIndex += bytes;
47
- let decoder = new TextDecoder(encoding.replace(/[^\x20-\x7E]/g, ""));
48
- return decoder.decode(byteBuffer.buffer);
49
- }
50
- }
51
-
52
- /**
53
- * @param string {string}
54
- * @param padLength {number}
55
- * @returns {IndexedByteArray}
56
- */
57
- export function getStringBytes(string, padLength = 0)
58
- {
59
- let len = string.length;
60
- if (padLength > 0)
61
- {
62
- len = padLength;
63
- }
64
- const arr = new IndexedByteArray(len);
65
- writeStringAsBytes(arr, string, padLength);
66
- return arr;
67
- }
68
-
69
- /**
70
- * @param string {string}
71
- * @returns {IndexedByteArray}
72
- */
73
- export function getStringBytesZero(string)
74
- {
75
- return getStringBytes(string, string.length + 1);
76
- }
77
-
78
- /**
79
- * @param string {string}
80
- * @param outArray {IndexedByteArray}
81
- * @param padLength {number}
82
- * @returns {IndexedByteArray} modified IN PLACE
83
- */
84
- export function writeStringAsBytes(outArray, string, padLength = 0)
85
- {
86
- if (padLength > 0)
87
- {
88
- if (string.length > padLength)
89
- {
90
- string = string.slice(0, padLength);
91
- }
92
- }
93
- for (let i = 0; i < string.length; i++)
94
- {
95
- outArray[outArray.currentIndex++] = string.charCodeAt(i);
96
- }
97
-
98
- // pad with zeros if needed
99
- if (padLength > string.length)
100
- {
101
- for (let i = 0; i < padLength - string.length; i++)
102
- {
103
- outArray[outArray.currentIndex++] = 0;
104
- }
105
- }
106
- return outArray;
107
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Reads VLQ From a MIDI byte array
3
- * @param MIDIbyteArray {IndexedByteArray}
4
- * @returns {number}
5
- */
6
- export function readVariableLengthQuantity(MIDIbyteArray)
7
- {
8
- let out = 0;
9
- while (MIDIbyteArray)
10
- {
11
- const byte = MIDIbyteArray[MIDIbyteArray.currentIndex++];
12
- // extract the first 7 bytes
13
- out = (out << 7) | (byte & 127);
14
-
15
- // if the last byte isn't 1, stop reading
16
- if ((byte >> 7) !== 1)
17
- {
18
- break;
19
- }
20
- }
21
- return out;
22
- }
23
-
24
- /**
25
- * Write a VLQ from a number to a byte array
26
- * @param number {number}
27
- * @returns {number[]}
28
- */
29
- export function writeVariableLengthQuantity(number)
30
- {
31
- // Add the first byte
32
- let bytes = [number & 127];
33
- number >>= 7;
34
-
35
- // Continue processing the remaining bytes
36
- while (number > 0)
37
- {
38
- bytes.unshift((number & 127) | 128);
39
- number >>= 7;
40
- }
41
- return bytes;
42
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * indexed_array.js
3
- * purpose: exteds Uint8Array with a currentIndex property
4
- */
5
-
6
- export class IndexedByteArray extends Uint8Array
7
- {
8
- /**
9
- * The current index of the array
10
- * @type {number}
11
- */
12
- currentIndex = 0;
13
-
14
- /**
15
- * Creates a new instance of an Uint8Array with a currentIndex property
16
- * @param args {any} same as for Uint8Array
17
- */
18
- constructor(args)
19
- {
20
- super(args);
21
- }
22
-
23
- /**
24
- * @param start {number?}
25
- * @param end {number?}
26
- * @returns {IndexedByteArray}
27
- */
28
- slice(start, end)
29
- {
30
- const a = super.slice(start, end);
31
- a.currentIndex = 0;
32
- return a;
33
- }
34
- }
35
-
36
-
37
- /**
38
- * @param arrs {(IndexedByteArray|Uint8Array)[]}
39
- * @returns {IndexedByteArray|Uint8Array}
40
- */
41
- export function combineArrays(arrs)
42
- {
43
- const length = arrs.reduce((sum, current) => sum + current.length, 0);
44
- const newArr = new IndexedByteArray(length);
45
- let offset = 0;
46
- for (const arr of arrs)
47
- {
48
- newArr.set(arr, offset);
49
- offset += arr.length;
50
- }
51
- return newArr;
52
- }