spessasynth_lib 3.25.23 → 3.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/README.md +29 -114
  2. package/index.js +33 -33
  3. package/package.json +16 -6
  4. package/external_midi/README.md +0 -4
  5. package/external_midi/midi_handler.js +0 -130
  6. package/external_midi/web_midi_link.js +0 -43
  7. package/externals/fflate/LICENSE +0 -21
  8. package/externals/fflate/fflate.min.js +0 -1
  9. package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
  10. package/externals/stbvorbis_sync/LICENSE +0 -202
  11. package/externals/stbvorbis_sync/NOTICE +0 -6
  12. package/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
  13. package/midi/README.md +0 -32
  14. package/midi/basic_midi.js +0 -565
  15. package/midi/midi_builder.js +0 -202
  16. package/midi/midi_data.js +0 -63
  17. package/midi/midi_loader.js +0 -324
  18. package/midi/midi_message.js +0 -254
  19. package/midi/midi_sequence.js +0 -225
  20. package/midi/midi_tools/get_note_times.js +0 -154
  21. package/midi/midi_tools/midi_editor.js +0 -611
  22. package/midi/midi_tools/midi_writer.js +0 -99
  23. package/midi/midi_tools/rmidi_writer.js +0 -567
  24. package/midi/midi_tools/used_keys_loaded.js +0 -238
  25. package/midi/xmf_loader.js +0 -454
  26. package/sequencer/README.md +0 -32
  27. package/sequencer/sequencer_engine/events.js +0 -104
  28. package/sequencer/sequencer_engine/play.js +0 -353
  29. package/sequencer/sequencer_engine/process_event.js +0 -169
  30. package/sequencer/sequencer_engine/process_tick.js +0 -106
  31. package/sequencer/sequencer_engine/sequencer_engine.js +0 -335
  32. package/sequencer/sequencer_engine/song_control.js +0 -229
  33. package/sequencer/worklet_wrapper/default_sequencer_options.js +0 -8
  34. package/sequencer/worklet_wrapper/sequencer.js +0 -807
  35. package/sequencer/worklet_wrapper/sequencer_message.js +0 -53
  36. package/soundfont/README.md +0 -13
  37. package/soundfont/basic_soundfont/basic_instrument.js +0 -77
  38. package/soundfont/basic_soundfont/basic_preset.js +0 -336
  39. package/soundfont/basic_soundfont/basic_sample.js +0 -197
  40. package/soundfont/basic_soundfont/basic_soundfont.js +0 -565
  41. package/soundfont/basic_soundfont/basic_zone.js +0 -64
  42. package/soundfont/basic_soundfont/basic_zones.js +0 -43
  43. package/soundfont/basic_soundfont/generator.js +0 -220
  44. package/soundfont/basic_soundfont/modulator.js +0 -378
  45. package/soundfont/basic_soundfont/riff_chunk.js +0 -149
  46. package/soundfont/basic_soundfont/write_dls/art2.js +0 -173
  47. package/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
  48. package/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -400
  49. package/soundfont/basic_soundfont/write_dls/ins.js +0 -103
  50. package/soundfont/basic_soundfont/write_dls/lins.js +0 -18
  51. package/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
  52. package/soundfont/basic_soundfont/write_dls/rgn2.js +0 -121
  53. package/soundfont/basic_soundfont/write_dls/wave.js +0 -94
  54. package/soundfont/basic_soundfont/write_dls/write_dls.js +0 -119
  55. package/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
  56. package/soundfont/basic_soundfont/write_dls/wvpl.js +0 -32
  57. package/soundfont/basic_soundfont/write_sf2/ibag.js +0 -39
  58. package/soundfont/basic_soundfont/write_sf2/igen.js +0 -80
  59. package/soundfont/basic_soundfont/write_sf2/imod.js +0 -46
  60. package/soundfont/basic_soundfont/write_sf2/inst.js +0 -34
  61. package/soundfont/basic_soundfont/write_sf2/pbag.js +0 -39
  62. package/soundfont/basic_soundfont/write_sf2/pgen.js +0 -82
  63. package/soundfont/basic_soundfont/write_sf2/phdr.js +0 -42
  64. package/soundfont/basic_soundfont/write_sf2/pmod.js +0 -46
  65. package/soundfont/basic_soundfont/write_sf2/sdta.js +0 -80
  66. package/soundfont/basic_soundfont/write_sf2/shdr.js +0 -55
  67. package/soundfont/basic_soundfont/write_sf2/write.js +0 -222
  68. package/soundfont/dls/articulator_converter.js +0 -396
  69. package/soundfont/dls/dls_destinations.js +0 -38
  70. package/soundfont/dls/dls_preset.js +0 -44
  71. package/soundfont/dls/dls_sample.js +0 -75
  72. package/soundfont/dls/dls_soundfont.js +0 -186
  73. package/soundfont/dls/dls_sources.js +0 -62
  74. package/soundfont/dls/dls_zone.js +0 -95
  75. package/soundfont/dls/read_articulation.js +0 -299
  76. package/soundfont/dls/read_instrument.js +0 -121
  77. package/soundfont/dls/read_instrument_list.js +0 -17
  78. package/soundfont/dls/read_lart.js +0 -35
  79. package/soundfont/dls/read_region.js +0 -152
  80. package/soundfont/dls/read_samples.js +0 -270
  81. package/soundfont/load_soundfont.js +0 -21
  82. package/soundfont/read_sf2/generators.js +0 -46
  83. package/soundfont/read_sf2/instruments.js +0 -66
  84. package/soundfont/read_sf2/modulators.js +0 -36
  85. package/soundfont/read_sf2/presets.js +0 -80
  86. package/soundfont/read_sf2/samples.js +0 -304
  87. package/soundfont/read_sf2/soundfont.js +0 -305
  88. package/soundfont/read_sf2/zones.js +0 -263
  89. package/synthetizer/README.md +0 -10
  90. package/synthetizer/audio_effects/effects_config.js +0 -25
  91. package/synthetizer/audio_effects/fancy_chorus.js +0 -162
  92. package/synthetizer/audio_effects/rb_compressed.min.js +0 -1
  93. package/synthetizer/audio_effects/reverb.js +0 -35
  94. package/synthetizer/audio_effects/reverb_as_binary.js +0 -18
  95. package/synthetizer/audio_engine/README.md +0 -25
  96. package/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -266
  97. package/synthetizer/audio_engine/engine_components/controller_tables.js +0 -88
  98. package/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -149
  99. package/synthetizer/audio_engine/engine_components/lfo.js +0 -26
  100. package/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
  101. package/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -471
  102. package/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
  103. package/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
  104. package/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -228
  105. package/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -120
  106. package/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
  107. package/synthetizer/audio_engine/engine_components/voice.js +0 -519
  108. package/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -401
  109. package/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -263
  110. package/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -132
  111. package/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -48
  112. package/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -241
  113. package/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -27
  114. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -253
  115. package/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -66
  116. package/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
  117. package/synthetizer/audio_engine/engine_methods/note_on.js +0 -175
  118. package/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
  119. package/synthetizer/audio_engine/engine_methods/program_change.js +0 -61
  120. package/synthetizer/audio_engine/engine_methods/render_voice.js +0 -196
  121. package/synthetizer/audio_engine/engine_methods/soundfont_management/clear_sound_font.js +0 -30
  122. package/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -22
  123. package/synthetizer/audio_engine/engine_methods/soundfont_management/reload_sound_font.js +0 -40
  124. package/synthetizer/audio_engine/engine_methods/soundfont_management/send_preset_list.js +0 -34
  125. package/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js +0 -21
  126. package/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -20
  127. package/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -55
  128. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
  129. package/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
  130. package/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
  131. package/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -776
  132. package/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -24
  133. package/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -33
  134. package/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -31
  135. package/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
  136. package/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -27
  137. package/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
  138. package/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
  139. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
  140. package/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
  141. package/synthetizer/audio_engine/main_processor.js +0 -765
  142. package/synthetizer/audio_engine/message_protocol/README.md +0 -13
  143. package/synthetizer/audio_engine/message_protocol/message_sending.js +0 -22
  144. package/synthetizer/audio_engine/message_protocol/worklet_message.js +0 -107
  145. package/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -14
  146. package/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
  147. package/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -122
  148. package/synthetizer/synth_constants.js +0 -20
  149. package/synthetizer/worklet_processor.min.js +0 -21
  150. package/synthetizer/worklet_wrapper/key_modifier_manager.js +0 -104
  151. package/synthetizer/worklet_wrapper/sfman_message.js +0 -9
  152. package/synthetizer/worklet_wrapper/synth_event_handler.js +0 -214
  153. package/synthetizer/worklet_wrapper/synth_soundfont_manager.js +0 -109
  154. package/synthetizer/worklet_wrapper/synthetizer.js +0 -1027
  155. package/synthetizer/worklet_wrapper/worklet_processor.js +0 -454
  156. package/synthetizer/worklet_wrapper/worklet_url.js +0 -16
  157. package/utils/README.md +0 -5
  158. package/utils/buffer_to_wav.js +0 -186
  159. package/utils/byte_functions/big_endian.js +0 -32
  160. package/utils/byte_functions/little_endian.js +0 -77
  161. package/utils/byte_functions/string.js +0 -107
  162. package/utils/byte_functions/variable_length_quantity.js +0 -42
  163. package/utils/fill_with_defaults.js +0 -21
  164. package/utils/indexed_array.js +0 -52
  165. package/utils/loggin.js +0 -79
  166. package/utils/other.js +0 -92
  167. package/utils/sysex_detector.js +0 -58
  168. package/utils/xg_hacks.js +0 -193
@@ -1,106 +0,0 @@
1
- import { SpessaSynthSequencerReturnMessageType } from "../worklet_wrapper/sequencer_message.js";
2
-
3
- /**
4
- * Processes a single tick
5
- * @this {SpessaSynthSequencer}
6
- */
7
- export function processTick()
8
- {
9
- if (!this.isActive)
10
- {
11
- return;
12
- }
13
- let current = this.currentTime;
14
- while (this.playedTime < current)
15
- {
16
- // find the next event
17
- let trackIndex = this._findFirstEventIndex();
18
- let event = this.tracks[trackIndex][this.eventIndex[trackIndex]];
19
- this._processEvent(event, trackIndex);
20
-
21
- this.eventIndex[trackIndex]++;
22
-
23
- // find the next event
24
- trackIndex = this._findFirstEventIndex();
25
- if (this.tracks[trackIndex].length <= this.eventIndex[trackIndex])
26
- {
27
- // the song has ended
28
- if (this.loop)
29
- {
30
- this.setTimeTicks(this.midiData.loop.start);
31
- return;
32
- }
33
- this.eventIndex[trackIndex]--;
34
- this.pause(true);
35
- if (this.songs.length > 1)
36
- {
37
- this.nextSong();
38
- }
39
- return;
40
- }
41
- let eventNext = this.tracks[trackIndex][this.eventIndex[trackIndex]];
42
- this.playedTime += this.oneTickToSeconds * (eventNext.ticks - event.ticks);
43
-
44
- const canLoop = this.loop && (this.loopCount > 0 || this.loopCount === -1);
45
-
46
- // if we reached loop.end
47
- if ((this.midiData.loop.end <= event.ticks) && canLoop)
48
- {
49
- // loop
50
- if (this.loopCount !== Infinity)
51
- {
52
- this.loopCount--;
53
- this.post(SpessaSynthSequencerReturnMessageType.loopCountChange, this.loopCount);
54
- }
55
- this.setTimeTicks(this.midiData.loop.start);
56
- return;
57
- }
58
- // if the song has ended
59
- else if (current >= this.duration)
60
- {
61
- if (canLoop)
62
- {
63
- // loop
64
- if (this.loopCount !== Infinity)
65
- {
66
- this.loopCount--;
67
- this.post(SpessaSynthSequencerReturnMessageType.loopCountChange, this.loopCount);
68
- }
69
- this.setTimeTicks(this.midiData.loop.start);
70
- return;
71
- }
72
- // stop the playback
73
- this.eventIndex[trackIndex]--;
74
- this.pause(true);
75
- if (this.songs.length > 1)
76
- {
77
- this.nextSong();
78
- }
79
- return;
80
- }
81
- }
82
- }
83
-
84
-
85
- /**
86
- * @returns {number} the index of the first to the current played time
87
- * @this {SpessaSynthSequencer}
88
- */
89
- export function _findFirstEventIndex()
90
- {
91
- let index = 0;
92
- let ticks = Infinity;
93
- this.tracks.forEach((track, i) =>
94
- {
95
- if (this.eventIndex[i] >= track.length)
96
- {
97
- return;
98
- }
99
- if (track[this.eventIndex[i]].ticks < ticks)
100
- {
101
- index = i;
102
- ticks = track[this.eventIndex[i]].ticks;
103
- }
104
- });
105
- return index;
106
- }
@@ -1,335 +0,0 @@
1
- import { SpessaSynthSequencerReturnMessageType } from "../worklet_wrapper/sequencer_message.js";
2
- import { _addNewMidiPort, _processEvent } from "./process_event.js";
3
- import { _findFirstEventIndex, processTick } from "./process_tick.js";
4
- import { assignMIDIPort, loadNewSequence, loadNewSongList, nextSong, previousSong } from "./song_control.js";
5
- import { _playTo, _recalculateStartTime, play, setTimeTicks } from "./play.js";
6
- import { messageTypes, midiControllers } from "../../midi/midi_message.js";
7
- import {
8
- post,
9
- sendMIDICC,
10
- sendMIDIMessage,
11
- sendMIDIPitchWheel,
12
- sendMIDIProgramChange,
13
- sendMIDIReset
14
- } from "./events.js";
15
- import { SpessaSynthWarn } from "../../utils/loggin.js";
16
-
17
- import { MIDI_CHANNEL_COUNT } from "../../synthetizer/synth_constants.js";
18
-
19
- class SpessaSynthSequencer
20
- {
21
- /**
22
- * All the sequencer's songs
23
- * @type {BasicMIDI[]}
24
- */
25
- songs = [];
26
-
27
- /**
28
- * Current song index
29
- * @type {number}
30
- */
31
- songIndex = 0;
32
-
33
- /**
34
- * shuffled song indexes
35
- * @type {number[]}
36
- */
37
- shuffledSongIndexes = [];
38
-
39
- /**
40
- * the synth to use
41
- * @type {SpessaSynthProcessor}
42
- */
43
- synth;
44
-
45
- /**
46
- * if the sequencer is active
47
- * @type {boolean}
48
- */
49
- isActive = false;
50
-
51
- /**
52
- * If the event should instead be sent back to the main thread instead of synth
53
- * @type {boolean}
54
- */
55
- sendMIDIMessages = false;
56
-
57
- /**
58
- * sequencer's loop count
59
- * @type {number}
60
- */
61
- loopCount = Infinity;
62
-
63
- /**
64
- * event's number in this.events
65
- * @type {number[]}
66
- */
67
- eventIndex = [];
68
-
69
- /**
70
- * tracks the time that has already been played
71
- * @type {number}
72
- */
73
- playedTime = 0;
74
-
75
- /**
76
- * The (relative) time when the sequencer was paused. If it's not paused, then it's undefined.
77
- * @type {number}
78
- */
79
- pausedTime = undefined;
80
-
81
- /**
82
- * Absolute playback startTime, bases on the synth's time
83
- * @type {number}
84
- */
85
- absoluteStartTime = 0;
86
- /**
87
- * Currently playing notes (for pausing and resuming)
88
- * @type {{
89
- * midiNote: number,
90
- * channel: number,
91
- * velocity: number
92
- * }[]}
93
- */
94
- playingNotes = [];
95
-
96
- /**
97
- * controls if the sequencer loops (defaults to true)
98
- * @type {boolean}
99
- */
100
- loop = true;
101
-
102
- /**
103
- * controls if the songs are ordered randomly
104
- * @type {boolean}
105
- */
106
- shuffleMode = false;
107
-
108
- /**
109
- * the current track data
110
- * @type {BasicMIDI}
111
- */
112
- midiData = undefined;
113
-
114
- /**
115
- * midi port number for the corresponding track
116
- * @type {number[]}
117
- */
118
- midiPorts = [];
119
- midiPortChannelOffset = 0;
120
- /**
121
- * stored as:
122
- * Object<midi port, channel offset>
123
- * @type {Object<number, number>}
124
- */
125
- midiPortChannelOffsets = {};
126
-
127
- /**
128
- * @type {boolean}
129
- */
130
- skipToFirstNoteOn = true;
131
-
132
- /**
133
- * If true, seq will stay paused when seeking or changing the playback rate
134
- * @type {boolean}
135
- */
136
- preservePlaybackState = false;
137
-
138
- /**
139
- * @param spessasynthProcessor {SpessaSynthProcessor}
140
- */
141
- constructor(spessasynthProcessor)
142
- {
143
- this.synth = spessasynthProcessor;
144
- this.absoluteStartTime = this.synth.currentSynthTime;
145
- }
146
-
147
- /**
148
- * Controls the playback's rate
149
- * @type {number}
150
- * @private
151
- */
152
- _playbackRate = 1;
153
-
154
- /**
155
- * @param value {number}
156
- */
157
- set playbackRate(value)
158
- {
159
- const time = this.currentTime;
160
- this._playbackRate = value;
161
- this.currentTime = time;
162
- }
163
-
164
- get currentTime()
165
- {
166
- // return the paused time if it's set to something other than undefined
167
- if (this.pausedTime !== undefined)
168
- {
169
- return this.pausedTime;
170
- }
171
-
172
- return (this.synth.currentSynthTime - this.absoluteStartTime) * this._playbackRate;
173
- }
174
-
175
- set currentTime(time)
176
- {
177
- if (time > this.duration || time < 0)
178
- {
179
- // time is 0
180
- if (this.skipToFirstNoteOn)
181
- {
182
- this.setTimeTicks(this.midiData.firstNoteOn - 1);
183
- }
184
- else
185
- {
186
- this.setTimeTicks(0);
187
- }
188
- return;
189
- }
190
- if (this.skipToFirstNoteOn)
191
- {
192
- if (time < this.firstNoteTime)
193
- {
194
- this.setTimeTicks(this.midiData.firstNoteOn - 1);
195
- return;
196
- }
197
- }
198
- this.stop();
199
- this.playingNotes = [];
200
- const wasPaused = this.paused && this.preservePlaybackState;
201
- this.pausedTime = undefined;
202
- this.post(SpessaSynthSequencerReturnMessageType.timeChange, this.synth.currentSynthTime - time);
203
- if (this.midiData.duration === 0)
204
- {
205
- SpessaSynthWarn("No duration!");
206
- this.post(SpessaSynthSequencerReturnMessageType.pause, true);
207
- return;
208
- }
209
- this._playTo(time);
210
- this._recalculateStartTime(time);
211
- if (wasPaused)
212
- {
213
- this.pause();
214
- }
215
- else
216
- {
217
- this.play();
218
- }
219
- }
220
-
221
- /**
222
- * true if paused, false if playing or stopped
223
- * @returns {boolean}
224
- */
225
- get paused()
226
- {
227
- return this.pausedTime !== undefined;
228
- }
229
-
230
- /**
231
- * Pauses the playback
232
- * @param isFinished {boolean}
233
- */
234
- pause(isFinished = false)
235
- {
236
- if (this.paused)
237
- {
238
- SpessaSynthWarn("Already paused");
239
- return;
240
- }
241
- this.pausedTime = this.currentTime;
242
- this.stop();
243
- this.post(SpessaSynthSequencerReturnMessageType.pause, isFinished);
244
- }
245
-
246
- /**
247
- * Stops the playback
248
- */
249
- stop()
250
- {
251
- this.clearProcessHandler();
252
- // disable sustain
253
- for (let i = 0; i < 16; i++)
254
- {
255
- this.synth.controllerChange(i, midiControllers.sustainPedal, 0);
256
- }
257
- this.synth.stopAllChannels();
258
- if (this.sendMIDIMessages)
259
- {
260
- for (let note of this.playingNotes)
261
- {
262
- this.sendMIDIMessage([messageTypes.noteOff | (note.channel % 16), note.midiNote]);
263
- }
264
- for (let c = 0; c < MIDI_CHANNEL_COUNT; c++)
265
- {
266
- this.sendMIDICC(c, midiControllers.allNotesOff, 0);
267
- }
268
- }
269
- }
270
-
271
- loadCurrentSong(autoPlay = true)
272
- {
273
- let index = this.songIndex;
274
- if (this.shuffleMode)
275
- {
276
- index = this.shuffledSongIndexes[this.songIndex];
277
- }
278
- this.loadNewSequence(this.songs[index], autoPlay);
279
- }
280
-
281
- _resetTimers()
282
- {
283
- this.playedTime = 0;
284
- this.eventIndex = Array(this.tracks.length).fill(0);
285
- }
286
-
287
- setProcessHandler()
288
- {
289
- this.isActive = true;
290
- }
291
-
292
- clearProcessHandler()
293
- {
294
- this.isActive = false;
295
- }
296
-
297
- shuffleSongIndexes()
298
- {
299
- const indexes = this.songs.map((_, i) => i);
300
- this.shuffledSongIndexes = [];
301
- while (indexes.length > 0)
302
- {
303
- const index = indexes[Math.floor(Math.random() * indexes.length)];
304
- this.shuffledSongIndexes.push(index);
305
- indexes.splice(indexes.indexOf(index), 1);
306
- }
307
- }
308
- }
309
-
310
- // Web MIDI sending
311
- SpessaSynthSequencer.prototype.sendMIDIMessage = sendMIDIMessage;
312
- SpessaSynthSequencer.prototype.sendMIDIReset = sendMIDIReset;
313
- SpessaSynthSequencer.prototype.sendMIDICC = sendMIDICC;
314
- SpessaSynthSequencer.prototype.sendMIDIProgramChange = sendMIDIProgramChange;
315
- SpessaSynthSequencer.prototype.sendMIDIPitchWheel = sendMIDIPitchWheel;
316
- SpessaSynthSequencer.prototype.assignMIDIPort = assignMIDIPort;
317
-
318
- SpessaSynthSequencer.prototype.post = post;
319
-
320
- SpessaSynthSequencer.prototype._processEvent = _processEvent;
321
- SpessaSynthSequencer.prototype._addNewMidiPort = _addNewMidiPort;
322
- SpessaSynthSequencer.prototype.processTick = processTick;
323
- SpessaSynthSequencer.prototype._findFirstEventIndex = _findFirstEventIndex;
324
-
325
- SpessaSynthSequencer.prototype.loadNewSequence = loadNewSequence;
326
- SpessaSynthSequencer.prototype.loadNewSongList = loadNewSongList;
327
- SpessaSynthSequencer.prototype.nextSong = nextSong;
328
- SpessaSynthSequencer.prototype.previousSong = previousSong;
329
-
330
- SpessaSynthSequencer.prototype.play = play;
331
- SpessaSynthSequencer.prototype._playTo = _playTo;
332
- SpessaSynthSequencer.prototype.setTimeTicks = setTimeTicks;
333
- SpessaSynthSequencer.prototype._recalculateStartTime = _recalculateStartTime;
334
-
335
- export { SpessaSynthSequencer };
@@ -1,229 +0,0 @@
1
- import { SpessaSynthSequencerReturnMessageType } from "../worklet_wrapper/sequencer_message.js";
2
- import { consoleColors, formatTime } from "../../utils/other.js";
3
- import {
4
- SpessaSynthGroupCollapsed,
5
- SpessaSynthGroupEnd,
6
- SpessaSynthInfo,
7
- SpessaSynthWarn
8
- } from "../../utils/loggin.js";
9
- import { MIDIData } from "../../midi/midi_data.js";
10
- import { MIDI } from "../../midi/midi_loader.js";
11
- import { BasicMIDI } from "../../midi/basic_midi.js";
12
-
13
-
14
- /**
15
- * @param trackNum {number}
16
- * @param port {number}
17
- * @this {SpessaSynthSequencer}
18
- */
19
- export function assignMIDIPort(trackNum, port)
20
- {
21
- // do not assign ports to empty tracks
22
- if (this.midiData.usedChannelsOnTrack[trackNum].size === 0)
23
- {
24
- return;
25
- }
26
-
27
- // assign new 16 channels if the port is not occupied yet
28
- if (this.midiPortChannelOffset === 0)
29
- {
30
- this.midiPortChannelOffset += 16;
31
- this.midiPortChannelOffsets[port] = 0;
32
- }
33
-
34
- if (this.midiPortChannelOffsets[port] === undefined)
35
- {
36
- if (this.synth.midiAudioChannels.length < this.midiPortChannelOffset + 15)
37
- {
38
- this._addNewMidiPort();
39
- }
40
- this.midiPortChannelOffsets[port] = this.midiPortChannelOffset;
41
- this.midiPortChannelOffset += 16;
42
- }
43
-
44
- this.midiPorts[trackNum] = port;
45
- }
46
-
47
- /**
48
- * Loads a new sequence
49
- * @param parsedMidi {BasicMIDI}
50
- * @param autoPlay {boolean}
51
- * @this {SpessaSynthSequencer}
52
- */
53
- export function loadNewSequence(parsedMidi, autoPlay = true)
54
- {
55
- this.stop();
56
- if (!parsedMidi.tracks)
57
- {
58
- throw new Error("This MIDI has no tracks!");
59
- }
60
-
61
- this.oneTickToSeconds = 60 / (120 * parsedMidi.timeDivision);
62
-
63
- /**
64
- * @type {BasicMIDI}
65
- */
66
- this.midiData = parsedMidi;
67
-
68
- // check for embedded soundfont
69
- if (this.midiData.embeddedSoundFont !== undefined)
70
- {
71
- SpessaSynthInfo("%cEmbedded soundfont detected! Using it.", consoleColors.recognized);
72
- this.synth.setEmbeddedSoundFont(this.midiData.embeddedSoundFont, this.midiData.bankOffset);
73
- }
74
- else
75
- {
76
- if (this.synth.overrideSoundfont)
77
- {
78
- // clean up the embedded soundfont
79
- this.synth.clearSoundFont(true, true);
80
- }
81
- SpessaSynthGroupCollapsed("%cPreloading samples...", consoleColors.info);
82
- // smart preloading: load only samples used in the midi!
83
- const used = this.midiData.getUsedProgramsAndKeys(this.synth.soundfontManager);
84
- for (const [programBank, combos] of Object.entries(used))
85
- {
86
- const bank = parseInt(programBank.split(":")[0]);
87
- const program = parseInt(programBank.split(":")[1]);
88
- const preset = this.synth.getPreset(bank, program);
89
- SpessaSynthInfo(
90
- `%cPreloading used samples on %c${preset.presetName}%c...`,
91
- consoleColors.info,
92
- consoleColors.recognized,
93
- consoleColors.info
94
- );
95
- for (const combo of combos)
96
- {
97
- const split = combo.split("-");
98
- preset.preloadSpecific(parseInt(split[0]), parseInt(split[1]));
99
- }
100
- }
101
- SpessaSynthGroupEnd();
102
- }
103
-
104
- /**
105
- * the midi track data
106
- * @type {MIDIMessage[][]}
107
- */
108
- this.tracks = this.midiData.tracks;
109
-
110
- // copy over the port data
111
- this.midiPorts = this.midiData.midiPorts.slice();
112
-
113
- // clear last port data
114
- this.midiPortChannelOffset = 0;
115
- this.midiPortChannelOffsets = {};
116
- // assign port offsets
117
- this.midiData.midiPorts.forEach((port, trackIndex) =>
118
- {
119
- this.assignMIDIPort(trackIndex, port);
120
- });
121
-
122
- /**
123
- * Same as "audio.duration" property (seconds)
124
- * @type {number}
125
- */
126
- this.duration = this.midiData.duration;
127
- this.firstNoteTime = this.midiData.MIDIticksToSeconds(this.midiData.firstNoteOn);
128
- SpessaSynthInfo(`%cTotal song time: ${formatTime(Math.ceil(this.duration)).time}`, consoleColors.recognized);
129
-
130
- this.post(SpessaSynthSequencerReturnMessageType.songChange, [this.songIndex, autoPlay]);
131
-
132
- if (this.duration <= 1)
133
- {
134
- SpessaSynthWarn(
135
- `%cVery short song: (${formatTime(Math.round(this.duration)).time}). Disabling loop!`,
136
- consoleColors.warn
137
- );
138
- this.loop = false;
139
- }
140
- if (autoPlay)
141
- {
142
- this.play(true);
143
- }
144
- else
145
- {
146
- // this shall not play: play to the first note and then wait
147
- const targetTime = this.skipToFirstNoteOn ? this.midiData.firstNoteOn - 1 : 0;
148
- this.setTimeTicks(targetTime);
149
- this.pause();
150
- }
151
- }
152
-
153
- /**
154
- * @param midiBuffers {MIDIFile[]}
155
- * @param autoPlay {boolean}
156
- * @this {SpessaSynthSequencer}
157
- */
158
- export function loadNewSongList(midiBuffers, autoPlay = true)
159
- {
160
- /**
161
- * parse the MIDIs (only the array buffers, MIDI is unchanged)
162
- * @type {BasicMIDI[]}
163
- */
164
- this.songs = midiBuffers.reduce((mids, b) =>
165
- {
166
- if (b.duration)
167
- {
168
- mids.push(BasicMIDI.copyFrom(b));
169
- return mids;
170
- }
171
- try
172
- {
173
- mids.push(new MIDI(b.binary, b.altName || ""));
174
- }
175
- catch (e)
176
- {
177
- console.error(e);
178
- this.post(SpessaSynthSequencerReturnMessageType.midiError, e);
179
- return mids;
180
- }
181
- return mids;
182
- }, []);
183
- if (this.songs.length < 1)
184
- {
185
- return;
186
- }
187
- this.songIndex = 0;
188
- if (this.songs.length > 1)
189
- {
190
- this.loop = false;
191
- }
192
- this.shuffleSongIndexes();
193
- const midiDatas = this.songs.map(s => new MIDIData(s));
194
- this.post(SpessaSynthSequencerReturnMessageType.songListChange, midiDatas);
195
- this.loadCurrentSong(autoPlay);
196
- }
197
-
198
- /**
199
- * @this {SpessaSynthSequencer}
200
- */
201
- export function nextSong()
202
- {
203
- if (this.songs.length === 1)
204
- {
205
- this.currentTime = 0;
206
- return;
207
- }
208
- this.songIndex++;
209
- this.songIndex %= this.songs.length;
210
- this.loadCurrentSong();
211
- }
212
-
213
- /**
214
- * @this {SpessaSynthSequencer}
215
- */
216
- export function previousSong()
217
- {
218
- if (this.songs.length === 1)
219
- {
220
- this.currentTime = 0;
221
- return;
222
- }
223
- this.songIndex--;
224
- if (this.songIndex < 0)
225
- {
226
- this.songIndex = this.songs.length - 1;
227
- }
228
- this.loadCurrentSong();
229
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * @type {SequencerOptions}
3
- */
4
- export const DEFAULT_SEQUENCER_OPTIONS = {
5
- skipToFirstNoteOn: true,
6
- autoPlay: true,
7
- preservePlaybackState: false
8
- };