Compare commits
16 Commits
be93f9f55a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bd0989031 | |||
| dccf4f45ef | |||
| 9099529403 | |||
| 3795ea9d78 | |||
| fa24c61bbf | |||
| 83427fe503 | |||
| cef2d6666b | |||
| bfe9e47db1 | |||
| bcc91db4a7 | |||
| 1f7a8c6f1b | |||
| 8b0551b18f | |||
| eaca051191 | |||
| b78a629429 | |||
| 366219a269 | |||
| 3618e3c591 | |||
| b490aa9951 |
+17
@@ -62,6 +62,23 @@ app.mount("/static/audio", StaticFiles(directory=settings.STORAGE_DIR), name="au
|
|||||||
# khi PyInstaller onefile, __file__ trỏ vào thư mục giải nén tạm _MEI...
|
# khi PyInstaller onefile, __file__ trỏ vào thư mục giải nén tạm _MEI...
|
||||||
# nhưng static/templates nằm trong sys._MEIPASS/app (config.py đã xử lý).
|
# nhưng static/templates nằm trong sys._MEIPASS/app (config.py đã xử lý).
|
||||||
STATIC_DIR = os.path.join(settings.APP_DIR, "static")
|
STATIC_DIR = os.path.join(settings.APP_DIR, "static")
|
||||||
|
# ⚠️ Fallback an toàn: nếu vì lý do nào đó static không nằm đúng chỗ (vd
|
||||||
|
# bundle thiếu file, chạy từ nơi khác), thử các vị trí khác; nếu vẫn không
|
||||||
|
# có → TỰ TẠO thư mục rỗng để app KHÔNG crash khi khởi động (lỗi "Directory
|
||||||
|
# does not exist" từ StaticFiles làm engine chết ngay lúc import — đã gặp).
|
||||||
|
if not os.path.isdir(STATIC_DIR):
|
||||||
|
for cand in [
|
||||||
|
os.path.join(getattr(sys, "_MEIPASS", ""), "app", "static"),
|
||||||
|
os.path.join(os.path.dirname(os.path.abspath(__file__)), "static"),
|
||||||
|
]:
|
||||||
|
if cand and os.path.isdir(cand):
|
||||||
|
STATIC_DIR = cand
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
os.makedirs(STATIC_DIR, exist_ok=True)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||||
|
|
||||||
# Include routers
|
# Include routers
|
||||||
|
|||||||
+256
-5
@@ -6469,6 +6469,155 @@ const SystemManagerModal = ({
|
|||||||
}, "Xóa")))))))));
|
}, "Xóa")))))))));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════════════════════
|
||||||
|
ABOUT / HELP / PREFERENCES MODALS (menu Help + Tools → Preferences)
|
||||||
|
═══════════════════════════════════════════════════════════════════ */
|
||||||
|
const APP_VERSION = '1.0.0'; // khớp src-tauri/tauri.conf.json
|
||||||
|
|
||||||
|
const AboutModal = ({ isOpen, onClose }) => {
|
||||||
|
if (!isOpen) return null;
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/70 backdrop-blur-sm" onClick={onClose}>
|
||||||
|
<div className="bg-[#1e1e24] border border-zinc-700 rounded-xl shadow-2xl w-full max-w-md p-6 text-slate-200" onClick={e => e.stopPropagation()}>
|
||||||
|
<div className="flex items-center gap-3 mb-4">
|
||||||
|
<img src="/favicon.svg" alt="SonicForge Studio" className="w-12 h-12 rounded-lg bg-zinc-900 border border-zinc-700 shadow-lg object-contain p-0.5" />
|
||||||
|
<div>
|
||||||
|
<h2 className="text-lg font-bold text-white">SonicForge Studio</h2>
|
||||||
|
<p className="text-xs text-zinc-400">Professional DAW — v{APP_VERSION}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
<p className="text-zinc-300 leading-relaxed">Phần mềm sản xuất âm nhạc (DAW) — soạn nhạc, ghi âm, chỉnh sửa MIDI/Audio, SoundFont & VST, trộn và master.</p>
|
||||||
|
<div className="pt-2 border-t border-zinc-800 space-y-1 text-xs">
|
||||||
|
<div className="flex items-center gap-2"><span className="text-zinc-500 w-20 shrink-0">Developer</span><span className="text-cyan-400 font-semibold">Lộc Phạm</span></div>
|
||||||
|
<div className="flex items-center gap-2"><span className="text-zinc-500 w-20 shrink-0">Email</span><a href="mailto:tranloclqd@gmail.com" className="text-cyan-400 hover:underline">tranloclqd@gmail.com</a></div>
|
||||||
|
<div className="flex items-center gap-2"><span className="text-zinc-500 w-20 shrink-0">Version</span><span className="text-zinc-300">{APP_VERSION}</span></div>
|
||||||
|
<div className="flex items-center gap-2"><span className="text-zinc-500 w-20 shrink-0">Build</span><span className="text-zinc-300">Standalone (Tauri v2 + PyInstaller)</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-5 flex justify-end">
|
||||||
|
<button onClick={onClose} className="px-4 py-1.5 bg-cyan-700 hover:bg-cyan-600 rounded text-xs font-bold text-white transition">Đóng</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const HelpModal = ({ isOpen, onClose, lang }) => {
|
||||||
|
if (!isOpen) return null;
|
||||||
|
const vi = lang !== 'en';
|
||||||
|
const sections = vi ? [
|
||||||
|
{ title: '🚀 Bắt đầu nhanh', body: 'Nhấn phím Cách (Space) để Play/Pause. Nhấn phím / để dừng. Dùng nút Record (●) để ghi âm/MIDI. Tạo track mới từ menu Track hoặc nút "+ Add Track".' },
|
||||||
|
{ title: '🎹 MIDI & ARM', body: 'Bật nút ARM đỏ trên track để nhận phím từ MIDI keyboard. Vào menu Tools → MIDI Devices để chọn thiết bị. Khi ARM + bấm phím, âm preview phát và VU meter nhảy theo trường độ.' },
|
||||||
|
{ title: '🎼 Piano Roll', body: 'Nhấp đúp vào MIDI item để mở Piano Roll. Dùng Ctrl+scroll hoặc nút +/− để zoom. Nhấp để vẽ note, kéo để di chuyển, Ctrl+kéo để copy. Phím tắt: C (vẽ), E (tẩy), Space (nghe).' },
|
||||||
|
{ title: '🎛️ FX & Master', body: 'Chọn track → nút FX để mở FX Rack (thêm EQ, compressor...). Bấm nút PWR ở Master để mở Mastering Panel: EQ 4 băng, compressor, limiter. Mọi thay đổi áp dụng realtime.' },
|
||||||
|
{ title: '🧪 SoundFont & VST', body: 'Vào Tools → Plugin Manager để quét SoundFont (.sf2/.sf3) và VSTi. Track MIDI dùng SoundFont làm nhạc cụ — chọn instrument từ nút Synth trên track.' },
|
||||||
|
{ title: '🤖 AI', body: 'Tools → Config AI Providers để cấu hình API (OpenAI, Gemini, Ollama...). Dùng AI Prompt Generator (nút ✨) để sinh MIDI/ý tưởng; AI MIDI Preset Manager để lưu preset.' },
|
||||||
|
{ title: '💾 Lưu & Xuất', body: 'Ctrl+S lưu project (cloud/temp), Ctrl+Shift+S Save As. Export WAV qua nút Export — chọn vùng, format, bitrate rồi Render.' },
|
||||||
|
{ title: '⌨️ Phím tắt', body: 'Space: Play/Pause · /: Stop · Ctrl+Z/Y: Undo/Redo · Ctrl+C/X/V: Copy/Cut/Paste · Ctrl+S: Save · Ctrl+N: New · S: Split · Ctrl+E: Edit in new tab · Ctrl+wheel: zoom timeline' },
|
||||||
|
] : [
|
||||||
|
{ title: '🚀 Quick start', body: 'Press Space to Play/Pause. Press / to stop. Use Record (●) to capture audio/MIDI. Add tracks from the Track menu or the "+ Add Track" button.' },
|
||||||
|
{ title: '🎹 MIDI & ARM', body: 'Enable the red ARM button on a track to receive keys from a MIDI keyboard. Go to Tools → MIDI Devices to pick your device. When ARM + key press, preview audio plays and the VU meter animates for the note length.' },
|
||||||
|
{ title: '🎼 Piano Roll', body: 'Double-click a MIDI item to open the Piano Roll. Use Ctrl+scroll or +/− buttons to zoom. Click to draw notes, drag to move, Ctrl+drag to copy. Shortcuts: C (draw), E (erase), Space (listen).' },
|
||||||
|
{ title: '🎛️ FX & Master', body: 'Select a track → FX button to open the FX Rack (EQ, compressor...). Press the PWR button on the Master to open the Mastering Panel: 4-band EQ, compressor, limiter — all realtime.' },
|
||||||
|
{ title: '🧪 SoundFont & VST', body: 'Tools → Plugin Manager scans SoundFonts (.sf2/.sf3) and VSTi. MIDI tracks use SoundFonts as instruments — pick one from the Synth button on the track.' },
|
||||||
|
{ title: '🤖 AI', body: 'Tools → Config AI Providers to set up APIs (OpenAI, Gemini, Ollama...). Use the AI Prompt Generator (✨) to create MIDI/ideas; AI MIDI Preset Manager stores presets.' },
|
||||||
|
{ title: '💾 Save & Export', body: 'Ctrl+S saves the project (cloud/temp), Ctrl+Shift+S Save As. Export WAV via the Export button — pick range, format, bitrate, then Render.' },
|
||||||
|
{ title: '⌨️ Shortcuts', body: 'Space: Play/Pause · /: Stop · Ctrl+Z/Y: Undo/Redo · Ctrl+C/X/V: Copy/Cut/Paste · Ctrl+S: Save · Ctrl+N: New · S: Split · Ctrl+E: Edit in new tab · Ctrl+wheel: zoom timeline' },
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/70 backdrop-blur-sm" onClick={onClose}>
|
||||||
|
<div className="bg-[#1e1e24] border border-zinc-700 rounded-xl shadow-2xl w-full max-w-2xl max-h-[85vh] flex flex-col text-slate-200" onClick={e => e.stopPropagation()}>
|
||||||
|
<div className="flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0">
|
||||||
|
<h2 className="text-base font-bold text-white">{vi ? 'Hướng dẫn sử dụng SonicForge Studio' : 'SonicForge Studio User Guide'}</h2>
|
||||||
|
<button onClick={onClose} className="w-6 h-6 rounded hover:bg-zinc-700 text-zinc-400 hover:text-white text-sm">✕</button>
|
||||||
|
</div>
|
||||||
|
<div className="overflow-y-auto px-5 py-4 space-y-3">
|
||||||
|
{sections.map((s, i) => (
|
||||||
|
<div key={i} className="bg-zinc-900/60 border border-zinc-800 rounded-lg p-3">
|
||||||
|
<h3 className="text-sm font-bold text-cyan-400 mb-1">{s.title}</h3>
|
||||||
|
<p className="text-xs text-zinc-300 leading-relaxed">{s.body}</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="px-5 py-3 border-t border-zinc-800 flex justify-end shrink-0">
|
||||||
|
<button onClick={onClose} className="px-4 py-1.5 bg-cyan-700 hover:bg-cyan-600 rounded text-xs font-bold text-white transition">{vi ? 'Đóng' : 'Close'}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PreferencesModal = ({ isOpen, onClose, prefs, onPrefsChange }) => {
|
||||||
|
if (!isOpen) return null;
|
||||||
|
const vi = prefs.language !== 'en';
|
||||||
|
const themes = [
|
||||||
|
{ id: 'dark', name: vi ? 'Tối (mặc định)' : 'Dark (default)', swatch: 'from-zinc-700 to-zinc-900', ring: 'ring-cyan-400' },
|
||||||
|
{ id: 'midnight', name: vi ? 'Đêm xanh' : 'Midnight', swatch: 'from-sky-800 to-slate-950', ring: 'ring-sky-400' },
|
||||||
|
{ id: 'forest', name: vi ? 'Rừng xanh' : 'Forest', swatch: 'from-emerald-700 to-green-950', ring: 'ring-emerald-400' },
|
||||||
|
{ id: 'violet', name: vi ? 'Tím' : 'Violet', swatch: 'from-violet-700 to-purple-950', ring: 'ring-violet-400' },
|
||||||
|
{ id: 'graphite', name: vi ? 'Than chì' : 'Graphite', swatch: 'from-zinc-600 to-neutral-900', ring: 'ring-zinc-300' },
|
||||||
|
];
|
||||||
|
const set = (k, v) => onPrefsChange({ ...prefs, [k]: v });
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/70 backdrop-blur-sm" onClick={onClose}>
|
||||||
|
<div className="bg-[#1e1e24] border border-zinc-700 rounded-xl shadow-2xl w-full max-w-md max-h-[85vh] overflow-y-auto p-5 text-slate-200" onClick={e => e.stopPropagation()}>
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h2 className="text-base font-bold text-white">{vi ? 'Tùy chọn (Preferences)' : 'Preferences'}</h2>
|
||||||
|
<button onClick={onClose} className="w-6 h-6 rounded hover:bg-zinc-700 text-zinc-400 hover:text-white text-sm">✕</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Theme */}
|
||||||
|
<div className="mb-5">
|
||||||
|
<h3 className="text-xs font-bold text-zinc-400 uppercase tracking-wider mb-2">{vi ? '🎨 Chủ đề màu' : '🎨 Theme'}</h3>
|
||||||
|
<div className="grid grid-cols-1 gap-1.5">
|
||||||
|
{themes.map(th => (
|
||||||
|
<button key={th.id} onClick={() => set('theme', th.id)}
|
||||||
|
className={`flex items-center gap-2.5 px-2.5 py-2 rounded-lg border text-xs text-left transition ${prefs.theme === th.id ? 'border-cyan-500 bg-zinc-800' : 'border-zinc-700 bg-zinc-900 hover:bg-zinc-800'}`}>
|
||||||
|
<span className={`w-6 h-6 rounded-md bg-gradient-to-br ${th.swatch} ring-1 ring-black/40 shrink-0 ${prefs.theme === th.id ? `ring-2 ${th.ring}` : ''}`}></span>
|
||||||
|
<span className="text-zinc-200">{th.name}</span>
|
||||||
|
{prefs.theme === th.id && <span className="ml-auto text-cyan-400 text-[10px] font-bold">✓</span>}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Language */}
|
||||||
|
<div className="mb-5">
|
||||||
|
<h3 className="text-xs font-bold text-zinc-400 uppercase tracking-wider mb-2">{vi ? '🌐 Ngôn ngữ' : '🌐 Language'}</h3>
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
{[{ id: 'vi', label: 'Tiếng Việt' }, { id: 'en', label: 'English' }].map(l => (
|
||||||
|
<button key={l.id} onClick={() => set('language', l.id)}
|
||||||
|
className={`flex-1 px-2 py-1.5 rounded-lg border text-xs font-semibold transition ${prefs.language === l.id ? 'border-cyan-500 bg-cyan-900/40 text-cyan-300' : 'border-zinc-700 bg-zinc-900 text-zinc-400 hover:bg-zinc-800'}`}>
|
||||||
|
{l.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<p className="text-[10px] text-zinc-500 mt-1">{vi ? 'Áp dụng ngay cho menu & hướng dẫn.' : 'Applies immediately to menus & guide.'}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Button font size */}
|
||||||
|
<div className="mb-5">
|
||||||
|
<h3 className="text-xs font-bold text-zinc-400 uppercase tracking-wider mb-2">{vi ? '🔠 Cỡ chữ nút bấm' : '🔠 Button font size'}</h3>
|
||||||
|
<div className="flex gap-1.5">
|
||||||
|
{[{ id: 'sm', label: vi ? 'Nhỏ' : 'Small' }, { id: 'md', label: vi ? 'Vừa' : 'Medium' }, { id: 'lg', label: vi ? 'Lớn' : 'Large' }].map(f => (
|
||||||
|
<button key={f.id} onClick={() => set('buttonFontSize', f.id)}
|
||||||
|
className={`flex-1 px-2 py-1.5 rounded-lg border text-xs font-semibold transition ${prefs.buttonFontSize === f.id ? 'border-cyan-500 bg-cyan-900/40 text-cyan-300' : 'border-zinc-700 bg-zinc-900 text-zinc-400 hover:bg-zinc-800'}`}>
|
||||||
|
{f.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-2 pt-2 border-t border-zinc-800">
|
||||||
|
<button onClick={onClose} className="px-3 py-1.5 bg-zinc-700 hover:bg-zinc-600 rounded text-xs font-bold text-white transition">{vi ? 'Hủy' : 'Cancel'}</button>
|
||||||
|
<button onClick={onClose} className="px-4 py-1.5 bg-cyan-700 hover:bg-cyan-600 rounded text-xs font-bold text-white transition">{vi ? 'Lưu & Đóng' : 'Save & Close'}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const AIPresetModal = ({ isOpen, onClose }) => {
|
const AIPresetModal = ({ isOpen, onClose }) => {
|
||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
|
|
||||||
@@ -14500,6 +14649,11 @@ const App = () => {
|
|||||||
if (window.triggerMidiVuActivity) {
|
if (window.triggerMidiVuActivity) {
|
||||||
window.triggerMidiVuActivity(as.trackId, scaledVel);
|
window.triggerMidiVuActivity(as.trackId, scaledVel);
|
||||||
}
|
}
|
||||||
|
// Giữ VU theo trường độ: tăng counter note đang giữ
|
||||||
|
// (tick giữ peak cho tới khi note-off)
|
||||||
|
try {
|
||||||
|
heldMidiNotesRef.current[as.trackId] = (heldMidiNotesRef.current[as.trackId] || 0) + 1;
|
||||||
|
} catch (err) { }
|
||||||
window.SonicSF.playNote(pitch, scaledVel, 60000, undefined, asProg, null, asCh, asSe);
|
window.SonicSF.playNote(pitch, scaledVel, 60000, undefined, asProg, null, asCh, asSe);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -14512,6 +14666,10 @@ const App = () => {
|
|||||||
if (window.triggerMidiVuActivity) {
|
if (window.triggerMidiVuActivity) {
|
||||||
window.triggerMidiVuActivity(at.id, scaledVel);
|
window.triggerMidiVuActivity(at.id, scaledVel);
|
||||||
}
|
}
|
||||||
|
// Giữ VU theo trường độ: tăng counter note đang giữ
|
||||||
|
try {
|
||||||
|
heldMidiNotesRef.current[at.id] = (heldMidiNotesRef.current[at.id] || 0) + 1;
|
||||||
|
} catch (err) { }
|
||||||
window.SonicSF.playNote(pitch, scaledVel, 60000, undefined, atProg, atDest, atCh, atSe);
|
window.SonicSF.playNote(pitch, scaledVel, 60000, undefined, atProg, atDest, atCh, atSe);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -14535,6 +14693,16 @@ const App = () => {
|
|||||||
if (!st.synth_engine && st.midiChannel === undefined) return;
|
if (!st.synth_engine && st.midiChannel === undefined) return;
|
||||||
var stCh = assignTrackMidiChannel(st, stopTracks);
|
var stCh = assignTrackMidiChannel(st, stopTracks);
|
||||||
window.SonicSF.stopNote(stCh, pitch);
|
window.SonicSF.stopNote(stCh, pitch);
|
||||||
|
// Giảm counter note đang giữ — hết note → VU được phép decay/tắt
|
||||||
|
// (tick sẽ thấy counter = 0 và không còn giữ peak nữa)
|
||||||
|
try {
|
||||||
|
if (heldMidiNotesRef.current[st.id] !== undefined) {
|
||||||
|
heldMidiNotesRef.current[st.id] = Math.max(0, heldMidiNotesRef.current[st.id] - 1);
|
||||||
|
if (heldMidiNotesRef.current[st.id] === 0) {
|
||||||
|
delete heldMidiNotesRef.current[st.id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15494,6 +15662,11 @@ const App = () => {
|
|||||||
}, [isPlaying]);
|
}, [isPlaying]);
|
||||||
|
|
||||||
const midiVuActivityRef = useRef({});
|
const midiVuActivityRef = useRef({});
|
||||||
|
// Đếm số note MIDI đang GIỮ per-track (ARM + MIDI keyboard live input).
|
||||||
|
// VU tick dùng ref này: còn note giữ → giữ peak (không decay) → VU animate
|
||||||
|
// ĐÚNG trường độ âm thanh (user bug: nhấn phím giữ âm còn kêu nhưng VU tắt
|
||||||
|
// sau ~0.5s vì decay 0.75/frame). Hết note (note-off) → mới decay/tắt.
|
||||||
|
const heldMidiNotesRef = useRef({});
|
||||||
const triggerMidiVuActivity = (trackId, velocity) => {
|
const triggerMidiVuActivity = (trackId, velocity) => {
|
||||||
if (!trackId) return;
|
if (!trackId) return;
|
||||||
const velFactor = typeof velocity === 'number' ? (velocity > 1 ? velocity / 127 : velocity) : 0.8;
|
const velFactor = typeof velocity === 'number' ? (velocity > 1 ? velocity / 127 : velocity) : 0.8;
|
||||||
@@ -15538,6 +15711,51 @@ const App = () => {
|
|||||||
const [aiPresetModalOpen, setAiPresetModalOpen] = useState(false);
|
const [aiPresetModalOpen, setAiPresetModalOpen] = useState(false);
|
||||||
const [aiPresetVersion, setAiPresetVersion] = useState(0);
|
const [aiPresetVersion, setAiPresetVersion] = useState(0);
|
||||||
const [showMasteringModal, setShowMasteringModal] = useState(false);
|
const [showMasteringModal, setShowMasteringModal] = useState(false);
|
||||||
|
// ── Help / About / Preferences (menu Help + Tools) ──
|
||||||
|
const [aboutModalOpen, setAboutModalOpen] = useState(false);
|
||||||
|
const [helpModalOpen, setHelpModalOpen] = useState(false);
|
||||||
|
const [preferencesModalOpen, setPreferencesModalOpen] = useState(false);
|
||||||
|
const [prefs, setPrefs] = useState(() => {
|
||||||
|
try {
|
||||||
|
const saved = localStorage.getItem('sf_prefs');
|
||||||
|
if (saved) return JSON.parse(saved);
|
||||||
|
} catch (e) { }
|
||||||
|
return { theme: 'dark', language: 'vi', buttonFontSize: 'md' };
|
||||||
|
});
|
||||||
|
// Áp dụng theme + font size lên <html> ngay khi đổi
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
document.documentElement.setAttribute('data-theme', prefs.theme || 'dark');
|
||||||
|
document.documentElement.setAttribute('data-btnfont', prefs.buttonFontSize || 'md');
|
||||||
|
localStorage.setItem('sf_prefs', JSON.stringify(prefs));
|
||||||
|
} catch (e) { }
|
||||||
|
}, [prefs]);
|
||||||
|
// Load preferences từ server (nếu có tài khoản) khi khởi động
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
if (window.SonicAPI && window.SonicAPI.getPreferences) {
|
||||||
|
window.SonicAPI.getPreferences().then(res => {
|
||||||
|
if (cancelled || !res || !res.success || !res.preferences) return;
|
||||||
|
const p = res.preferences;
|
||||||
|
if (p.theme || p.language || p.buttonFontSize) {
|
||||||
|
setPrefs(prev => ({
|
||||||
|
theme: p.theme || prev.theme,
|
||||||
|
language: p.language || prev.language,
|
||||||
|
buttonFontSize: p.buttonFontSize || prev.buttonFontSize
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}).catch(() => { });
|
||||||
|
}
|
||||||
|
return () => { cancelled = true; };
|
||||||
|
}, []);
|
||||||
|
// Lưu preferences lên server khi đổi
|
||||||
|
const handlePrefsChange = (next) => {
|
||||||
|
setPrefs(next);
|
||||||
|
try { localStorage.setItem('sf_prefs', JSON.stringify(next)); } catch (e) { }
|
||||||
|
if (window.SonicAPI && window.SonicAPI.savePreferences) {
|
||||||
|
window.SonicAPI.savePreferences(next).catch(() => { });
|
||||||
|
}
|
||||||
|
};
|
||||||
// Unified FX Rack target context (unified_fx_rack_panel.md): { trackId, trackName } | null
|
// Unified FX Rack target context (unified_fx_rack_panel.md): { trackId, trackName } | null
|
||||||
const [fxRackTarget, setFxRackTarget] = useState(null);
|
const [fxRackTarget, setFxRackTarget] = useState(null);
|
||||||
window.__openFxRack = (trackId, trackName) => setFxRackTarget({ trackId, trackName });
|
window.__openFxRack = (trackId, trackName) => setFxRackTarget({ trackId, trackName });
|
||||||
@@ -20595,6 +20813,9 @@ const App = () => {
|
|||||||
// âm cũ — user 06:45: tắt âm MAIN items khi vào SECTION-TAB → VU main
|
// âm cũ — user 06:45: tắt âm MAIN items khi vào SECTION-TAB → VU main
|
||||||
// items phải tắt theo, không "diễn" tiếp).
|
// items phải tắt theo, không "diễn" tiếp).
|
||||||
try { midiVuActivityRef.current = {}; } catch (e) { }
|
try { midiVuActivityRef.current = {}; } catch (e) { }
|
||||||
|
// Clear luôn counter note đang giữ — nếu không, sau stop (âm đã dừng)
|
||||||
|
// tick vẫn thấy heldCnt > 0 → giữ peak → VU dính mãi (user bug 08:08).
|
||||||
|
try { heldMidiNotesRef.current = {}; } catch (e) { }
|
||||||
stopMidiCapture();
|
stopMidiCapture();
|
||||||
if (window.SonicSF) {
|
if (window.SonicSF) {
|
||||||
try { window.SonicSF.stopAll(); } catch (e) { console.warn('[Stop] stopAll error:', e); }
|
try { window.SonicSF.stopAll(); } catch (e) { console.warn('[Stop] stopAll error:', e); }
|
||||||
@@ -25856,14 +26077,20 @@ STRICT CONSTRAINTS:
|
|||||||
// velocity thấp (âm SF nhỏ < 0.03) → VU không nhảy (user bug 07:10).
|
// velocity thấp (âm SF nhỏ < 0.03) → VU không nhảy (user bug 07:10).
|
||||||
let midiPeak = isAudible ? (midiVuActivityRef.current[vuKey] || 0) : 0;
|
let midiPeak = isAudible ? (midiVuActivityRef.current[vuKey] || 0) : 0;
|
||||||
if (midiPeak > 0) {
|
if (midiPeak > 0) {
|
||||||
// Decay 0.75 (~0.5s) — cân bằng: note đơn/velocity thấp hiển thị rõ
|
// ARM + MIDI keyboard: còn note đang GIỮ → giữ nguyên peak, KHÔNG
|
||||||
// NHƯNG tắt nhanh sau hết note (decay 0.85 ~1s quá lâu — user:
|
// decay → VU animate đúng trường độ âm thanh (user bug 08:08: âm còn
|
||||||
// "vẫn diễn animation" sau khi âm hết — bug 07:15).
|
// kêu nhưng VU tắt sau ~0.5s vì decay 0.75/frame). Hết note → decay
|
||||||
|
// 0.75 (~0.5s) tắt nhanh như trước.
|
||||||
|
const heldCnt = heldMidiNotesRef.current[vuKey] || 0;
|
||||||
|
if (heldCnt > 0) {
|
||||||
|
// Giữ nguyên peak trong khi âm đang kêu (không decay)
|
||||||
|
} else {
|
||||||
midiVuActivityRef.current[vuKey] = midiPeak * 0.75;
|
midiVuActivityRef.current[vuKey] = midiPeak * 0.75;
|
||||||
if (midiVuActivityRef.current[vuKey] < 0.01) {
|
if (midiVuActivityRef.current[vuKey] < 0.01) {
|
||||||
midiVuActivityRef.current[vuKey] = 0;
|
midiVuActivityRef.current[vuKey] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ⚠️ KHÔNG gộp sfAudioPeak vào audioPeak: SF là 1 output CHUNG cho mọi
|
// ⚠️ KHÔNG gộp sfAudioPeak vào audioPeak: SF là 1 output CHUNG cho mọi
|
||||||
// track MIDI → gộp làm track VU nhảy CÙNG NHAU (user bug 07:00).
|
// track MIDI → gộp làm track VU nhảy CÙNG NHAU (user bug 07:00).
|
||||||
// audioPeak chỉ theo âm TRACK thật (vNode/sub-node analyser).
|
// audioPeak chỉ theo âm TRACK thật (vNode/sub-node analyser).
|
||||||
@@ -26249,13 +26476,25 @@ STRICT CONSTRAINTS:
|
|||||||
setPluginManagerModalOpen(true);
|
setPluginManagerModalOpen(true);
|
||||||
window.SonicAPI.listPlugins().then(data => setPluginsData(data)).catch(() => {});
|
window.SonicAPI.listPlugins().then(data => setPluginsData(data)).catch(() => {});
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
sep: true
|
||||||
|
}, {
|
||||||
|
label: 'Preferences...',
|
||||||
|
icon: 'settings-2',
|
||||||
|
action: () => setPreferencesModalOpen(true)
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
label: 'Help',
|
label: 'Help',
|
||||||
items: [{
|
items: [{
|
||||||
label: 'About SonicForge',
|
label: 'Hướng dẫn sử dụng...',
|
||||||
|
icon: 'book-open',
|
||||||
|
action: () => setHelpModalOpen(true)
|
||||||
|
}, {
|
||||||
|
sep: true
|
||||||
|
}, {
|
||||||
|
label: 'About SonicForge Studio...',
|
||||||
icon: 'info',
|
icon: 'info',
|
||||||
action: () => showToast('SonicForge Studio v1.0 - Professional DAW', 'info')
|
action: () => setAboutModalOpen(true)
|
||||||
}]
|
}]
|
||||||
}].map(menu => /*#__PURE__*/React.createElement("div", {
|
}].map(menu => /*#__PURE__*/React.createElement("div", {
|
||||||
key: menu.label,
|
key: menu.label,
|
||||||
@@ -29231,6 +29470,18 @@ STRICT CONSTRAINTS:
|
|||||||
const active = providers.find(p => p.is_active) || providers[0];
|
const active = providers.find(p => p.is_active) || providers[0];
|
||||||
if (active) setSelectedProviderId(active.id);
|
if (active) setSelectedProviderId(active.id);
|
||||||
}
|
}
|
||||||
|
}), /*#__PURE__*/React.createElement(AboutModal, {
|
||||||
|
isOpen: aboutModalOpen,
|
||||||
|
onClose: () => setAboutModalOpen(false)
|
||||||
|
}), /*#__PURE__*/React.createElement(HelpModal, {
|
||||||
|
isOpen: helpModalOpen,
|
||||||
|
onClose: () => setHelpModalOpen(false),
|
||||||
|
lang: prefs.language
|
||||||
|
}), /*#__PURE__*/React.createElement(PreferencesModal, {
|
||||||
|
isOpen: preferencesModalOpen,
|
||||||
|
onClose: () => setPreferencesModalOpen(false),
|
||||||
|
prefs: prefs,
|
||||||
|
onPrefsChange: handlePrefsChange
|
||||||
}), /*#__PURE__*/React.createElement(SystemManagerModal, {
|
}), /*#__PURE__*/React.createElement(SystemManagerModal, {
|
||||||
isOpen: systemManagerModalOpen,
|
isOpen: systemManagerModalOpen,
|
||||||
onClose: () => setSystemManagerModalOpen(false)
|
onClose: () => setSystemManagerModalOpen(false)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -3,8 +3,27 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<title>SonicForge Studio - Professional DAW Editor</title>
|
<title>SonicForge Studio - Professional DAW Editor</title>
|
||||||
|
<script>
|
||||||
|
// ── Chặn BROWSER ZOOM toàn trang ──
|
||||||
|
// UI dùng px cố định cho item/button/label — browser zoom (Ctrl+wheel,
|
||||||
|
// Ctrl+plus/minus/0, pinch) scale TOÀN BỘ làm control phóng to theo.
|
||||||
|
// Chặn ở capture phase bằng preventDefault() (KHÔNG stopPropagation —
|
||||||
|
// các vùng zoom chuyên dụng: timeline, piano roll, canvas, EQ vẫn nhận
|
||||||
|
// event và tự xử lý zoom nội dung của chúng).
|
||||||
|
document.addEventListener('wheel', function (e) {
|
||||||
|
if (e.ctrlKey || e.metaKey) e.preventDefault();
|
||||||
|
}, { capture: true, passive: false });
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
if ((e.ctrlKey || e.metaKey) && ['+', '-', '=', '_', '0'].indexOf(e.key) !== -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}, { capture: true });
|
||||||
|
// Pinch zoom (Safari/WebKit gesture events)
|
||||||
|
document.addEventListener('gesturestart', function (e) { e.preventDefault(); }, { passive: false });
|
||||||
|
document.addEventListener('gesturechange', function (e) { e.preventDefault(); }, { passive: false });
|
||||||
|
</script>
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<script src="https://unpkg.com/lucide@latest"></script>
|
<script src="https://unpkg.com/lucide@latest"></script>
|
||||||
@@ -24,7 +43,7 @@
|
|||||||
<script src="/static/js/services/midiExtractor.js?v=202607281052"></script>
|
<script src="/static/js/services/midiExtractor.js?v=202607281052"></script>
|
||||||
<script src="/static/js/services/promptTemplateManager.js?v=202607281039"></script>
|
<script src="/static/js/services/promptTemplateManager.js?v=202607281039"></script>
|
||||||
<script src="/static/js/services/undoRedoEngine.js?v=202607290941"></script>
|
<script src="/static/js/services/undoRedoEngine.js?v=202607290941"></script>
|
||||||
<script src="/static/js/app.precompiled.js?v=202608081200" defer></script>
|
<script src="/static/js/app.precompiled.js?v=202608081600" defer></script>
|
||||||
<link rel="stylesheet" href="/static/css/styles.css?v=202607271016">
|
<link rel="stylesheet" href="/static/css/styles.css?v=202607271016">
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
@@ -33,8 +52,43 @@
|
|||||||
--top-bar-height: 80px;
|
--top-bar-height: 80px;
|
||||||
--status-bar-height: 25px;
|
--status-bar-height: 25px;
|
||||||
--panel-border-color: #2a2a2a;
|
--panel-border-color: #2a2a2a;
|
||||||
|
/* Theme (Preferences) — có thể override bằng data-theme trên <html> */
|
||||||
|
--sf-bg: #1e1e1e;
|
||||||
|
--sf-panel: #262626;
|
||||||
|
--sf-header: #2e2e2e;
|
||||||
|
--sf-border: #181818;
|
||||||
|
--sf-accent: #00ffcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── THEME presets (Tools → Preferences) ── */
|
||||||
|
html[data-theme="dark"] {
|
||||||
|
--sf-bg: #1e1e1e; --sf-panel: #262626; --sf-header: #2e2e2e; --sf-border: #181818; --sf-accent: #00ffcc;
|
||||||
|
}
|
||||||
|
html[data-theme="midnight"] {
|
||||||
|
--sf-bg: #0f172a; --sf-panel: #1e293b; --sf-header: #1e293b; --sf-border: #0f172a; --sf-accent: #38bdf8;
|
||||||
|
}
|
||||||
|
html[data-theme="forest"] {
|
||||||
|
--sf-bg: #111c15; --sf-panel: #1b2a1e; --sf-header: #1e2d21; --sf-border: #0c1510; --sf-accent: #34d399;
|
||||||
|
}
|
||||||
|
html[data-theme="violet"] {
|
||||||
|
--sf-bg: #170f26; --sf-panel: #221537; --sf-header: #251640; --sf-border: #110a1c; --sf-accent: #a78bfa;
|
||||||
|
}
|
||||||
|
html[data-theme="graphite"] {
|
||||||
|
--sf-bg: #18181b; --sf-panel: #232327; --sf-header: #27272a; --sf-border: #101012; --sf-accent: #e4e4e7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Áp theme lên các vùng chính của app shell */
|
||||||
|
.daw-app-shell { background-color: var(--sf-bg) !important; }
|
||||||
|
.daw-panel { background-color: var(--sf-panel) !important; }
|
||||||
|
.daw-header { background-color: var(--sf-header) !important; }
|
||||||
|
body { background-color: var(--sf-bg) !important; }
|
||||||
|
::-webkit-scrollbar-thumb { background: var(--sf-accent); }
|
||||||
|
|
||||||
|
/* ── BUTTON FONT SIZE (Tools → Preferences) ── */
|
||||||
|
html[data-btnfont="sm"] button { font-size: 10px !important; }
|
||||||
|
html[data-btnfont="md"] button { font-size: 12px !important; }
|
||||||
|
html[data-btnfont="lg"] button { font-size: 14px !important; }
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color: #1a1a1a;
|
background-color: #1a1a1a;
|
||||||
color: #c0c0c0;
|
color: #c0c0c0;
|
||||||
|
|||||||
+30
-1
@@ -1,5 +1,7 @@
|
|||||||
# build_windows.ps1 — ONE-COMMAND build: daw_engine.exe (PyInstaller) + Tauri v2 (NSIS + MSI)
|
# build_windows.ps1 - ONE-COMMAND build: daw_engine.exe (PyInstaller) + Tauri v2 (NSIS + MSI)
|
||||||
# Chay tren Windows: powershell -ExecutionPolicy Bypass -File build_windows.ps1
|
# Chay tren Windows: powershell -ExecutionPolicy Bypass -File build_windows.ps1
|
||||||
|
# LUU Y: file nay chi dung ky tu ASCII (khong dau, khong em-dash) - PowerShell 5.1
|
||||||
|
# doc .ps1 khong BOM theo ANSI, ky tu Unicode bi hong -> "String is missing terminator".
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
Set-Location $PSScriptRoot
|
Set-Location $PSScriptRoot
|
||||||
|
|
||||||
@@ -9,11 +11,38 @@ python -m pip install -r requirements.txt pyinstaller pywin32
|
|||||||
|
|
||||||
Write-Host "== [2/6] Frontend bundle (app.jsx -> app.precompiled.js) =="
|
Write-Host "== [2/6] Frontend bundle (app.jsx -> app.precompiled.js) =="
|
||||||
npm install
|
npm install
|
||||||
|
# Dam bao @babel/standalone co (build.mjs import truc tiep - da gap
|
||||||
|
# ERR_MODULE_NOT_FOUND tren may Windows khi package.json cu thieu dep).
|
||||||
|
if (-not (Test-Path "node_modules\@babel\standalone")) {
|
||||||
|
Write-Host "Thieu @babel/standalone - dang cai them..."
|
||||||
|
npm install @babel/standalone --no-audit --no-fund
|
||||||
|
}
|
||||||
|
if (-not (Test-Path "node_modules\@babel\standalone")) {
|
||||||
|
Write-Host "ERROR: Khong cai duoc @babel/standalone. Kiem tra ket noi npm!" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
node build.mjs # @babel/standalone; thay cho 'npm run build' (Babel 8 ESM-only CLI conflict)
|
node build.mjs # @babel/standalone; thay cho 'npm run build' (Babel 8 ESM-only CLI conflict)
|
||||||
|
|
||||||
Write-Host "== [3/6] Build daw_engine.exe (PyInstaller) =="
|
Write-Host "== [3/6] Build daw_engine.exe (PyInstaller) =="
|
||||||
pyinstaller engine.spec --clean --noconfirm
|
pyinstaller engine.spec --clean --noconfirm
|
||||||
|
|
||||||
|
Write-Host "== [3.5/6] Verify bundle contents (app/static, app/templates phai co) =="
|
||||||
|
# Bat loi bundle NGAY tai build (da gap 2 lan: chay pyinstaller tu noi khac
|
||||||
|
# -> static/templates thieu -> exe crash 'Directory ...\app\static does not exist').
|
||||||
|
# Dung tools/verify_bundle.py (parse TOC bang ast, chap nhan ca / va \) thay
|
||||||
|
# vi regex thong thuong (TOC Windows co the dung backslash -> false positive).
|
||||||
|
# Truoc tien kiem tra engine.spec phai la ban moi (collect_data_files).
|
||||||
|
$specContent = Get-Content "engine.spec" -Raw -ErrorAction SilentlyContinue
|
||||||
|
if ($specContent -notmatch "collect_data_files\('app'") {
|
||||||
|
Write-Host "ERROR: engine.spec CU (thieu collect_data_files('app')). Pull code moi truoc khi build!" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
python tools\verify_bundle.py
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "ERROR: Bundle thieu asset - dung build, kiem tra engine.spec datas!" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "== [4/6] Sidecar binary -> src-tauri/binaries (tauri triple naming) =="
|
Write-Host "== [4/6] Sidecar binary -> src-tauri/binaries (tauri triple naming) =="
|
||||||
New-Item -ItemType Directory -Force src-tauri\binaries | Out-Null
|
New-Item -ItemType Directory -Force src-tauri\binaries | Out-Null
|
||||||
Copy-Item dist\daw_engine.exe src-tauri\binaries\daw_engine-x86_64-pc-windows-msvc.exe -Force
|
Copy-Item dist\daw_engine.exe src-tauri\binaries\daw_engine-x86_64-pc-windows-msvc.exe -Force
|
||||||
|
|||||||
+34
-5
@@ -28,6 +28,19 @@ def _pick_port():
|
|||||||
|
|
||||||
|
|
||||||
def _parent_alive(pid):
|
def _parent_alive(pid):
|
||||||
|
# Windows: os.kill(pid, 0) KHONG kiem tra ton tai — no goi
|
||||||
|
# TerminateProcess (giai thich: moi sig khac CTRL_C/BREAK deu terminate).
|
||||||
|
# => watchdog se GIET LUON tien trinh cha (Tauri) sau 1s dau tien.
|
||||||
|
# Dung OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION): tra ve NULL khi
|
||||||
|
# pid khong con ton tai.
|
||||||
|
if os.name == "nt":
|
||||||
|
import ctypes
|
||||||
|
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
||||||
|
h = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, pid)
|
||||||
|
if not h:
|
||||||
|
return False # tien trinh da chet
|
||||||
|
ctypes.windll.kernel32.CloseHandle(h)
|
||||||
|
return True
|
||||||
try:
|
try:
|
||||||
os.kill(pid, 0)
|
os.kill(pid, 0)
|
||||||
return True
|
return True
|
||||||
@@ -37,16 +50,32 @@ def _parent_alive(pid):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
os.environ.setdefault("SF_DESKTOP", "1")
|
os.environ.setdefault("SF_DESKTOP", "1")
|
||||||
|
|
||||||
|
# Log dir tao SOM de stderr co the tro vao file (xem duoi).
|
||||||
|
log_dir = os.path.join(
|
||||||
|
os.environ.get("APPDATA") or os.path.expanduser("~"),
|
||||||
|
APP_DATA_DIR_NAME, "logs",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
os.makedirs(log_dir, exist_ok=True)
|
||||||
|
except OSError:
|
||||||
|
log_dir = os.path.expanduser("~")
|
||||||
|
|
||||||
|
# Windowed app (engine.spec console=False): Windows khong tao console ->
|
||||||
|
# sys.stdout/sys.stderr = None -> uvicorn logging crash
|
||||||
|
# ('NoneType' object has no attribute 'isatty'). Tro stdout/stderr vao
|
||||||
|
# FILE (KHONG phai devnull) — neu devnull thi moi exception bi nuot im
|
||||||
|
# lang (trieu chung 'stuck khong logs, khong loi').
|
||||||
|
if sys.stdout is None:
|
||||||
|
sys.stdout = open(os.path.join(log_dir, "stdout.log"), "w", encoding="utf-8")
|
||||||
|
if sys.stderr is None:
|
||||||
|
sys.stderr = open(os.path.join(log_dir, "stderr.log"), "w", encoding="utf-8")
|
||||||
|
|
||||||
port = _pick_port()
|
port = _pick_port()
|
||||||
os.environ["SF_PORT"] = str(port)
|
os.environ["SF_PORT"] = str(port)
|
||||||
|
|
||||||
# Log ra file — khi dong goi console=False, stdout khong nhin thay duoc.
|
# Log ra file — khi dong goi console=False, stdout khong nhin thay duoc.
|
||||||
try:
|
try:
|
||||||
log_dir = os.path.join(
|
|
||||||
os.environ.get("APPDATA") or os.path.expanduser("~"),
|
|
||||||
APP_DATA_DIR_NAME, "logs",
|
|
||||||
)
|
|
||||||
os.makedirs(log_dir, exist_ok=True)
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
||||||
|
|||||||
+53
-11
@@ -9,20 +9,36 @@ from PyInstaller.utils.hooks import collect_dynamic_libs, collect_submodules, co
|
|||||||
binaries = collect_dynamic_libs('pedalboard')
|
binaries = collect_dynamic_libs('pedalboard')
|
||||||
binaries += collect_dynamic_libs('soundfile')
|
binaries += collect_dynamic_libs('soundfile')
|
||||||
|
|
||||||
# Root tuyet doi cua thu muc chua spec — datas PHẢI absolute: PyInstaller
|
# Root tuyet doi cua thu muc chua spec — dung cho cac datas KHONG nam trong
|
||||||
# resolve duong dan relative theo CWD luc chay lenh (KHONG theo spec file),
|
# package 'app' (vd thu muc md/). Cac assets cua app (static/templates/models)
|
||||||
# chay tu noi khac -> khong tim thay -> bo qua am tham -> app/static thieu
|
# duoc bundle qua collect_data_files('app').
|
||||||
# trong bundle -> RuntimeError 'app\static does not exist' luc chay (da gap).
|
|
||||||
_SPEC_ROOT = os.path.abspath(SPECPATH)
|
_SPEC_ROOT = os.path.abspath(SPECPATH)
|
||||||
|
|
||||||
# Assets doc (read-only) + thu muc storage (khoi tao rong; khi frozen,
|
# ⚠️ GOC ROOT CUA MOI LOI 'app\static does not exist' (gap 3 lan):
|
||||||
# config.py chuyen storage sang %APPDATA%\SonicForgeDAW\storage)
|
# lenh `pyinstaller engine.spec` (entry-point script) KHONG them CWD vao
|
||||||
|
# sys.path (chi `python -m PyInstaller` moi them). collect_data_files('app')
|
||||||
|
# import package qua sys.path -> khong thay 'app' -> tra ve [] AM THAM ->
|
||||||
|
# bundle thieu static/templates -> exe crash luc chay. Fix: chen _SPEC_ROOT
|
||||||
|
# vao sys.path TRUOC khi collect de import 'app' luon hoạt dong.
|
||||||
|
import sys as _sys
|
||||||
|
if _SPEC_ROOT not in _sys.path:
|
||||||
|
_sys.path.insert(0, _SPEC_ROOT)
|
||||||
|
|
||||||
|
# Assets cua app: bundle QUA IMPORT SYSTEM (collect_data_files) — an toan nhat.
|
||||||
|
# Loai tru storage (57MB soundfonts/uploads — vo ich trong onefile, config.py
|
||||||
|
# da chuyen storage sang %APPDATA%\\SonicForgeDAW khi frozen) va __pycache__.
|
||||||
|
datas = collect_data_files('app', excludes=['**/storage/**', '**/__pycache__/**', '**/*.pyc'])
|
||||||
|
# Fallback cuoi cung: neu collect_data_files van tra ve rong (phong moi truong
|
||||||
|
# hop ky la), dung datas TINH absolute — tinh huong xau nhat van co du assets.
|
||||||
|
if not datas:
|
||||||
|
print("WARN: collect_data_files('app') tra ve rong - dung datas tinh absolute")
|
||||||
datas = [
|
datas = [
|
||||||
(os.path.join(_SPEC_ROOT, 'app', 'templates'), 'app/templates'), # index.html, favicon.svg
|
(os.path.join(_SPEC_ROOT, 'app', 'templates'), 'app/templates'), # index.html, favicon.svg
|
||||||
(os.path.join(_SPEC_ROOT, 'app', 'static'), 'app/static'), # js/css/processors
|
(os.path.join(_SPEC_ROOT, 'app', 'static'), 'app/static'), # js/css/processors
|
||||||
(os.path.join(_SPEC_ROOT, 'app', 'models'), 'app/models'), # project_schema.json (projects.py)
|
(os.path.join(_SPEC_ROOT, 'app', 'models'), 'app/models'), # project_schema.json (projects.py)
|
||||||
(os.path.join(_SPEC_ROOT, 'app', 'storage'), 'app/storage'),
|
]
|
||||||
(os.path.join(_SPEC_ROOT, 'md'), 'md'), # /ai-prompt-generator
|
datas += [
|
||||||
|
(os.path.join(_SPEC_ROOT, 'md'), 'md'), # /ai-prompt-generator (doc, ngoai package app)
|
||||||
]
|
]
|
||||||
|
|
||||||
# librosa 0.11 dùng lazy_loader.attach_stub -> lúc RUNTIME cần file .pyi
|
# librosa 0.11 dùng lazy_loader.attach_stub -> lúc RUNTIME cần file .pyi
|
||||||
@@ -32,9 +48,35 @@ datas += collect_data_files('librosa', includes=['**/*.pyi'])
|
|||||||
|
|
||||||
# scipy >= 1.18 tach scipy.stats thanh nhieu module con (vd
|
# scipy >= 1.18 tach scipy.stats thanh nhieu module con (vd
|
||||||
# _ansari_swilk_statistics) import lazy ben trong ham -> hook scipy cua
|
# _ansari_swilk_statistics) import lazy ben trong ham -> hook scipy cua
|
||||||
# PyInstaller miss -> ModuleNotFoundError luc runtime. Collect toan bo
|
# PyInstaller miss -> ModuleNotFoundError luc runtime. Giai phap TRIET DE:
|
||||||
# submodules cua scipy de khong sot module nao (stats/signal/ndimage...).
|
# scan FILESYSTEM toan bo site-packages/scipy (khong import, khong walk —
|
||||||
_scipy_hidden = collect_submodules('scipy')
|
# pkgutil.walk_packages BO QUA AM THAM subpackage import loi luc build,
|
||||||
|
# da gap: may user mat ca cay scipy.sparse.csgraph._shortest_path).
|
||||||
|
# Bat moi module .py + C-extension .pyd/.so -> hiddenimports day du.
|
||||||
|
import importlib.util as _ilu
|
||||||
|
import glob as _glob
|
||||||
|
_scipy_spec = _ilu.find_spec('scipy')
|
||||||
|
_scipy_dir = os.path.dirname(os.path.abspath(_scipy_spec.origin))
|
||||||
|
_scipy_hidden = []
|
||||||
|
for _ext in ('*.py', '*.pyd', '*.so'):
|
||||||
|
for _f in _glob.glob(os.path.join(_scipy_dir, '**', _ext), recursive=True):
|
||||||
|
_rel = os.path.relpath(_f, _scipy_dir)
|
||||||
|
_base = os.path.basename(_rel).split('.')[0] # bo .cpython-312-x86_64... .so
|
||||||
|
_pkg = os.path.dirname(_rel).replace(os.sep, '.')
|
||||||
|
_mod = ('scipy.' + _pkg + '.' + _base) if _pkg else ('scipy.' + _base)
|
||||||
|
if _mod not in _scipy_hidden:
|
||||||
|
_scipy_hidden.append(_mod)
|
||||||
|
# Cung co bang hiddenimport TINH: _morestats import module nay o top-level
|
||||||
|
# (scipy 1.18+); collect_submodules du phong nhung neu miss (version khac
|
||||||
|
# tren may user) thi dong nay van dam bao bundle co.
|
||||||
|
if 'scipy.stats._ansari_swilk_statistics' not in _scipy_hidden:
|
||||||
|
_scipy_hidden.append('scipy.stats._ansari_swilk_statistics')
|
||||||
|
# scipy.sparse.csgraph cung lazy-import C-extension tu ben trong ham (vd
|
||||||
|
# _shortest_path, _traversal, _matching) — hiddenimport tinh phong walk miss.
|
||||||
|
for _m in ('scipy.sparse.csgraph._shortest_path', 'scipy.sparse.csgraph._traversal',
|
||||||
|
'scipy.sparse.csgraph._matching', 'scipy.sparse.csgraph._min_spanning_tree'):
|
||||||
|
if _m not in _scipy_hidden:
|
||||||
|
_scipy_hidden.append(_m)
|
||||||
|
|
||||||
a = Analysis(
|
a = Analysis(
|
||||||
['desktop_engine.py'],
|
['desktop_engine.py'],
|
||||||
|
|||||||
Generated
+10
@@ -9,6 +9,7 @@
|
|||||||
"@babel/cli": "^8.0.4",
|
"@babel/cli": "^8.0.4",
|
||||||
"@babel/core": "^8.0.1",
|
"@babel/core": "^8.0.1",
|
||||||
"@babel/preset-react": "^8.0.1",
|
"@babel/preset-react": "^8.0.1",
|
||||||
|
"@babel/standalone": "^7.29.8",
|
||||||
"jsdom": "^30.0.1",
|
"jsdom": "^30.0.1",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.8",
|
||||||
"react-dom": "^19.2.8"
|
"react-dom": "^19.2.8"
|
||||||
@@ -355,6 +356,15 @@
|
|||||||
"@babel/core": "^8.0.0"
|
"@babel/core": "^8.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@babel/standalone": {
|
||||||
|
"version": "7.29.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/standalone/-/standalone-7.29.8.tgz",
|
||||||
|
"integrity": "sha512-XgbPNz+u6JzB7cKGnPDoS1U24J5td8yp3HFWbT/6f4/ASZ0PqaQGIvts1o5v5AI+f6i3jdVB/L/o2CYLCv101A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@babel/template": {
|
"node_modules/@babel/template": {
|
||||||
"version": "8.0.0",
|
"version": "8.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-8.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/template/-/template-8.0.0.tgz",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"@babel/cli": "^8.0.4",
|
"@babel/cli": "^8.0.4",
|
||||||
"@babel/core": "^8.0.1",
|
"@babel/core": "^8.0.1",
|
||||||
"@babel/preset-react": "^8.0.1",
|
"@babel/preset-react": "^8.0.1",
|
||||||
|
"@babel/standalone": "^7.29.8",
|
||||||
"jsdom": "^30.0.1",
|
"jsdom": "^30.0.1",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.8",
|
||||||
"react-dom": "^19.2.8"
|
"react-dom": "^19.2.8"
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Verify PyInstaller bundle TOC chua du app assets (app/static, app/templates).
|
||||||
|
|
||||||
|
Dung boi build_windows.ps1 (buoc 3.5/6) de bat loi bundle NGAY tai build:
|
||||||
|
python tools/verify_bundle.py
|
||||||
|
Exit code 0 = OK, 1 = thieu asset.
|
||||||
|
|
||||||
|
Ly do ton tai: da gap 2 lan exe crash 'Directory ...\\app\\static does not exist'
|
||||||
|
vi chay pyinstaller tu noi khac -> datas relative khong resolve -> bo qua am tham.
|
||||||
|
"""
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
REQUIRED = ["app/static", "app/templates"]
|
||||||
|
|
||||||
|
|
||||||
|
def find_toc(build_dir: str) -> str:
|
||||||
|
# PyInstaller 6.x: build/engine/Analysis-00.toc (hoac *-00.toc khac)
|
||||||
|
for pattern in (
|
||||||
|
os.path.join(build_dir, "engine", "Analysis-00.toc"),
|
||||||
|
os.path.join(build_dir, "engine", "*-00.toc"),
|
||||||
|
os.path.join(build_dir, "**", "Analysis-00.toc"),
|
||||||
|
os.path.join(build_dir, "**", "*-00.toc"),
|
||||||
|
):
|
||||||
|
hits = glob.glob(pattern, recursive=True)
|
||||||
|
if hits:
|
||||||
|
return hits[0]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
build_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "build"))
|
||||||
|
toc = find_toc(build_dir)
|
||||||
|
if not toc:
|
||||||
|
print(f"WARN: khong tim thay TOC trong {build_dir} - bo qua verify (tiep tuc build)")
|
||||||
|
return 0
|
||||||
|
print(f"Verify TOC: {toc}")
|
||||||
|
with open(toc, "r", encoding="utf-8", errors="replace") as f:
|
||||||
|
raw = f.read()
|
||||||
|
# TOC Windows co the dung backslash (app\\static) — normalize het ve forward
|
||||||
|
# slash de kiem tra khong bi false positive. TOC la Python literal nen
|
||||||
|
# backslash bi DOUBLE-escape ('app\\\\static') — thay 2 lan (\\\\ truoc,
|
||||||
|
# roi \\) de ca 2 dang deu ve '/'.
|
||||||
|
text = raw.replace("\\\\", "/").replace("\\", "/")
|
||||||
|
missing = []
|
||||||
|
for req in REQUIRED:
|
||||||
|
# Tim theo prefix thuc su trong TOC (vd 'app/static/js/...' hoac
|
||||||
|
# string repr 'app/static/...' trong tuple DATA entry).
|
||||||
|
if not re.search(re.escape(req) + r"(?=[/'\"]|$)", text):
|
||||||
|
missing.append(req)
|
||||||
|
if missing:
|
||||||
|
print(f"ERROR: Bundle thieu: {', '.join(missing)}. Kiem tra engine.spec datas!")
|
||||||
|
return 1
|
||||||
|
print("OK: app/static + app/templates co trong bundle.")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -1,3 +1,93 @@
|
|||||||
|
### [2026-08-08] FIX: verify_bundle.py vẫn false-positive trên Windows — TOC là Python literal nên backslash bị DOUBLE-escape ('app\\\\static')
|
||||||
|
- **Tóm tắt thay đổi:** Fix LAN 2 normalize `replace('\\','/')` 1 lần KHÔNG đủ: TOC file là Python literal (repr) → path Windows ghi thành `app\\\\static` (2 backslash trên disk) → replace 1 lần ra `app//static` → regex `app/static(?=[/'"])` không match → vẫn báo "Bundle thieu" DÙ bundle đủ. Fix: normalize 2 bước — `replace("\\\\","/")` (bắt double-escape) rồi `replace("\\","/")` (backslash đơn). Verify bằng TOC giả lập Windows repr: cả 2 entry match True.
|
||||||
|
- **Các file ảnh hưởng:** `tools/verify_bundle.py` (dòng normalize)
|
||||||
|
- **Ghi chú/Test (nếu có):** Test TOC Windows repr `'app\\\\static\\\\js\\\\app.js'` → normalize ra `app/static/js/app.js` → regex match. User: pull code mới rồi chạy lại build_windows.ps1 (bước 3.5 sẽ hết báo thiếu nếu bundle thực sự đủ).
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX (LAN 3 - GOC ROOT): 'app\\static does not exist' — sys.path thieu CWD khi chay 'pyinstaller' (entry point)
|
||||||
|
- **Tóm tắt thay đổi:** Lỗi 'app\static does not exist' vẫn tái diễn dù đã 2 lần sửa datas (absolute path roi collect_data_files). Lần này tìm ra GOC ROOT THẬT SỰ: lệnh `pyinstaller engine.spec` (entry-point script cua PyInstaller) KHONG them CWD vao sys.path — chi `python -m PyInstaller` moi them. `collect_data_files('app')` import package 'app' qua sys.path -> khong thay -> tra ve [] AM THAM -> bundle thieu static/templates (dung canh: tren may dev chay `python -m PyInstaller` nen CWD co trong sys.path -> tuong da dung; may Windows chay `pyinstaller` -> CWD khong co -> collect rong -> TOC khong co app/static — dung voi loi verify cua user). Fix trong `engine.spec`:
|
||||||
|
1. `sys.path.insert(0, _SPEC_ROOT)` TRUOC khi goi collect_data_files — import 'app' luon hoạt dong bat ke CWD.
|
||||||
|
2. Fallback cuoi: neu collect_data_files van tra ve rong -> datas TINH absolute (app/templates, app/static, app/models) + in WARN de debug.
|
||||||
|
- **Cac file anh huong:** `engine.spec` (sys.path insert + fallback datas tinh)
|
||||||
|
- **Ghi chu/Test (neu co):** VERIFY DUNG DIEU KIEN THAT BAI: build tu /tmp (CWD khac project root — giong `pyinstaller` entry point khong co CWD trong sys.path) -> TOC co app/static (124) + app/templates (12), khong co WARN "tra ve rong"; tools/verify_bundle.py -> OK exit 0; chay binary frozen -> /health OK, index 200, static js 200. pytest 86 passed. User: pull engine.spec moi roi chay lai build_windows.ps1.
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX (lan 2): ERR_MODULE_NOT_FOUND '@babel/standalone' vẫn xảy ra — build_windows.ps1 TỰ cài dep nếu thiếu
|
||||||
|
- **Tóm tắt thay đổi:** User vẫn gặp ERR_MODULE_NOT_FOUND '@babel/standalone' dù đã thêm vào package.json — máy Windows chưa pull package.json mới hoặc npm install chưa cài. Fix: `build_windows.ps1` bước [2/6] — sau `npm install`, TỰ KIỂM TRA `node_modules\@babel\standalone`; thiếu → `npm install @babel/standalone --no-audit --no-fund`; vẫn thiếu → ERROR + exit 1. Không còn phụ thuộc package.json mới trên máy user.
|
||||||
|
- **Các file ảnh hưởng:** `build_windows.ps1` (bước 2 tự cài @babel/standalone)
|
||||||
|
- **Ghi chú/Test (nếu có):** File ASCII-only + UTF-8 BOM (không lặp lỗi PS5.1), brace depth 0. User: pull build_windows.ps1 mới (hoặc toàn bộ) rồi chạy lại.
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX: build.mjs ERR_MODULE_NOT_FOUND '@babel/standalone' trên Windows — package.json thiếu dependency
|
||||||
|
- **Tóm tắt thay đổi:** User chạy build_windows.ps1 (bước 2/6 node build.mjs) nhận `Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/standalone' imported from build.mjs`. Root cause: `build.mjs` import `@babel/standalone` nhưng **package.json KHÔNG khai báo** dependency này (máy dev có sẵn trong node_modules từ trước nên không lộ; máy Windows `npm install` chỉ cài theo package.json → thiếu). Fix: thêm `"@babel/standalone": "^7.29.8"` vào dependencies + chạy `npm install` cập nhật `package-lock.json`.
|
||||||
|
- **Các file ảnh hưởng:** `package.json` (+@babel/standalone), `package-lock.json` (npm install)
|
||||||
|
- **Ghi chú/Test (nếu có):** npm install OK (up to date), package-lock có node_modules/@babel/standalone, `node build.mjs` BUILD OK 1123403 bytes + node --check OK. User: pull code mới rồi chạy lại build_windows.ps1.
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX: verify bundle [3.5/6] false-positive 'app/static thieu' + check spec version — tools/verify_bundle.py
|
||||||
|
- **Tóm tắt thay đổi:** User chạy build_windows.ps1 — bước verify [3.5/6] mới báo "ERROR: Bundle thieu: app/static, app/templates" nhưng thực tế bundle ĐỦ (collect_data_files('app') đã hoạt động — verify bằng build Linux). Root cause: script verify cũ dùng regex `-notmatch "app/static"` trên raw TOC — trên Windows TOC chứa `app\static` (BACKSLASH) → regex forward-slash không match → FALSE POSITIVE báo thiếu. Fix:
|
||||||
|
1. **tools/verify_bundle.py** (mới): verify TOC bằng Python — đọc text, `replace('\\','/')` normalize backslash→forward, regex theo prefix `app/static(?=[/'"]|$)`; exit 0 OK / 1 thiếu; không có TOC → WARN + exit 0 (không chặn build). Test 4 case: backslash OK, forward OK, thiếu static → ERROR, không TOC → WARN.
|
||||||
|
2. **build_windows.ps1 [3.5/6]**: trước tiên check `engine.spec` có chứa `collect_data_files('app')` — nếu spec CŨ (chưa pull code mới) → báo rõ "engine.spec CU... Pull code moi" + exit 1 (tránh nhầm lẫn nguyên nhân). Sau đó chạy `python tools\verify_bundle.py` + check `$LASTEXITCODE`.
|
||||||
|
- **Các file ảnh hưởng:** `tools/verify_bundle.py` (mới), `build_windows.ps1` (bước 3.5 gọi script + check spec)
|
||||||
|
- **Ghi chú/Test (nếu có):** verify_bundle.py test 4 case đều đúng; chạy với TOC THẬT (build Linux PyInstaller 6.21) → "Thiếu: KHÔNG — OK". Binary frozen: /health OK, index 200, static js 200. pytest 86 passed. User: pull code mới (có tools/verify_bundle.py) rồi chạy lại build_windows.ps1.
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX: build_windows.ps1 lỗi parse PowerShell — "String is missing terminator" (file chứa ký tự Unicode, PS 5.1 đọc theo ANSI)
|
||||||
|
- **Tóm tắt thay đổi:** User chạy build_windows.ps1 trên Windows nhận ParserError "String is missing terminator" ở dòng 57 + "Missing closing '}'" ở dòng 34. Root cause: bản mình thêm bước verify [3.5/6] có chứa ký tự Unicode (em-dash `—` trong comment + chuỗi tiếng Việt có dấu "thiếu/Dừng/kiểm tra"). PowerShell 5.1 đọc file .ps1 KHÔNG có BOM theo ANSI/Windows-1252 → byte UTF-8 của `—` (E2 80 94) giải mã thành `â€"` — dấu ngoặc kép giả chui vào giữa chuỗi → chuỗi "mất terminator" + block `{}` lệch. Fix:
|
||||||
|
1. Viết lại toàn bộ build_windows.ps1 **chỉ ASCII** (bỏ dấu tiếng Việt, bỏ em-dash, dùng `->`).
|
||||||
|
2. Thêm **UTF-8 BOM** (EF BB BF) vào đầu file — PowerShell đọc đúng encoding bất kể.
|
||||||
|
3. Giữ nguyên bước verify [3.5/6] (TOC check app/static + app/templates).
|
||||||
|
- **Các file ảnh hưởng:** `build_windows.ps1` (ASCII-only + BOM)
|
||||||
|
- **Ghi chú/Test (nếu có):** File giờ 0 ký tự non-ASCII, có BOM; brace depth = 0 (cân bằng), không có dòng Write-Host quote lẻ. Lưu ý chung: MỌI .ps1/.bat trong dự án phải ASCII-only + BOM (PS 5.1 ANSI bug) — tránh tiếng Việt có dấu/em-dash trong file script Windows.
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX (LẦN 2): Windows exe vẫn crash 'app\static does not exist' + stuck 'Đang khởi động Engine' — bundle qua collect_data_files + fallback + verify build
|
||||||
|
- **Tóm tắt thay đổi:** User build bản Windows vẫn gặp RuntimeError `Directory '..._MEIxxxx\app\static' does not exist` (lần 2 — fix trước dùng datas ABSOLUTE theo SPECPATH nhưng trên máy user vẫn thiếu static trong bundle) + UI stuck "Đang khởi động SonicForge Engine". 3 lớp phòng thủ:
|
||||||
|
1. **engine.spec — bundle qua IMPORT SYSTEM**: bỏ datas đường dẫn tĩnh, thay bằng `collect_data_files('app', excludes=['**/storage/**','**/__pycache__/**','**/*.pyc'])` — PyInstaller tự tìm assets (static/templates/models) qua package import, KHÔNG phụ thuộc CWD/SPECPATH lúc chạy lệnh (nguyên nhân gốc: chạy pyinstaller từ thư mục khác → relative path không resolve → bỏ qua âm thầm). Loại luôn `app/storage` (57MB soundfonts — vô ích trong onefile, config.py đã redirect %APPDATA%). Giữ `md/` (ngoài package) + librosa .pyi.
|
||||||
|
2. **app/main.py — fallback an toàn**: nếu STATIC_DIR không tồn tại → thử `sys._MEIPASS/app/static` và `dirname(__file__)/static`; vẫn thiếu → **tự os.makedirs** → StaticFiles không còn crash lúc import (engine không chết, app hiện lỗi rõ thay vì 6 hộp thoại + stuck loader).
|
||||||
|
3. **build_windows.ps1 — verify post-build [3.5/6]**: sau pyinstaller, đọc Analysis-00.toc kiểm tra `app/static` + `app/templates` có trong bundle — thiếu → in ERROR đỏ + `exit 1` (bắt lỗi NGAY lúc build, không đợi chạy app mới vỡ).
|
||||||
|
- **Các file ảnh hưởng:** `engine.spec` (collect_data_files('app') + bỏ storage), `app/main.py` (fallback static dir), `build_windows.ps1` (verify TOC post-build)
|
||||||
|
- **Ghi chú/Test (nếu có):** VERIFY THẬT trên Linux (PyInstaller 6.21, cùng spec): Analysis-00.toc chứa app/static (124), app/templates (12), app/models (5); exe 155MB (giảm 57MB); chạy binary frozen → /health OK, index 200, static js 200, favicon 200, không crash. pytest 86 passed. User cần chạy lại `build_windows.ps1` (bước 3.5 sẽ tự kiểm tra bundle).
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] IMPROVE: About modal — logo dùng favicon của app (app/templates/favicon.svg, serve /favicon.svg)
|
||||||
|
- **Tóm tắt thay đổi:** User yêu cầu logo trong About modal phải là logo của web/app — favicon lưu trong hệ thống. Trước đây AboutModal dùng div gradient chữ "SF". Fix: thay bằng `<img src="/favicon.svg">` (route đã có sẵn trong app/main.py — serve từ TEMPLATES_DIR; file app/templates/favicon.svg, SVG 1254x1254). Hiển thị 48x48 object-contain, nền tối + border cho nổi trên modal.
|
||||||
|
- **Các file ảnh hưởng:** `app/static/js/app.jsx` (AboutModal img), `app/static/js/app.precompiled.js` (rebuild), `app/templates/index.html` (bump v=202608081600)
|
||||||
|
- **Ghi chú/Test (nếu có):** BUILD OK 1123403 bytes, node --check OK, pytest 86 passed. Verify: /favicon.svg 200 image/svg+xml, bundle chứa "favicon.svg".
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FEAT: Menu Help (About + Hướng dẫn sử dụng) + Tools → Preferences (Theme/Language/Button font size)
|
||||||
|
- **Tóm tắt thay đổi:** User yêu cầu 2 nhóm tính năng:
|
||||||
|
1. **Menu Help**:
|
||||||
|
- `About SonicForge Studio...` → **AboutModal** mới: dev **Lộc Phạm**, email **tranloclqd@gmail.com**, version `1.0.0` (khớp tauri.conf.json), build Standalone (Tauri v2 + PyInstaller).
|
||||||
|
- `Hướng dẫn sử dụng...` → **HelpModal** mới: 8 mục hướng dẫn song ngữ (vi/en theo language preference): Bắt đầu nhanh, MIDI & ARM, Piano Roll, FX & Master, SoundFont & VST, AI, Lưu & Xuất, Phím tắt.
|
||||||
|
2. **Tools → Preferences...** → **PreferencesModal** mới quản lý:
|
||||||
|
- **Theme** (5 preset): dark (mặc định), midnight, forest, violet, graphite — áp qua `data-theme` trên `<html>` + CSS variables `--sf-bg/--sf-panel/--sf-header/--sf-border/--sf-accent` (thêm trong index.html `<style>`, override .daw-app-shell/.daw-panel/.daw-header/body/scrollbar).
|
||||||
|
- **Language**: vi/en — áp ngay cho HelpModal + PreferencesModal (menu chính giữ nguyên — app vốn song ngữ lẫn lộn).
|
||||||
|
- **Button font size**: sm/md/lg — áp qua `data-btnfont` trên `<html>` + CSS `html[data-btnfont=...] button { font-size: ... !important }`.
|
||||||
|
3. **Lưu trữ**: localStorage `sf_prefs` + server `/api/v1/user/preferences` (window.SonicAPI.getPreferences/savePreferences — endpoint đã có sẵn). Load server prefs khi khởi động.
|
||||||
|
- **Các file ảnh hưởng:** `app/static/js/app.jsx` (AboutModal/HelpModal/PreferencesModal mới + state prefs + menu Tools/Help + render 3 modal), `app/static/js/app.precompiled.js` (rebuild), `app/templates/index.html` (CSS theme + data-btnfont + bump v=202608081500)
|
||||||
|
- **Ghi chú/Test (nếu có):** BUILD OK 1123418 bytes, node --check OK, pytest 86 passed. Verify serve: index 200, precompiled 200, bundle chứa đủ "Hướng dẫn sử dụng", "tranloclqd@gmail.com", "data-btnfont", "Preferences". Lưu ý: button font size dùng !important nên override cả text-xs của Tailwind — đúng ý "đổi cỡ chữ button" nhưng có thể làm một số nút hơi to/nhỏ so với thiết kế gốc.
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX: VU meter giữ animation đúng TRƯỜNG ĐỘ âm thanh khi ARM + nhấn/giữ phím MIDI keyboard
|
||||||
|
- **Tóm tắt thay đổi:** User yêu cầu: bật ARM + nhấn phím MIDI keyboard preview — khi âm CÒN PLAY thì VU meter phải còn animate cho đúng trường độ âm thanh. Trước đây: note-on → `triggerMidiVuActivity` set peak → VU tick decay 0.75/frame → VU tắt sau ~0.5s DÙ âm còn kêu (note dài 60000ms, chỉ tắt khi note-off). Root cause: VU tick decay theo thời gian, không biết note đang giữ. Fix:
|
||||||
|
1. **`heldMidiNotesRef`** (mới): đếm số note MIDI đang GIỮ per-track (ARM + keyboard live). Note-on → tăng counter (cả nhánh armed sub-tab PIANO_ROLL lẫn armed main track); note-off → giảm, về 0 thì xóa.
|
||||||
|
2. **VU tick**: `heldCnt = heldMidiNotesRef.current[vuKey]` — còn note giữ (heldCnt > 0) → GIỮ NGUYÊN peak, KHÔNG decay → VU animate suốt trường độ; hết note (note-off) → decay 0.75 (~0.5s) tắt nhanh như cũ (giữ hành vi user bug 07:15 "hết âm → VU tắt ngay").
|
||||||
|
3. **stopAllPlayback**: clear luôn `heldMidiNotesRef.current = {}` cùng với `midiVuActivityRef` — tránh sau STOP (âm đã dừng) tick vẫn thấy counter > 0 → giữ peak → VU dính mãi.
|
||||||
|
- **Các file ảnh hưởng:** `app/static/js/app.jsx` (heldMidiNotesRef + note-on/note-off counters + VU tick giữ peak), `app/static/js/app.precompiled.js` (rebuild), `app/templates/index.html` (bump v=202608081400)
|
||||||
|
- **Ghi chú/Test (nếu có):** BUILD OK 1109174 bytes, node --check OK, pytest 86 passed + 5 skipped. Luồng: nhấn giữ phím → VU giữ peak; nhả phím (note-off) → VU decay ~0.5s rồi tắt; STOP → VU tắt ngay. Keybed click (mousedown duration 500ms) giữ nguyên hành vi cũ (không qua heldMidiNotesRef).
|
||||||
|
|
||||||
|
---
|
||||||
|
### [2026-08-08] FIX: Chặn browser zoom toàn trang — item/button/label giữ nguyên kích thước khi phóng to UI
|
||||||
|
- **Tóm tắt thay đổi:** User yêu cầu: khi phóng to giao diện, các item/button/label PHẢI GIỮ NGUYÊN kích thước hiện tại — chỉ các vùng flexible co giãn + cho phép user tự kéo resize (resizer TCP/sidebar/media-explorer/track-height ĐÃ có sẵn). Root cause: layout vốn dùng px cố định (không scale theo window), nhưng **browser zoom toàn trang** (Ctrl+wheel, Ctrl+plus/minus/0, pinch gesture) scale TOÀN BỘ UI → control phóng to theo. WebView2 (Tauri) mặc định bật zoom control. Fix trong `app/templates/index.html`:
|
||||||
|
1. Meta viewport thêm `maximum-scale=1.0, user-scalable=no`.
|
||||||
|
2. Inline script chặn zoom ở **capture phase** bằng `preventDefault()` — KHÔNG `stopPropagation()` nên các vùng zoom CHUYÊN DỤNG vẫn nhận event và hoạt động bình thường: timeline zoom (Ctrl+wheel, 18999), piano-roll grid zoom (7351), waveform canvas zoom (12189), EQ canvas wheel (10144).
|
||||||
|
3. Chặn keydown Ctrl+'+'/'-'/'='/'_'/'0' + gesturestart/gesturechange (pinch Safari/WebKit).
|
||||||
|
- **Các file ảnh hưởng:** `app/templates/index.html` (meta viewport + zoom-guard script inline)
|
||||||
|
- **Ghi chú/Test (nếu có):** index.html serve OK (uvicorn), script extract + node --check OK. Không đụng app.jsx/app.precompiled.js (index.html no-cache nên không cần bump stamp). Resizer panel giữ nguyên — user vẫn kéo được TCP width (280-600), sidebar (200-600), media-explorer (20-80%), track height (110-300).
|
||||||
|
|
||||||
|
---
|
||||||
### [2026-08-08] FIX: Windows runtime — ModuleNotFoundError scipy.stats._ansari_swilk_statistics + ValueError librosa stub (PyInstaller bundle)
|
### [2026-08-08] FIX: Windows runtime — ModuleNotFoundError scipy.stats._ansari_swilk_statistics + ValueError librosa stub (PyInstaller bundle)
|
||||||
- **Tóm tắt thay đổi:** User chạy bản Windows exe gặp 2 lỗi runtime (hộp thoại error):
|
- **Tóm tắt thay đổi:** User chạy bản Windows exe gặp 2 lỗi runtime (hộp thoại error):
|
||||||
1. `ModuleNotFoundError: No module named 'scipy.stats._ansari_swilk_statistics'` — scipy >= 1.18 tách `scipy.stats` thành nhiều module con import LAZY bên trong hàm (vd `_ansari_swilk_statistics`) → hook scipy của PyInstaller không thấy → thiếu trong bundle. Fix: `engine.spec` thêm `collect_submodules('scipy')` vào hiddenimports (collect toàn bộ stats/signal/ndimage/... — không sót module nào).
|
1. `ModuleNotFoundError: No module named 'scipy.stats._ansari_swilk_statistics'` — scipy >= 1.18 tách `scipy.stats` thành nhiều module con import LAZY bên trong hàm (vd `_ansari_swilk_statistics`) → hook scipy của PyInstaller không thấy → thiếu trong bundle. Fix: `engine.spec` thêm `collect_submodules('scipy')` vào hiddenimports (collect toàn bộ stats/signal/ndimage/... — không sót module nào).
|
||||||
|
|||||||
Reference in New Issue
Block a user