Spaces:
Sleeping
Sleeping
File size: 1,934 Bytes
5e84ffc 448b42a 5e84ffc 448b42a 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 |
"""Console application for interval practice."""
from typing import List
from improvisation_lab.application.base_console_app import \
ConsoleBasePracticeApp
from improvisation_lab.config import Config
from improvisation_lab.domain.music_theory import Notes
from improvisation_lab.presentation.interval_practice import (
ConsoleIntervalPracticeView, IntervalViewTextManager)
from improvisation_lab.service import IntervalPracticeService
class ConsoleIntervalPracticeApp(ConsoleBasePracticeApp):
"""Console application class for interval practice."""
def __init__(self, service: IntervalPracticeService, config: Config):
"""Initialize the application using console UI.
Args:
service: IntervalPracticeService instance.
config: Config instance.
"""
super().__init__(service, config)
self.text_manager = IntervalViewTextManager()
self.ui = ConsoleIntervalPracticeView(self.text_manager)
def _get_current_note(self) -> str:
"""Return the current note to be processed.
Returns:
The current note to be processed.
"""
if self.phrases is None:
raise ValueError("Phrases are not initialized.")
return self.phrases[self.current_phrase_idx][self.current_note_idx].value
def _get_current_phrase(self) -> List[Notes]:
"""Return the current phrase to be processed."""
if self.phrases is None:
raise ValueError("Phrases are not initialized.")
return self.phrases[self.current_phrase_idx]
def _generate_melody(self) -> List[List[Notes]]:
"""Generate melody specific to the practice type.
Returns:
The generated melody.
"""
return self.service.generate_melody(
num_notes=self.config.interval_practice.num_problems,
interval=self.config.interval_practice.interval,
)
|