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
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import { Modulator } from "../modulator.js";
|
|
2
|
-
import { Generator } from "../generator.js";
|
|
3
|
-
import { generatorLimits, generatorTypes } from "../generator_types.js";
|
|
4
|
-
import { BasicInstrument } from "../basic_instrument.js";
|
|
5
|
-
|
|
6
|
-
const notGlobalizedTypes = new Set([
|
|
7
|
-
generatorTypes.velRange,
|
|
8
|
-
generatorTypes.keyRange,
|
|
9
|
-
generatorTypes.instrument,
|
|
10
|
-
generatorTypes.exclusiveClass,
|
|
11
|
-
generatorTypes.endOper,
|
|
12
|
-
generatorTypes.sampleModes,
|
|
13
|
-
generatorTypes.startloopAddrsOffset,
|
|
14
|
-
generatorTypes.startloopAddrsCoarseOffset,
|
|
15
|
-
generatorTypes.endloopAddrsOffset,
|
|
16
|
-
generatorTypes.endloopAddrsCoarseOffset,
|
|
17
|
-
generatorTypes.startAddrsOffset,
|
|
18
|
-
generatorTypes.startAddrsCoarseOffset,
|
|
19
|
-
generatorTypes.endAddrOffset,
|
|
20
|
-
generatorTypes.endAddrsCoarseOffset,
|
|
21
|
-
generatorTypes.initialAttenuation, // written into wsmp, there's no global wsmp
|
|
22
|
-
generatorTypes.fineTune, // written into wsmp, there's no global wsmp
|
|
23
|
-
generatorTypes.coarseTune, // written into wsmp, there's no global wsmp
|
|
24
|
-
generatorTypes.keyNumToVolEnvHold, // KEY TO SOMETHING:
|
|
25
|
-
generatorTypes.keyNumToVolEnvDecay,// cannot be globalized as they modify their respective generators
|
|
26
|
-
generatorTypes.keyNumToModEnvHold, // (for example, keyNumToVolEnvDecay modifies VolEnvDecay)
|
|
27
|
-
generatorTypes.keyNumToModEnvDecay
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Combines preset zones
|
|
32
|
-
* @param preset {BasicPreset}
|
|
33
|
-
* @param globalize {boolean}
|
|
34
|
-
* @returns {BasicInstrument}
|
|
35
|
-
*/
|
|
36
|
-
export function combineZones(preset, globalize = true)
|
|
37
|
-
{
|
|
38
|
-
/**
|
|
39
|
-
* @param main {Generator[]}
|
|
40
|
-
* @param adder {Generator[]}
|
|
41
|
-
*/
|
|
42
|
-
function addUnique(main, adder)
|
|
43
|
-
{
|
|
44
|
-
main.push(...adder.filter(g => !main.find(mg => mg.generatorType === g.generatorType)));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @param r1 {SoundFontRange}
|
|
49
|
-
* @param r2 {SoundFontRange}
|
|
50
|
-
* @returns {SoundFontRange}
|
|
51
|
-
*/
|
|
52
|
-
function subtractRanges(r1, r2)
|
|
53
|
-
{
|
|
54
|
-
return { min: Math.max(r1.min, r2.min), max: Math.min(r1.max, r2.max) };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param main {Modulator[]}
|
|
59
|
-
* @param adder {Modulator[]}
|
|
60
|
-
*/
|
|
61
|
-
function addUniqueMods(main, adder)
|
|
62
|
-
{
|
|
63
|
-
main.push(...adder.filter(m => !main.find(mm => Modulator.isIdentical(m, mm))));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const outputInstrument = new BasicInstrument();
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @type {Generator[]}
|
|
70
|
-
*/
|
|
71
|
-
const globalPresetGenerators = [];
|
|
72
|
-
/**
|
|
73
|
-
* @type {Modulator[]}
|
|
74
|
-
*/
|
|
75
|
-
const globalPresetModulators = [];
|
|
76
|
-
// find the global zone and apply ranges, generators, and modulators
|
|
77
|
-
const globalPresetZone = preset.globalZone;
|
|
78
|
-
globalPresetGenerators.push(...globalPresetZone.generators);
|
|
79
|
-
globalPresetModulators.push(...globalPresetZone.modulators);
|
|
80
|
-
let globalPresetKeyRange = globalPresetZone.keyRange;
|
|
81
|
-
let globalPresetVelRange = globalPresetZone.velRange;
|
|
82
|
-
// for each non-global preset zone
|
|
83
|
-
for (const presetZone of preset.presetZones)
|
|
84
|
-
{
|
|
85
|
-
// use global ranges if not provided
|
|
86
|
-
let presetZoneKeyRange = presetZone.keyRange;
|
|
87
|
-
if (!presetZone.hasKeyRange)
|
|
88
|
-
{
|
|
89
|
-
presetZoneKeyRange = globalPresetKeyRange;
|
|
90
|
-
}
|
|
91
|
-
let presetZoneVelRange = presetZone.velRange;
|
|
92
|
-
if (!presetZone.hasVelRange)
|
|
93
|
-
{
|
|
94
|
-
presetZoneVelRange = globalPresetVelRange;
|
|
95
|
-
}
|
|
96
|
-
// add unique generators and modulators from the global zone
|
|
97
|
-
const presetGenerators = presetZone.generators.map(g => new Generator(g.generatorType, g.generatorValue));
|
|
98
|
-
addUnique(presetGenerators, globalPresetGenerators);
|
|
99
|
-
const presetModulators = [...presetZone.modulators];
|
|
100
|
-
addUniqueMods(presetModulators, globalPresetModulators);
|
|
101
|
-
const instrument = presetZone.instrument;
|
|
102
|
-
const iZones = instrument.instrumentZones;
|
|
103
|
-
/**
|
|
104
|
-
* @type {Generator[]}
|
|
105
|
-
*/
|
|
106
|
-
const globalInstGenerators = [];
|
|
107
|
-
/**
|
|
108
|
-
* @type {Modulator[]}
|
|
109
|
-
*/
|
|
110
|
-
const globalInstModulators = [];
|
|
111
|
-
const globalInstZone = instrument.globalZone;
|
|
112
|
-
globalInstGenerators.push(...globalInstZone.generators);
|
|
113
|
-
globalInstModulators.push(...globalInstZone.modulators);
|
|
114
|
-
let globalInstKeyRange = globalInstZone.keyRange;
|
|
115
|
-
let globalInstVelRange = globalInstZone.velRange;
|
|
116
|
-
// for each non-global instrument zone
|
|
117
|
-
for (const instZone of iZones)
|
|
118
|
-
{
|
|
119
|
-
// use global ranges if not provided
|
|
120
|
-
let instZoneKeyRange = instZone.keyRange;
|
|
121
|
-
if (!instZone.hasKeyRange)
|
|
122
|
-
{
|
|
123
|
-
instZoneKeyRange = globalInstKeyRange;
|
|
124
|
-
}
|
|
125
|
-
let instZoneVelRange = instZone.velRange;
|
|
126
|
-
if (!instZone.hasVelRange)
|
|
127
|
-
{
|
|
128
|
-
instZoneVelRange = globalInstVelRange;
|
|
129
|
-
}
|
|
130
|
-
instZoneKeyRange = subtractRanges(instZoneKeyRange, presetZoneKeyRange);
|
|
131
|
-
instZoneVelRange = subtractRanges(instZoneVelRange, presetZoneVelRange);
|
|
132
|
-
|
|
133
|
-
// if either of the zones is out of range (i.e.m min larger than the max),
|
|
134
|
-
// then we discard that zone
|
|
135
|
-
if (instZoneKeyRange.max < instZoneKeyRange.min || instZoneVelRange.max < instZoneVelRange.min)
|
|
136
|
-
{
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// add unique generators and modulators from the global zone
|
|
141
|
-
const instGenerators = instZone.generators.map(g => new Generator(g.generatorType, g.generatorValue));
|
|
142
|
-
addUnique(instGenerators, globalInstGenerators);
|
|
143
|
-
const instModulators = [...instZone.modulators];
|
|
144
|
-
addUniqueMods(instModulators, globalInstModulators);
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* sum preset modulators to instruments (amount) sf spec page 54
|
|
148
|
-
* @type {Modulator[]}
|
|
149
|
-
*/
|
|
150
|
-
const finalModList = [...instModulators];
|
|
151
|
-
for (const mod of presetModulators)
|
|
152
|
-
{
|
|
153
|
-
const identicalInstMod = finalModList.findIndex(
|
|
154
|
-
m => Modulator.isIdentical(mod, m));
|
|
155
|
-
if (identicalInstMod !== -1)
|
|
156
|
-
{
|
|
157
|
-
// sum the amounts
|
|
158
|
-
// (this makes a new modulator
|
|
159
|
-
// because otherwise it would overwrite the one in the soundfont!
|
|
160
|
-
finalModList[identicalInstMod] = finalModList[identicalInstMod].sumTransform(
|
|
161
|
-
mod);
|
|
162
|
-
}
|
|
163
|
-
else
|
|
164
|
-
{
|
|
165
|
-
finalModList.push(mod);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// clone the generators as the values are modified during DLS conversion (keyNumToSomething)
|
|
170
|
-
let finalGenList = instGenerators.map(g => new Generator(g.generatorType, g.generatorValue));
|
|
171
|
-
for (const gen of presetGenerators)
|
|
172
|
-
{
|
|
173
|
-
if (gen.generatorType === generatorTypes.velRange ||
|
|
174
|
-
gen.generatorType === generatorTypes.keyRange ||
|
|
175
|
-
gen.generatorType === generatorTypes.instrument ||
|
|
176
|
-
gen.generatorType === generatorTypes.endOper ||
|
|
177
|
-
gen.generatorType === generatorTypes.sampleModes)
|
|
178
|
-
{
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const identicalInstGen = instGenerators.findIndex(g => g.generatorType === gen.generatorType);
|
|
182
|
-
if (identicalInstGen !== -1)
|
|
183
|
-
{
|
|
184
|
-
// if exists, sum to that generator
|
|
185
|
-
const newAmount = finalGenList[identicalInstGen].generatorValue + gen.generatorValue;
|
|
186
|
-
finalGenList[identicalInstGen] = new Generator(gen.generatorType, newAmount);
|
|
187
|
-
}
|
|
188
|
-
else
|
|
189
|
-
{
|
|
190
|
-
// if not, sum to the default generator
|
|
191
|
-
const newAmount = generatorLimits[gen.generatorType].def + gen.generatorValue;
|
|
192
|
-
finalGenList.push(new Generator(gen.generatorType, newAmount));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// remove unwanted
|
|
197
|
-
finalGenList = finalGenList.filter(g =>
|
|
198
|
-
g.generatorType !== generatorTypes.sampleID &&
|
|
199
|
-
g.generatorType !== generatorTypes.keyRange &&
|
|
200
|
-
g.generatorType !== generatorTypes.velRange &&
|
|
201
|
-
g.generatorType !== generatorTypes.endOper &&
|
|
202
|
-
g.generatorType !== generatorTypes.instrument &&
|
|
203
|
-
g.generatorValue !== generatorLimits[g.generatorType].def
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
// create the zone and copy over values
|
|
207
|
-
const zone = outputInstrument.createZone();
|
|
208
|
-
zone.keyRange = instZoneKeyRange;
|
|
209
|
-
zone.velRange = instZoneVelRange;
|
|
210
|
-
if (zone.keyRange.min === 0 && zone.keyRange.max === 127)
|
|
211
|
-
{
|
|
212
|
-
zone.keyRange.min = -1;
|
|
213
|
-
}
|
|
214
|
-
if (zone.velRange.min === 0 && zone.velRange.max === 127)
|
|
215
|
-
{
|
|
216
|
-
zone.velRange.min = -1;
|
|
217
|
-
}
|
|
218
|
-
zone.setSample(instZone.sample);
|
|
219
|
-
zone.addGenerators(...finalGenList);
|
|
220
|
-
zone.addModulators(...finalModList);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const globalZone = outputInstrument.globalZone;
|
|
224
|
-
if (globalize)
|
|
225
|
-
{
|
|
226
|
-
// create a global zone and add repeating generators to it
|
|
227
|
-
// also modulators
|
|
228
|
-
// iterate over every type of generator
|
|
229
|
-
for (let checkedType = 0; checkedType < 58; checkedType++)
|
|
230
|
-
{
|
|
231
|
-
// not these though
|
|
232
|
-
if (notGlobalizedTypes.has(checkedType))
|
|
233
|
-
{
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* @type {Record<string, number>}
|
|
238
|
-
*/
|
|
239
|
-
let occurencesForValues = {};
|
|
240
|
-
const defaultForChecked = generatorLimits[checkedType]?.def || 0;
|
|
241
|
-
occurencesForValues[defaultForChecked] = 0;
|
|
242
|
-
for (const z of outputInstrument.instrumentZones)
|
|
243
|
-
{
|
|
244
|
-
const gen = z.generators.find(g => g.generatorType === checkedType);
|
|
245
|
-
if (gen)
|
|
246
|
-
{
|
|
247
|
-
const value = gen.generatorValue;
|
|
248
|
-
if (occurencesForValues[value] === undefined)
|
|
249
|
-
{
|
|
250
|
-
occurencesForValues[value] = 1;
|
|
251
|
-
}
|
|
252
|
-
else
|
|
253
|
-
{
|
|
254
|
-
occurencesForValues[value]++;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
else
|
|
258
|
-
{
|
|
259
|
-
occurencesForValues[defaultForChecked]++;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// if the checked type has the keyNumTo something generator set, it cannot be globalized.
|
|
263
|
-
let relativeCounterpart;
|
|
264
|
-
switch (checkedType)
|
|
265
|
-
{
|
|
266
|
-
default:
|
|
267
|
-
continue;
|
|
268
|
-
|
|
269
|
-
case generatorTypes.decayVolEnv:
|
|
270
|
-
relativeCounterpart = generatorTypes.keyNumToVolEnvDecay;
|
|
271
|
-
break;
|
|
272
|
-
case generatorTypes.holdVolEnv:
|
|
273
|
-
relativeCounterpart = generatorTypes.keyNumToVolEnvHold;
|
|
274
|
-
break;
|
|
275
|
-
case generatorTypes.decayModEnv:
|
|
276
|
-
relativeCounterpart = generatorTypes.keyNumToModEnvDecay;
|
|
277
|
-
break;
|
|
278
|
-
case generatorTypes.holdModEnv:
|
|
279
|
-
relativeCounterpart = generatorTypes.keyNumToModEnvHold;
|
|
280
|
-
}
|
|
281
|
-
const relative = z.generators.find(g => g.generatorType === relativeCounterpart);
|
|
282
|
-
if (relative !== undefined)
|
|
283
|
-
{
|
|
284
|
-
occurencesForValues = {};
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
// if at least one occurrence, find the most used one and add it to global
|
|
289
|
-
if (Object.keys(occurencesForValues).length > 0)
|
|
290
|
-
{
|
|
291
|
-
// [value, occurrences]
|
|
292
|
-
const valueToGlobalize = Object.entries(occurencesForValues).reduce((max, curr) =>
|
|
293
|
-
{
|
|
294
|
-
if (max[1] < curr[1])
|
|
295
|
-
{
|
|
296
|
-
return curr;
|
|
297
|
-
}
|
|
298
|
-
return max;
|
|
299
|
-
}, [0, 0]);
|
|
300
|
-
const targetValue = parseInt(valueToGlobalize[0]);
|
|
301
|
-
|
|
302
|
-
// if the global value is the default value just remove it, no need to add it
|
|
303
|
-
if (targetValue !== defaultForChecked)
|
|
304
|
-
{
|
|
305
|
-
globalZone.addGenerators(new Generator(checkedType, targetValue));
|
|
306
|
-
}
|
|
307
|
-
// remove from the zones
|
|
308
|
-
outputInstrument.instrumentZones.forEach(z =>
|
|
309
|
-
{
|
|
310
|
-
const gen = z.generators.findIndex(g =>
|
|
311
|
-
g.generatorType === checkedType);
|
|
312
|
-
if (gen !== -1)
|
|
313
|
-
{
|
|
314
|
-
if (z.generators[gen].generatorValue === targetValue)
|
|
315
|
-
{
|
|
316
|
-
// That exact value exists. Since it's global now, remove it
|
|
317
|
-
z.generators.splice(gen, 1);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else
|
|
321
|
-
{
|
|
322
|
-
// That type does not exist at all here.
|
|
323
|
-
// Since we're globalizing, we need to add the default here.
|
|
324
|
-
if (targetValue !== defaultForChecked)
|
|
325
|
-
{
|
|
326
|
-
z.addGenerators(new Generator(checkedType, defaultForChecked));
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// globalize only modulators that exist in all zones
|
|
334
|
-
const firstZone = outputInstrument.instrumentZones[0];
|
|
335
|
-
const modulators = firstZone.modulators.map(m => Modulator.copy(m));
|
|
336
|
-
for (const checkedModulator of modulators)
|
|
337
|
-
{
|
|
338
|
-
let existsForAllZones = true;
|
|
339
|
-
for (const zone of outputInstrument.instrumentZones)
|
|
340
|
-
{
|
|
341
|
-
if (!existsForAllZones)
|
|
342
|
-
{
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
// check if that zone has an existing modulator
|
|
346
|
-
const mod = zone.modulators.find(m => Modulator.isIdentical(m, checkedModulator));
|
|
347
|
-
if (!mod)
|
|
348
|
-
{
|
|
349
|
-
// does not exist for this zone, so it's not global.
|
|
350
|
-
existsForAllZones = false;
|
|
351
|
-
}
|
|
352
|
-
// exists.
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
if (existsForAllZones === true)
|
|
356
|
-
{
|
|
357
|
-
globalZone.addModulators(Modulator.copy(checkedModulator));
|
|
358
|
-
// delete it from local zones.
|
|
359
|
-
for (const zone of outputInstrument.instrumentZones)
|
|
360
|
-
{
|
|
361
|
-
const modulator = zone.modulators.find(m => Modulator.isIdentical(m, checkedModulator));
|
|
362
|
-
// Check if the amount is correct.
|
|
363
|
-
// If so, delete it since it's global.
|
|
364
|
-
// If not, then it will simply override global as it's identical.
|
|
365
|
-
if (modulator.transformAmount === checkedModulator.transformAmount)
|
|
366
|
-
{
|
|
367
|
-
zone.modulators.splice(zone.modulators.indexOf(modulator), 1);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return outputInstrument;
|
|
374
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { IndexedByteArray } from "../../../utils/indexed_array.js";
|
|
2
|
-
import { combineZones } from "./combine_zones.js";
|
|
3
|
-
import { writeRIFFChunkParts, writeRIFFChunkRaw } from "../riff_chunk.js";
|
|
4
|
-
import { writeDword } from "../../../utils/byte_functions/little_endian.js";
|
|
5
|
-
import { writeDLSRegion } from "./rgn2.js";
|
|
6
|
-
import { writeArticulator } from "./art2.js";
|
|
7
|
-
import { SpessaSynthGroupCollapsed, SpessaSynthGroupEnd } from "../../../utils/loggin.js";
|
|
8
|
-
import { consoleColors } from "../../../utils/other.js";
|
|
9
|
-
import { getStringBytes } from "../../../utils/byte_functions/string.js";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @this {BasicSoundBank}
|
|
13
|
-
* @param preset {BasicPreset}
|
|
14
|
-
* @returns {IndexedByteArray}
|
|
15
|
-
*/
|
|
16
|
-
export function writeIns(preset)
|
|
17
|
-
{
|
|
18
|
-
SpessaSynthGroupCollapsed(
|
|
19
|
-
`%cWriting %c${preset.presetName}%c...`,
|
|
20
|
-
consoleColors.info,
|
|
21
|
-
consoleColors.recognized,
|
|
22
|
-
consoleColors.info
|
|
23
|
-
);
|
|
24
|
-
// combine preset and instrument zones into a single instrument zone (region) list
|
|
25
|
-
const inst = combineZones(preset);
|
|
26
|
-
const global = inst.globalZone;
|
|
27
|
-
const zones = inst.instrumentZones;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// insh: instrument header
|
|
31
|
-
const inshData = new IndexedByteArray(12);
|
|
32
|
-
writeDword(inshData, zones.length); // cRegions
|
|
33
|
-
// bank MSB is in bits 8-14
|
|
34
|
-
let ulBank = (preset.bank & 127) << 8;
|
|
35
|
-
// bit 32 means drums
|
|
36
|
-
if (preset.bank === 128)
|
|
37
|
-
{
|
|
38
|
-
ulBank |= (1 << 31);
|
|
39
|
-
}
|
|
40
|
-
writeDword(inshData, ulBank); // ulBank
|
|
41
|
-
writeDword(inshData, preset.program & 127); // ulInstrument
|
|
42
|
-
|
|
43
|
-
const insh = writeRIFFChunkRaw(
|
|
44
|
-
"insh",
|
|
45
|
-
inshData
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// write global zone
|
|
49
|
-
const art2 = writeArticulator(global);
|
|
50
|
-
let lar2 = writeRIFFChunkRaw(
|
|
51
|
-
"lar2",
|
|
52
|
-
art2,
|
|
53
|
-
false,
|
|
54
|
-
true
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// write the region list
|
|
58
|
-
const lrgn = writeRIFFChunkParts(
|
|
59
|
-
"lrgn",
|
|
60
|
-
zones.reduce((arrs, z) =>
|
|
61
|
-
{
|
|
62
|
-
arrs.push(writeDLSRegion.apply(this, [z, global]));
|
|
63
|
-
return arrs;
|
|
64
|
-
}, []),
|
|
65
|
-
true
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// writeINFO
|
|
69
|
-
const inam = writeRIFFChunkRaw(
|
|
70
|
-
"INAM",
|
|
71
|
-
getStringBytes(preset.presetName, true)
|
|
72
|
-
);
|
|
73
|
-
const info = writeRIFFChunkRaw(
|
|
74
|
-
"INFO",
|
|
75
|
-
inam,
|
|
76
|
-
false,
|
|
77
|
-
true
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
SpessaSynthGroupEnd();
|
|
81
|
-
return writeRIFFChunkParts(
|
|
82
|
-
"ins ", [insh, lrgn, lar2, info],
|
|
83
|
-
true
|
|
84
|
-
);
|
|
85
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { writeRIFFChunkParts } from "../riff_chunk.js";
|
|
2
|
-
import { writeIns } from "./ins.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @this {BasicSoundBank}
|
|
6
|
-
* @returns {IndexedByteArray}
|
|
7
|
-
*/
|
|
8
|
-
export function writeLins()
|
|
9
|
-
{
|
|
10
|
-
return writeRIFFChunkParts(
|
|
11
|
-
"lins",
|
|
12
|
-
this.presets.map(p => writeIns.apply(this, [p])),
|
|
13
|
-
true
|
|
14
|
-
);
|
|
15
|
-
}
|