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