instrumental introduction

This commit is contained in:
2025-10-21 13:34:16 +02:00
parent 3a5d449424
commit 837a634997
6 changed files with 226 additions and 92 deletions
+50 -1
View File
@@ -20,6 +20,7 @@ export const STRUCTURE_SEGMENTS = {
allowMultiple: true,
optional: false,
inputHeight: 225,
requiresLyrics: true,
aliases: ["vers", "verse", "couplet"],
},
refrain: {
@@ -29,6 +30,7 @@ export const STRUCTURE_SEGMENTS = {
allowMultiple: true,
optional: false,
inputHeight: 170,
requiresLyrics: true,
aliases: ["chorus", "refrain"],
},
short_intro: {
@@ -39,6 +41,7 @@ export const STRUCTURE_SEGMENTS = {
optional: true,
inputHeight: 150,
exclusiveGroup: "intro",
requiresLyrics: false,
aliases: [
"introduction instrumentale courte",
"intro courte",
@@ -54,6 +57,7 @@ export const STRUCTURE_SEGMENTS = {
optional: true,
inputHeight: 150,
exclusiveGroup: "intro",
requiresLyrics: false,
aliases: [
"introduction instrumentale longue",
"intro longue",
@@ -68,6 +72,7 @@ export const STRUCTURE_SEGMENTS = {
allowMultiple: false,
optional: true,
inputHeight: 150,
requiresLyrics: true,
aliases: [
"pré-refrain",
"pre-refrain",
@@ -101,6 +106,12 @@ export const getSegmentMeta = (type) => {
return STRUCTURE_SEGMENTS[key] || null;
};
export const segmentRequiresLyrics = (type) => {
const meta = getSegmentMeta(type);
if (!meta) return true;
return meta.requiresLyrics !== false;
};
export const OPTIONAL_STRUCTURE_SEGMENTS = Object.keys(
STRUCTURE_SEGMENTS
).filter((key) => STRUCTURE_SEGMENTS[key]?.optional);
@@ -121,6 +132,7 @@ export const normalizeStructureType = (value) => {
export const sanitizeStructureList = (structure = []) => {
if (!Array.isArray(structure)) return [];
const output = [];
let shouldInjectPreChorus = false;
structure.forEach((segment) => {
const type = normalizeStructureType(segment);
@@ -144,10 +156,47 @@ export const sanitizeStructureList = (structure = []) => {
}
}
if (type === "pre_chorus") {
shouldInjectPreChorus = true;
return;
}
output.push(type);
});
return output;
let result = output;
if (shouldInjectPreChorus) {
const baseWithoutPre = result.filter((item) => item !== "pre_chorus");
const hasRefrain = baseWithoutPre.some((item) => item === "refrain");
const expanded = [];
baseWithoutPre.forEach((item, idx) => {
if (item === "refrain") {
const previous = expanded[expanded.length - 1];
if (previous !== "pre_chorus") {
expanded.push("pre_chorus");
}
}
expanded.push(item);
});
if (!hasRefrain) {
expanded.push("pre_chorus");
}
result = expanded;
}
const introIndex = result.findIndex(
(item) => item === "short_intro" || item === "long_intro"
);
if (introIndex > 0) {
const [intro] = result.splice(introIndex, 1);
result.unshift(intro);
}
return result;
};
export const formatStructureLabel = (type, occurrence = 1) => {