mirror of
https://gitlab.com/parroquia-san-leandro/cancionero-web.git
synced 2024-12-22 16:53:34 +01:00
fixed bug related to loop counter update
This commit is contained in:
parent
9c5602876c
commit
30dc36d262
1 changed files with 4 additions and 19 deletions
|
@ -84,15 +84,16 @@ class SongLoader:
|
||||||
text = re.sub(r"\\brk({})?", '', text)
|
text = re.sub(r"\\brk({})?", '', text)
|
||||||
|
|
||||||
extras = {}
|
extras = {}
|
||||||
for i in range(len(text)):
|
i = 0
|
||||||
|
while i <= len(text):
|
||||||
beginning = text[:i]
|
beginning = text[:i]
|
||||||
remain = text[i:]
|
remain = text[i:]
|
||||||
if re.match(r"\\fi", remain):
|
if re.match(r"\\fi", remain):
|
||||||
ignore = False
|
ignore = False
|
||||||
text = beginning + text[i + len("\\fi"):]
|
text = beginning + text[i + len("\\fi"):]
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if ignore:
|
if ignore:
|
||||||
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Command lookup
|
# Command lookup
|
||||||
|
@ -100,7 +101,6 @@ class SongLoader:
|
||||||
if re_transpose_match:
|
if re_transpose_match:
|
||||||
text = beginning + text[i + len(re_transpose_match.group(0)):]
|
text = beginning + text[i + len(re_transpose_match.group(0)):]
|
||||||
transpose = int(re_transpose_match.group(1))
|
transpose = int(re_transpose_match.group(1))
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_song_begin_match = re.match(r"\\beginsong *?{(.*?)}(\[.*?])?", remain)
|
re_song_begin_match = re.match(r"\\beginsong *?{(.*?)}(\[.*?])?", remain)
|
||||||
if re_song_begin_match:
|
if re_song_begin_match:
|
||||||
|
@ -120,14 +120,12 @@ class SongLoader:
|
||||||
replay_index = 0
|
replay_index = 0
|
||||||
for a in find_audios(self.index):
|
for a in find_audios(self.index):
|
||||||
current_song.add_audio(a)
|
current_song.add_audio(a)
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\\endsong", remain):
|
if re.match(r"\\endsong", remain):
|
||||||
text = beginning + text[i + len("\\endsong"):]
|
text = beginning + text[i + len("\\endsong"):]
|
||||||
self.songs.append(current_song)
|
self.songs.append(current_song)
|
||||||
current_song = None
|
current_song = None
|
||||||
self.index += 1
|
self.index += 1
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_verse_cmd_match = re.match(r"\\(begin|end)(verse|chorus)", remain)
|
re_verse_cmd_match = re.match(r"\\(begin|end)(verse|chorus)", remain)
|
||||||
if re_verse_cmd_match:
|
if re_verse_cmd_match:
|
||||||
|
@ -150,33 +148,27 @@ class SongLoader:
|
||||||
memorizing = False
|
memorizing = False
|
||||||
current_song.add_verse(current_verse)
|
current_song.add_verse(current_verse)
|
||||||
current_verse = None
|
current_verse = None
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_capo_match = re.match(r"\\capo{(\d+?)}", remain)
|
re_capo_match = re.match(r"\\capo{(\d+?)}", remain)
|
||||||
if re_capo_match and current_song:
|
if re_capo_match and current_song:
|
||||||
text = beginning + text[i + len(re_capo_match.group(0)):]
|
text = beginning + text[i + len(re_capo_match.group(0)):]
|
||||||
current_song.set_capo(int(re_capo_match.group(1)))
|
current_song.set_capo(int(re_capo_match.group(1)))
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\\ifchorded", remain):
|
if re.match(r"\\ifchorded", remain):
|
||||||
text = beginning + text[i + len("\\ifchorded"):]
|
text = beginning + text[i + len("\\ifchorded"):]
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\\else", remain):
|
if re.match(r"\\else", remain):
|
||||||
ignore = True
|
ignore = True
|
||||||
text = beginning + text[i + len("\\else"):]
|
text = beginning + text[i + len("\\else"):]
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_echo_match = re.match(r"\\echo[ \t]*?{((.|{.*?})*?)}", remain)
|
re_echo_match = re.match(r"\\echo[ \t]*?{((.|{.*?})*?)}", remain)
|
||||||
if re_echo_match:
|
if re_echo_match:
|
||||||
text = beginning + re_echo_match.group(1) + "\\echoend" + text[i + len(re_echo_match.group(0)):]
|
text = beginning + re_echo_match.group(1) + "\\echoend" + text[i + len(re_echo_match.group(0)):]
|
||||||
extra_put(extras, i, "echo")
|
extra_put(extras, i, "echo")
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\\echoend", remain):
|
if re.match(r"\\echoend", remain):
|
||||||
text = beginning + text[i + len("\\echoend"):]
|
text = beginning + text[i + len("\\echoend"):]
|
||||||
extra_put(extras, i, "echo")
|
extra_put(extras, i, "echo")
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_chord_match = re.match(r"\\\[(.+?)]", remain)
|
re_chord_match = re.match(r"\\\[(.+?)]", remain)
|
||||||
if re_chord_match:
|
if re_chord_match:
|
||||||
|
@ -185,51 +177,44 @@ class SongLoader:
|
||||||
extra_put(extras, i, "chord", c)
|
extra_put(extras, i, "chord", c)
|
||||||
if memorizing:
|
if memorizing:
|
||||||
memory.append(c)
|
memory.append(c)
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\^", remain):
|
if re.match(r"\^", remain):
|
||||||
text = beginning + text[i + len("^"):]
|
text = beginning + text[i + len("^"):]
|
||||||
if memory is not None and replay_index < len(memory):
|
if memory is not None and replay_index < len(memory):
|
||||||
extra_put(extras, i, "chord", memory[replay_index])
|
extra_put(extras, i, "chord", memory[replay_index])
|
||||||
replay_index += 1
|
replay_index += 1
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_dir_rep_match = re.match(r"\\([lr]rep)", remain)
|
re_dir_rep_match = re.match(r"\\([lr]rep)", remain)
|
||||||
if re_dir_rep_match:
|
if re_dir_rep_match:
|
||||||
text = beginning + text[i + len(re_dir_rep_match.group(0)):]
|
text = beginning + text[i + len(re_dir_rep_match.group(0)):]
|
||||||
extra_put(extras, i, "dir-rep", re_dir_rep_match.group(1))
|
extra_put(extras, i, "dir-rep", re_dir_rep_match.group(1))
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
re_rep_match = re.match(r"\\rep{(\d+?)}", remain)
|
re_rep_match = re.match(r"\\rep{(\d+?)}", remain)
|
||||||
if re_rep_match:
|
if re_rep_match:
|
||||||
text = beginning + text[i + len(re_rep_match.group(0)):]
|
text = beginning + text[i + len(re_rep_match.group(0)):]
|
||||||
extra_put(extras, i, 'rep', int(re_rep_match.group(1)))
|
extra_put(extras, i, 'rep', int(re_rep_match.group(1)))
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\\memorize", remain):
|
if re.match(r"\\memorize", remain):
|
||||||
text = beginning + text[i + len("\\memorize"):]
|
text = beginning + text[i + len("\\memorize"):]
|
||||||
memory = []
|
memory = []
|
||||||
memorizing = True
|
memorizing = True
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
if re.match(r"\\replay", remain):
|
if re.match(r"\\replay", remain):
|
||||||
text = beginning + text[i + len("\\replay"):]
|
text = beginning + text[i + len("\\replay"):]
|
||||||
replay_index = 0
|
replay_index = 0
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
# Command lookup end, removing any unrecognized command
|
# Command lookup end, removing any unrecognized command
|
||||||
re_macro_match = re.match(r"\\([^ \t{\[]+)[ \t]*?({.*?}|\[.*?])*", remain)
|
re_macro_match = re.match(r"\\([^ \t{\[]+)[ \t]*?({.*?}|\[.*?])*", remain)
|
||||||
if re_macro_match:
|
if re_macro_match:
|
||||||
text = beginning + text[i + len(re_macro_match.group(0)):]
|
text = beginning + text[i + len(re_macro_match.group(0)):]
|
||||||
print("Removed an unrecognized command:", re_macro_match.group(0))
|
print("Removed an unrecognized command:", re_macro_match.group(0))
|
||||||
i -= 1
|
|
||||||
continue
|
continue
|
||||||
|
i += 1
|
||||||
if not current_verse and text.strip() != '':
|
if not current_verse and text.strip() != '':
|
||||||
print("l outside v:", text)
|
print("l outside v:", text)
|
||||||
continue
|
continue
|
||||||
if ignore or text.strip() == '':
|
if ignore or text.strip() == '':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
current_verse.add_line(Line(text, extras))
|
current_verse.add_line(Line(text, extras))
|
||||||
|
|
||||||
def print_index(self, index_file="index.html"):
|
def print_index(self, index_file="index.html"):
|
||||||
|
|
Loading…
Reference in a new issue