Added comments to OepnSong files and stricter line-break tests

This commit is contained in:
Stewart Becker 2014-04-22 22:43:12 +01:00
parent 4416a57861
commit d39e1fd4a2
4 changed files with 37 additions and 10 deletions

View File

@ -45,11 +45,11 @@ class OpenSongImport(SongImport):
"""
Import songs exported from OpenSong
The format is described loosly on the `OpenSong File Format Specification
The format is described loosely on the `OpenSong File Format Specification
<http://www.opensong.org/d/manual/song_file_format_specification>`_ page on the OpenSong web site. However, it
doesn't describe the <lyrics> section, so here's an attempt:
If the first charachter of a line is a space, then the rest of that line is lyrics. If it is not a space the
If the first character of a line is a space, then the rest of that line is lyrics. If it is not a space the
following applies.
Verses can be expressed in one of 2 ways, either in complete verses, or by line grouping, i.e. grouping all line 1's
@ -93,12 +93,19 @@ class OpenSongImport(SongImport):
All verses are imported and tagged appropriately.
Guitar chords can be provided "above" the lyrics (the line is preceeded by a period "."), and one or more "_" can
Guitar chords can be provided "above" the lyrics (the line is preceded by a period "."), and one or more "_" can
be used to signify long-drawn-out words. Chords and "_" are removed by this importer. For example::
. A7 Bm
1 Some____ Words
Lines that contain only whitespace are ignored.
| indicates a blank line, and || a new slide.
Slide 1 Line 1|Slide 1 Line 2||Slide 2 Line 1|Slide 2 Line 2
Lines beginning with ; are comments
The <presentation> tag is used to populate the OpenLP verse display order field. The Author and Copyright tags are
also imported to the appropriate places.
"""
@ -193,7 +200,7 @@ class OpenSongImport(SongImport):
else:
lyrics = ''
for this_line in lyrics.split('\n'):
if not this_line:
if not this_line.strip():
continue
# skip this line if it is a comment
if this_line.startswith(';'):
@ -236,7 +243,12 @@ class OpenSongImport(SongImport):
this_line = this_line.replace('_', '')
this_line = this_line.replace('||', '\n[---]\n')
this_line = this_line.strip()
this_line = this_line.replace('|', '\n')
# If the line consists solely of a '|', then just use the implicit newline
# Otherwise, add a newline for each '|'
if this_line == '|':
this_line = ''
else:
this_line = this_line.replace('|', '\n')
verses[verse_tag][verse_num][inst].append(this_line)
# done parsing
# add verses in original order

View File

@ -13,6 +13,11 @@
<user2> </user2>
<user3> </user3>
<lyrics>[V]
;Test the chords format
;Chords beging with .
;Verses begin with their verse number
;Link words with _
;Comments begin with ;
. D D7 G D
1A______ma________zing grace! How sweet the sound!
2'Twas grace that taught my heart to fear,

View File

@ -12,28 +12,38 @@
<user1></user1>
<user2></user2>
<user3></user3>
<lyrics>[V1]
<lyrics>
;Test breaks and newlines
;A single | on the end of a line adds an extra \n
;Blank lines are ignored, even with a space prefix
[V1]
There's a garden where Jesus is waiting,
There's a place that is wondrously fair.
For it glows with the light of His presence,|
'Tis the beautiful garden of prayer.
;A double || on the end of a line adds a new slide
[V2]
There's a garden where Jesus is waiting,
And I go with my burden and care.
Just to learn from His lips, words of comfort,|
Just to learn from His lips, words of comfort,||
In the beautiful garden of prayer.
;A single | on a line adds just one line break
[V3]
There's a garden where Jesus is waiting,
And He bids you to come meet Him there,
Just to bow and receive a new blessing,|
Just to bow and receive a new blessing,
|
In the beautiful garden of prayer.
;A double || on a line adds a new slide
[C]
O the beautiful garden, the garden of prayer,
O the beautiful garden of prayer.
There my Savior awaits, and He opens the gates||
There my Savior awaits, and He opens the gates
||
To the beautiful garden of prayer.
</lyrics>
<hymn_number>DS0</hymn_number>

View File

@ -20,7 +20,7 @@
"v1"
],
[
"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,\n\nIn the beautiful garden of prayer.",
"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,\n[---]\nIn the beautiful garden of prayer.",
"v2"
],
[