File size: 1,870 Bytes
5e84ffc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Console-based piece practice view.

This module provides a console interface for visualizing
and interacting with piece practice sessions.
"""

from abc import ABC, abstractmethod
from typing import List

from improvisation_lab.domain.composition import PhraseData
from improvisation_lab.presentation.view_text_manager import ViewTextManager
from improvisation_lab.service.base_practice_service import PitchResult


class ConsolePracticeView(ABC):
    """Console-based implementation of piece practice."""

    def __init__(self, text_manager: ViewTextManager):
        """Initialize the console view with a text manager and song name.

        Args:
            text_manager: Text manager for updating and displaying text.
            song_name: Name of the song to be practiced.
        """
        self.text_manager = text_manager

    @abstractmethod
    def launch(self):
        """Run the console interface."""
        pass

    def display_phrase_info(self, phrase_number: int, phrases_data: List[PhraseData]):
        """Display phrase information in console.

        Args:
            phrase_number: Number of the phrase.
            phrases_data: List of phrase data.
        """
        self.text_manager.update_phrase_text(phrase_number, phrases_data)
        print("\n" + "-" * 50)
        print("\n" + self.text_manager.phrase_text + "\n")

    def display_pitch_result(self, pitch_result: PitchResult):
        """Display note status in console.

        Args:
            pitch_result: The result of the pitch detection.
        """
        self.text_manager.update_pitch_result(pitch_result)
        print(f"{self.text_manager.result_text:<80}", end="\r", flush=True)

    def display_practice_end(self):
        """Display practice end message in console."""
        self.text_manager.terminate_text()
        print(self.text_manager.phrase_text)