Skip to content

Commit

Permalink
Clean up old code
Browse files Browse the repository at this point in the history
  • Loading branch information
no-chris committed Jan 20, 2024
1 parent 5f251ec commit 75f540c
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions packages/chord-mark/src/parser/songLinesFactory.js
Expand Up @@ -82,9 +82,7 @@ export default function songLinesFactory() {

let blueprint = [];
let blueprintIndex = 0;
let blueprintLine = '';

let isRepeatingChords = false;
let shouldMultiplySection = false;
let shouldCopySection = false;

Expand Down Expand Up @@ -141,13 +139,12 @@ export default function songLinesFactory() {
shouldMultiplySection = currentSection.multiplyTimes > 0;
previousSectionLabelLine = _cloneDeep(line);

if (!isFirstOfLabel(currentSection, allLines)) {
blueprint = getNthOfLabel(allLines, currentSection.label, 1);
blueprintIndex = 0;
isRepeatingChords = true;
} else {
isRepeatingChords = false;
}
blueprint =
currentSectionStats.count > 1
? getNthOfLabel(allLines, currentSection.label, 1)
: [];
blueprintIndex = 0;

return line;
}

Expand Down Expand Up @@ -239,8 +236,8 @@ export default function songLinesFactory() {
}

function repeatLinesFromBlueprint(line) {
if (isRepeatingChords && line.type !== lineTypes.SECTION_LABEL) {
blueprintLine = blueprint[blueprintIndex];
if (blueprint.length && line.type !== lineTypes.SECTION_LABEL) {
let blueprintLine = blueprint[blueprintIndex];
let repeatedLine;

while (shouldRepeatLineFromBlueprint(blueprintLine, line)) {
Expand All @@ -259,6 +256,16 @@ export default function songLinesFactory() {
}
}

function shouldRepeatLineFromBlueprint(blueprintLine, currentLine) {
const nonRepeatableLinesTypes = [lineTypes.LYRIC, lineTypes.EMPTY_LINE];
return (
blueprintLine &&
!nonRepeatableLinesTypes.includes(blueprintLine.type) &&
blueprintLine.type !== currentLine.type &&
currentLine.type !== lineTypes.EMPTY_LINE
);
}

function copySection() {
if (shouldCopySection) {
const toCopy = getNthOfLabel(
Expand Down Expand Up @@ -399,24 +406,6 @@ export default function songLinesFactory() {
};
}

function isFirstOfLabel(currentLabel, allLines) {
return allLines.every(
(line) =>
line.type === lineTypes.SECTION_LABEL &&
line.model.label !== currentLabel.label
);
}

function shouldRepeatLineFromBlueprint(blueprintLine, currentLine) {
return (
blueprintLine &&
blueprintLine.type !== lineTypes.LYRIC &&
blueprintLine.type !== lineTypes.EMPTY_LINE &&
blueprintLine.type !== currentLine.type &&
currentLine.type !== lineTypes.EMPTY_LINE
);
}

function isLastLineOfSection(lineIndex, allSrcLines) {
const nextLine = allSrcLines[lineIndex + 1];
return typeof nextLine === 'undefined' || isSectionLabel(nextLine);
Expand Down

0 comments on commit 75f540c

Please sign in to comment.