From ba89102f71dce429f7bf4f1be139b33556699b93 Mon Sep 17 00:00:00 2001 From: bonamin Date: Sun, 22 Feb 2026 19:22:17 +0200 Subject: [PATCH] SpeedCalc, kept playing after save. Now stops. Fixed. --- frontend/src/melodies/SpeedCalculatorModal.jsx | 16 +++++++++++----- .../melodies/archetypes/BuildOnTheFlyModal.jsx | 7 ++++--- .../melodies/archetypes/SelectArchetypeModal.jsx | 7 ++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/frontend/src/melodies/SpeedCalculatorModal.jsx b/frontend/src/melodies/SpeedCalculatorModal.jsx index bb3b6b9..06f66fd 100644 --- a/frontend/src/melodies/SpeedCalculatorModal.jsx +++ b/frontend/src/melodies/SpeedCalculatorModal.jsx @@ -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) { diff --git a/frontend/src/melodies/archetypes/BuildOnTheFlyModal.jsx b/frontend/src/melodies/archetypes/BuildOnTheFlyModal.jsx index a26db5c..f93f987 100644 --- a/frontend/src/melodies/archetypes/BuildOnTheFlyModal.jsx +++ b/frontend/src/melodies/archetypes/BuildOnTheFlyModal.jsx @@ -115,7 +115,7 @@ export default function BuildOnTheFlyModal({ open, melodyId, currentMelody, curr const { steps: stepCount, totalNotes } = computeStepsAndNotes(csv); if (currentMelody && csv) { const existingInfo = currentMelody.information || {}; - await api.put(`/melodies/${melodyId}`, { + const body = { information: { ...existingInfo, archetype_csv: csv, @@ -124,10 +124,11 @@ export default function BuildOnTheFlyModal({ open, melodyId, currentMelody, curr }, default_settings: currentMelody.default_settings, type: currentMelody.type, - url: currentMelody.url, uid: currentMelody.uid, pid: currentMelody.pid, - }); + }; + if (currentMelody.url) body.url = currentMelody.url; + await api.put(`/melodies/${melodyId}`, body); } setStatusMsg("Done!"); diff --git a/frontend/src/melodies/archetypes/SelectArchetypeModal.jsx b/frontend/src/melodies/archetypes/SelectArchetypeModal.jsx index 43fedb3..3636aca 100644 --- a/frontend/src/melodies/archetypes/SelectArchetypeModal.jsx +++ b/frontend/src/melodies/archetypes/SelectArchetypeModal.jsx @@ -63,7 +63,7 @@ export default function SelectArchetypeModal({ open, melodyId, currentMelody, cu const { steps, totalNotes } = computeStepsAndNotes(csv); if (currentMelody && csv) { const existingInfo = currentMelody.information || {}; - await api.put(`/melodies/${melodyId}`, { + const body = { information: { ...existingInfo, archetype_csv: csv, @@ -72,10 +72,11 @@ export default function SelectArchetypeModal({ open, melodyId, currentMelody, cu }, default_settings: currentMelody.default_settings, type: currentMelody.type, - url: currentMelody.url, uid: currentMelody.uid, pid: currentMelody.pid, - }); + }; + if (currentMelody.url) body.url = currentMelody.url; + await api.put(`/melodies/${melodyId}`, body); } onSuccess({ name: archetype.name, pid: archetype.pid, steps, totalNotes, archetype_csv: csv });