Skip to content

Commit

Permalink
Works with more sample songs using standard verse/chorus/bridge verse…
Browse files Browse the repository at this point in the history
… markers
  • Loading branch information
ChrisMBarr committed Aug 28, 2023
1 parent 9861b29 commit 1215fa5
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 5 deletions.
Binary file added sample-files/Amazing Grace.sbsong
Binary file not shown.
Binary file added sample-files/Beautiful Garden Of Prayer.sbsong
Binary file not shown.
85 changes: 85 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,89 @@ describe('SongShowPlus', (): void => {
],
} as SongShowPlusSong);
});

it('should return a song for a ENGLISH SongShow Plus 7 file: "Amazing Grace.sbsong"', () => {
const testFile = readFileSync('./sample-files/Amazing Grace.sbsong');

expect(sspParser.parse(testFile)).toEqual({
id: '',
title: 'Amazing Grace (Demonstration)',
author: 'Newton, John / Excell, Edwin / Rees, John P.',
copyright: 'Public Domain',
ccli: '22025',
key: 'F G Ab',
comments: '',
verseOrder: '',
songBook: 'Demonstration Songs',
songNumber: '',
topics: ['Assurance', 'Grace', 'Praise', 'Salvation'],
lyricSections: [
{
title: 'Verse',
lyrics:
'Amazing grace! How sweet the sound!\nThat saved a wretch like me!\nI once was lost, but now am found;\nWas blind, but now I see.',
},
{
title: 'Verse',
lyrics:
"'Twas grace that taught my heart to fear,\nAnd grace my fears relieved.\nHow precious did that grace appear,\nThe hour I first believed.",
},
{
title: 'Verse',
lyrics:
'The Lord has promised good to me,\nHis Word my hope secures.\nHe will my shield and portion be\nAs long as life endures.',
},
{
title: 'Verse',
lyrics:
"Thro' many dangers, toils and snares\nI have already come.\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.",
},
{
title: 'Verse',
lyrics:
"When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.",
},
],
} as SongShowPlusSong);
});

it('should return a song for a ENGLISH SongShow Plus 7 file: "Beautiful Garden Of Prayer.sbsong"', () => {
const testFile = readFileSync('./sample-files/Beautiful Garden Of Prayer.sbsong');

expect(sspParser.parse(testFile)).toEqual({
id: '',
title: 'Beautiful Garden Of Prayer (Demonstration)',
author: 'Schroll, Eleanor Allen / Fillmore, James H.',
copyright: 'Public Domain',
ccli: '60252',
key: 'C Db D',
comments: '',
verseOrder: '',
songBook: 'Demonstration Songs',
songNumber: '',
topics: ['Devotion', 'Prayer'],
lyricSections: [
{
title: 'Verse',
lyrics:
"There's a garden where Jesus is waiting,\nThere's a place that is wondrously fair.\nFor it glows with the light of His presence,\n'Tis the beautiful garden of prayer.",
},
{
title: 'Verse',
lyrics:
"There's a garden where Jesus is waiting,\nAnd I go with my burden and care.\nJust to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.",
},
{
title: 'Verse',
lyrics:
"There's a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\nJust to bow and receive a new blessing,\nIn the beautiful garden of prayer.",
},
{
title: 'Chorus',
lyrics:
'O the beautiful garden, the garden of prayer,\nO the beautiful garden of prayer.\nThere my Savior awaits, and He opens the gates\nTo the beautiful garden of prayer.',
},
],
} as SongShowPlusSong);
});
});
25 changes: 20 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ export class SongShowPlus {
content: sectionContent,
};

//When a verse is found it only informs us of the location of the title
//Right after that is a byte telling us how long the lyric content is,
//and then the actual lyric data
if (
sectionBufferInfo.type === Block.BRIDGE ||
sectionBufferInfo.type === Block.CHORUS ||
sectionBufferInfo.type === Block.VERSE ||
sectionBufferInfo.type === Block.CUSTOM_VERSE
sectionBufferInfo.type === Block.VERSE
) {
//Inside a built-in song section like these, the content found above is garbage data
//we just need to provide meaningful labels here, similar to the ones a custom verse has in the data
thisSection.content = this.getBuiltInVerseFriendlyName(sectionBufferInfo.type);
thisSection.lyrics = this.getLyrics(dataView.buffer, byteOffset);
} else if (sectionBufferInfo.type === Block.CUSTOM_VERSE) {
//When a Custom Verse is found it only informs us of the location of the title
//Right after that is a byte telling us how long the lyric content is,
//and then the actual lyric data
thisSection.lyrics = this.getLyrics(
dataView.buffer,
byteOffset + sectionBufferInfo.blockLength
Expand All @@ -96,6 +100,17 @@ export class SongShowPlus {
return sections;
}

private getBuiltInVerseFriendlyName(type: Block): string {
if (type === Block.BRIDGE) {
return 'Bridge';
}
if (type === Block.CHORUS) {
return 'Chorus';
}
//Default
return 'Verse';
}

private getLyrics(buffer: ArrayBuffer, lyricStartOffset: number): string {
const blockLengthInfo = this.getBlockLength(buffer, lyricStartOffset);

Expand Down

0 comments on commit 1215fa5

Please sign in to comment.