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