FIX: sửa lỗi không load soundfont trên window, MIDI item không play được qua carla

This commit is contained in:
2026-08-10 10:50:02 +07:00
parent 1db892bb99
commit 1cf5b18492
5 changed files with 87 additions and 38 deletions
+5
View File
@@ -3051,3 +3051,8 @@
- **Tóm tắt thay đổi:** (1) **MIDI keyboard → Carla realtime**: `POST /api/v1/plugins/carla-midi` (note_on/note_off) gửi OSC UDP tới `/Carla/0/note_on|note_off` (pluginId 0 = plugin auto-load qua .carxs; cổng mặc định 22752 — đã xác minh từ source Carla: CarlaEngineOsc handleMsgNoteOn/NoteOff nhận `iii`/`ii`, CarlaEngineData oscPortUDP=22752, tên client standalone "Carla" từ carla_host.py; override qua env SF_CARLA_OSC_PORT hoặc `osc_port` trong carla_path.json). Frontend: `window.SonicCarlaMidi` (runtime.js) + hook vào **keybed piano roll** (onMouseDown/onMouseEnter) và **playDrawPreview** (vẽ/click note) — chỉ route khi track VSTi + ARM + carla_local. (2) **Soundfont từ thư mục user**: endpoint `/soundfont-instruments/{sf_id}` giờ truyền plugin_dirs → `PluginManager.list_soundfont_instruments` tìm cả thư mục user (bug "nhấn tên SF không thấy instrument"); `/available` truyền extra dirs; `render_engine._find_sf2_path` tìm thêm thư mục user (trước chỉ UPLOAD + /opt/daw_engine/soundfonts + static → soundfont user render câm).
- **Các file ảnh hưởng:** `app/api/v1/plugins.py` (+carla-midi, _send_carla_osc, _carla_osc_port), `app/core/vst_engine.py`, `app/core/render_engine.py`, `app/static/js/services/runtime.js` (+SonicCarlaMidi), `app/static/js/services/api.js` (+carlaMidi), `app/static/js/app.jsx` (keybed + playDrawPreview), `app/static/js/app.precompiled.js` (rebuild), `dist/daw_engine/_internal/app/static/**`, `wiki.md`
- **Ghi chú/Test (nếu có):** pytest: 86 passed, 7 skipped. OSC: hexdump 32B = `/Carla/0/note_on` + `,iii` + [0,60,100] (big-endian int32) — khớp expected; note_off = `,ii` + [ch,note]. Rebuild bundle BUILD OK. ⚠️ Cần rebuild PyInstaller trên Windows để nhận backend fix (dist backend nằm trong exe). Lưu ý: Carla phải ĐANG MỞ để nhận OSC; nếu đổi cổng OSC trong Carla → đặt SF_CARLA_OSC_PORT.
### [2026-08-09] Task: MIDI items play qua Carla + list instrument SF không cần libfluidsynth
- **Tóm tắt thay đổi:** (1) **Playback MIDI items → Carla**: `schedulePianoRollMidi` (app.jsx ~21133) giờ route note_on/note_off tới Carla qua `SonicCarlaMidi.shouldRoutePlayback()` (track VSTi + carla_local, KHÔNG cần ARM — user chủ động bấm Play) — schedule bằng setTimeout theo audio clock (preview, timing gần đúng). Keybed/draw preview vẫn yêu cầu ARM (shouldRoute). (2) **List instrument soundfont hoạt động không cần libfluidsynth**: `PluginManager.list_soundfont_instruments` bỏ early-return `if not ensure_pyfluidsynth(): return []`; thêm fallback đọc TRỰC TIẾP file SF2 qua `SoundFontInspector.inspect_sf2_file` (sf2utils — thuần Python, đọc preset header pdta/phdr → bank/program/name) — quan trọng trên Windows khi thiếu fluidsynth DLL. Giữ đường FluidSynth khi có lib.
- **Các file ảnh hưởng:** `app/core/vst_engine.py`, `app/static/js/services/runtime.js` (+shouldRoutePlayback), `app/static/js/app.jsx` (schedulePianoRollMidi), `app/static/js/app.precompiled.js` (rebuild), `dist/daw_engine/_internal/app/static/**`, `wiki.md`
- **Ghi chú/Test (nếu có):** pytest: 86 passed, 7 skipped. Test fallback trên máy KHÔNG có libfluidsynth (đúng kịch bản Windows): file sf2 thật → 137 presets (first: {bank:128, program:48, name:'Orchestra Kit', is_percussion:True}). Rebuild bundle BUILD OK; dist synced. ⚠️ Cần rebuild PyInstaller trên Windows để nhận backend fix (dist backend trong exe).