Ejemplo n.º 1
0
 def parse_init_cond(self, init_notes: List[str]) -> Iterator[str]:
     notes = init_notes.split()
     assert len(notes) == get_config()['voice_count'], (
         'Initial SATB harmony is not {}-part'.format(
             get_config()['voice_count']))
     for note_str in notes:
         yield note_str
Ejemplo n.º 2
0
    def solve(self):
        # Split input data into initial condition and chord formula template
        init_cond, *template = self.read_source()
        # Perform small bit of validation of initial condition
        init_notes = self.template_parser.parse_init_cond(init_cond)
        # Parse formula template into chord formula models
        chord_sequence = self.template_parser.parse_template(template.copy())

        if get_config()['user_intermed']:
            solutions = self.chord_transitioner.user_transition_chords(
                chord_sequence, init_notes)
        else:
            solutions = self.chord_transitioner.transition_chords(
                chord_sequence, init_notes)

        SolutionInterface().report_final_solutions(template.copy(), solutions)
Ejemplo n.º 3
0
 def _get_checking_priority(self, cur_abs_notes: List[NotePosPair],
                            next_rel_notes: List[NotePosPair],
                            trans_context: TransitionContext) -> List:
     transition_aggregator = {}
     agg_checker_queue = []
     if get_config()['include_inv']:
         cur_base, cur_abs_notes = self._split_by_base(
             cur_abs_notes, trans_context.cur_satb_chord.chord_formula
         )
         next_base, _ = self._split_by_base(
             next_rel_notes, trans_context.next_satb_chord.chord_formula
         )
         self._agg_trans(cur_base, next_base, transition_aggregator, full=True)
     for (cur_abs_note, next_rel_note) in product(cur_abs_notes, next_rel_notes):
         self._agg_trans(cur_abs_note, next_rel_note, transition_aggregator)
     for (diff, transitions) in transition_aggregator.items():
         heapq.heappush(agg_checker_queue, (diff, transitions))
     return agg_checker_queue
Ejemplo n.º 4
0
 def validate(cls, matchings: List[Transition],
              transition_context: TransitionContext):
     # Ensure that all voices are matched
     return len(matchings) == get_config()['voice_count']
Ejemplo n.º 5
0
 def replace_ess_notes(self, old: int, new: int) -> None:
     self.base_ess = self.base_ess - {old} | {new}
     assert len(self.base_ess) <= get_config()['voice_count'], (
         'Number of essential notes exceeded when replacing note requirement from '
         'pos {} to pos {}').format(old, new)
Ejemplo n.º 6
0
 def add_ess_notes(self, target: int) -> None:
     self.base_ess |= {target}
     assert len(self.base_ess) <= get_config()['voice_count'], (
         'Number of essential notes exceeded when requiring note at pos {}'.
         format(target))