SpeedCalc, kept playing after save. Now stops. Fixed.
This commit is contained in:
@@ -167,8 +167,12 @@ export default function SpeedCalculatorModal({ open, melody, builtMelody, archet
|
|||||||
// Reset on open — auto-load archetype CSV if available
|
// Reset on open — auto-load archetype CSV if available
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
setCapturedMax(info.maxSpeed > 0 ? info.maxSpeed : null);
|
const max = info.maxSpeed > 0 ? info.maxSpeed : null;
|
||||||
setCapturedNormal(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("");
|
setBinaryLoadError("");
|
||||||
setCurrentStep(-1);
|
setCurrentStep(-1);
|
||||||
setPlaying(false);
|
setPlaying(false);
|
||||||
@@ -315,11 +319,12 @@ export default function SpeedCalculatorModal({ open, melody, builtMelody, archet
|
|||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!capturedMax || !capturedNormal || !derivedMin) return;
|
if (!capturedMax || !capturedNormal || !derivedMin) return;
|
||||||
|
stopPlayback();
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setSaveError("");
|
setSaveError("");
|
||||||
setSaveSuccess(false);
|
setSaveSuccess(false);
|
||||||
try {
|
try {
|
||||||
await api.put(`/melodies/${melody.id}`, {
|
const body = {
|
||||||
information: {
|
information: {
|
||||||
...info,
|
...info,
|
||||||
minSpeed: derivedMin,
|
minSpeed: derivedMin,
|
||||||
@@ -327,10 +332,11 @@ export default function SpeedCalculatorModal({ open, melody, builtMelody, archet
|
|||||||
},
|
},
|
||||||
default_settings: melody.default_settings,
|
default_settings: melody.default_settings,
|
||||||
type: melody.type,
|
type: melody.type,
|
||||||
url: melody.url,
|
|
||||||
uid: melody.uid,
|
uid: melody.uid,
|
||||||
pid: melody.pid,
|
pid: melody.pid,
|
||||||
});
|
};
|
||||||
|
if (melody.url) body.url = melody.url;
|
||||||
|
await api.put(`/melodies/${melody.id}`, body);
|
||||||
setSaveSuccess(true);
|
setSaveSuccess(true);
|
||||||
setTimeout(() => onSaved(), 800);
|
setTimeout(() => onSaved(), 800);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export default function BuildOnTheFlyModal({ open, melodyId, currentMelody, curr
|
|||||||
const { steps: stepCount, totalNotes } = computeStepsAndNotes(csv);
|
const { steps: stepCount, totalNotes } = computeStepsAndNotes(csv);
|
||||||
if (currentMelody && csv) {
|
if (currentMelody && csv) {
|
||||||
const existingInfo = currentMelody.information || {};
|
const existingInfo = currentMelody.information || {};
|
||||||
await api.put(`/melodies/${melodyId}`, {
|
const body = {
|
||||||
information: {
|
information: {
|
||||||
...existingInfo,
|
...existingInfo,
|
||||||
archetype_csv: csv,
|
archetype_csv: csv,
|
||||||
@@ -124,10 +124,11 @@ export default function BuildOnTheFlyModal({ open, melodyId, currentMelody, curr
|
|||||||
},
|
},
|
||||||
default_settings: currentMelody.default_settings,
|
default_settings: currentMelody.default_settings,
|
||||||
type: currentMelody.type,
|
type: currentMelody.type,
|
||||||
url: currentMelody.url,
|
|
||||||
uid: currentMelody.uid,
|
uid: currentMelody.uid,
|
||||||
pid: currentMelody.pid,
|
pid: currentMelody.pid,
|
||||||
});
|
};
|
||||||
|
if (currentMelody.url) body.url = currentMelody.url;
|
||||||
|
await api.put(`/melodies/${melodyId}`, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatusMsg("Done!");
|
setStatusMsg("Done!");
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export default function SelectArchetypeModal({ open, melodyId, currentMelody, cu
|
|||||||
const { steps, totalNotes } = computeStepsAndNotes(csv);
|
const { steps, totalNotes } = computeStepsAndNotes(csv);
|
||||||
if (currentMelody && csv) {
|
if (currentMelody && csv) {
|
||||||
const existingInfo = currentMelody.information || {};
|
const existingInfo = currentMelody.information || {};
|
||||||
await api.put(`/melodies/${melodyId}`, {
|
const body = {
|
||||||
information: {
|
information: {
|
||||||
...existingInfo,
|
...existingInfo,
|
||||||
archetype_csv: csv,
|
archetype_csv: csv,
|
||||||
@@ -72,10 +72,11 @@ export default function SelectArchetypeModal({ open, melodyId, currentMelody, cu
|
|||||||
},
|
},
|
||||||
default_settings: currentMelody.default_settings,
|
default_settings: currentMelody.default_settings,
|
||||||
type: currentMelody.type,
|
type: currentMelody.type,
|
||||||
url: currentMelody.url,
|
|
||||||
uid: currentMelody.uid,
|
uid: currentMelody.uid,
|
||||||
pid: currentMelody.pid,
|
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 });
|
onSuccess({ name: archetype.name, pid: archetype.pid, steps, totalNotes, archetype_csv: csv });
|
||||||
|
|||||||
Reference in New Issue
Block a user