fix: scanner catalog empty + left column blank

Scanner: new instance with existing sf_scan_state.json
did not populate in-memory _catalog. Now re-inspects
unchanged files to fill catalog on first scan.
Frontend: left column reads instrumentSelectorData.
soundfonts instead of sfPresets (null when no presets).
Click SF in left column triggers on-demand fetch.
This commit is contained in:
2026-07-28 07:32:40 +07:00
parent 14e3a561a3
commit d40ac47d65
3 changed files with 53 additions and 25 deletions
+27 -15
View File
@@ -50,6 +50,22 @@ class SoundFontAutoScanner:
out.append((fname, os.path.join(directory, fname)))
return out
def _inspect_single(self, fname: str, full: str, inspector) -> dict:
if fname.lower().endswith(".sf2"):
sf_info = inspector.inspect_sf2_file(full) or {}
else:
sf_info = {}
if not sf_info.get("soundfont_id"):
sf_id = os.path.splitext(fname)[0].lower()
sf_info = {
"soundfont_id": sf_id,
"filename": fname,
"total_instruments": 0,
"instruments": [],
"_sf3": True
}
return sf_info
def scan_once(self) -> bool:
from app.core.soundfont_inspector import SoundFontInspector
inspector = SoundFontInspector(self.system_sf_dir, self.upload_sf_dir)
@@ -64,23 +80,19 @@ class SoundFontAutoScanner:
key = f"{source}:{sf_id}"
sig = _file_sig(full)
prev = self._state.get(key)
if prev and prev["size"] == sig[0] and prev["mtime"] == sig[1]:
if sf_id in self._catalog:
continue
unchanged = prev and prev["size"] == sig[0] and prev["mtime"] == sig[1]
if unchanged and sf_id in self._catalog:
continue
if unchanged:
with self._lock:
if sf_id in self._catalog:
continue
sf_info = self._inspect_single(fname, full, inspector)
self._catalog[sf_id] = sf_info
continue
found_new = True
logger.info("New/changed SF detected: %s", fname)
if fname.lower().endswith(".sf2"):
sf_info = inspector.inspect_sf2_file(full) or {}
else:
sf_info = {}
if not sf_info.get("soundfont_id"):
sf_info = {
"soundfont_id": sf_id,
"filename": fname,
"total_instruments": 0,
"instruments": [],
"_sf3": True
}
sf_info = self._inspect_single(fname, full, inspector)
with self._lock:
self._catalog[sf_id] = sf_info
self._state[key] = {"size": sig[0], "mtime": sig[1], "file": fname}