Skip to content

Commit

Permalink
fix putting MIDI program change before cc reset
Browse files Browse the repository at this point in the history
fix snapshot not applying after loading embedded soundfont
  • Loading branch information
spessasus committed Sep 8, 2024
1 parent 16698c0 commit fbf0e14
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SpessaSynth",
"version": "3.20.11",
"version": "3.20.12",
"type": "module",
"scripts": {
"start": "node src/website/server/server.js"
Expand Down
2 changes: 1 addition & 1 deletion src/spessasynth_lib/midi_parser/midi_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export function modifyMIDI(
/**
* @type {{index: number, track: number}[]}
*/
const firstNoteOnForTrack = getFirstVoiceForChannel(midiChannel, port, offset > 0);
const firstNoteOnForTrack = getFirstVoiceForChannel(midiChannel, port, true);
if(firstNoteOnForTrack.length === 0)
{
SpessaSynthWarn("Program change but no notes... ignoring!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export function loadNewSequence(parsedMidi)
if(this.midiData.embeddedSoundFont !== undefined)
{
SpessaSynthInfo("%cEmbedded soundfont detected! Using it.", consoleColors.recognized);
// set offet
this.synth.soundfontBankOffset = this.midiData.bankOffset;
this.synth.reloadSoundFont(this.midiData.embeddedSoundFont, true);
// preload all samples
this.synth.overrideSoundfont.samples.forEach(s => s.getAudioData());
this.synth.setEmbeddedSoundFont(this.midiData.embeddedSoundFont, this.midiData.bankOffset);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/spessasynth_lib/synthetizer/worklet_processor.min.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/spessasynth_lib/synthetizer/worklet_system/main_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
getPreset,
programChange,
reloadSoundFont, sampleDump, sendPresetList,
setDrums,
setDrums, setEmbeddedSoundFont,
setPreset,
} from './worklet_methods/program_control.js'
import { applySynthesizerSnapshot, sendSynthesizerSnapshot } from './worklet_methods/snapshot.js'
Expand Down Expand Up @@ -204,14 +204,21 @@ class SpessaSynthProcessor extends AudioWorkletProcessor

this.totalVoicesAmount = 0;

/**
* The snapshot that synth was restored from
* @type {SynthesizerSnapshot|undefined}
* @private
*/
this._snapshot = options.processorOptions?.startRenderingData?.snapshot;

this.port.onmessage = e => this.handleMessage(e.data);

// if sent, start rendering
if(options.processorOptions.startRenderingData)
{
if (options.processorOptions.startRenderingData.snapshot)
if (this._snapshot !== undefined)
{
this.applySynthesizerSnapshot(options.processorOptions.startRenderingData.snapshot);
this.applySynthesizerSnapshot(this._snapshot);
this.resetAllControllers();
}

Expand Down Expand Up @@ -411,6 +418,7 @@ SpessaSynthProcessor.prototype.setPreset = setPreset;
SpessaSynthProcessor.prototype.setDrums = setDrums;
SpessaSynthProcessor.prototype.reloadSoundFont = reloadSoundFont;
SpessaSynthProcessor.prototype.clearSoundFont = clearSoundFont;
SpessaSynthProcessor.prototype.setEmbeddedSoundFont = setEmbeddedSoundFont;
SpessaSynthProcessor.prototype.sampleDump = sampleDump;
SpessaSynthProcessor.prototype.sendPresetList = sendPresetList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,28 @@ export function reloadSoundFont(buffer, isOverride = false)
SpessaSynthInfo("%cSpessaSynth is ready!", consoleColors.recognized);
}

/**
* Sets the embedded (RMI soundfont)
* @param font {ArrayBuffer}
* @param offset {number}
* @this {SpessaSynthProcessor}
*/
export function setEmbeddedSoundFont(font, offset)
{
// set offet
this.soundfontBankOffset = offset;
this.reloadSoundFont(font, true);
// preload all samples
this.overrideSoundfont.samples.forEach(s => s.getAudioData());

// apply snapshot again if applicable
if(this._snapshot !== undefined)
{
this.applySynthesizerSnapshot(this._snapshot);
this.resetAllControllers();
}
}

/**
* saves a sample
* @param channel {number}
Expand Down
28 changes: 14 additions & 14 deletions src/website/minified/demo_main.min.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/website/minified/local_main.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions start.bat
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
git pull
node src/website/server/server.js

0 comments on commit fbf0e14

Please sign in to comment.