improvemtns again, to the archetype builder, and playback
This commit is contained in:
@@ -42,6 +42,22 @@ function getActiveBells(stepValue) {
|
||||
return bells;
|
||||
}
|
||||
|
||||
function parseBellNotation(notation) {
|
||||
notation = notation.trim();
|
||||
if (notation === "0" || !notation) return 0;
|
||||
let value = 0;
|
||||
for (const part of notation.split("+")) {
|
||||
const n = parseInt(part.trim(), 10);
|
||||
if (!isNaN(n) && n >= 1 && n <= 16) value |= 1 << (n - 1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseStepsString(stepsStr) {
|
||||
if (!stepsStr || !stepsStr.trim()) return [];
|
||||
return stepsStr.trim().split(",").map((s) => parseBellNotation(s));
|
||||
}
|
||||
|
||||
async function decodeBsmBinary(url) {
|
||||
const token = localStorage.getItem("access_token");
|
||||
const res = await fetch(url, {
|
||||
@@ -81,7 +97,7 @@ const BEAT_DURATION_MS = 80; // fixed tone length for playback
|
||||
const mutedStyle = { color: "var(--text-muted)" };
|
||||
const labelStyle = { color: "var(--text-secondary)" };
|
||||
|
||||
export default function PlaybackModal({ open, melody, builtMelody, files, onClose }) {
|
||||
export default function PlaybackModal({ open, melody, builtMelody, files, archetypeCsv, onClose }) {
|
||||
const info = melody?.information || {};
|
||||
const minSpeed = info.minSpeed || null;
|
||||
const maxSpeed = info.maxSpeed || null;
|
||||
@@ -115,7 +131,7 @@ export default function PlaybackModal({ open, melody, builtMelody, files, onClos
|
||||
setCurrentStep(-1);
|
||||
}, []);
|
||||
|
||||
// Load binary on open
|
||||
// Load steps on open — prefer archetype_csv, fall back to binary
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
stopPlayback();
|
||||
@@ -126,14 +142,23 @@ export default function PlaybackModal({ open, melody, builtMelody, files, onClos
|
||||
return;
|
||||
}
|
||||
|
||||
// builtMelody.binary_url is a relative path needing /api prefix;
|
||||
// files.binary_url from the /files endpoint is already a full URL path.
|
||||
// Prefer CSV from archetype (no network request needed)
|
||||
const csv = archetypeCsv || info.archetype_csv || null;
|
||||
if (csv) {
|
||||
const parsed = parseStepsString(csv);
|
||||
setSteps(parsed);
|
||||
stepsRef.current = parsed;
|
||||
setLoadError("");
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back to binary fetch
|
||||
const binaryUrl = builtMelody?.binary_url
|
||||
? `/api${builtMelody.binary_url}`
|
||||
: files?.binary_url || null;
|
||||
|
||||
if (!binaryUrl) {
|
||||
setLoadError("No binary file available for this melody.");
|
||||
setLoadError("No binary or archetype data available for this melody.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user