Beispiel #1
0
    def rebuild_secondary_chord(self, secondary_chord, base_tonality):
        if self.secondary_shift_type == SecondaryShiftType.Standard:
            orig_principal_chord_template = secondary_chord.chord_template.principal_chord_template
            if not isinstance(orig_principal_chord_template, TertianChordTemplate):
                raise Exception('Secondary chord requires TertianChordTemplate for this operation.')
            new_scale_degree = ((orig_principal_chord_template.scale_degree - 1) + self.step_increment) % 7 + 1
            new_principal_chord_template = TertianChordTemplate(orig_principal_chord_template.diatonic_basis,
                                                                new_scale_degree,
                                                                orig_principal_chord_template.chord_type,
                                                                orig_principal_chord_template.tension_intervals,
                                                                orig_principal_chord_template.inversion,
                                                                orig_principal_chord_template.inversion_interval)

            secondary_chord_template = SecondaryChordTemplate(new_principal_chord_template,
                                                              secondary_chord.chord_template.secondary_scale_degree,
                                                              secondary_chord.chord_template.secondary_modality)
            new_secondary_chord = SecondaryChord(secondary_chord_template, base_tonality)
            return new_secondary_chord
        else:
            orig_template = secondary_chord.chord_template
            new_degree = ((orig_template.secondary_scale_degree - 1) + self.step_increment) % 7 + 1
            secondary_chord_template = SecondaryChordTemplate(orig_template.principal_chord_template,
                                                              new_degree,
                                                              orig_template.secondary_modality)
            new_secondary_chord = SecondaryChord(secondary_chord_template, base_tonality)
            return new_secondary_chord
Beispiel #2
0
    def remap_chord(self, hc):
        from tonalmodel.interval import Interval as TonalInterval
        chord = hc.chord

        if not isinstance(chord, SecondaryChord):
            f = self.__hc_flip_map[hc] if hc in self.__hc_flip_map.keys() else \
                ChromaticPitchReflectionFunction(hc.tonality, self.cue_pitch, self.domain_pitch_range)
            # FlipOnTonality(hc.tonality, self.cue_pitch, self.domain_pitch_range)
            new_chord_tones = [f.tonal_function[t[0]] for t in chord.tones]
            chords = ChordClassifier.classify_all_roots(
                new_chord_tones, f.range_tonality)
            if chords is not None and len(chords) > 0:
                return chords[0]
            else:
                raise Exception(
                    'Cannot remap/classify chord {0} based on chord.'.format(
                        ', '.join(
                            str(t.diatonic_symbol) for t in new_chord_tones)))
        else:
            if hc in self.__hc_flip_map.keys():
                secondary_function = self.__hc_flip_map[hc].tonal_function
            else:
                secondary_function = self._build_secondary_flip_function(
                    hc).tonal_function

            base_f = self._build_chromatic_reflection(hc)
            root_mapped_tonality = base_f.range_tonality
            mapped_denominator = TonalInterval.calculate_tone_interval(
                root_mapped_tonality.root_tone, secondary_function.
                range_tonality.root_tone).diatonic_distance + 1

            # Alternatively, in the else part, we could have done:
            #   secondary_function = f.tonal_function.create_adapted_function(secondary_tonality, secondary_tonality)
            # but to be consistent within the logic, we go for the reflection_tests constructiobn of
            # the secondary function
            # as embodied in tFlip._build_secondary_flip_function()

            new_chord_tones = [secondary_function[t[0]] for t in chord.tones]
            secondary_tonality = secondary_function.range_tonality
            chords = ChordClassifier.classify_all_roots(
                new_chord_tones, secondary_tonality)

            if chords is not None and len(chords) > 0:
                new_chord = chords[0]
            else:
                raise Exception(
                    'Cannot remap/classify chord {0} based on chord.'.format(
                        ', '.join(
                            str(t.diatonic_symbol) for t in new_chord_tones)))

            # mapped_numerator = TonalInterval.calculate_tone_interval(
            #    new_chord.root_tone,
            #    secondary_function.range_tonality.root_tone).diatonic_distance + 1
            secondary_chord_template = SecondaryChordTemplate(
                new_chord.chord_template, mapped_denominator,
                secondary_tonality.modality.modality_type)
            secondary_chord = SecondaryChord(secondary_chord_template,
                                             root_mapped_tonality,
                                             secondary_function.range_tonality)
            return secondary_chord
Beispiel #3
0
    def construct_secondary_chord_template(self, primary_template, secondary_numeral_str, secondary_modality):
        numeral = LineConstructor.NUMERAL_MAP[secondary_numeral_str]

        if secondary_modality is not None:
            if secondary_modality in LineConstructor.MODALITY_SHORT_NAME_MAP:
                modality = LineConstructor.MODALITY_SHORT_NAME_MAP[secondary_modality]
            elif secondary_modality[0] == '!':
                modality = ModalityType(secondary_modality[1:])
            else:
                modality = ModalityType(secondary_modality)
        else:
            modality = None

        return SecondaryChordTemplate(primary_template, numeral, modality)
Beispiel #4
0
    def remap_chord(self, hc):

        chord = hc.chord
        chord_tonality = hc.tonality

        if not isinstance(chord, SecondaryChord):
            f = self.hc_flip_map[hc] if hc in self.hc_flip_map.keys() else \
                DiatonicPitchReflectionFunction(hc.tonality, self.cue_pitch, self.domain_pitch_range)
            new_chord_tones = [f.tonal_function[t[0]] for t in chord.tones]
            chords = ChordClassifier.classify_all_roots(
                new_chord_tones, chord_tonality)
            if chords is not None and len(chords) > 0:
                return chords[0]
            else:
                raise Exception(
                    'Cannot remap/classify chord {0} based on chord.'.format(
                        ', '.join(str(t) for t in new_chord_tones)))
        else:
            secondary_tonality = chord.secondary_tonality
            if hc in self.hc_flip_map.keys():
                secondary_function = self.hc_flip_map[hc].tonal_function
            else:
                secondary_function = self._build_secondary_flip_function(
                    hc).tonal_function

            # Alternatively, in the else part, we could have done:
            #   secondary_function = f.tonal_function.create_adapted_function(secondary_tonality, secondary_tonality)
            # but to be consistent within the logic, we go for the reflection_tests constructiobn
            # of the secondary function
            # as embodied in tFlip._build_secondary_flip_function()

            new_chord_tones = [secondary_function[t[0]] for t in chord.tones]
            chords = ChordClassifier.classify_all_roots(
                new_chord_tones, secondary_tonality)

            if chords is not None and len(chords) > 0:
                new_chord = chords[0]
            else:
                raise Exception(
                    'Cannot remap/classify chord {0} based on chord.'.format(
                        ', '.join(str(t) for t in new_chord_tones)))

            secondary_chord_template = SecondaryChordTemplate(
                new_chord.chord_template,
                chord.chord_template.secondary_scale_degree,
                secondary_tonality.modality.modality_type)
            secondary_chord = SecondaryChord(secondary_chord_template,
                                             chord_tonality)
            return secondary_chord
Beispiel #5
0
    def remap_chord(self, hc, new_tonality):

        chord = hc.chord
        chord_tonality = new_tonality

        f, _ = self._build_shift_function(hc)

        if not isinstance(chord, SecondaryChord):
            new_chord_tones = [f.tonal_function[t[0]] for t in chord.tones]
            chords = ChordClassifier.classify_all_roots(
                new_chord_tones, chord_tonality)
            if chords is not None and len(chords) > 0:
                return chords[0]
            else:
                raise Exception(
                    'Cannot remap/classify chord {0} based on chord.'.format(
                        ', '.join(t.diatonic_symbol for t in new_chord_tones)))
        else:
            new_chord_tones = [f.tonal_function[t[0]] for t in chord.tones]
            chords = ChordClassifier.classify_all_roots(
                new_chord_tones, f.range_tonality)
            if chords is not None and len(chords) > 0:
                new_chord = chords[0]
            else:
                raise Exception(
                    'Cannot remap/classify chord {0} based on chord.'.format(
                        ', '.join(str(t) for t in new_chord_tones)))

            temp_range_tonality = Tonality.create(self.range_modality_type if self.range_modality_type is not None
                                                  else hc.tonality.modality_type,
                                                  self.root_shift_interval.get_end_tone(hc.tonality.diatonic_tone),
                                                  self.modal_index if self.modal_index is not None
                                                  else hc.tonality.modal_index) if self.root_shift_interval else \
                hc.tonality

            secondary_chord_template = SecondaryChordTemplate(
                new_chord.chord_template,
                chord.chord_template.secondary_scale_degree,
                chord.secondary_tonality.modality.modality_type)
            secondary_chord = SecondaryChord(secondary_chord_template,
                                             temp_range_tonality)
            return secondary_chord