diff --git a/manim_slides/commons.py b/manim_slides/commons.py index 82ac09c3..5fa418cc 100644 --- a/manim_slides/commons.py +++ b/manim_slides/commons.py @@ -54,7 +54,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None: "-v", "--verbosity", type=click.Choice( - ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], + ["PERF", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], case_sensitive=False, ), help="Verbosity of CLI output", diff --git a/manim_slides/logger.py b/manim_slides/logger.py index 168f00b8..3530d5a4 100644 --- a/manim_slides/logger.py +++ b/manim_slides/logger.py @@ -5,7 +5,9 @@ import logging +from rich.console import Console from rich.logging import RichHandler +from rich.theme import Theme __all__ = ["logger", "make_logger"] @@ -33,9 +35,12 @@ def make_logger() -> logging.Logger: RichHandler.KEYWORDS = HIGHLIGHTED_KEYWORDS rich_handler = RichHandler( show_time=True, + console=Console(theme=Theme({"logging.level.perf": "magenta"})), ) + logging.addLevelName(5, "PERF") logger = logging.getLogger("manim-slides") logger.addHandler(rich_handler) + return logger diff --git a/manim_slides/present.py b/manim_slides/present.py index 2e9730be..133811f4 100644 --- a/manim_slides/present.py +++ b/manim_slides/present.py @@ -448,6 +448,21 @@ def run(self) -> None: lag = now() - last_time sleep_time = 1 / self.current_presentation.fps + + logger.log( + 5, + f"Took {lag:.3f} seconds to process the current frame, that must play at a rate of one every {sleep_time:.3f} seconds.", + ) + + if sleep_time - lag < 0: + logger.warn( + "The FPS rate could not be matched. " + "This is normal when manually transitioning between slides.\n" + "If you feel that the FPS are too low, " + "consider checking this issue:\n" + "https://github.com/jeertmans/manim-slides/issues/179." + ) + sleep_time = max(sleep_time - lag, 0) time.sleep(sleep_time) last_time = now()