feat: add SoundFont inspection engine + AI instrument schema

- SoundFontInspector (sf2utils) scans .sf2, generates full/condensed catalog
- GET /api/v1/plugins/soundfonts/catalog with lazy init + cache invalidation
- AI tool generate_multitrack_midi now requires soundfont_id/bank/program
- Condensed catalog auto-injected into AI system prompt with bank rules
- Server render: FluidSynth program_select uses bank/program + channel routing (drums→ch9)
- VST3 pedalboard path inserts CC0 bank select + program change before notes
- DecentSamplerManager loads .dspreset with CWD fix for relative sample paths
- Pianobook render branch in render_engine.py
- Client SonicSF: controllerChange, programChange, applyAITrackInstrument
- Post-AI track creation applies instrument via applyAITrackInstrument
- Background cache rescan on .sf2 upload, frontend re-fetches catalog
- libcurl4 + VST3 dirs in Dockerfile
This commit is contained in:
2026-07-26 12:36:48 +07:00
parent f16467eba1
commit 89c7237379
12 changed files with 361 additions and 13 deletions
+42 -2
View File
@@ -30,9 +30,45 @@
return window.__sharedAudioCtx;
};
// ── Per-channel MIDI state (16 GM channels) ──
const _channels = Array.from({ length: 16 }, () => ({ bank: 0, program: 0, isPercussion: false }));
let _nextMelodicChannel = 0;
const SonicSF = {
loadedFonts: {},
controllerChange: function (channel, controller, value) {
if (channel < 0 || channel > 15) return;
if (controller === 0) {
_channels[channel].bank = value;
_channels[channel].isPercussion = (value === 128);
}
},
programChange: function (channel, program) {
if (channel < 0 || channel > 15) return;
_channels[channel].program = program;
},
allocateChannel: function (bank) {
if (bank === 128) return 9;
const ch = _nextMelodicChannel % 9;
_nextMelodicChannel = (_nextMelodicChannel + 1) % 9;
return ch;
},
applyAITrackInstrument: function (bank, program) {
const channel = this.allocateChannel(bank);
this.controllerChange(channel, 0, bank);
this.programChange(channel, program);
return channel;
},
getChannelState: function (channel) {
if (channel < 0 || channel > 15) return null;
return { ..._channels[channel] };
},
// Load SoundFont from URL → ArrayBuffer → store in memory
loadSoundFont: async function (url) {
if (this.loadedFonts[url]) return this.loadedFonts[url];
@@ -43,7 +79,7 @@
return buffer;
},
playNote: function (note, velocity, durationMs, startTime, program, destinationNode) {
playNote: function (note, velocity, durationMs, startTime, program, destinationNode, channel) {
const ctx = getCtx();
const freq = 440 * Math.pow(2, (note - 69) / 12);
if (freq <= 0 || isNaN(freq)) return null;
@@ -59,7 +95,11 @@
let releaseTime = 0.2;
let volFactor = 0.25;
const prog = program !== undefined ? parseInt(program) : 0;
let prog = program !== undefined ? parseInt(program) : 0;
if (channel !== undefined && channel >= 0 && channel < 16) {
const chState = _channels[channel];
prog = chState.program || prog;
}
if (prog >= 0 && prog <= 7) { // Pianos
oscType = 'sine';
decayTime = 0.3;