Skip to content

Rework Object Handling #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pyamll/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Vocal(Enum):

@dataclass
class VocalElement:
word_index: int
text: str
line_index:int
is_part_of_word:bool = False
is_explicit: bool = False
start_time: float = 0
end_time: float = 0
Expand Down Expand Up @@ -47,13 +47,14 @@ def is_last_element(self, element:VocalElement|int) -> bool:
def __str__(self):
_str = ""

index = 0
part_of_word = False
for i in range(len(self.elements)):
if self.elements[i].word_index > index:
_str += " "
index = self.elements[i].word_index
_str += str(self.elements[i])
return _str
part_of_word = self.elements[i].is_part_of_word
if not part_of_word:
_str+=" "

return _str.strip()

class Lyrics(list):
element_map = []
Expand Down Expand Up @@ -105,13 +106,15 @@ def process_lyrics(lyrics_str:str) -> Lyrics:
if word.strip() == "":
continue

# if / in word like heart/beat then the first word will have the bool but not last
if '/' in word:
syllables = word.split('/')
for syllable_counter in range(len(syllables)):
line.elements.append(VocalElement(word_index=word_counter, text=syllables[syllable_counter], line_index=len(line_objects)))
line.elements.append(
VocalElement(text=syllables[syllable_counter], is_part_of_word=(syllable_counter != len(syllables)-1) ,line_index=len(line_objects)))
continue

line.elements.append(VocalElement(word_index=word_counter, text=word, line_index=len(line_objects)))
line.elements.append(VocalElement(text=word, line_index=len(line_objects)))

line_objects.append(line)
return Lyrics(line_objects)
11 changes: 3 additions & 8 deletions pyamll/parser/swlrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ def export_as_swlrc(lyrics:Lyrics) -> dict:
for line in lyrics.init_list:
line:Line = line
_lead_list = []
for i,element in enumerate(line.elements):
for element in line.elements:
element:VocalElement = element
_is_part_of_word = False
try:
if line.elements[i+1].word_index == element.word_index:
_is_part_of_word = True
except IndexError:
pass

_lead_list.append({
"Text": element.text,
"IsPartOfWord": _is_part_of_word,
"IsPartOfWord": element.is_part_of_word,
"StartTime": element.start_time,
"EndTime": element.end_time
})
Expand Down