spessasynth_core 3.27.8 → 4.0.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 (157) hide show
  1. package/README.md +85 -51
  2. package/dist/index.d.ts +4057 -0
  3. package/dist/index.js +17188 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +23 -6
  6. package/index.js +0 -132
  7. package/src/externals/README.md +0 -6
  8. package/src/externals/fflate/LICENSE +0 -21
  9. package/src/externals/fflate/fflate.min.js +0 -1
  10. package/src/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  11. package/src/externals/stbvorbis_sync/LICENSE +0 -202
  12. package/src/externals/stbvorbis_sync/NOTICE +0 -6
  13. package/src/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  14. package/src/midi/README.md +0 -32
  15. package/src/midi/basic_midi.js +0 -587
  16. package/src/midi/midi_builder.js +0 -203
  17. package/src/midi/midi_loader.js +0 -321
  18. package/src/midi/midi_message.js +0 -254
  19. package/src/midi/midi_sequence.js +0 -230
  20. package/src/midi/midi_tools/get_note_times.js +0 -154
  21. package/src/midi/midi_tools/midi_editor.js +0 -611
  22. package/src/midi/midi_tools/midi_writer.js +0 -105
  23. package/src/midi/midi_tools/rmidi_writer.js +0 -566
  24. package/src/midi/midi_tools/used_keys_loaded.js +0 -256
  25. package/src/midi/xmf_loader.js +0 -454
  26. package/src/sequencer/README.md +0 -9
  27. package/src/sequencer/events.js +0 -81
  28. package/src/sequencer/play.js +0 -362
  29. package/src/sequencer/process_event.js +0 -165
  30. package/src/sequencer/process_tick.js +0 -104
  31. package/src/sequencer/sequencer_engine.js +0 -372
  32. package/src/sequencer/song_control.js +0 -196
  33. package/src/soundfont/README.md +0 -11
  34. package/src/soundfont/basic_soundfont/basic_global_zone.js +0 -6
  35. package/src/soundfont/basic_soundfont/basic_instrument.js +0 -115
  36. package/src/soundfont/basic_soundfont/basic_instrument_zone.js +0 -45
  37. package/src/soundfont/basic_soundfont/basic_preset.js +0 -313
  38. package/src/soundfont/basic_soundfont/basic_preset_zone.js +0 -39
  39. package/src/soundfont/basic_soundfont/basic_sample.js +0 -477
  40. package/src/soundfont/basic_soundfont/basic_soundbank.js +0 -740
  41. package/src/soundfont/basic_soundfont/basic_zone.js +0 -145
  42. package/src/soundfont/basic_soundfont/generator.js +0 -76
  43. package/src/soundfont/basic_soundfont/generator_types.js +0 -151
  44. package/src/soundfont/basic_soundfont/modulator.js +0 -581
  45. package/src/soundfont/basic_soundfont/riff_chunk.js +0 -195
  46. package/src/soundfont/basic_soundfont/write_dls/art2.js +0 -174
  47. package/src/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  48. package/src/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -374
  49. package/src/soundfont/basic_soundfont/write_dls/ins.js +0 -85
  50. package/src/soundfont/basic_soundfont/write_dls/lins.js +0 -15
  51. package/src/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  52. package/src/soundfont/basic_soundfont/write_dls/rgn2.js +0 -120
  53. package/src/soundfont/basic_soundfont/write_dls/wave.js +0 -71
  54. package/src/soundfont/basic_soundfont/write_dls/write_dls.js +0 -124
  55. package/src/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  56. package/src/soundfont/basic_soundfont/write_dls/wvpl.js +0 -35
  57. package/src/soundfont/basic_soundfont/write_sf2/ibag.js +0 -60
  58. package/src/soundfont/basic_soundfont/write_sf2/igen.js +0 -91
  59. package/src/soundfont/basic_soundfont/write_sf2/imod.js +0 -62
  60. package/src/soundfont/basic_soundfont/write_sf2/inst.js +0 -42
  61. package/src/soundfont/basic_soundfont/write_sf2/pbag.js +0 -57
  62. package/src/soundfont/basic_soundfont/write_sf2/pgen.js +0 -92
  63. package/src/soundfont/basic_soundfont/write_sf2/phdr.js +0 -61
  64. package/src/soundfont/basic_soundfont/write_sf2/pmod.js +0 -62
  65. package/src/soundfont/basic_soundfont/write_sf2/sdta.js +0 -131
  66. package/src/soundfont/basic_soundfont/write_sf2/shdr.js +0 -77
  67. package/src/soundfont/basic_soundfont/write_sf2/write.js +0 -287
  68. package/src/soundfont/dls/articulator_converter.js +0 -402
  69. package/src/soundfont/dls/dls_destinations.js +0 -38
  70. package/src/soundfont/dls/dls_instrument.js +0 -20
  71. package/src/soundfont/dls/dls_preset.js +0 -43
  72. package/src/soundfont/dls/dls_sample.js +0 -238
  73. package/src/soundfont/dls/dls_soundfont.js +0 -183
  74. package/src/soundfont/dls/dls_sources.js +0 -63
  75. package/src/soundfont/dls/dls_zone.js +0 -89
  76. package/src/soundfont/dls/read_articulation.js +0 -300
  77. package/src/soundfont/dls/read_instrument.js +0 -118
  78. package/src/soundfont/dls/read_instrument_list.js +0 -17
  79. package/src/soundfont/dls/read_lart.js +0 -35
  80. package/src/soundfont/dls/read_region.js +0 -157
  81. package/src/soundfont/dls/read_samples.js +0 -154
  82. package/src/soundfont/load_soundfont.js +0 -21
  83. package/src/soundfont/read_sf2/generators.js +0 -43
  84. package/src/soundfont/read_sf2/instrument_zones.js +0 -75
  85. package/src/soundfont/read_sf2/instruments.js +0 -71
  86. package/src/soundfont/read_sf2/modulators.js +0 -25
  87. package/src/soundfont/read_sf2/preset_zones.js +0 -79
  88. package/src/soundfont/read_sf2/presets.js +0 -80
  89. package/src/soundfont/read_sf2/samples.js +0 -317
  90. package/src/soundfont/read_sf2/soundfont.js +0 -452
  91. package/src/soundfont/read_sf2/zones.js +0 -28
  92. package/src/synthetizer/README.md +0 -7
  93. package/src/synthetizer/audio_engine/README.md +0 -9
  94. package/src/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -289
  95. package/src/synthetizer/audio_engine/engine_components/controller_tables.js +0 -90
  96. package/src/synthetizer/audio_engine/engine_components/dynamic_modulator_system.js +0 -95
  97. package/src/synthetizer/audio_engine/engine_components/enums.js +0 -18
  98. package/src/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -151
  99. package/src/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  100. package/src/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  101. package/src/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -551
  102. package/src/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  103. package/src/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  104. package/src/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -265
  105. package/src/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -124
  106. package/src/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  107. package/src/synthetizer/audio_engine/engine_components/voice.js +0 -525
  108. package/src/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -402
  109. package/src/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -274
  110. package/src/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -159
  111. package/src/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -53
  112. package/src/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -254
  113. package/src/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -20
  114. package/src/synthetizer/audio_engine/engine_methods/data_entry/awe32.js +0 -198
  115. package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -281
  116. package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -109
  117. package/src/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  118. package/src/synthetizer/audio_engine/engine_methods/note_on.js +0 -220
  119. package/src/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  120. package/src/synthetizer/audio_engine/engine_methods/program_change.js +0 -35
  121. package/src/synthetizer/audio_engine/engine_methods/render_voice.js +0 -214
  122. package/src/synthetizer/audio_engine/engine_methods/soundfont_management/embedded_sound_bank.js +0 -42
  123. package/src/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -0
  124. package/src/synthetizer/audio_engine/engine_methods/soundfont_management/update_preset_list.js +0 -19
  125. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -23
  126. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -56
  127. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  128. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  129. package/src/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  130. package/src/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -1058
  131. package/src/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -23
  132. package/src/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -31
  133. package/src/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -29
  134. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  135. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -26
  136. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  137. package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  138. package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  139. package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  140. package/src/synthetizer/audio_engine/main_processor.js +0 -817
  141. package/src/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -16
  142. package/src/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  143. package/src/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -116
  144. package/src/synthetizer/audio_engine/synth_processor_options.js +0 -18
  145. package/src/synthetizer/synth_constants.js +0 -26
  146. package/src/utils/README.md +0 -8
  147. package/src/utils/buffer_to_wav.js +0 -197
  148. package/src/utils/byte_functions/big_endian.js +0 -32
  149. package/src/utils/byte_functions/little_endian.js +0 -77
  150. package/src/utils/byte_functions/string.js +0 -92
  151. package/src/utils/byte_functions/variable_length_quantity.js +0 -42
  152. package/src/utils/fill_with_defaults.js +0 -21
  153. package/src/utils/indexed_array.js +0 -34
  154. package/src/utils/loggin.js +0 -71
  155. package/src/utils/other.js +0 -92
  156. package/src/utils/sysex_detector.js +0 -58
  157. package/src/utils/xg_hacks.js +0 -193
@@ -1,551 +0,0 @@
1
- import {
2
- CONTROLLER_TABLE_SIZE,
3
- CUSTOM_CONTROLLER_TABLE_SIZE,
4
- customControllers,
5
- dataEntryStates,
6
- NON_CC_INDEX_OFFSET
7
- } from "./controller_tables.js";
8
- import {
9
- resetControllers,
10
- resetControllersRP15Compliant,
11
- resetParameters
12
- } from "../engine_methods/controller_control/reset_controllers.js";
13
- import { renderVoice } from "../engine_methods/render_voice.js";
14
- import { panAndMixVoice } from "./stereo_panner.js";
15
- import { killNote } from "../engine_methods/stopping_notes/kill_note.js";
16
- import { setTuning } from "../engine_methods/tuning_control/set_tuning.js";
17
- import { setModulationDepth } from "../engine_methods/tuning_control/set_modulation_depth.js";
18
- import { dataEntryFine } from "../engine_methods/data_entry/data_entry_fine.js";
19
- import { controllerChange } from "../engine_methods/controller_control/controller_change.js";
20
- import { stopAllNotes } from "../engine_methods/stopping_notes/stop_all_notes.js";
21
- import { muteChannel } from "../engine_methods/mute_channel.js";
22
- import { transposeChannel } from "../engine_methods/tuning_control/transpose_channel.js";
23
- import { dataEntryCoarse } from "../engine_methods/data_entry/data_entry_coarse.js";
24
- import { noteOn } from "../engine_methods/note_on.js";
25
- import { noteOff } from "../engine_methods/stopping_notes/note_off.js";
26
- import { polyPressure } from "../engine_methods/tuning_control/poly_pressure.js";
27
- import { channelPressure } from "../engine_methods/tuning_control/channel_pressure.js";
28
- import { pitchWheel } from "../engine_methods/tuning_control/pitch_wheel.js";
29
- import { setOctaveTuning } from "../engine_methods/tuning_control/set_octave_tuning.js";
30
- import { programChange } from "../engine_methods/program_change.js";
31
- import { chooseBank, isSystemXG, parseBankSelect } from "../../../utils/xg_hacks.js";
32
- import { DEFAULT_PERCUSSION, GENERATOR_OVERRIDE_NO_CHANGE_VALUE } from "../../synth_constants.js";
33
- import { modulatorSources } from "../../../soundfont/basic_soundfont/modulator.js";
34
- import { DynamicModulatorSystem } from "./dynamic_modulator_system.js";
35
- import { computeModulators } from "./compute_modulator.js";
36
- import { generatorLimits, GENERATORS_AMOUNT } from "../../../soundfont/basic_soundfont/generator_types.js";
37
-
38
- /**
39
- * This class represents a single MIDI Channel within the synthesizer.
40
- */
41
- class MidiAudioChannel
42
- {
43
- /**
44
- * An array of MIDI controller values and values used by modulators as the source (e.g., pitch bend, bend range, etc.).
45
- * These are stored as 14-bit values.
46
- * Refer to controller_tables.js for the index definitions.
47
- * @type {Int16Array}
48
- */
49
- midiControllers = new Int16Array(CONTROLLER_TABLE_SIZE);
50
-
51
- /**
52
- * An array indicating if a controller, at the equivalent index in the midiControllers array, is locked
53
- * (i.e., not allowed changing).
54
- * A locked controller cannot be modified.
55
- * @type {boolean[]}
56
- */
57
- lockedControllers = Array(CONTROLLER_TABLE_SIZE).fill(false);
58
-
59
- /**
60
- * An array of custom (non-SF2) control values such as RPN pitch tuning, transpose, modulation depth, etc.
61
- * Refer to controller_tables.js for the index definitions.
62
- * @type {Float32Array}
63
- */
64
- customControllers = new Float32Array(CUSTOM_CONTROLLER_TABLE_SIZE);
65
-
66
- /**
67
- * The key shift of the channel (in semitones).
68
- * @type {number}
69
- */
70
- channelTransposeKeyShift = 0;
71
-
72
- /**
73
- * An array of octave tuning values for each note on the channel.
74
- * Each index corresponds to a note (0 = C, 1 = C#, ..., 11 = B).
75
- * Note: Repeaded every 12 notes
76
- * @type {Int8Array}
77
- */
78
- channelOctaveTuning = new Int8Array(128);
79
-
80
- /**
81
- * Will be updated every time something tuning-related gets changed.
82
- * This is used to avoid a big addition for every voice rendering call.
83
- * @type {number}
84
- */
85
- channelTuningCents = 0;
86
-
87
- /**
88
- * A system for dynamic modulator assignment for advanced system exclusives.
89
- * @type {DynamicModulatorSystem}
90
- */
91
- sysExModulators = new DynamicModulatorSystem();
92
-
93
- /**
94
- * An array of offsets generators for SF2 nrpn support.
95
- * A value of 0 means no change; -10 means 10 lower, etc.
96
- * @type {Int16Array}
97
- */
98
- generatorOffsets = new Int16Array(GENERATORS_AMOUNT);
99
-
100
- /**
101
- * A small optimization that disables applying offsets until at least one is set.
102
- * @type {boolean}
103
- */
104
- generatorOffsetsEnabled = false;
105
-
106
- /**
107
- * An array of override generators for AWE32 support.
108
- * A value of 32,767 means unchanged, as it is not allowed anywhere.
109
- * @type {Int16Array}
110
- */
111
- generatorOverrides = new Int16Array(GENERATORS_AMOUNT);
112
-
113
- /**
114
- * A small optimization that disables applying overrides until at least one is set.
115
- * @type {boolean}
116
- */
117
- generatorOverridesEnabled = false;
118
-
119
- /**
120
- * Indicates whether the sustain (hold) pedal is active.
121
- * @type {boolean}
122
- */
123
- holdPedal = false;
124
-
125
- /**
126
- * Indicates whether this channel is a drum channel.
127
- * @type {boolean}
128
- */
129
- drumChannel = false;
130
-
131
- /**
132
- * If greater than 0, overrides the velocity value for the channel, otherwise it's disabled.
133
- * @type {number}
134
- */
135
- velocityOverride = 0;
136
-
137
- /**
138
- * Enables random panning for every note played on this channel.
139
- * @type {boolean}
140
- */
141
- randomPan = false;
142
-
143
- /**
144
- * The current state of the data entry for the channel.
145
- * @type {dataEntryStates}
146
- */
147
- dataEntryState = dataEntryStates.Idle;
148
-
149
- /**
150
- * The bank number of the channel (used for patch changes).
151
- * @type {number}
152
- */
153
- bank = 0;
154
-
155
- /**
156
- * The bank number sent as channel properties.
157
- * @type {number}
158
- */
159
- sentBank = 0;
160
-
161
- /**
162
- * The bank LSB number of the channel (used for patch changes in XG mode).
163
- * @type {number}
164
- */
165
- bankLSB = 0;
166
-
167
- /**
168
- * The preset currently assigned to the channel.
169
- * @type {?BasicPreset}
170
- */
171
- preset = undefined;
172
-
173
- /**
174
- * Indicates whether the program on this channel is locked.
175
- * @type {boolean}
176
- */
177
- lockPreset = false;
178
-
179
- /**
180
- * Indicates the MIDI system when the preset was locked.
181
- * @type {SynthSystem}
182
- */
183
- lockedSystem = "gs";
184
-
185
- /**
186
- * Indicates whether the GS NRPN parameters are enabled for this channel.
187
- * @type {boolean}
188
- */
189
- lockGSNRPNParams = false;
190
-
191
- /**
192
- * The vibrato settings for the channel.
193
- * @type {Object}
194
- * @property {number} depth - Depth of the vibrato effect in cents.
195
- * @property {number} delay - Delay before the vibrato effect starts (in seconds).
196
- * @property {number} rate - Rate of the vibrato oscillation (in Hz).
197
- */
198
- channelVibrato = { delay: 0, depth: 0, rate: 0 };
199
-
200
- /**
201
- * Indicates whether the channel is muted.
202
- * @type {boolean}
203
- */
204
- isMuted = false;
205
-
206
- /**
207
- * An array of voices currently active on the channel.
208
- * @type {Voice[]}
209
- */
210
- voices = [];
211
-
212
- /**
213
- * An array of voices that are sustained on the channel.
214
- * @type {Voice[]}
215
- */
216
- sustainedVoices = [];
217
-
218
- /**
219
- * The channel's number (0-based index)
220
- * @type {number}
221
- */
222
- channelNumber;
223
-
224
- /**
225
- * Parent processor instance.
226
- * @type {SpessaSynthProcessor}
227
- */
228
- synth;
229
-
230
- /**
231
- * Constructs a new MIDI channel
232
- * @param synth {SpessaSynthProcessor}
233
- * @param preset {BasicPreset}
234
- * @param channelNumber {number}
235
- */
236
- constructor(synth, preset, channelNumber)
237
- {
238
- this.synth = synth;
239
- this.preset = preset;
240
- this.channelNumber = channelNumber;
241
- this.resetGeneratorOverrides();
242
- this.resetGeneratorOffsets();
243
- }
244
-
245
- get isXGChannel()
246
- {
247
- return isSystemXG(this.synth.system) || (this.lockPreset && isSystemXG(this.lockedSystem));
248
- }
249
-
250
- /**
251
- * @param type {customControllers|number}
252
- * @param value {number}
253
- */
254
- setCustomController(type, value)
255
- {
256
- this.customControllers[type] = value;
257
- this.updateChannelTuning();
258
- }
259
-
260
- updateChannelTuning()
261
- {
262
- this.channelTuningCents =
263
- this.customControllers[customControllers.channelTuning] // RPN channel fine tuning
264
- + this.customControllers[customControllers.channelTransposeFine] // user tuning (transpose)
265
- + this.customControllers[customControllers.masterTuning] // master tuning, set by sysEx
266
- + (this.customControllers[customControllers.channelTuningSemitones] * 100); // RPN channel coarse tuning
267
- }
268
-
269
- /**
270
- * @param outputLeft {Float32Array} the left output buffer
271
- * @param outputRight {Float32Array} the right output buffer
272
- * @param reverbOutputLeft {Float32Array} left output for reverb
273
- * @param reverbOutputRight {Float32Array} right output for reverb
274
- * @param chorusOutputLeft {Float32Array} left output for chorus
275
- * @param chorusOutputRight {Float32Array} right output for chorus
276
- * @param startIndex {number}
277
- * @param sampleCount {number}
278
- */
279
- renderAudio(
280
- outputLeft, outputRight,
281
- reverbOutputLeft, reverbOutputRight,
282
- chorusOutputLeft, chorusOutputRight,
283
- startIndex, sampleCount
284
- )
285
- {
286
- this.voices = this.voices.filter(v => !this.renderVoice(
287
- v, this.synth.currentSynthTime,
288
- outputLeft, outputRight,
289
- reverbOutputLeft, reverbOutputRight,
290
- chorusOutputLeft, chorusOutputRight,
291
- startIndex, sampleCount
292
- ));
293
- }
294
-
295
- /**
296
- * @param locked {boolean}
297
- */
298
- setPresetLock(locked)
299
- {
300
- this.lockPreset = locked;
301
- if (locked)
302
- {
303
- this.lockedSystem = this.synth.system;
304
- }
305
- }
306
-
307
- /**
308
- * @param bank {number}
309
- * @param isLSB {boolean}
310
- */
311
- setBankSelect(bank, isLSB = false)
312
- {
313
- if (this.lockPreset)
314
- {
315
- return;
316
- }
317
- if (isLSB)
318
- {
319
- this.bankLSB = bank;
320
- }
321
- else
322
- {
323
- this.bank = bank;
324
- const bankLogic = parseBankSelect(
325
- this.getBankSelect(),
326
- bank,
327
- this.synth.system,
328
- false,
329
- this.drumChannel,
330
- this.channelNumber
331
- );
332
- switch (bankLogic.drumsStatus)
333
- {
334
- default:
335
- case 0:
336
- break;
337
-
338
- case 1:
339
- if (this.channelNumber % 16 === DEFAULT_PERCUSSION)
340
- {
341
- // cannot disable drums on channel 9
342
- this.bank = 127;
343
- }
344
- break;
345
-
346
- case 2:
347
- this.setDrums(true);
348
- break;
349
- }
350
- }
351
- }
352
-
353
- /**
354
- * @returns {number}
355
- */
356
- getBankSelect()
357
- {
358
- return chooseBank(this.bank, this.bankLSB, this.drumChannel, this.isXGChannel);
359
- }
360
-
361
- /**
362
- * Changes a preset of this channel
363
- * @param preset {BasicPreset}
364
- */
365
- setPreset(preset)
366
- {
367
- if (this.lockPreset)
368
- {
369
- return;
370
- }
371
- this.preset = preset;
372
- }
373
-
374
- /**
375
- * Sets drums on channel.
376
- * @param isDrum {boolean}
377
- */
378
- setDrums(isDrum)
379
- {
380
- if (this.lockPreset)
381
- {
382
- return;
383
- }
384
- if (this.drumChannel === isDrum)
385
- {
386
- return;
387
- }
388
- if (isDrum)
389
- {
390
- // clear transpose
391
- this.channelTransposeKeyShift = 0;
392
- this.drumChannel = true;
393
- }
394
- else
395
- {
396
- this.drumChannel = false;
397
- }
398
- this.synth.callEvent("drumchange", {
399
- channel: this.channelNumber,
400
- isDrumChannel: this.drumChannel
401
- });
402
- this.programChange(this.preset.program);
403
- this.sendChannelProperty();
404
- }
405
-
406
- // noinspection JSUnusedGlobalSymbols
407
- /**
408
- * Sets a custom vibrato
409
- * @param depth {number} cents
410
- * @param rate {number} Hz
411
- * @param delay {number} seconds
412
- */
413
- setVibrato(depth, rate, delay)
414
- {
415
- if (this.lockGSNRPNParams)
416
- {
417
- return;
418
- }
419
- this.channelVibrato.rate = rate;
420
- this.channelVibrato.delay = delay;
421
- this.channelVibrato.depth = depth;
422
- }
423
-
424
- // noinspection JSUnusedGlobalSymbols
425
- /**
426
- * Yes
427
- */
428
- disableAndLockGSNRPN()
429
- {
430
- this.lockGSNRPNParams = true;
431
- this.channelVibrato.rate = 0;
432
- this.channelVibrato.delay = 0;
433
- this.channelVibrato.depth = 0;
434
- }
435
-
436
-
437
- /**
438
- * @typedef {Object} ChannelProperty
439
- * @property {number} voicesAmount - the channel's current voice amount
440
- * @property {number} pitchBend - the channel's current pitch bend from -8192 do 8192
441
- * @property {number} pitchBendRangeSemitones - the pitch bend's range, in semitones
442
- * @property {boolean} isMuted - indicates whether the channel is muted
443
- * @property {boolean} isDrum - indicates whether the channel is a drum channel
444
- * @property {number} transposition - the channel's transposition, in semitones
445
- * @property {number} bank - the bank number of the current preset
446
- * @property {number} program - the MIDI program number of the current preset
447
- */
448
-
449
-
450
- /**
451
- * Sends this channel's property
452
- */
453
- sendChannelProperty()
454
- {
455
- if (!this.synth.enableEventSystem)
456
- {
457
- return;
458
- }
459
- /**
460
- * @type {ChannelProperty}
461
- */
462
- const data = {
463
- voicesAmount: this.voices.length,
464
- pitchBend: this.midiControllers[NON_CC_INDEX_OFFSET + modulatorSources.pitchWheel],
465
- pitchBendRangeSemitones: this.midiControllers[NON_CC_INDEX_OFFSET + modulatorSources.pitchWheelRange] / 128,
466
- isMuted: this.isMuted,
467
- isDrum: this.drumChannel,
468
- transposition: this.channelTransposeKeyShift + this.customControllers[customControllers.channelTransposeFine] / 100,
469
- bank: this.sentBank,
470
- program: this.preset?.program
471
- };
472
- this.synth?.onChannelPropertyChange?.(data, this.channelNumber);
473
- }
474
-
475
- resetGeneratorOverrides()
476
- {
477
- this.generatorOverrides.fill(GENERATOR_OVERRIDE_NO_CHANGE_VALUE);
478
- this.generatorOverridesEnabled = false;
479
- }
480
-
481
- /**
482
- * @param gen {generatorTypes}
483
- * @param value {number}
484
- * @param realtime {boolean}
485
- */
486
- setGeneratorOverride(gen, value, realtime = false)
487
- {
488
- this.generatorOverrides[gen] = value;
489
- this.generatorOverridesEnabled = true;
490
- if (realtime)
491
- {
492
- this.voices.forEach(v =>
493
- {
494
- v.generators[gen] = value;
495
- this.computeModulators(v);
496
- });
497
- }
498
- }
499
-
500
- resetGeneratorOffsets()
501
- {
502
- this.generatorOffsets.fill(0);
503
- this.generatorOffsetsEnabled = false;
504
- }
505
-
506
- /**
507
- * @param gen {generatorTypes}
508
- * @param value {number}
509
- */
510
- setGeneratorOffset(gen, value)
511
- {
512
- this.generatorOffsets[gen] = value * generatorLimits[gen].nrpn;
513
- this.generatorOffsetsEnabled = true;
514
- this.voices.forEach(v =>
515
- {
516
- this.computeModulators(v);
517
- });
518
- }
519
- }
520
-
521
- // voice
522
- MidiAudioChannel.prototype.renderVoice = renderVoice;
523
- MidiAudioChannel.prototype.panAndMixVoice = panAndMixVoice;
524
- MidiAudioChannel.prototype.killNote = killNote;
525
- MidiAudioChannel.prototype.stopAllNotes = stopAllNotes;
526
- MidiAudioChannel.prototype.muteChannel = muteChannel;
527
- MidiAudioChannel.prototype.computeModulators = computeModulators;
528
-
529
- // MIDI messages
530
- MidiAudioChannel.prototype.noteOn = noteOn;
531
- MidiAudioChannel.prototype.noteOff = noteOff;
532
- MidiAudioChannel.prototype.polyPressure = polyPressure;
533
- MidiAudioChannel.prototype.channelPressure = channelPressure;
534
- MidiAudioChannel.prototype.pitchWheel = pitchWheel;
535
- MidiAudioChannel.prototype.programChange = programChange;
536
-
537
- // Tuning
538
- MidiAudioChannel.prototype.setTuning = setTuning;
539
- MidiAudioChannel.prototype.setOctaveTuning = setOctaveTuning;
540
- MidiAudioChannel.prototype.setModulationDepth = setModulationDepth;
541
- MidiAudioChannel.prototype.transposeChannel = transposeChannel;
542
-
543
- // CC
544
- MidiAudioChannel.prototype.controllerChange = controllerChange;
545
- MidiAudioChannel.prototype.resetControllers = resetControllers;
546
- MidiAudioChannel.prototype.resetControllersRP15Compliant = resetControllersRP15Compliant;
547
- MidiAudioChannel.prototype.resetParameters = resetParameters;
548
- MidiAudioChannel.prototype.dataEntryFine = dataEntryFine;
549
- MidiAudioChannel.prototype.dataEntryCoarse = dataEntryCoarse;
550
-
551
- export { MidiAudioChannel };