instrumental introduction
This commit is contained in:
@@ -12,7 +12,11 @@ import { navigate } from "../../navigation/NavigationService";
|
||||
import { useUser } from "../../providers/UserDataProvider";
|
||||
import { Palette, Style } from "../../styles";
|
||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||
import { sanitizeStructureList } from "../../utils/songStructure";
|
||||
import {
|
||||
normalizeStructureType,
|
||||
sanitizeStructureList,
|
||||
segmentRequiresLyrics,
|
||||
} from "../../utils/songStructure";
|
||||
|
||||
const CreatingLyrics = ({ active, config, selections }) => {
|
||||
const [progress, setProgress] = useState(0);
|
||||
@@ -74,21 +78,40 @@ const CreatingLyrics = ({ active, config, selections }) => {
|
||||
});
|
||||
const rawLyrics = Array.isArray(data?.lyrics) ? data.lyrics : [];
|
||||
const normalizedLyrics = rawLyrics.map((section) => {
|
||||
const sanitizedType =
|
||||
sanitizeStructureList([section?.type])[0] || section?.type || "";
|
||||
const sanitizedType = normalizeStructureType(section?.type);
|
||||
return {
|
||||
...section,
|
||||
type: sanitizedType,
|
||||
lyrics: section?.lyrics || "",
|
||||
};
|
||||
});
|
||||
const alignedLyrics =
|
||||
sanitizedStructure.length > 0 &&
|
||||
sanitizedStructure.length === normalizedLyrics.length
|
||||
? normalizedLyrics.map((section, index) => ({
|
||||
...section,
|
||||
type: sanitizedStructure[index],
|
||||
}))
|
||||
: normalizedLyrics;
|
||||
|
||||
const remaining = [...normalizedLyrics];
|
||||
const takeForType = (type, { fallback = true } = {}) => {
|
||||
const index = remaining.findIndex((item) => item.type === type);
|
||||
if (index !== -1) {
|
||||
return remaining.splice(index, 1)[0];
|
||||
}
|
||||
if (!fallback) return null;
|
||||
return remaining.shift() || null;
|
||||
};
|
||||
|
||||
const structuredLyrics = sanitizedStructure.length
|
||||
? sanitizedStructure.map((rawType) => {
|
||||
const type = normalizeStructureType(rawType);
|
||||
if (!segmentRequiresLyrics(type)) {
|
||||
const match = takeForType(type, { fallback: false });
|
||||
return { type, lyrics: match?.lyrics || "" };
|
||||
}
|
||||
const match = takeForType(type, { fallback: true });
|
||||
return {
|
||||
type,
|
||||
lyrics: match?.lyrics || "",
|
||||
};
|
||||
})
|
||||
: normalizedLyrics;
|
||||
|
||||
const alignedLyrics = structuredLyrics.concat(remaining);
|
||||
const processedResult = {
|
||||
...data,
|
||||
lyrics: alignedLyrics,
|
||||
|
||||
Reference in New Issue
Block a user