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,254 +0,0 @@
1
- import { IndexedByteArray } from "../utils/indexed_array.js";
2
-
3
- /**
4
- * midi_message.js
5
- * purpose: contains enums for midi events and controllers and functions to parse them
6
- */
7
-
8
- export class MIDIMessage
9
- {
10
- /**
11
- * Absolute number of MIDI ticks from the start of the track.
12
- * @type {number}
13
- */
14
- ticks;
15
-
16
- /**
17
- * The MIDI message status byte. Note that for meta events, it is the second byte. (not 0xFF)
18
- * @type {number}
19
- */
20
- messageStatusByte;
21
-
22
- /**
23
- * Message's binary data
24
- * @type {IndexedByteArray}
25
- */
26
- messageData;
27
-
28
- /**
29
- * @param ticks {number}
30
- * @param byte {number} the message status byte
31
- * @param data {IndexedByteArray}
32
- */
33
- constructor(ticks, byte, data)
34
- {
35
- this.ticks = ticks;
36
- this.messageStatusByte = byte;
37
- this.messageData = data;
38
- }
39
- }
40
-
41
- /**
42
- * Gets the status byte's channel
43
- * @param statusByte
44
- * @returns {number} channel is -1 for system messages -2 for meta and -3 for sysex
45
- */
46
- export function getChannel(statusByte)
47
- {
48
- const eventType = statusByte & 0xF0;
49
- const channel = statusByte & 0x0F;
50
-
51
- let resultChannel = channel;
52
-
53
- switch (eventType)
54
- {
55
- // midi (and meta and sysex headers)
56
- case 0x80:
57
- case 0x90:
58
- case 0xA0:
59
- case 0xB0:
60
- case 0xC0:
61
- case 0xD0:
62
- case 0xE0:
63
- break;
64
-
65
- case 0xF0:
66
- switch (channel)
67
- {
68
- case 0x0:
69
- resultChannel = -3;
70
- break;
71
-
72
- case 0x1:
73
- case 0x2:
74
- case 0x3:
75
- case 0x4:
76
- case 0x5:
77
- case 0x6:
78
- case 0x7:
79
- case 0x8:
80
- case 0x9:
81
- case 0xA:
82
- case 0xB:
83
- case 0xC:
84
- case 0xD:
85
- case 0xE:
86
- resultChannel = -1;
87
- break;
88
-
89
- case 0xF:
90
- resultChannel = -2;
91
- break;
92
- }
93
- break;
94
-
95
- default:
96
- resultChannel = -1;
97
- }
98
-
99
- return resultChannel;
100
- }
101
-
102
- // all the midi statuses dictionary
103
- export const messageTypes = {
104
- noteOff: 0x80,
105
- noteOn: 0x90,
106
- polyPressure: 0xA0,
107
- controllerChange: 0xB0,
108
- programChange: 0xC0,
109
- channelPressure: 0xD0,
110
- pitchBend: 0xE0,
111
- systemExclusive: 0xF0,
112
- timecode: 0xF1,
113
- songPosition: 0xF2,
114
- songSelect: 0xF3,
115
- tuneRequest: 0xF6,
116
- clock: 0xF8,
117
- start: 0xFA,
118
- continue: 0xFB,
119
- stop: 0xFC,
120
- activeSensing: 0xFE,
121
- reset: 0xFF,
122
- sequenceNumber: 0x00,
123
- text: 0x01,
124
- copyright: 0x02,
125
- trackName: 0x03,
126
- instrumentName: 0x04,
127
- lyric: 0x05,
128
- marker: 0x06,
129
- cuePoint: 0x07,
130
- programName: 0x08,
131
- midiChannelPrefix: 0x20,
132
- midiPort: 0x21,
133
- endOfTrack: 0x2F,
134
- setTempo: 0x51,
135
- smpteOffset: 0x54,
136
- timeSignature: 0x58,
137
- keySignature: 0x59,
138
- sequenceSpecific: 0x7F
139
- };
140
-
141
-
142
- /**
143
- * Gets the event's status and channel from the status byte
144
- * @param statusByte {number} the status byte
145
- * @returns {{channel: number, status: number}} channel will be -1 for sysex and meta
146
- */
147
- export function getEvent(statusByte)
148
- {
149
- const status = statusByte & 0xF0;
150
- const channel = statusByte & 0x0F;
151
-
152
- let eventChannel = -1;
153
- let eventStatus = statusByte;
154
-
155
- if (status >= 0x80 && status <= 0xE0)
156
- {
157
- eventChannel = channel;
158
- eventStatus = status;
159
- }
160
-
161
- return {
162
- status: eventStatus,
163
- channel: eventChannel
164
- };
165
- }
166
-
167
-
168
- /**
169
- * @enum {number}
170
- */
171
- export const midiControllers = {
172
- bankSelect: 0,
173
- modulationWheel: 1,
174
- breathController: 2,
175
- footController: 4,
176
- portamentoTime: 5,
177
- dataEntryMsb: 6,
178
- mainVolume: 7,
179
- balance: 8,
180
- pan: 10,
181
- expressionController: 11,
182
- effectControl1: 12,
183
- effectControl2: 13,
184
- generalPurposeController1: 16,
185
- generalPurposeController2: 17,
186
- generalPurposeController3: 18,
187
- generalPurposeController4: 19,
188
- lsbForControl0BankSelect: 32,
189
- lsbForControl1ModulationWheel: 33,
190
- lsbForControl2BreathController: 34,
191
- lsbForControl4FootController: 36,
192
- lsbForControl5PortamentoTime: 37,
193
- lsbForControl6DataEntry: 38,
194
- lsbForControl7MainVolume: 39,
195
- lsbForControl8Balance: 40,
196
- lsbForControl10Pan: 42,
197
- lsbForControl11ExpressionController: 43,
198
- lsbForControl12EffectControl1: 44,
199
- lsbForControl13EffectControl2: 45,
200
- sustainPedal: 64,
201
- portamentoOnOff: 65,
202
- sostenutoPedal: 66,
203
- softPedal: 67,
204
- legatoFootswitch: 68,
205
- hold2Pedal: 69,
206
- soundVariation: 70,
207
- filterResonance: 71,
208
- releaseTime: 72,
209
- attackTime: 73,
210
- brightness: 74,
211
- decayTime: 75,
212
- vibratoRate: 76,
213
- vibratoDepth: 77,
214
- vibratoDelay: 78,
215
- soundController10: 79,
216
- generalPurposeController5: 80,
217
- generalPurposeController6: 81,
218
- generalPurposeController7: 82,
219
- generalPurposeController8: 83,
220
- portamentoControl: 84,
221
- reverbDepth: 91,
222
- tremoloDepth: 92,
223
- chorusDepth: 93,
224
- detuneDepth: 94,
225
- phaserDepth: 95,
226
- dataIncrement: 96,
227
- dataDecrement: 97,
228
- NRPNLsb: 98,
229
- NRPNMsb: 99,
230
- RPNLsb: 100,
231
- RPNMsb: 101,
232
- allSoundOff: 120,
233
- resetAllControllers: 121,
234
- localControlOnOff: 122,
235
- allNotesOff: 123,
236
- omniModeOff: 124,
237
- omniModeOn: 125,
238
- monoModeOn: 126,
239
- polyModeOn: 127
240
- };
241
-
242
-
243
- /**
244
- * @type {{"11": number, "12": number, "13": number, "14": number, "8": number, "9": number, "10": number}}
245
- */
246
- export const dataBytesAmount = {
247
- 0x8: 2, // note off
248
- 0x9: 2, // note on
249
- 0xA: 2, // note at
250
- 0xB: 2, // cc change
251
- 0xC: 1, // pg change
252
- 0xD: 1, // channel after touch
253
- 0xE: 2 // pitch wheel
254
- };
@@ -1,225 +0,0 @@
1
- /**
2
- * This is the base type for MIDI files. It contains all the "metadata" and information.
3
- * It extends to:
4
- * - BasicMIDI, which contains the actual track data of the MIDI file. Essentially the MIDI file itself.
5
- * - MIDIData, which contains all properties that MIDI does, except for tracks and the embedded soundfont.
6
- * MIDIData is the "shell" of the file which is available on the main thread at all times, containing the metadata.
7
- */
8
- class MIDISequenceData
9
- {
10
- /**
11
- * The time division of the sequence, representing the number of ticks per beat.
12
- * @type {number}
13
- */
14
- timeDivision = 0;
15
-
16
- /**
17
- * The duration of the sequence, in seconds.
18
- * @type {number}
19
- */
20
- duration = 0;
21
-
22
- /**
23
- * The tempo changes in the sequence, ordered from the last change to the first.
24
- * Each change is represented by an object with a tick position and a tempo value in beats per minute.
25
- * @type {{ticks: number, tempo: number}[]}
26
- */
27
- tempoChanges = [{ ticks: 0, tempo: 120 }];
28
-
29
- /**
30
- * A string containing the copyright information for the MIDI sequence if detected.
31
- * @type {string}
32
- */
33
- copyright = "";
34
-
35
- /**
36
- * The number of tracks in the MIDI sequence.
37
- * @type {number}
38
- */
39
- tracksAmount = 0;
40
-
41
- /**
42
- * The track names in the MIDI file, an empty string if not set.
43
- * @type {string[]}
44
- */
45
- trackNames = [];
46
-
47
- /**
48
- * An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
49
- * @type {Uint8Array[]}
50
- */
51
- lyrics = [];
52
-
53
- /**
54
- * An array of tick positions where lyrics events occur in the sequence.
55
- * @type {number[]}
56
- */
57
- lyricsTicks = [];
58
-
59
- /**
60
- * The tick position of the first note-on event in the MIDI sequence.
61
- * @type {number}
62
- */
63
- firstNoteOn = 0;
64
-
65
- /**
66
- * The MIDI key range used in the sequence, represented by a minimum and maximum note value.
67
- * @type {{min: number, max: number}}
68
- */
69
- keyRange = { min: 0, max: 127 };
70
-
71
- /**
72
- * The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
73
- * @type {number}
74
- */
75
- lastVoiceEventTick = 0;
76
-
77
- /**
78
- * An array of MIDI port numbers used by each track in the sequence.
79
- * @type {number[]}
80
- */
81
- midiPorts = [0];
82
-
83
- /**
84
- * An array of channel offsets for each MIDI port, using the SpessaSynth method.
85
- * @type {number[]}
86
- */
87
- midiPortChannelOffsets = [0];
88
-
89
- /**
90
- * A list of sets, where each set contains the MIDI channels used by each track in the sequence.
91
- * @type {Set<number>[]}
92
- */
93
- usedChannelsOnTrack = [];
94
-
95
- /**
96
- * The loop points (in ticks) of the sequence, including both start and end points.
97
- * @type {{start: number, end: number}}
98
- */
99
- loop = { start: 0, end: 0 };
100
-
101
- /**
102
- * The name of the MIDI sequence.
103
- * @type {string}
104
- */
105
- midiName = "";
106
-
107
- /**
108
- * A boolean indicating if the sequence's name is the same as the file name.
109
- * @type {boolean}
110
- */
111
- midiNameUsesFileName = false;
112
-
113
- /**
114
- * The file name of the MIDI sequence, if provided during parsing.
115
- * @type {string}
116
- */
117
- fileName = "";
118
-
119
- /**
120
- * The raw, encoded MIDI name, represented as a Uint8Array.
121
- * Useful when the MIDI file uses a different code page.
122
- * @type {Uint8Array}
123
- */
124
- rawMidiName;
125
-
126
- /**
127
- * The format of the MIDI file, which can be 0, 1, or 2, indicating the type of the MIDI file.
128
- * @type {number}
129
- */
130
- format = 0;
131
-
132
- /**
133
- * The RMID (Resource-Interchangeable MIDI) info data, if the file is RMID formatted.
134
- * Otherwise, this field is undefined.
135
- * Chunk type (e.g. "INAM"): Chunk data as a binary array.
136
- * @type {Object<string, IndexedByteArray>}
137
- */
138
- RMIDInfo = {};
139
-
140
- /**
141
- * The bank offset used for RMID files.
142
- * @type {number}
143
- */
144
- bankOffset = 0;
145
-
146
- /**
147
- * If the MIDI file is a Soft Karaoke file (.kar), this flag is set to true.
148
- * https://www.mixagesoftware.com/en/midikit/help/HTML/karaoke_formats.html
149
- * @type {boolean}
150
- */
151
- isKaraokeFile = false;
152
-
153
- /**
154
- * Indicates if this file is a Multi-Port MIDI file.
155
- * @type {boolean}
156
- */
157
- isMultiPort = false;
158
-
159
- /**
160
- * Converts ticks to time in seconds
161
- * @param ticks {number} time in MIDI ticks
162
- * @returns {number} time in seconds
163
- */
164
- MIDIticksToSeconds(ticks)
165
- {
166
- let totalSeconds = 0;
167
-
168
- while (ticks > 0)
169
- {
170
- // tempo changes are reversed, so the first element is the last tempo change
171
- // and the last element is the first tempo change
172
- // (always at tick 0 and tempo 120)
173
- // find the last tempo change that has occurred
174
- let tempo = this.tempoChanges.find(v => v.ticks < ticks);
175
-
176
- // calculate the difference and tempo time
177
- let timeSinceLastTempo = ticks - tempo.ticks;
178
- totalSeconds += (timeSinceLastTempo * 60) / (tempo.tempo * this.timeDivision);
179
- ticks -= timeSinceLastTempo;
180
- }
181
-
182
- return totalSeconds;
183
- }
184
-
185
- /**
186
- * INTERNAL USE ONLY!
187
- * DO NOT USE IN SPESSASYNTH_LIB
188
- * @param sequence {MIDISequenceData}
189
- * @protected
190
- */
191
- _copyFromSequence(sequence)
192
- {
193
- // properties can be assigned
194
- this.midiName = sequence.midiName;
195
- this.midiNameUsesFileName = sequence.midiNameUsesFileName;
196
- this.fileName = sequence.fileName;
197
- this.timeDivision = sequence.timeDivision;
198
- this.duration = sequence.duration;
199
- this.copyright = sequence.copyright;
200
- this.tracksAmount = sequence.tracksAmount;
201
- this.firstNoteOn = sequence.firstNoteOn;
202
- this.lastVoiceEventTick = sequence.lastVoiceEventTick;
203
- this.format = sequence.format;
204
- this.bankOffset = sequence.bankOffset;
205
- this.isKaraokeFile = sequence.isKaraokeFile;
206
- this.isMultiPort = sequence.isMultiPort;
207
-
208
- // copying arrays
209
- this.tempoChanges = [...sequence.tempoChanges];
210
- this.lyrics = sequence.lyrics.map(arr => new Uint8Array(arr));
211
- this.lyricsTicks = [...sequence.lyricsTicks];
212
- this.midiPorts = [...sequence.midiPorts];
213
- this.trackNames = [...sequence.trackNames];
214
- this.midiPortChannelOffsets = [...sequence.midiPortChannelOffsets];
215
- this.usedChannelsOnTrack = sequence.usedChannelsOnTrack.map(set => new Set(set));
216
- this.rawMidiName = sequence.rawMidiName ? new Uint8Array(sequence.rawMidiName) : undefined;
217
-
218
- // copying objects
219
- this.loop = { ...sequence.loop };
220
- this.keyRange = { ...sequence.keyRange };
221
- this.RMIDInfo = { ...sequence.RMIDInfo };
222
- }
223
- }
224
-
225
- export { MIDISequenceData };
@@ -1,154 +0,0 @@
1
- import { IndexedByteArray } from "../../utils/indexed_array.js";
2
- import { readBytesAsUintBigEndian } from "../../utils/byte_functions/big_endian.js";
3
- import { DEFAULT_PERCUSSION } from "../../synthetizer/synth_constants.js";
4
-
5
- /**
6
- * Calculates all note times in seconds.
7
- * @this {BasicMIDI}
8
- * @param minDrumLength {number} the shortest a drum note (channel 10) can be, in seconds.
9
- * @returns {{
10
- * midiNote: number,
11
- * start: number,
12
- * length: number,
13
- * velocity: number,
14
- * }[][]} an array of 16 channels, each channel containing its notes,
15
- * with their key number, velocity, absolute start time and length in seconds.
16
- */
17
- export function getNoteTimes(minDrumLength = 0)
18
- {
19
-
20
- /**
21
- * gets tempo from the midi message
22
- * @param event {MIDIMessage}
23
- * @return {number} the tempo in bpm
24
- */
25
- function getTempo(event)
26
- {
27
- // simulate IndexedByteArray
28
- event.messageData = new IndexedByteArray(event.messageData.buffer);
29
- event.messageData.currentIndex = 0;
30
- return 60000000 / readBytesAsUintBigEndian(event.messageData, 3);
31
- }
32
-
33
- /**
34
- * an array of 16 arrays (channels)
35
- * @type {{
36
- * midiNote: number,
37
- * start: number,
38
- * length: number,
39
- * velocity: number,
40
- * }[][]}
41
- */
42
- const noteTimes = [];
43
- // flatten and sort by ticks
44
- const trackData = this.tracks;
45
- let events = trackData.flat();
46
- events.sort((e1, e2) => e1.ticks - e2.ticks);
47
-
48
- for (let i = 0; i < 16; i++)
49
- {
50
- noteTimes.push([]);
51
- }
52
- let elapsedTime = 0;
53
- let oneTickToSeconds = 60 / (120 * this.timeDivision);
54
- let eventIndex = 0;
55
- let unfinished = 0;
56
- /**
57
- * @type {{
58
- * midiNote: number,
59
- * start: number,
60
- * length: number,
61
- * velocity: number,
62
- * }[][]}
63
- */
64
- const unfinishedNotes = [];
65
- for (let i = 0; i < 16; i++)
66
- {
67
- unfinishedNotes.push([]);
68
- }
69
- const noteOff = (midiNote, channel) =>
70
- {
71
- const noteIndex = unfinishedNotes[channel].findIndex(n => n.midiNote === midiNote);
72
- const note = unfinishedNotes[channel][noteIndex];
73
- if (note)
74
- {
75
- const time = elapsedTime - note.start;
76
- note.length = time;
77
- if (channel === DEFAULT_PERCUSSION)
78
- {
79
- note.length = time < minDrumLength ? minDrumLength : time;
80
- }
81
- // delete from unfinished
82
- unfinishedNotes[channel].splice(noteIndex, 1);
83
- }
84
- unfinished--;
85
- };
86
- while (eventIndex < events.length)
87
- {
88
- const event = events[eventIndex];
89
-
90
- const status = event.messageStatusByte >> 4;
91
- const channel = event.messageStatusByte & 0x0F;
92
-
93
- // note off
94
- if (status === 0x8)
95
- {
96
- noteOff(event.messageData[0], channel);
97
- }
98
- // note on
99
- else if (status === 0x9)
100
- {
101
- if (event.messageData[1] === 0)
102
- {
103
- // never mind, its note off
104
- noteOff(event.messageData[0], channel);
105
- }
106
- else
107
- {
108
- // stop previous
109
- noteOff(event.messageData[0], channel);
110
- const noteTime = {
111
- midiNote: event.messageData[0],
112
- start: elapsedTime,
113
- length: -1,
114
- velocity: event.messageData[1] / 127
115
- };
116
- noteTimes[channel].push(noteTime);
117
- unfinishedNotes[channel].push(noteTime);
118
- unfinished++;
119
-
120
- }
121
- }
122
- // set tempo
123
- else if (event.messageStatusByte === 0x51)
124
- {
125
- oneTickToSeconds = 60 / (getTempo(event) * this.timeDivision);
126
- }
127
-
128
- if (++eventIndex >= events.length)
129
- {
130
- break;
131
- }
132
-
133
- elapsedTime += oneTickToSeconds * (events[eventIndex].ticks - event.ticks);
134
- }
135
-
136
- // finish the unfinished notes
137
- if (unfinished > 0)
138
- {
139
- // for every channel, for every note that is unfinished (has -1 length)
140
- unfinishedNotes.forEach((channelNotes, channel) =>
141
- {
142
- channelNotes.forEach(note =>
143
- {
144
- const time = elapsedTime - note.start;
145
- note.length = time;
146
- if (channel === DEFAULT_PERCUSSION)
147
- {
148
- note.length = time < minDrumLength ? minDrumLength : time;
149
- }
150
- });
151
- });
152
- }
153
- return noteTimes;
154
- }