forked from openlp/openlp
fix split to work with chords
This commit is contained in:
parent
897f2c2d89
commit
bfade0050a
@ -53,8 +53,8 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
self.verse_type_combo_box.currentIndexChanged.connect(self.on_verse_type_combo_box_changed)
|
||||
self.force_split_button.clicked.connect(self.on_force_split_button_clicked)
|
||||
if Settings().value('songs/enable chords'):
|
||||
self.transpose_down_button.clicked.connect(self.on_transepose_down_button_clicked)
|
||||
self.transpose_up_button.clicked.connect(self.on_transepose_up_button_clicked)
|
||||
self.transpose_down_button.clicked.connect(self.on_transpose_down_button_clicked)
|
||||
self.transpose_up_button.clicked.connect(self.on_transpose_up_button_clicked)
|
||||
|
||||
def insert_verse(self, verse_tag, verse_num=1):
|
||||
"""
|
||||
@ -89,7 +89,7 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
"""
|
||||
text = self.verse_text_edit.toPlainText()
|
||||
position = self.verse_text_edit.textCursor().position()
|
||||
insert_string = '[##-divide-##]'
|
||||
insert_string = '[--}{--]'
|
||||
if position and text[position - 1] != '\n':
|
||||
insert_string = '\n' + insert_string
|
||||
if position == len(text) or text[position] != '\n':
|
||||
@ -116,7 +116,7 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
"""
|
||||
self.update_suggested_verse_number()
|
||||
|
||||
def on_transepose_up_button_clicked(self):
|
||||
def on_transpose_up_button_clicked(self):
|
||||
"""
|
||||
The transpose up button clicked
|
||||
"""
|
||||
@ -133,7 +133,7 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
self.verse_text_edit.setFocus()
|
||||
self.verse_text_edit.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
def on_transepose_down_button_clicked(self):
|
||||
def on_transpose_down_button_clicked(self):
|
||||
"""
|
||||
The transpose down button clicked
|
||||
"""
|
||||
|
@ -546,12 +546,12 @@ def delete_song(song_id, song_plugin):
|
||||
song_plugin.manager.delete_object(Song, song_id)
|
||||
|
||||
|
||||
def transpose_lyrics(lyrics, transepose_value):
|
||||
def transpose_lyrics(lyrics, transpose_value):
|
||||
"""
|
||||
Transepose lyrics
|
||||
Transpose lyrics
|
||||
|
||||
:param lyrcs: The lyrics to be transposed
|
||||
:param transepose_value: The value to transpose the lyrics with
|
||||
:param lyrics: The lyrics to be transposed
|
||||
:param transpose_value: The value to transpose the lyrics with
|
||||
:return: The transposed lyrics
|
||||
"""
|
||||
# Split text by verse delimiter - both normal and optional
|
||||
@ -562,16 +562,17 @@ def transpose_lyrics(lyrics, transepose_value):
|
||||
if verse.startswith('---[') or verse == '[---]':
|
||||
transposed_lyrics += verse
|
||||
else:
|
||||
transposed_lyrics += transpose_verse(verse, transepose_value, notation)
|
||||
transposed_lyrics += transpose_verse(verse, transpose_value, notation)
|
||||
return transposed_lyrics
|
||||
|
||||
|
||||
def transpose_verse(verse_text, transepose_value, notation):
|
||||
def transpose_verse(verse_text, transpose_value, notation):
|
||||
"""
|
||||
Transepose lyrics
|
||||
Transpose Verse
|
||||
|
||||
:param lyrcs: The lyrics to be transposed
|
||||
:param transepose_value: The value to transpose the lyrics with
|
||||
:param verse_text: The lyrics to be transposed
|
||||
:param transpose_value: The value to transpose the lyrics with
|
||||
:param notation: which notation to use
|
||||
:return: The transposed lyrics
|
||||
"""
|
||||
if '[' not in verse_text:
|
||||
@ -589,11 +590,11 @@ def transpose_verse(verse_text, transepose_value, notation):
|
||||
if word == ']':
|
||||
in_tag = False
|
||||
transposed_lyrics += word
|
||||
elif word == '/':
|
||||
elif word == '/' or word == '--}{--':
|
||||
transposed_lyrics += word
|
||||
else:
|
||||
# This MUST be a chord
|
||||
transposed_lyrics += transpose_chord(word, transepose_value, notation)
|
||||
transposed_lyrics += transpose_chord(word, transpose_value, notation)
|
||||
# If still inside a chord tag something is wrong!
|
||||
if in_tag:
|
||||
return verse_text
|
||||
@ -629,36 +630,36 @@ def transpose_chord(chord, transpose_value, notation):
|
||||
for i in range(0, len(chord_split)):
|
||||
if i > 0:
|
||||
transposed_chord += '/'
|
||||
currentchord = chord_split[i]
|
||||
if currentchord and currentchord[0] == '(':
|
||||
current_chord = chord_split[i]
|
||||
if current_chord and current_chord[0] == '(':
|
||||
transposed_chord += '('
|
||||
if len(currentchord) > 1:
|
||||
currentchord = currentchord[1:]
|
||||
if len(current_chord) > 1:
|
||||
current_chord = current_chord[1:]
|
||||
else:
|
||||
currentchord = ''
|
||||
if len(currentchord) > 0:
|
||||
if len(currentchord) > 1:
|
||||
if '#b'.find(currentchord[1]) == -1:
|
||||
note = currentchord[0:1]
|
||||
rest = currentchord[1:]
|
||||
current_chord = ''
|
||||
if len(current_chord) > 0:
|
||||
if len(current_chord) > 1:
|
||||
if '#b'.find(current_chord[1]) == -1:
|
||||
note = current_chord[0:1]
|
||||
rest = current_chord[1:]
|
||||
else:
|
||||
note = currentchord[0:2]
|
||||
rest = currentchord[2:]
|
||||
note = current_chord[0:2]
|
||||
rest = current_chord[2:]
|
||||
else:
|
||||
note = currentchord
|
||||
note = current_chord
|
||||
rest = ''
|
||||
notenumber = notes_flat.index(note) if note not in notes_sharp else notes_sharp.index(note)
|
||||
notenumber += transpose_value
|
||||
while notenumber > 11:
|
||||
notenumber -= 12
|
||||
while notenumber < 0:
|
||||
notenumber += 12
|
||||
note_number = notes_flat.index(note) if note not in notes_sharp else notes_sharp.index(note)
|
||||
note_number += transpose_value
|
||||
while note_number > 11:
|
||||
note_number -= 12
|
||||
while note_number < 0:
|
||||
note_number += 12
|
||||
if i == 0:
|
||||
current_chord = notes_sharp[notenumber] if notes_preferred[notenumber] == '#' else notes_flat[
|
||||
notenumber]
|
||||
current_chord = notes_sharp[note_number] if notes_preferred[note_number] == '#' else notes_flat[
|
||||
note_number]
|
||||
last_chord = current_chord
|
||||
else:
|
||||
current_chord = notes_flat[notenumber] if last_chord not in notes_sharp else notes_sharp[notenumber]
|
||||
current_chord = notes_flat[note_number] if last_chord not in notes_sharp else notes_sharp[note_number]
|
||||
if not (note not in notes_flat and note not in notes_sharp):
|
||||
transposed_chord += current_chord + rest
|
||||
else:
|
||||
|
@ -589,7 +589,7 @@ class SongMediaItem(MediaManagerItem):
|
||||
verse_index = VerseType.from_tag(verse_tag)
|
||||
verse_tag = VerseType.translated_tags[verse_index].upper()
|
||||
verse_def = '{tag}{label}'.format(tag=verse_tag, label=verse[0]['label'])
|
||||
force_verse = verse[1].split('[##-divide-##]\n', 2)
|
||||
force_verse = verse[1].split('[--}{--]\n', 2)
|
||||
for split_verse in force_verse:
|
||||
service_item.add_from_text(split_verse, verse_def)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user