spessasynth_core 1.1.2 → 1.1.4
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/LICENSE +3 -26
- package/README.md +156 -474
- package/index.js +73 -8
- package/package.json +21 -8
- package/src/externals/fflate/LICENSE +21 -0
- package/src/externals/fflate/fflate.min.js +1 -0
- package/src/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +12 -0
- package/src/externals/stbvorbis_sync/LICENSE +202 -0
- package/src/externals/stbvorbis_sync/NOTICE +6 -0
- package/src/externals/stbvorbis_sync/stbvorbis_sync.min.js +1 -0
- package/src/midi/README.md +32 -0
- package/src/midi/basic_midi.js +567 -0
- package/src/midi/midi_builder.js +202 -0
- package/src/midi/midi_loader.js +324 -0
- package/{spessasynth_core/midi_parser → src/midi}/midi_message.js +58 -35
- package/src/midi/midi_sequence.js +224 -0
- package/src/midi/midi_tools/get_note_times.js +154 -0
- package/src/midi/midi_tools/midi_editor.js +611 -0
- package/src/midi/midi_tools/midi_writer.js +99 -0
- package/src/midi/midi_tools/rmidi_writer.js +567 -0
- package/src/midi/midi_tools/used_keys_loaded.js +238 -0
- package/src/midi/xmf_loader.js +454 -0
- package/src/sequencer/README.md +5 -0
- package/src/sequencer/events.js +81 -0
- package/src/sequencer/play.js +349 -0
- package/src/sequencer/process_event.js +165 -0
- package/{spessasynth_core/sequencer/worklet_sequencer → src/sequencer}/process_tick.js +103 -84
- package/src/sequencer/sequencer_engine.js +367 -0
- package/src/sequencer/song_control.js +201 -0
- package/src/soundfont/README.md +13 -0
- package/src/soundfont/basic_soundfont/basic_instrument.js +77 -0
- package/src/soundfont/basic_soundfont/basic_preset.js +336 -0
- package/src/soundfont/basic_soundfont/basic_sample.js +206 -0
- package/src/soundfont/basic_soundfont/basic_soundfont.js +565 -0
- package/src/soundfont/basic_soundfont/basic_zone.js +64 -0
- package/src/soundfont/basic_soundfont/basic_zones.js +43 -0
- package/src/soundfont/basic_soundfont/generator.js +220 -0
- package/src/soundfont/basic_soundfont/modulator.js +378 -0
- package/src/soundfont/basic_soundfont/riff_chunk.js +149 -0
- package/src/soundfont/basic_soundfont/write_dls/art2.js +173 -0
- package/src/soundfont/basic_soundfont/write_dls/articulator.js +49 -0
- package/src/soundfont/basic_soundfont/write_dls/combine_zones.js +400 -0
- package/src/soundfont/basic_soundfont/write_dls/ins.js +103 -0
- package/src/soundfont/basic_soundfont/write_dls/lins.js +18 -0
- package/src/soundfont/basic_soundfont/write_dls/modulator_converter.js +330 -0
- package/src/soundfont/basic_soundfont/write_dls/rgn2.js +121 -0
- package/src/soundfont/basic_soundfont/write_dls/wave.js +94 -0
- package/src/soundfont/basic_soundfont/write_dls/write_dls.js +119 -0
- package/src/soundfont/basic_soundfont/write_dls/wsmp.js +78 -0
- package/src/soundfont/basic_soundfont/write_dls/wvpl.js +32 -0
- package/src/soundfont/basic_soundfont/write_sf2/ibag.js +39 -0
- package/src/soundfont/basic_soundfont/write_sf2/igen.js +80 -0
- package/src/soundfont/basic_soundfont/write_sf2/imod.js +46 -0
- package/src/soundfont/basic_soundfont/write_sf2/inst.js +34 -0
- package/src/soundfont/basic_soundfont/write_sf2/pbag.js +39 -0
- package/src/soundfont/basic_soundfont/write_sf2/pgen.js +82 -0
- package/src/soundfont/basic_soundfont/write_sf2/phdr.js +42 -0
- package/src/soundfont/basic_soundfont/write_sf2/pmod.js +46 -0
- package/src/soundfont/basic_soundfont/write_sf2/sdta.js +80 -0
- package/src/soundfont/basic_soundfont/write_sf2/shdr.js +55 -0
- package/src/soundfont/basic_soundfont/write_sf2/write.js +222 -0
- package/src/soundfont/dls/articulator_converter.js +396 -0
- package/src/soundfont/dls/dls_destinations.js +38 -0
- package/src/soundfont/dls/dls_preset.js +44 -0
- package/src/soundfont/dls/dls_sample.js +75 -0
- package/src/soundfont/dls/dls_soundfont.js +186 -0
- package/src/soundfont/dls/dls_sources.js +62 -0
- package/src/soundfont/dls/dls_zone.js +95 -0
- package/src/soundfont/dls/read_articulation.js +299 -0
- package/src/soundfont/dls/read_instrument.js +121 -0
- package/src/soundfont/dls/read_instrument_list.js +17 -0
- package/src/soundfont/dls/read_lart.js +35 -0
- package/src/soundfont/dls/read_region.js +152 -0
- package/src/soundfont/dls/read_samples.js +270 -0
- package/src/soundfont/load_soundfont.js +21 -0
- package/src/soundfont/read_sf2/generators.js +46 -0
- package/{spessasynth_core/soundfont/chunk → src/soundfont/read_sf2}/instruments.js +20 -14
- package/src/soundfont/read_sf2/modulators.js +36 -0
- package/src/soundfont/read_sf2/presets.js +80 -0
- package/src/soundfont/read_sf2/samples.js +304 -0
- package/src/soundfont/read_sf2/soundfont.js +305 -0
- package/{spessasynth_core/soundfont/chunk → src/soundfont/read_sf2}/zones.js +68 -69
- package/src/synthetizer/README.md +7 -0
- package/src/synthetizer/audio_engine/README.md +9 -0
- package/src/synthetizer/audio_engine/engine_components/compute_modulator.js +266 -0
- package/src/synthetizer/audio_engine/engine_components/controller_tables.js +88 -0
- package/src/synthetizer/audio_engine/engine_components/key_modifier_manager.js +150 -0
- package/{spessasynth_core/synthetizer/worklet_system/worklet_utilities → src/synthetizer/audio_engine/engine_components}/lfo.js +9 -6
- package/src/synthetizer/audio_engine/engine_components/lowpass_filter.js +282 -0
- package/src/synthetizer/audio_engine/engine_components/midi_audio_channel.js +467 -0
- package/src/synthetizer/audio_engine/engine_components/modulation_envelope.js +181 -0
- package/{spessasynth_core/synthetizer/worklet_system/worklet_utilities → src/synthetizer/audio_engine/engine_components}/modulator_curves.js +33 -30
- package/src/synthetizer/audio_engine/engine_components/soundfont_manager.js +221 -0
- package/src/synthetizer/audio_engine/engine_components/stereo_panner.js +120 -0
- package/{spessasynth_core/synthetizer/worklet_system/worklet_utilities → src/synthetizer/audio_engine/engine_components}/unit_converter.js +11 -4
- package/src/synthetizer/audio_engine/engine_components/voice.js +519 -0
- package/src/synthetizer/audio_engine/engine_components/volume_envelope.js +401 -0
- package/src/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +263 -0
- package/src/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +132 -0
- package/src/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +48 -0
- package/src/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +241 -0
- package/src/synthetizer/audio_engine/engine_methods/create_midi_channel.js +27 -0
- package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +253 -0
- package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +66 -0
- package/src/synthetizer/audio_engine/engine_methods/mute_channel.js +17 -0
- package/src/synthetizer/audio_engine/engine_methods/note_on.js +175 -0
- package/src/synthetizer/audio_engine/engine_methods/portamento_time.js +92 -0
- package/src/synthetizer/audio_engine/engine_methods/program_change.js +61 -0
- package/src/synthetizer/audio_engine/engine_methods/render_voice.js +196 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/clear_sound_font.js +30 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +22 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/reload_sound_font.js +28 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/send_preset_list.js +31 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js +21 -0
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +20 -0
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +55 -0
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +16 -0
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +30 -0
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +63 -0
- package/src/synthetizer/audio_engine/engine_methods/system_exclusive.js +776 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +24 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +33 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +31 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +15 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +27 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +19 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +27 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +15 -0
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +34 -0
- package/src/synthetizer/audio_engine/main_processor.js +804 -0
- package/src/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +15 -0
- package/src/synthetizer/audio_engine/snapshot/channel_snapshot.js +175 -0
- package/src/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +116 -0
- package/src/synthetizer/synth_constants.js +22 -0
- package/{spessasynth_core → src}/utils/README.md +1 -0
- package/src/utils/buffer_to_wav.js +185 -0
- package/src/utils/byte_functions/big_endian.js +32 -0
- package/src/utils/byte_functions/little_endian.js +77 -0
- package/src/utils/byte_functions/string.js +107 -0
- package/src/utils/byte_functions/variable_length_quantity.js +42 -0
- package/src/utils/fill_with_defaults.js +21 -0
- package/src/utils/indexed_array.js +52 -0
- package/{spessasynth_core → src}/utils/loggin.js +70 -78
- package/src/utils/other.js +92 -0
- package/src/utils/sysex_detector.js +58 -0
- package/src/utils/xg_hacks.js +193 -0
- package/.idea/inspectionProfiles/Project_Default.xml +0 -10
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/spessasynth_core.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/spessasynth_core/midi_parser/README.md +0 -3
- package/spessasynth_core/midi_parser/midi_loader.js +0 -386
- package/spessasynth_core/sequencer/sequencer.js +0 -202
- package/spessasynth_core/sequencer/worklet_sequencer/play.js +0 -209
- package/spessasynth_core/sequencer/worklet_sequencer/process_event.js +0 -120
- package/spessasynth_core/sequencer/worklet_sequencer/song_control.js +0 -112
- package/spessasynth_core/soundfont/README.md +0 -4
- package/spessasynth_core/soundfont/chunk/generators.js +0 -205
- package/spessasynth_core/soundfont/chunk/modulators.js +0 -232
- package/spessasynth_core/soundfont/chunk/presets.js +0 -264
- package/spessasynth_core/soundfont/chunk/riff_chunk.js +0 -46
- package/spessasynth_core/soundfont/chunk/samples.js +0 -250
- package/spessasynth_core/soundfont/soundfont_parser.js +0 -301
- package/spessasynth_core/synthetizer/README.md +0 -6
- package/spessasynth_core/synthetizer/synthesizer.js +0 -303
- package/spessasynth_core/synthetizer/worklet_system/README.md +0 -3
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/controller_control.js +0 -290
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/data_entry.js +0 -280
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/note_off.js +0 -102
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/note_on.js +0 -77
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/program_control.js +0 -140
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/system_exclusive.js +0 -266
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/tuning_control.js +0 -104
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/vibrato_control.js +0 -29
- package/spessasynth_core/synthetizer/worklet_system/worklet_methods/voice_control.js +0 -222
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js +0 -95
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/modulation_envelope.js +0 -73
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/stereo_panner.js +0 -76
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/volume_envelope.js +0 -194
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/wavetable_oscillator.js +0 -83
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/worklet_modulator.js +0 -173
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +0 -106
- package/spessasynth_core/synthetizer/worklet_system/worklet_utilities/worklet_voice.js +0 -313
- package/spessasynth_core/utils/buffer_to_wav.js +0 -70
- package/spessasynth_core/utils/byte_functions.js +0 -141
- package/spessasynth_core/utils/other.js +0 -49
- package/spessasynth_core/utils/shiftable_array.js +0 -26
- package/spessasynth_core/utils/stbvorbis_sync.js +0 -1877
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @this {SpessaSynthProcessor}
|
|
3
|
+
*/
|
|
4
|
+
export function sendPresetList()
|
|
5
|
+
{
|
|
6
|
+
/**
|
|
7
|
+
* @type {{bank: number, presetName: string, program: number}[]}
|
|
8
|
+
*/
|
|
9
|
+
const mainFont = this.soundfontManager.getPresetList();
|
|
10
|
+
if (this.overrideSoundfont !== undefined)
|
|
11
|
+
{
|
|
12
|
+
this.overrideSoundfont.presets.forEach(p =>
|
|
13
|
+
{
|
|
14
|
+
const bankCheck = p.bank === 128 ? 128 : p.bank + this.soundfontBankOffset;
|
|
15
|
+
const exists = mainFont.find(pr => pr.bank === bankCheck && pr.program === p.program);
|
|
16
|
+
if (exists !== undefined)
|
|
17
|
+
{
|
|
18
|
+
exists.presetName = p.presetName;
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
{
|
|
22
|
+
mainFont.push({
|
|
23
|
+
presetName: p.presetName,
|
|
24
|
+
bank: bankCheck,
|
|
25
|
+
program: p.program
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
this.callEvent("presetlistchange", mainFont);
|
|
31
|
+
}
|
package/src/synthetizer/audio_engine/engine_methods/soundfont_management/set_embedded_sound_font.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the embedded (RMI soundfont)
|
|
3
|
+
* @param font {ArrayBuffer}
|
|
4
|
+
* @param offset {number}
|
|
5
|
+
* @this {SpessaSynthProcessor}
|
|
6
|
+
*/
|
|
7
|
+
export function setEmbeddedSoundFont(font, offset)
|
|
8
|
+
{
|
|
9
|
+
// set offset
|
|
10
|
+
this.soundfontBankOffset = offset;
|
|
11
|
+
this.reloadSoundFont(font, true);
|
|
12
|
+
// preload all samples
|
|
13
|
+
this.overrideSoundfont.samples.forEach(s => s.getAudioData());
|
|
14
|
+
|
|
15
|
+
// apply snapshot again if applicable
|
|
16
|
+
if (this._snapshot !== undefined)
|
|
17
|
+
{
|
|
18
|
+
this.applySynthesizerSnapshot(this._snapshot);
|
|
19
|
+
this.resetAllControllers();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { generatorTypes } from "../../../../soundfont/basic_soundfont/generator.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stops a note nearly instantly
|
|
5
|
+
* @param midiNote {number}
|
|
6
|
+
* @param releaseTime {number} ticks
|
|
7
|
+
* @this {MidiAudioChannel}
|
|
8
|
+
*/
|
|
9
|
+
export function killNote(midiNote, releaseTime = -12000)
|
|
10
|
+
{
|
|
11
|
+
this.voices.forEach(v =>
|
|
12
|
+
{
|
|
13
|
+
if (v.realKey !== midiNote)
|
|
14
|
+
{
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
v.modulatedGenerators[generatorTypes.releaseVolEnv] = releaseTime; // set release to be very short
|
|
18
|
+
v.release(this.synth.currentSynthTime);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SpessaSynthWarn } from "../../../../utils/loggin.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Release a note
|
|
5
|
+
* @param midiNote {number}
|
|
6
|
+
* @this {MidiAudioChannel}
|
|
7
|
+
*/
|
|
8
|
+
export function noteOff(midiNote)
|
|
9
|
+
{
|
|
10
|
+
if (midiNote > 127 || midiNote < 0)
|
|
11
|
+
{
|
|
12
|
+
SpessaSynthWarn(`Received a noteOn for note`, midiNote, "Ignoring.");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let realKey = midiNote + this.channelTransposeKeyShift;
|
|
17
|
+
|
|
18
|
+
// if high performance mode, kill notes instead of stopping them
|
|
19
|
+
if (this.synth.highPerformanceMode)
|
|
20
|
+
{
|
|
21
|
+
// if the channel is percussion channel, do not kill the notes
|
|
22
|
+
if (!this.drumChannel)
|
|
23
|
+
{
|
|
24
|
+
this.killNote(realKey, -6950);
|
|
25
|
+
this.synth.callEvent("noteoff", {
|
|
26
|
+
midiNote: midiNote,
|
|
27
|
+
channel: this.channelNumber
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const channelVoices = this.voices;
|
|
34
|
+
channelVoices.forEach(v =>
|
|
35
|
+
{
|
|
36
|
+
if (v.realKey !== realKey || v.isInRelease === true)
|
|
37
|
+
{
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// if hold pedal, move to sustain
|
|
41
|
+
if (this.holdPedal)
|
|
42
|
+
{
|
|
43
|
+
this.sustainedVoices.push(v);
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
{
|
|
47
|
+
v.release(this.synth.currentSynthTime);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
this.synth.callEvent("noteoff", {
|
|
51
|
+
midiNote: midiNote,
|
|
52
|
+
channel: this.channelNumber
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SpessaSynthInfo } from "../../../../utils/loggin.js";
|
|
2
|
+
import { consoleColors } from "../../../../utils/other.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @this {SpessaSynthProcessor}
|
|
6
|
+
* @param force {boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function stopAllChannels(force = false)
|
|
9
|
+
{
|
|
10
|
+
SpessaSynthInfo("%cStop all received!", consoleColors.info);
|
|
11
|
+
for (let i = 0; i < this.midiAudioChannels.length; i++)
|
|
12
|
+
{
|
|
13
|
+
this.midiAudioChannels[i].stopAllNotes(force);
|
|
14
|
+
}
|
|
15
|
+
this.callEvent("stopall", undefined);
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stops all notes on a given channel
|
|
3
|
+
* @param force {boolean}
|
|
4
|
+
* @this {MidiAudioChannel}
|
|
5
|
+
*/
|
|
6
|
+
export function stopAllNotes(force = false)
|
|
7
|
+
{
|
|
8
|
+
if (force)
|
|
9
|
+
{
|
|
10
|
+
// force stop all
|
|
11
|
+
this.voices.length = 0;
|
|
12
|
+
this.sustainedVoices.length = 0;
|
|
13
|
+
this.sendChannelProperty();
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
{
|
|
17
|
+
this.voices.forEach(v =>
|
|
18
|
+
{
|
|
19
|
+
if (v.isInRelease)
|
|
20
|
+
{
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
v.release(this.synth.currentSynthTime);
|
|
24
|
+
});
|
|
25
|
+
this.sustainedVoices.forEach(v =>
|
|
26
|
+
{
|
|
27
|
+
v.release(this.synth.currentSynthTime);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param channel {MidiAudioChannel}
|
|
3
|
+
* @param voice {Voice}
|
|
4
|
+
* @return {number}
|
|
5
|
+
*/
|
|
6
|
+
function getPriority(channel, voice)
|
|
7
|
+
{
|
|
8
|
+
let priority = 0;
|
|
9
|
+
if (channel.drumChannel)
|
|
10
|
+
{
|
|
11
|
+
// important
|
|
12
|
+
priority += 5;
|
|
13
|
+
}
|
|
14
|
+
if (voice.isInRelease)
|
|
15
|
+
{
|
|
16
|
+
// not important
|
|
17
|
+
priority -= 5;
|
|
18
|
+
}
|
|
19
|
+
// less velocity = less important
|
|
20
|
+
priority += voice.velocity / 25; // map to 0-5
|
|
21
|
+
// the newer, more important
|
|
22
|
+
priority -= voice.volumeEnvelope.state;
|
|
23
|
+
if (voice.isInRelease)
|
|
24
|
+
{
|
|
25
|
+
priority -= 5;
|
|
26
|
+
}
|
|
27
|
+
priority -= voice.volumeEnvelope.currentAttenuationDb / 50;
|
|
28
|
+
return priority;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @this {SpessaSynthProcessor}
|
|
33
|
+
* @param amount {number}
|
|
34
|
+
*/
|
|
35
|
+
export function voiceKilling(amount)
|
|
36
|
+
{
|
|
37
|
+
let allVoices = [];
|
|
38
|
+
for (const channel of this.midiAudioChannels)
|
|
39
|
+
{
|
|
40
|
+
for (const voice of channel.voices)
|
|
41
|
+
{
|
|
42
|
+
if (!voice.finished)
|
|
43
|
+
{
|
|
44
|
+
const priority = getPriority(channel, voice);
|
|
45
|
+
allVoices.push({ channel, voice, priority });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Step 2: Sort voices by priority (ascending order)
|
|
51
|
+
allVoices.sort((a, b) => a.priority - b.priority);
|
|
52
|
+
const voicesToRemove = allVoices.slice(0, amount);
|
|
53
|
+
|
|
54
|
+
for (const { channel, voice } of voicesToRemove)
|
|
55
|
+
{
|
|
56
|
+
const index = channel.voices.indexOf(voice);
|
|
57
|
+
if (index > -1)
|
|
58
|
+
{
|
|
59
|
+
channel.voices.splice(index, 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|