File size: 1,376 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
"""Text management for melody practice.

This class manages the text displayed
in both the web and console versions of the melody practice.
"""

from typing import List, Optional

from improvisation_lab.domain.composition import PhraseData
from improvisation_lab.presentation.view_text_manager import ViewTextManager


class PieceViewTextManager(ViewTextManager):
    """Displayed text management for melody practice."""

    def __init__(self):
        """Initialize the text manager."""
        super().__init__()

    def update_phrase_text(
        self, current_phrase_idx: int, phrases: Optional[List[PhraseData]]
    ):
        """Update the phrase text.

        Args:
            current_phrase_idx: The index of the current phrase.
            phrases: The list of phrases.
        """
        if not phrases:
            self.phrase_text = "No phrase data"
            return self.phrase_text

        current_phrase = phrases[current_phrase_idx]
        self.phrase_text = (
            f"Phrase {current_phrase_idx + 1}: "
            f"{current_phrase.chord_name}\n"
            f"{' -> '.join(current_phrase.notes)}"
        )

        if current_phrase_idx < len(phrases) - 1:
            next_phrase = phrases[current_phrase_idx + 1]
            self.phrase_text += (
                f"\nNext: {next_phrase.chord_name} ({next_phrase.notes[0]})"
            )