forked from openlp/openlp
Apply 28 suggestion(s) to 2 file(s)
This commit is contained in:
parent
1b09d0cf89
commit
f2230245e1
@ -584,8 +584,8 @@ def transpose_verse(verse_text, transpose_value, notation, key):
|
||||
# 6/9 chords should be noted 6-9 or 69 or 6add9
|
||||
lyric_list = re.split(r'(\[|\]|/)', verse_text)
|
||||
transposed_lyrics = ''
|
||||
isbass = False
|
||||
lastchord = None
|
||||
is_bass = False
|
||||
last_chord = None
|
||||
in_tag = False
|
||||
for word in lyric_list:
|
||||
if not in_tag:
|
||||
@ -597,15 +597,15 @@ def transpose_verse(verse_text, transpose_value, notation, key):
|
||||
in_tag = False
|
||||
transposed_lyrics += word
|
||||
elif word == '/':
|
||||
isbass = True
|
||||
is_bass = True
|
||||
transposed_lyrics += word
|
||||
elif word == '--}{--':
|
||||
transposed_lyrics += word
|
||||
else:
|
||||
# This MUST be a chord
|
||||
transposed_chord, key, lastchord = transpose_chord(word, transpose_value, notation, key, lastchord,
|
||||
transposed_chord, key, last_chord = transpose_chord(word, transpose_value, notation, key, last_chord,
|
||||
isbass)
|
||||
isbass = False
|
||||
is bass = False
|
||||
transposed_lyrics += transposed_chord
|
||||
# If still inside a chord tag something is wrong!
|
||||
if in_tag:
|
||||
@ -614,7 +614,7 @@ def transpose_verse(verse_text, transpose_value, notation, key):
|
||||
return transposed_lyrics, key
|
||||
|
||||
|
||||
def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
def transpose_chord(chord, transpose_value, notation, key, last_chord, is_bass):
|
||||
"""
|
||||
Transpose chord according to the notation used.
|
||||
NOTE: This function has a javascript equivalent in chords.js - make sure to update both!
|
||||
@ -754,7 +754,7 @@ def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
'Labm': ['Rebb', 'Reb', 'Mibb', 'Mib', 'Fab', 'Solbb', 'Solb', 'Labb', 'Lab', 'Sibb', 'Sib', 'Dob']
|
||||
}
|
||||
}
|
||||
notenumbers = {
|
||||
note_numbers = {
|
||||
'german': {
|
||||
'C': 0, 'H#': 0, 'B##': 0, 'Bx': 0, 'Dbb': 0,
|
||||
'C#': 1, 'Db': 1,
|
||||
@ -801,7 +801,7 @@ def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
chord = chord.replace('♭', 'b').replace('♯', '#')
|
||||
transposed_chord = ''
|
||||
minor = ''
|
||||
thischordchangeskey = False
|
||||
is_key_change_chord = False
|
||||
notes_sharp = notes_sharp_notation[notation]
|
||||
notes_flat = notes_flat_notation[notation]
|
||||
notes_preferred = ['b', '#', '#', 'b', '#', 'b', '#', '#', 'b', '#', 'b', '#']
|
||||
@ -815,7 +815,7 @@ def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
transposed_chord += '='
|
||||
if len(chord) > 1:
|
||||
chord = chord[1:]
|
||||
thischordchangeskey = True
|
||||
is_key_change_chord = True
|
||||
else:
|
||||
chord = ''
|
||||
if chord and chord[0] == '|':
|
||||
@ -844,28 +844,28 @@ def transpose_chord(chord, transpose_value, notation, key, lastchord, isbass):
|
||||
chord = chord[1:] if len(chord) > 1 else ''
|
||||
else:
|
||||
minor = ''
|
||||
note_number = notenumbers[notation][note]
|
||||
note_number = note_numbers[notation][note]
|
||||
note_number += transpose_value
|
||||
while note_number > 11:
|
||||
note_number -= 12
|
||||
while note_number < 0:
|
||||
note_number += 12
|
||||
if isbass:
|
||||
if lastchord:
|
||||
note = scales[notation][lastchord][note_number]
|
||||
if is_bass:
|
||||
if last_chord:
|
||||
note = scales[notation][last_chord][note_number]
|
||||
elif key:
|
||||
note = scales[notation][key][note_number]
|
||||
else:
|
||||
note = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[note_number]
|
||||
else:
|
||||
if not key or thischordchangeskey:
|
||||
if not key or is_key_change_chord:
|
||||
note = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[note_number]
|
||||
else:
|
||||
note = scales[notation][key][note_number]
|
||||
transposed_chord += note + minor + chord
|
||||
if thischordchangeskey:
|
||||
if is_key_change_chord:
|
||||
key = note + minor
|
||||
else:
|
||||
if not isbass:
|
||||
lastchord = note + minor
|
||||
return transposed_chord, key, lastchord
|
||||
if not is_bass:
|
||||
last_chord = note + minor
|
||||
return transposed_chord, key, last_chord
|
||||
|
@ -276,16 +276,16 @@ def test_transpose_chord_up():
|
||||
# GIVEN: A Chord
|
||||
chord = 'C'
|
||||
key = None
|
||||
lastchord = None
|
||||
isbass = False
|
||||
last_chord = None
|
||||
is_bass = False
|
||||
|
||||
# WHEN: Transposing it 1 up
|
||||
new_chord, key, lastchord = transpose_chord(chord, 1, 'english', key, lastchord, isbass)
|
||||
new_chord, key, last_chord = transpose_chord(chord, 1, 'english', key, last_chord, is_bass)
|
||||
|
||||
# THEN: The chord should be transposed up one note
|
||||
assert new_chord == 'C#', 'The chord should be transposed up.'
|
||||
assert key is None, 'The key should not be set'
|
||||
assert lastchord == 'C#', 'If not isbass, then lastchord should be returned'
|
||||
assert last_chord == 'C#', 'If not is_bass, then last_chord should be returned'
|
||||
|
||||
|
||||
def test_transpose_chord_up_adv():
|
||||
@ -295,21 +295,21 @@ def test_transpose_chord_up_adv():
|
||||
# GIVEN: An advanced Chord
|
||||
chord = '(D/F#)'
|
||||
key = None
|
||||
lastchord = None
|
||||
isbass = False
|
||||
chordsplit = chord.split("/")
|
||||
last_chord = None
|
||||
is_bass = False
|
||||
chord_split = chord.split("/")
|
||||
# WHEN: Transposing it 1 up
|
||||
new_chord, key, lastchord = transpose_chord(chordsplit[0], 1, 'english', key, lastchord, isbass)
|
||||
new_chord, key, last_chord = transpose_chord(chord_split[0], 1, 'english', key, last_chord, is_bass)
|
||||
|
||||
# AFTER "/" isbass is true, lastchord is set
|
||||
isbass = True
|
||||
new_bass, key, lastchord = transpose_chord(chordsplit[1], 1, 'english', key, lastchord, isbass)
|
||||
is_bass = True
|
||||
new_bass, key, last_chord = transpose_chord(chord_split[1], 1, 'english', key, last_chord, is_bass)
|
||||
|
||||
# THEN: The chord should be transposed up one note
|
||||
assert new_chord == '(Eb', 'The chord should be transposed up.'
|
||||
assert new_bass == 'G)', 'Bass should be transposed up.'
|
||||
assert key is None, 'no key should be defined'
|
||||
assert lastchord == 'Eb', 'lastchord is generated'
|
||||
assert last_chord == 'Eb', 'last_chord is generated'
|
||||
|
||||
|
||||
def test_transpose_chord_down():
|
||||
@ -319,16 +319,16 @@ def test_transpose_chord_down():
|
||||
# GIVEN: A Chord
|
||||
chord = 'C'
|
||||
key = None
|
||||
lastchord = None
|
||||
isbass = False
|
||||
last_chord = None
|
||||
is_bass = False
|
||||
|
||||
# WHEN: Transposing it 1 down
|
||||
new_chord, key, lastchord = transpose_chord(chord, -1, 'english', key, lastchord, isbass)
|
||||
new_chord, key, last_chord = transpose_chord(chord, -1, 'english', key, last_chord, is_bass)
|
||||
|
||||
# THEN: The chord should be transposed down one note
|
||||
assert new_chord == 'B', 'The chord should be transposed down.'
|
||||
assert key is None, 'The key should not be set'
|
||||
assert lastchord == 'B', 'If not isbass, then lastchord should be returned'
|
||||
assert last_chord == 'B', 'If not is_bass, then last_chord should be returned'
|
||||
|
||||
|
||||
def test_transpose_chord_error():
|
||||
|
Loading…
Reference in New Issue
Block a user