Support for more complex chords; have chordless songs in <div class="nochords">

This commit is contained in:
STEPHANVS 2021-07-04 18:02:22 +02:00
parent db64a7d5bf
commit 7badda1668
No known key found for this signature in database
GPG Key ID: 4EFE47E471FD62A9
1 changed files with 16 additions and 11 deletions

View File

@ -44,13 +44,15 @@ from openlp.core.lib.formattingtags import FormattingTags
log = logging.getLogger(__name__)
ENGLISH_NOTES = '[CDEFGAB]'
GERMAN_NOTES = '[CDEFGAH]'
NEOLATIN_NOTES = '(Do|Re|Mi|Fa|Sol|La|Si)'
CHORD_SUFFIXES = '(b|bb)?(#)?(m|maj7|maj|min7|min|sus)?(1|2|3|4|5|6|7|8|9)?'
ENGLISH_NOTES = '[CDEFGAB]?'
GERMAN_NOTES = '[CDEFGABH]?'
NEOLATIN_NOTES = '(Do|Re|Mi|Fa|Sol|La|Si)?'
CHORD_PREFIXES = '(=|\(|\|)*?'
CHORD_SUFFIXES = '(b|bb|#|##|x|-|m|maj|min|sus|dim|0|1|2|3|4|5|6|7|8|9|\))*?'
SLIM_CHARS = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'
CHORD_TEMPLATE = '<span class="chordline">{chord}</span>'
FIRST_CHORD_TEMPLATE = '<span class="chordline firstchordline">{chord}</span>'
FIRST_CHORD_TEMPLATE = '<span class="chordline">{chord}</span>'
NO_CHORD_TEMPLATE = '<span class="nochordline">{chord}</span>'
CHORD_LINE_TEMPLATE = '<span class="chord"><span><strong>{chord}</strong></span></span>{tail}{whitespace}{remainder}'
WHITESPACE_TEMPLATE = '<span class="ws">{whitespaces}</span>'
VERSE = 'The Lord said to {r}Noah{/r}: \n' \
@ -78,8 +80,8 @@ def _construct_chord_regex(notes):
:param notes: The regular expression for a set of valid notes
:return: An expanded regular expression for valid chords
"""
chord = notes + CHORD_SUFFIXES
return '(' + chord + '(/' + chord + ')?)'
#chord = CHORD_PREFIXES + notes + CHORD_SUFFIXES
return '(' + CHORD_PREFIXES + notes + CHORD_SUFFIXES + '(/' + notes + CHORD_SUFFIXES + ')?)'
def _construct_chord_match(notes):
@ -186,11 +188,11 @@ def render_chords_in_line(match):
# The actual chord, would be "G" in match "[G]sweet the "
chord = match.group(1)
# The tailing word of the chord, would be "sweet" in match "[G]sweet the "
tail = match.group(11)
tail = match.group(6)
# The remainder of the line, until line end or next chord. Would be " the " in match "[G]sweet the "
remainder = match.group(12)
remainder = match.group(7)
# Line end if found, else None
end = match.group(13)
end = match.group(8)
# Based on char width calculate width of chord
for chord_char in chord:
if chord_char not in SLIM_CHARS:
@ -268,7 +270,10 @@ def render_chords(text):
rendered_lines.append(new_line)
else:
chords_on_prev_line = False
rendered_lines.append(html.escape(line))
#rendered_lines.append(html.escape(line))
chord_template = NO_CHORD_TEMPLATE
new_line = chord_template.format(chord=line)
rendered_lines.append(new_line)
return '{br}'.join(rendered_lines)