Skip to content

Commit

Permalink
add validators for overlapped notes
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMelody committed Sep 19, 2024
1 parent 4899870 commit 3fcd273
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions libresvip/model/pitch_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import portion

from libresvip.core.exceptions import NotesOverlappedError
from libresvip.core.time_interval import PiecewiseIntervalDict
from libresvip.core.time_sync import TimeSynchronizer
from libresvip.model.base import Note
from libresvip.model.portamento import PortamentoPitch
from libresvip.utils.translation import gettext_lazy as _


@dataclasses.dataclass
Expand All @@ -33,6 +35,9 @@ def __post_init__(self, note_list: list[Note]) -> None:
self.interval_dict[portion.closedopen(0.0, current_head)] = current_note.key_number
prev_portamento_end = current_head
for next_note in note_list[1:]:
if current_note.end_pos > next_note.start_pos:
msg = _("Notes Overlapped")
raise NotesOverlappedError(msg)
next_head = self.synchronizer.get_actual_secs_from_ticks(next_note.start_pos)
next_dur = self.synchronizer.get_duration_secs_from_ticks(
next_note.start_pos, next_note.end_pos
Expand Down
6 changes: 5 additions & 1 deletion libresvip/plugins/svp/layer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import more_itertools

from libresvip.core.exceptions import ParamsError
from libresvip.core.exceptions import NotesOverlappedError, ParamsError
from libresvip.utils.music_math import clamp
from libresvip.utils.search import find_index
from libresvip.utils.translation import gettext_lazy as _

from .constants import MAX_BREAK
from .lambert_w import LambertW
Expand Down Expand Up @@ -135,6 +136,9 @@ def __post_init__(self, _note_list: list[NoteStruct]) -> None:
for current_note, next_note in more_itertools.pairwise(self.note_list):
if current_note.key == next_note.key:
continue
elif current_note.end > next_note.start:
msg = _("Notes Overlapped")
raise NotesOverlappedError(msg)
if (diameter := current_note.portamento_right + next_note.portamento_left) and (
next_note.start - current_note.end <= MAX_BREAK
):
Expand Down
17 changes: 11 additions & 6 deletions libresvip/plugins/ustx/ustx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pypinyin

from libresvip.core.constants import DEFAULT_BPM
from libresvip.core.exceptions import NotesOverlappedError
from libresvip.core.lyric_phoneme.chinese import CHINESE_RE
from libresvip.core.lyric_phoneme.japanese import is_kana, to_romaji
from libresvip.model.base import (
Expand All @@ -17,6 +18,7 @@
)
from libresvip.model.point import Point
from libresvip.utils.music_math import db_to_float
from libresvip.utils.translation import gettext_lazy as _

from .model import (
UNote,
Expand Down Expand Up @@ -165,12 +167,15 @@ def parse_notes(self, notes: list[UNote], tick_prefix: int) -> list[Note]:
note.pronunciation = " ".join(pypinyin.lazy_pinyin(chinese_char.group()))
else:
note.pronunciation = ustx_note.lyric.removeprefix("?")
if (
prev_ustx_note is not None
and prev_ustx_note.lyric in self.breath_lyrics
and prev_ustx_note.end == ustx_note.position
):
note.head_tag = "V"
if prev_ustx_note is not None:
if prev_ustx_note.end > ustx_note.position:
msg = _("Notes Overlapped")
raise NotesOverlappedError(msg)
elif (
prev_ustx_note.end == ustx_note.position
and prev_ustx_note.lyric in self.breath_lyrics
):
note.head_tag = "V"
if (
ustx_note.lyric not in self.breath_lyrics
and ustx_note.lyric not in self.silence_lyrics
Expand Down

0 comments on commit 3fcd273

Please sign in to comment.