spessasynth_core 3.27.8 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -51
- package/dist/index.d.ts +4057 -0
- package/dist/index.js +17178 -0
- package/dist/index.js.map +1 -0
- package/package.json +24 -6
- package/index.js +0 -132
- package/src/externals/README.md +0 -6
- package/src/externals/fflate/LICENSE +0 -21
- package/src/externals/fflate/fflate.min.js +0 -1
- package/src/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
- package/src/externals/stbvorbis_sync/LICENSE +0 -202
- package/src/externals/stbvorbis_sync/NOTICE +0 -6
- package/src/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
- package/src/midi/README.md +0 -32
- package/src/midi/basic_midi.js +0 -587
- package/src/midi/midi_builder.js +0 -203
- package/src/midi/midi_loader.js +0 -321
- package/src/midi/midi_message.js +0 -254
- package/src/midi/midi_sequence.js +0 -230
- package/src/midi/midi_tools/get_note_times.js +0 -154
- package/src/midi/midi_tools/midi_editor.js +0 -611
- package/src/midi/midi_tools/midi_writer.js +0 -105
- package/src/midi/midi_tools/rmidi_writer.js +0 -566
- package/src/midi/midi_tools/used_keys_loaded.js +0 -256
- package/src/midi/xmf_loader.js +0 -454
- package/src/sequencer/README.md +0 -9
- package/src/sequencer/events.js +0 -81
- package/src/sequencer/play.js +0 -362
- package/src/sequencer/process_event.js +0 -165
- package/src/sequencer/process_tick.js +0 -104
- package/src/sequencer/sequencer_engine.js +0 -372
- package/src/sequencer/song_control.js +0 -196
- package/src/soundfont/README.md +0 -11
- package/src/soundfont/basic_soundfont/basic_global_zone.js +0 -6
- package/src/soundfont/basic_soundfont/basic_instrument.js +0 -115
- package/src/soundfont/basic_soundfont/basic_instrument_zone.js +0 -45
- package/src/soundfont/basic_soundfont/basic_preset.js +0 -313
- package/src/soundfont/basic_soundfont/basic_preset_zone.js +0 -39
- package/src/soundfont/basic_soundfont/basic_sample.js +0 -477
- package/src/soundfont/basic_soundfont/basic_soundbank.js +0 -740
- package/src/soundfont/basic_soundfont/basic_zone.js +0 -145
- package/src/soundfont/basic_soundfont/generator.js +0 -76
- package/src/soundfont/basic_soundfont/generator_types.js +0 -151
- package/src/soundfont/basic_soundfont/modulator.js +0 -581
- package/src/soundfont/basic_soundfont/riff_chunk.js +0 -195
- package/src/soundfont/basic_soundfont/write_dls/art2.js +0 -174
- package/src/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
- package/src/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -374
- package/src/soundfont/basic_soundfont/write_dls/ins.js +0 -85
- package/src/soundfont/basic_soundfont/write_dls/lins.js +0 -15
- package/src/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
- package/src/soundfont/basic_soundfont/write_dls/rgn2.js +0 -120
- package/src/soundfont/basic_soundfont/write_dls/wave.js +0 -71
- package/src/soundfont/basic_soundfont/write_dls/write_dls.js +0 -124
- package/src/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
- package/src/soundfont/basic_soundfont/write_dls/wvpl.js +0 -35
- package/src/soundfont/basic_soundfont/write_sf2/ibag.js +0 -60
- package/src/soundfont/basic_soundfont/write_sf2/igen.js +0 -91
- package/src/soundfont/basic_soundfont/write_sf2/imod.js +0 -62
- package/src/soundfont/basic_soundfont/write_sf2/inst.js +0 -42
- package/src/soundfont/basic_soundfont/write_sf2/pbag.js +0 -57
- package/src/soundfont/basic_soundfont/write_sf2/pgen.js +0 -92
- package/src/soundfont/basic_soundfont/write_sf2/phdr.js +0 -61
- package/src/soundfont/basic_soundfont/write_sf2/pmod.js +0 -62
- package/src/soundfont/basic_soundfont/write_sf2/sdta.js +0 -131
- package/src/soundfont/basic_soundfont/write_sf2/shdr.js +0 -77
- package/src/soundfont/basic_soundfont/write_sf2/write.js +0 -287
- package/src/soundfont/dls/articulator_converter.js +0 -402
- package/src/soundfont/dls/dls_destinations.js +0 -38
- package/src/soundfont/dls/dls_instrument.js +0 -20
- package/src/soundfont/dls/dls_preset.js +0 -43
- package/src/soundfont/dls/dls_sample.js +0 -238
- package/src/soundfont/dls/dls_soundfont.js +0 -183
- package/src/soundfont/dls/dls_sources.js +0 -63
- package/src/soundfont/dls/dls_zone.js +0 -89
- package/src/soundfont/dls/read_articulation.js +0 -300
- package/src/soundfont/dls/read_instrument.js +0 -118
- package/src/soundfont/dls/read_instrument_list.js +0 -17
- package/src/soundfont/dls/read_lart.js +0 -35
- package/src/soundfont/dls/read_region.js +0 -157
- package/src/soundfont/dls/read_samples.js +0 -154
- package/src/soundfont/load_soundfont.js +0 -21
- package/src/soundfont/read_sf2/generators.js +0 -43
- package/src/soundfont/read_sf2/instrument_zones.js +0 -75
- package/src/soundfont/read_sf2/instruments.js +0 -71
- package/src/soundfont/read_sf2/modulators.js +0 -25
- package/src/soundfont/read_sf2/preset_zones.js +0 -79
- package/src/soundfont/read_sf2/presets.js +0 -80
- package/src/soundfont/read_sf2/samples.js +0 -317
- package/src/soundfont/read_sf2/soundfont.js +0 -452
- package/src/soundfont/read_sf2/zones.js +0 -28
- package/src/synthetizer/README.md +0 -7
- package/src/synthetizer/audio_engine/README.md +0 -9
- package/src/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -289
- package/src/synthetizer/audio_engine/engine_components/controller_tables.js +0 -90
- package/src/synthetizer/audio_engine/engine_components/dynamic_modulator_system.js +0 -95
- package/src/synthetizer/audio_engine/engine_components/enums.js +0 -18
- package/src/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -151
- package/src/synthetizer/audio_engine/engine_components/lfo.js +0 -26
- package/src/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
- package/src/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -551
- package/src/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
- package/src/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
- package/src/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -265
- package/src/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -124
- package/src/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
- package/src/synthetizer/audio_engine/engine_components/voice.js +0 -525
- package/src/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -402
- package/src/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -274
- package/src/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -159
- package/src/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -53
- package/src/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -254
- package/src/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -20
- package/src/synthetizer/audio_engine/engine_methods/data_entry/awe32.js +0 -198
- package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -281
- package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -109
- package/src/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
- package/src/synthetizer/audio_engine/engine_methods/note_on.js +0 -220
- package/src/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
- package/src/synthetizer/audio_engine/engine_methods/program_change.js +0 -35
- package/src/synthetizer/audio_engine/engine_methods/render_voice.js +0 -214
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/embedded_sound_bank.js +0 -42
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/update_preset_list.js +0 -19
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -23
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -56
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
- package/src/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -1058
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -23
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -31
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -29
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -26
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
- package/src/synthetizer/audio_engine/main_processor.js +0 -817
- package/src/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -16
- package/src/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
- package/src/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -116
- package/src/synthetizer/audio_engine/synth_processor_options.js +0 -18
- package/src/synthetizer/synth_constants.js +0 -26
- package/src/utils/README.md +0 -8
- package/src/utils/buffer_to_wav.js +0 -197
- package/src/utils/byte_functions/big_endian.js +0 -32
- package/src/utils/byte_functions/little_endian.js +0 -77
- package/src/utils/byte_functions/string.js +0 -92
- package/src/utils/byte_functions/variable_length_quantity.js +0 -42
- package/src/utils/fill_with_defaults.js +0 -21
- package/src/utils/indexed_array.js +0 -34
- package/src/utils/loggin.js +0 -71
- package/src/utils/other.js +0 -92
- package/src/utils/sysex_detector.js +0 -58
- package/src/utils/xg_hacks.js +0 -193
package/src/midi/midi_message.js
DELETED
|
@@ -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,230 +0,0 @@
|
|
|
1
|
-
import { IndexedByteArray } from "../utils/indexed_array.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This is the base type for MIDI files. It contains all the "metadata" and information.
|
|
5
|
-
* It extends to:
|
|
6
|
-
* - BasicMIDI, which contains the actual track data of the MIDI file. Essentially the MIDI file itself.
|
|
7
|
-
* - MIDIData, which contains all properties that MIDI does, except for tracks and the embedded soundfont.
|
|
8
|
-
* MIDIData is the "shell" of the file which is available on the main thread at all times, containing the metadata.
|
|
9
|
-
*/
|
|
10
|
-
class MIDISequenceData
|
|
11
|
-
{
|
|
12
|
-
/**
|
|
13
|
-
* The time division of the sequence, representing the number of ticks per beat.
|
|
14
|
-
* @type {number}
|
|
15
|
-
*/
|
|
16
|
-
timeDivision = 0;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The duration of the sequence, in seconds.
|
|
20
|
-
* @type {number}
|
|
21
|
-
*/
|
|
22
|
-
duration = 0;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The tempo changes in the sequence, ordered from the last change to the first.
|
|
26
|
-
* Each change is represented by an object with a tick position and a tempo value in beats per minute.
|
|
27
|
-
* @type {{ticks: number, tempo: number}[]}
|
|
28
|
-
*/
|
|
29
|
-
tempoChanges = [{ ticks: 0, tempo: 120 }];
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A string containing the copyright information for the MIDI sequence if detected.
|
|
33
|
-
* @type {string}
|
|
34
|
-
*/
|
|
35
|
-
copyright = "";
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The number of tracks in the MIDI sequence.
|
|
39
|
-
* @type {number}
|
|
40
|
-
*/
|
|
41
|
-
tracksAmount = 0;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The track names in the MIDI file, an empty string if not set.
|
|
45
|
-
* @type {string[]}
|
|
46
|
-
*/
|
|
47
|
-
trackNames = [];
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* An array containing the lyrics of the sequence, stored as binary chunks (Uint8Array).
|
|
51
|
-
* @type {Uint8Array[]}
|
|
52
|
-
*/
|
|
53
|
-
lyrics = [];
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* An array of tick positions where lyrics events occur in the sequence.
|
|
57
|
-
* @type {number[]}
|
|
58
|
-
*/
|
|
59
|
-
lyricsTicks = [];
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The tick position of the first note-on event in the MIDI sequence.
|
|
63
|
-
* @type {number}
|
|
64
|
-
*/
|
|
65
|
-
firstNoteOn = 0;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The MIDI key range used in the sequence, represented by a minimum and maximum note value.
|
|
69
|
-
* @type {{min: number, max: number}}
|
|
70
|
-
*/
|
|
71
|
-
keyRange = { min: 0, max: 127 };
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The tick position of the last voice event (such as note-on, note-off, or control change) in the sequence.
|
|
75
|
-
* @type {number}
|
|
76
|
-
*/
|
|
77
|
-
lastVoiceEventTick = 0;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* An array of MIDI port numbers used by each track in the sequence.
|
|
81
|
-
* @type {number[]}
|
|
82
|
-
*/
|
|
83
|
-
midiPorts = [0];
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* An array of channel offsets for each MIDI port, using the SpessaSynth method.
|
|
87
|
-
* @type {number[]}
|
|
88
|
-
*/
|
|
89
|
-
midiPortChannelOffsets = [0];
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* A list of sets, where each set contains the MIDI channels used by each track in the sequence.
|
|
93
|
-
* @type {Set<number>[]}
|
|
94
|
-
*/
|
|
95
|
-
usedChannelsOnTrack = [];
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The loop points (in ticks) of the sequence, including both start and end points.
|
|
99
|
-
* @type {{start: number, end: number}}
|
|
100
|
-
*/
|
|
101
|
-
loop = { start: 0, end: 0 };
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* The name of the MIDI sequence.
|
|
105
|
-
* @type {string}
|
|
106
|
-
*/
|
|
107
|
-
midiName = "";
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* A boolean indicating if the sequence's name is the same as the file name.
|
|
111
|
-
* @type {boolean}
|
|
112
|
-
*/
|
|
113
|
-
midiNameUsesFileName = false;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* The file name of the MIDI sequence, if provided during parsing.
|
|
117
|
-
* @type {string}
|
|
118
|
-
*/
|
|
119
|
-
fileName = "";
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* The raw, encoded MIDI name, represented as a Uint8Array.
|
|
123
|
-
* Useful when the MIDI file uses a different code page.
|
|
124
|
-
* @type {Uint8Array}
|
|
125
|
-
*/
|
|
126
|
-
rawMidiName;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The format of the MIDI file, which can be 0, 1, or 2, indicating the type of the MIDI file.
|
|
130
|
-
* @type {number}
|
|
131
|
-
*/
|
|
132
|
-
format = 0;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* The RMID (Resource-Interchangeable MIDI) info data, if the file is RMID formatted.
|
|
136
|
-
* Otherwise, this field is undefined.
|
|
137
|
-
* Chunk type (e.g. "INAM"): Chunk data as a binary array.
|
|
138
|
-
* @type {Record<string, IndexedByteArray>}
|
|
139
|
-
*/
|
|
140
|
-
RMIDInfo = {};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* The bank offset used for RMID files.
|
|
144
|
-
* @type {number}
|
|
145
|
-
*/
|
|
146
|
-
bankOffset = 0;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* If the MIDI file is a Soft Karaoke file (.kar), this flag is set to true.
|
|
150
|
-
* https://www.mixagesoftware.com/en/midikit/help/HTML/karaoke_formats.html
|
|
151
|
-
* @type {boolean}
|
|
152
|
-
*/
|
|
153
|
-
isKaraokeFile = false;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Indicates if this file is a Multi-Port MIDI file.
|
|
157
|
-
* @type {boolean}
|
|
158
|
-
*/
|
|
159
|
-
isMultiPort = false;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Converts ticks to time in seconds
|
|
163
|
-
* @param ticks {number} time in MIDI ticks
|
|
164
|
-
* @returns {number} time in seconds
|
|
165
|
-
*/
|
|
166
|
-
MIDIticksToSeconds(ticks)
|
|
167
|
-
{
|
|
168
|
-
let totalSeconds = 0;
|
|
169
|
-
|
|
170
|
-
while (ticks > 0)
|
|
171
|
-
{
|
|
172
|
-
// tempo changes are reversed, so the first element is the last tempo change
|
|
173
|
-
// and the last element is the first tempo change
|
|
174
|
-
// (always at tick 0 and tempo 120)
|
|
175
|
-
// find the last tempo change that has occurred
|
|
176
|
-
let tempo = this.tempoChanges.find(v => v.ticks < ticks);
|
|
177
|
-
|
|
178
|
-
// calculate the difference and tempo time
|
|
179
|
-
let timeSinceLastTempo = ticks - tempo.ticks;
|
|
180
|
-
totalSeconds += (timeSinceLastTempo * 60) / (tempo.tempo * this.timeDivision);
|
|
181
|
-
ticks -= timeSinceLastTempo;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return totalSeconds;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* INTERNAL USE ONLY!
|
|
189
|
-
* @param sequence {MIDISequenceData}
|
|
190
|
-
* @protected
|
|
191
|
-
*/
|
|
192
|
-
_copyFromSequence(sequence)
|
|
193
|
-
{
|
|
194
|
-
// properties can be assigned
|
|
195
|
-
this.midiName = sequence.midiName;
|
|
196
|
-
this.midiNameUsesFileName = sequence.midiNameUsesFileName;
|
|
197
|
-
this.fileName = sequence.fileName;
|
|
198
|
-
this.timeDivision = sequence.timeDivision;
|
|
199
|
-
this.duration = sequence.duration;
|
|
200
|
-
this.copyright = sequence.copyright;
|
|
201
|
-
this.tracksAmount = sequence.tracksAmount;
|
|
202
|
-
this.firstNoteOn = sequence.firstNoteOn;
|
|
203
|
-
this.lastVoiceEventTick = sequence.lastVoiceEventTick;
|
|
204
|
-
this.format = sequence.format;
|
|
205
|
-
this.bankOffset = sequence.bankOffset;
|
|
206
|
-
this.isKaraokeFile = sequence.isKaraokeFile;
|
|
207
|
-
this.isMultiPort = sequence.isMultiPort;
|
|
208
|
-
|
|
209
|
-
// copying arrays
|
|
210
|
-
this.tempoChanges = [...sequence.tempoChanges];
|
|
211
|
-
this.lyrics = sequence.lyrics.map(arr => new Uint8Array(arr));
|
|
212
|
-
this.lyricsTicks = [...sequence.lyricsTicks];
|
|
213
|
-
this.midiPorts = [...sequence.midiPorts];
|
|
214
|
-
this.trackNames = [...sequence.trackNames];
|
|
215
|
-
this.midiPortChannelOffsets = [...sequence.midiPortChannelOffsets];
|
|
216
|
-
this.usedChannelsOnTrack = sequence.usedChannelsOnTrack.map(set => new Set(set));
|
|
217
|
-
this.rawMidiName = sequence.rawMidiName ? new Uint8Array(sequence.rawMidiName) : undefined;
|
|
218
|
-
|
|
219
|
-
// copying objects
|
|
220
|
-
this.loop = { ...sequence.loop };
|
|
221
|
-
this.keyRange = { ...sequence.keyRange };
|
|
222
|
-
this.RMIDInfo = {};
|
|
223
|
-
for (const [key, value] of Object.entries(sequence.RMIDInfo))
|
|
224
|
-
{
|
|
225
|
-
this.RMIDInfo[key] = new IndexedByteArray(value);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
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
|
-
}
|