Skip to content

Commit

Permalink
rename textLine to lyricLine
Browse files Browse the repository at this point in the history
  • Loading branch information
no-chris committed Aug 29, 2021
1 parent 1660d24 commit 7f764c3
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/parser/lineTypes.js
Expand Up @@ -6,7 +6,7 @@ export default {
CHORD: 'chord',
CHORD_LINE_REPEATER: 'chordLineRepeater',
EMPTY_LINE: 'emptyLine',
LYRIC: 'lyric',
SECTION_LABEL: 'sectionLabel',
TEXT: 'text',
TIME_SIGNATURE: 'timeSignature',
};
25 changes: 13 additions & 12 deletions src/parser/songLinesFactory.js
Expand Up @@ -21,7 +21,7 @@ const defaultTimeSignature = '4/4';
* @typedef {Object} SongLine
* @type {Object}
* @property {String} string - original line in source file
* @property {String} type - chord|text|timeSignature|sectionLabel...
* @property {String} type - chord|lyric|timeSignature|sectionLabel...
* @property {Boolean} [isFromSectionRepeat] - line created by a section repeat directive (x3...)
* @property {Boolean} [isFromAutoRepeatChords] - line created by auto repeats of chords from a section to another
*/
Expand All @@ -40,8 +40,9 @@ const defaultTimeSignature = '4/4';
*/

/**
* @typedef {SongLine} SongTextLine
* @typedef {SongLine} SongLyricLine
* @type {Object}
* @property {LyricLine} model
*/

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ export default function songLinesFactory() {
}

/**
* @returns {SongTextLine}
* @returns {SongLyricLine}
*/
function getEmptyLine(string) {
return {
Expand All @@ -126,7 +127,7 @@ export default function songLinesFactory() {
}

/**
* @returns {SongChordLine|SongTextLine}
* @returns {SongChordLine|SongLyricLine}
*/
function getChordLine(string) {
let line;
Expand All @@ -141,13 +142,13 @@ export default function songLinesFactory() {
};
previousChordLine = line;
} catch (e) {
line = getTextLine(string);
line = getLyricLine(string);
}
return line;
}

/**
* @returns {SongChordLine|SongTextLine}
* @returns {SongChordLine|SongLyricLine}
*/
function getPreviousChordLine(string) {
if (previousChordLine) {
Expand All @@ -156,16 +157,16 @@ export default function songLinesFactory() {
isFromChordLineRepeater: true,
};
}
return getTextLine(string);
return getLyricLine(string);
}

/**
* @returns {SongTextLine}
* @returns {SongLyricLine}
*/
function getTextLine(string) {
function getLyricLine(string) {
return {
string,
type: lineTypes.TEXT,
type: lineTypes.LYRIC,
model: parseLyricLine(string),
};
}
Expand Down Expand Up @@ -257,7 +258,7 @@ export default function songLinesFactory() {
} else if (isEmptyLine(lineSrc)) {
line = getEmptyLine(lineSrc);
} else {
line = getTextLine(lineSrc);
line = getLyricLine(lineSrc);
}

repeatLinesFromBlueprint(line);
Expand Down Expand Up @@ -287,7 +288,7 @@ function isFirstOfLabel(currentLabel, allLines) {
function shouldRepeatLineFromBlueprint(blueprintLine, currentLine) {
return (
blueprintLine &&
blueprintLine.type !== lineTypes.TEXT &&
blueprintLine.type !== lineTypes.LYRIC &&
blueprintLine.type !== lineTypes.EMPTY_LINE &&
blueprintLine.type !== currentLine.type &&
currentLine.type !== lineTypes.EMPTY_LINE
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/components/renderLyricLine.js
@@ -0,0 +1,9 @@
import lyricLineTpl from './tpl/lyricLine.hbs';

/**
* @param {SongLyricLine} lyricLine
* @returns {String} rendered html
*/
export default function render(lyricLine) {
return lyricLineTpl({ lyricLine: lyricLine.model.lyrics });
}
21 changes: 11 additions & 10 deletions src/renderer/components/renderSong.js
Expand Up @@ -6,11 +6,11 @@ import chordLyricsSpacer from '../spacers/chord/chordLyrics';

import { forEachChordInSong } from '../../parser/helper/songs';

import renderChordLine from './renderChordLine'; //fixme should be renderChordLineModel
import renderChordLineModel from './renderChordLine';
import renderEmptyLine from './renderEmptyLine';
import renderLine from './renderLine';
import renderSectionLabel from './renderSectionLabel';
import renderTextLine from './renderTextLine';
import renderLyricLine from './renderLyricLine';
import renderTimeSignature from './renderTimeSignature';

import songTpl from './tpl/song.hbs';
Expand Down Expand Up @@ -79,17 +79,12 @@ export default function renderSong(
let rendered;

if (line.type === lineTypes.CHORD) {
// todo: move this in renderChordLine?
let spaced = alignBars
? alignedChordSpacer(line.model, maxBeatsWidth)
: simpleChordSpacer(line.model);

const nextLine = allFilteredLines[lineIndex + 1];
if (
alignChordsWithLyrics &&
nextLine &&
nextLine.type === lineTypes.TEXT
) {
if (shouldAlignChords(alignChordsWithLyrics, nextLine)) {
const { chordLine, lyricsLine } = chordLyricsSpacer(
spaced,
nextLine.model
Expand All @@ -98,7 +93,7 @@ export default function renderSong(
spaced = chordLine;
}

rendered = renderChordLine(spaced);
rendered = renderChordLineModel(spaced);
} else if (line.type === lineTypes.EMPTY_LINE) {
rendered = renderEmptyLine();
} else if (line.type === lineTypes.SECTION_LABEL) {
Expand All @@ -109,7 +104,7 @@ export default function renderSong(
} else if (line.type === lineTypes.TIME_SIGNATURE) {
rendered = renderTimeSignature(line);
} else {
rendered = renderTextLine(line);
rendered = renderLyricLine(line);
}
return renderLine(rendered, {
isFromSectionRepeat: line.isFromSectionRepeat,
Expand All @@ -133,3 +128,9 @@ export default function renderSong(

return songTpl({ song });
}

function shouldAlignChords(alignChordsWithLyrics, nextLine) {
return (
alignChordsWithLyrics && nextLine && nextLine.type === lineTypes.LYRIC
);
}
9 changes: 0 additions & 9 deletions src/renderer/components/renderTextLine.js

This file was deleted.

1 change: 1 addition & 0 deletions src/renderer/components/tpl/lyricLine.hbs
@@ -0,0 +1 @@
<span class="cmLyricLine">{{{ this.lyricLine }}}</span>
1 change: 0 additions & 1 deletion src/renderer/components/tpl/textLine.hbs

This file was deleted.

20 changes: 10 additions & 10 deletions tests/integration/parser/parseSong.spec.js
Expand Up @@ -41,7 +41,7 @@ Let it be`;
model: parseChordLine('C.. G..'),
},
{
type: 'text',
type: 'lyric',
string: 'When I find myself in times of trouble',
model: parseLyricLine(
'When I find myself in times of trouble'
Expand All @@ -53,7 +53,7 @@ Let it be`;
model: parseChordLine('Am.. F..'),
},
{
type: 'text',
type: 'lyric',
string: 'Mother mary comes to me',
model: parseLyricLine('Mother mary comes to me'),
},
Expand All @@ -63,7 +63,7 @@ Let it be`;
model: parseChordLine('C.. G..'),
},
{
type: 'text',
type: 'lyric',
string: 'Speaking words of wisdom',
model: parseLyricLine('Speaking words of wisdom'),
},
Expand All @@ -73,7 +73,7 @@ Let it be`;
model: parseChordLine('F. Em. Dm. C.'),
},
{
type: 'text',
type: 'lyric',
string: 'Let it be',
model: parseLyricLine('Let it be'),
},
Expand All @@ -84,7 +84,7 @@ Let it be`;
model: parseChordLine('Am.. G..'),
},
{
type: 'text',
type: 'lyric',
string: 'Let it be, let it be',
model: parseLyricLine('Let it be, let it be'),
},
Expand All @@ -94,7 +94,7 @@ Let it be`;
model: parseChordLine('C.. F..'),
},
{
type: 'text',
type: 'lyric',
string: 'Let it be, let it be',
model: parseLyricLine('Let it be, let it be'),
},
Expand All @@ -104,7 +104,7 @@ Let it be`;
model: parseChordLine('C.. G..'),
},
{
type: 'text',
type: 'lyric',
string: 'Whispers words of wisdom',
model: parseLyricLine('Whispers words of wisdom'),
},
Expand All @@ -114,7 +114,7 @@ Let it be`;
model: parseChordLine('F. Em. Dm. C.'),
},
{
type: 'text',
type: 'lyric',
string: 'Let it be',
model: parseLyricLine('Let it be'),
},
Expand Down Expand Up @@ -147,7 +147,7 @@ Let it be`;
model: parseChordLine('C.. G..'),
},
{
type: 'text',
type: 'lyric',
string: 'When I find myself in times of trouble',
model: parseLyricLine(
'When I find myself in times of trouble'
Expand All @@ -159,7 +159,7 @@ Let it be`;
model: parseChordLine('Am.. F..'),
},
{
type: 'text',
type: 'lyric',
string: 'Mother mary comes to me',
model: parseLyricLine('Mother mary comes to me'),
},
Expand Down

0 comments on commit 7f764c3

Please sign in to comment.