SpeedCalc, kept playing after save. Now stops. Fixed.

This commit is contained in:
2026-02-22 19:22:17 +02:00
parent fadd492421
commit ba89102f71
3 changed files with 19 additions and 11 deletions

View File

@@ -167,8 +167,12 @@ export default function SpeedCalculatorModal({ open, melody, builtMelody, archet
// Reset on open — auto-load archetype CSV if available
useEffect(() => {
if (open) {
setCapturedMax(info.maxSpeed > 0 ? info.maxSpeed : null);
setCapturedNormal(null);
const max = info.maxSpeed > 0 ? info.maxSpeed : null;
const min = info.minSpeed > 0 ? info.minSpeed : null;
// Reverse-calculate Normal from MIN and MAX: normal = sqrt(min * max)
const normal = (max !== null && min !== null) ? Math.round(Math.sqrt(min * max)) : null;
setCapturedMax(max);
setCapturedNormal(normal);
setBinaryLoadError("");
setCurrentStep(-1);
setPlaying(false);
@@ -315,11 +319,12 @@ export default function SpeedCalculatorModal({ open, melody, builtMelody, archet
const handleSave = async () => {
if (!capturedMax || !capturedNormal || !derivedMin) return;
stopPlayback();
setSaving(true);
setSaveError("");
setSaveSuccess(false);
try {
await api.put(`/melodies/${melody.id}`, {
const body = {
information: {
...info,
minSpeed: derivedMin,
@@ -327,10 +332,11 @@ export default function SpeedCalculatorModal({ open, melody, builtMelody, archet
},
default_settings: melody.default_settings,
type: melody.type,
url: melody.url,
uid: melody.uid,
pid: melody.pid,
});
};
if (melody.url) body.url = melody.url;
await api.put(`/melodies/${melody.id}`, body);
setSaveSuccess(true);
setTimeout(() => onSaved(), 800);
} catch (err) {